1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public License Version
5
* 1.1 (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is the Netscape security libraries.
16
* The Initial Developer of the Original Code is
17
* Netscape Communications Corporation.
18
* Portions created by the Initial Developer are Copyright (C) 1994-2000
19
* the Initial Developer. All Rights Reserved.
22
* Dr Stephen Henson <stephen.henson@gemplus.com>
23
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the MPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the MPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
38
/* $Id: keyhi.h,v 1.13.2.2 2006/06/08 05:42:36 wtchang%redhat.com Exp $ */
50
/*#include "secpkcs5.h" */
56
** Destroy a subject-public-key-info object.
58
extern void SECKEY_DestroySubjectPublicKeyInfo(CERTSubjectPublicKeyInfo *spki);
61
** Copy subject-public-key-info "src" to "dst". "dst" is filled in
62
** appropriately (memory is allocated for each of the sub objects).
64
extern SECStatus SECKEY_CopySubjectPublicKeyInfo(PRArenaPool *arena,
65
CERTSubjectPublicKeyInfo *dst,
66
CERTSubjectPublicKeyInfo *src);
69
** Update the PQG parameters for a cert's public key.
70
** Only done for DSA and Fortezza certs
73
SECKEY_UpdateCertPQG(CERTCertificate * subjectCert);
76
/* Compare the KEA parameters of two public keys.
77
* Only used by fortezza. */
80
SECKEY_KEAParamCompare(CERTCertificate *cert1,CERTCertificate *cert2);
83
** Return the strength of the public key in bytes
85
extern unsigned SECKEY_PublicKeyStrength(SECKEYPublicKey *pubk);
88
** Return the strength of the public key in bits
90
extern unsigned SECKEY_PublicKeyStrengthInBits(SECKEYPublicKey *pubk);
93
** Return the length of the signature in bytes
95
extern unsigned SECKEY_SignatureLen(const SECKEYPublicKey *pubk);
98
** Make a copy of the private key "privKey"
100
extern SECKEYPrivateKey *SECKEY_CopyPrivateKey(SECKEYPrivateKey *privKey);
103
** Make a copy of the public key "pubKey"
105
extern SECKEYPublicKey *SECKEY_CopyPublicKey(SECKEYPublicKey *pubKey);
108
** Convert a private key "privateKey" into a public key
110
extern SECKEYPublicKey *SECKEY_ConvertToPublicKey(SECKEYPrivateKey *privateKey);
113
* create a new RSA key pair. The private Key is returned...
115
SECKEYPrivateKey *SECKEY_CreateRSAPrivateKey(int keySizeInBits,
116
SECKEYPublicKey **pubk, void *cx);
119
* create a new DH key pair. The private Key is returned...
121
SECKEYPrivateKey *SECKEY_CreateDHPrivateKey(SECKEYDHParams *param,
122
SECKEYPublicKey **pubk, void *cx);
125
* create a new EC key pair. The private Key is returned...
127
SECKEYPrivateKey *SECKEY_CreateECPrivateKey(SECKEYECParams *param,
128
SECKEYPublicKey **pubk, void *cx);
131
** Create a subject-public-key-info based on a public key.
133
extern CERTSubjectPublicKeyInfo *
134
SECKEY_CreateSubjectPublicKeyInfo(SECKEYPublicKey *k);
137
** Decode a DER encoded public key into an SECKEYPublicKey structure.
139
extern SECKEYPublicKey *SECKEY_DecodeDERPublicKey(SECItem *pubkder);
142
** Convert a base64 ascii encoded DER public key to our internal format.
144
extern SECKEYPublicKey *SECKEY_ConvertAndDecodePublicKey(char *pubkstr);
147
** Convert a base64 ascii encoded DER public key and challenge to spki,
148
** and verify the signature and challenge data are correct
150
extern CERTSubjectPublicKeyInfo *
151
SECKEY_ConvertAndDecodePublicKeyAndChallenge(char *pkacstr, char *challenge,
155
** Encode a CERTSubjectPublicKeyInfo structure. into a
156
** DER encoded subject public key info.
159
SECKEY_EncodeDERSubjectPublicKeyInfo(SECKEYPublicKey *pubk);
162
** Decode a DER encoded subject public key info into a
163
** CERTSubjectPublicKeyInfo structure.
165
extern CERTSubjectPublicKeyInfo *
166
SECKEY_DecodeDERSubjectPublicKeyInfo(SECItem *spkider);
169
** Convert a base64 ascii encoded DER subject public key info to our
172
extern CERTSubjectPublicKeyInfo *
173
SECKEY_ConvertAndDecodeSubjectPublicKeyInfo(char *spkistr);
176
* extract the public key from a subject Public Key info structure.
179
extern SECKEYPublicKey *
180
SECKEY_ExtractPublicKey(CERTSubjectPublicKeyInfo *);
183
** Destroy a private key object.
186
extern void SECKEY_DestroyPrivateKey(SECKEYPrivateKey *key);
190
** Destroy a public key object.
193
extern void SECKEY_DestroyPublicKey(SECKEYPublicKey *key);
195
/* Destroy and zero out a private key info structure. for now this
196
* function zero's out memory allocated in an arena for the key
197
* since PORT_FreeArena does not currently do this.
199
* NOTE -- If a private key info is allocated in an arena, one should
200
* not call this function with freeit = PR_FALSE. The function should
204
SECKEY_DestroyPrivateKeyInfo(SECKEYPrivateKeyInfo *pvk, PRBool freeit);
206
/* Destroy and zero out an encrypted private key info.
208
* NOTE -- If a encrypted private key info is allocated in an arena, one should
209
* not call this function with freeit = PR_FALSE. The function should
213
SECKEY_DestroyEncryptedPrivateKeyInfo(SECKEYEncryptedPrivateKeyInfo *epki,
216
/* Copy private key info structure.
217
* poolp is the arena into which the contents of from is to be copied.
218
* NULL is a valid entry.
219
* to is the destination private key info
220
* from is the source private key info
221
* if either from or to is NULL or an error occurs, SECFailure is
222
* returned. otherwise, SECSuccess is returned.
225
SECKEY_CopyPrivateKeyInfo(PRArenaPool *poolp,
226
SECKEYPrivateKeyInfo *to,
227
SECKEYPrivateKeyInfo *from);
230
SECKEY_CacheStaticFlags(SECKEYPrivateKey* key);
232
/* Copy encrypted private key info structure.
233
* poolp is the arena into which the contents of from is to be copied.
234
* NULL is a valid entry.
235
* to is the destination encrypted private key info
236
* from is the source encrypted private key info
237
* if either from or to is NULL or an error occurs, SECFailure is
238
* returned. otherwise, SECSuccess is returned.
241
SECKEY_CopyEncryptedPrivateKeyInfo(PRArenaPool *poolp,
242
SECKEYEncryptedPrivateKeyInfo *to,
243
SECKEYEncryptedPrivateKeyInfo *from);
245
* Accessor functions for key type of public and private keys.
247
KeyType SECKEY_GetPrivateKeyType(SECKEYPrivateKey *privKey);
248
KeyType SECKEY_GetPublicKeyType(SECKEYPublicKey *pubKey);
251
* Creates a PublicKey from its DER encoding.
252
* Currently only supports RSA and DSA keys.
255
SECKEY_ImportDERPublicKey(SECItem *derKey, CK_KEY_TYPE type);
257
SECKEYPrivateKeyList*
258
SECKEY_NewPrivateKeyList(void);
261
SECKEY_DestroyPrivateKeyList(SECKEYPrivateKeyList *keys);
264
SECKEY_RemovePrivateKeyListNode(SECKEYPrivateKeyListNode *node);
267
SECKEY_AddPrivateKeyToListTail( SECKEYPrivateKeyList *list,
268
SECKEYPrivateKey *key);
270
#define PRIVKEY_LIST_HEAD(l) ((SECKEYPrivateKeyListNode*)PR_LIST_HEAD(&l->list))
271
#define PRIVKEY_LIST_NEXT(n) ((SECKEYPrivateKeyListNode *)n->links.next)
272
#define PRIVKEY_LIST_END(n,l) (((void *)n) == ((void *)&l->list))
275
SECKEY_NewPublicKeyList(void);
278
SECKEY_DestroyPublicKeyList(SECKEYPublicKeyList *keys);
281
SECKEY_RemovePublicKeyListNode(SECKEYPublicKeyListNode *node);
284
SECKEY_AddPublicKeyToListTail( SECKEYPublicKeyList *list,
285
SECKEYPublicKey *key);
287
#define PUBKEY_LIST_HEAD(l) ((SECKEYPublicKeyListNode*)PR_LIST_HEAD(&l->list))
288
#define PUBKEY_LIST_NEXT(n) ((SECKEYPublicKeyListNode *)n->links.next)
289
#define PUBKEY_LIST_END(n,l) (((void *)n) == ((void *)&l->list))
292
* Length in bits of the EC's field size. This is also the length of
293
* the x and y coordinates of EC points, such as EC public keys and
296
* Return 0 on failure (unknown EC domain parameters).
298
extern int SECKEY_ECParamsToKeySize(const SECItem *params);
301
* Length in bits of the EC base point order, usually denoted n. This
302
* is also the length of EC private keys and ECDSA signature components
305
* Return 0 on failure (unknown EC domain parameters).
307
extern int SECKEY_ECParamsToBasePointOrderLen(const SECItem *params);
311
#endif /* _KEYHI_H_ */