OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 #ifndef _KEYHI_H_ | 5 #ifndef _KEYHI_H_ |
6 #define _KEYHI_H_ | 6 #define _KEYHI_H_ |
7 | 7 |
8 #include "plarena.h" | 8 #include "plarena.h" |
9 | 9 |
10 #include "seccomon.h" | 10 #include "seccomon.h" |
11 #include "secoidt.h" | 11 #include "secoidt.h" |
12 #include "secdert.h" | 12 #include "secdert.h" |
13 #include "keythi.h" | 13 #include "keythi.h" |
14 #include "certt.h" | 14 #include "certt.h" |
15 /*#include "secpkcs5.h" */ | 15 /*#include "secpkcs5.h" */ |
16 | 16 |
17 SEC_BEGIN_PROTOS | 17 SEC_BEGIN_PROTOS |
18 | 18 |
19 | |
20 /* | 19 /* |
21 ** Destroy a subject-public-key-info object. | 20 ** Destroy a subject-public-key-info object. |
22 */ | 21 */ |
23 extern void SECKEY_DestroySubjectPublicKeyInfo(CERTSubjectPublicKeyInfo *spki); | 22 extern void SECKEY_DestroySubjectPublicKeyInfo(CERTSubjectPublicKeyInfo *spki); |
24 | 23 |
25 /* | 24 /* |
26 ** Copy subject-public-key-info "src" to "dst". "dst" is filled in | 25 ** Copy subject-public-key-info "src" to "dst". "dst" is filled in |
27 ** appropriately (memory is allocated for each of the sub objects). | 26 ** appropriately (memory is allocated for each of the sub objects). |
28 */ | 27 */ |
29 extern SECStatus SECKEY_CopySubjectPublicKeyInfo(PLArenaPool *arena, | 28 extern SECStatus SECKEY_CopySubjectPublicKeyInfo(PLArenaPool *arena, |
30 » » » » » CERTSubjectPublicKeyInfo *dst, | 29 CERTSubjectPublicKeyInfo *dst, |
31 » » » » » CERTSubjectPublicKeyInfo *src); | 30 CERTSubjectPublicKeyInfo *src); |
32 | 31 |
33 /* | 32 /* |
34 ** Update the PQG parameters for a cert's public key. | 33 ** Update the PQG parameters for a cert's public key. |
35 ** Only done for DSA certs | 34 ** Only done for DSA certs |
36 */ | 35 */ |
37 extern SECStatus | 36 extern SECStatus |
38 SECKEY_UpdateCertPQG(CERTCertificate * subjectCert); | 37 SECKEY_UpdateCertPQG(CERTCertificate *subjectCert); |
39 | 38 |
40 /* | 39 /* |
41 ** Return the number of bits in the provided big integer. This assumes that the | 40 ** Return the number of bits in the provided big integer. This assumes that the |
42 ** SECItem contains a big-endian number and counts from the first non-zero bit. | 41 ** SECItem contains a big-endian number and counts from the first non-zero bit. |
43 */ | 42 */ |
44 extern unsigned SECKEY_BigIntegerBitLength(const SECItem *number); | 43 extern unsigned SECKEY_BigIntegerBitLength(const SECItem *number); |
45 | 44 |
46 /* | 45 /* |
47 ** Return the strength of the public key in bytes | 46 ** Return the strength of the public key in bytes |
48 */ | 47 */ |
(...skipping 21 matching lines...) Expand all Loading... |
70 | 69 |
71 /* | 70 /* |
72 ** Convert a private key "privateKey" into a public key | 71 ** Convert a private key "privateKey" into a public key |
73 */ | 72 */ |
74 extern SECKEYPublicKey *SECKEY_ConvertToPublicKey(SECKEYPrivateKey *privateKey); | 73 extern SECKEYPublicKey *SECKEY_ConvertToPublicKey(SECKEYPrivateKey *privateKey); |
75 | 74 |
76 /* | 75 /* |
77 * create a new RSA key pair. The private Key is returned... | 76 * create a new RSA key pair. The private Key is returned... |
78 */ | 77 */ |
79 SECKEYPrivateKey *SECKEY_CreateRSAPrivateKey(int keySizeInBits, | 78 SECKEYPrivateKey *SECKEY_CreateRSAPrivateKey(int keySizeInBits, |
80 » » » » » SECKEYPublicKey **pubk, void *cx); | 79 SECKEYPublicKey **pubk, void *cx); |
81 » | 80 |
82 /* | 81 /* |
83 * create a new DH key pair. The private Key is returned... | 82 * create a new DH key pair. The private Key is returned... |
84 */ | 83 */ |
85 SECKEYPrivateKey *SECKEY_CreateDHPrivateKey(SECKEYDHParams *param, | 84 SECKEYPrivateKey *SECKEY_CreateDHPrivateKey(SECKEYDHParams *param, |
86 » » » » » SECKEYPublicKey **pubk, void *cx); | 85 SECKEYPublicKey **pubk, void *cx); |
87 | 86 |
88 /* | 87 /* |
89 * create a new EC key pair. The private Key is returned... | 88 * create a new EC key pair. The private Key is returned... |
90 */ | 89 */ |
91 SECKEYPrivateKey *SECKEY_CreateECPrivateKey(SECKEYECParams *param, | 90 SECKEYPrivateKey *SECKEY_CreateECPrivateKey(SECKEYECParams *param, |
92 SECKEYPublicKey **pubk, void *cx); | 91 SECKEYPublicKey **pubk, void *cx); |
93 | 92 |
94 /* | 93 /* |
95 ** Create a subject-public-key-info based on a public key. | 94 ** Create a subject-public-key-info based on a public key. |
96 */ | 95 */ |
97 extern CERTSubjectPublicKeyInfo * | 96 extern CERTSubjectPublicKeyInfo * |
98 SECKEY_CreateSubjectPublicKeyInfo(const SECKEYPublicKey *k); | 97 SECKEY_CreateSubjectPublicKeyInfo(const SECKEYPublicKey *k); |
99 | 98 |
100 /* | 99 /* |
101 ** Convert a base64 ascii encoded DER public key and challenge to spki, | 100 ** Convert a base64 ascii encoded DER public key and challenge to spki, |
102 ** and verify the signature and challenge data are correct | 101 ** and verify the signature and challenge data are correct |
103 */ | 102 */ |
104 extern CERTSubjectPublicKeyInfo * | 103 extern CERTSubjectPublicKeyInfo * |
105 SECKEY_ConvertAndDecodePublicKeyAndChallenge(char *pkacstr, char *challenge, | 104 SECKEY_ConvertAndDecodePublicKeyAndChallenge(char *pkacstr, char *challenge, |
106 » » » » » » » » void *cx); | 105 void *cx); |
107 | 106 |
108 /* | 107 /* |
109 ** Encode a CERTSubjectPublicKeyInfo structure. into a | 108 ** Encode a CERTSubjectPublicKeyInfo structure. into a |
110 ** DER encoded subject public key info. | 109 ** DER encoded subject public key info. |
111 */ | 110 */ |
112 SECItem * | 111 SECItem * |
113 SECKEY_EncodeDERSubjectPublicKeyInfo(const SECKEYPublicKey *pubk); | 112 SECKEY_EncodeDERSubjectPublicKeyInfo(const SECKEYPublicKey *pubk); |
114 | 113 |
115 /* | 114 /* |
116 ** Decode a DER encoded subject public key info into a | 115 ** Decode a DER encoded subject public key info into a |
117 ** CERTSubjectPublicKeyInfo structure. | 116 ** CERTSubjectPublicKeyInfo structure. |
118 */ | 117 */ |
119 extern CERTSubjectPublicKeyInfo * | 118 extern CERTSubjectPublicKeyInfo * |
120 SECKEY_DecodeDERSubjectPublicKeyInfo(const SECItem *spkider); | 119 SECKEY_DecodeDERSubjectPublicKeyInfo(const SECItem *spkider); |
(...skipping 11 matching lines...) Expand all Loading... |
132 */ | 131 */ |
133 extern SECKEYPublicKey * | 132 extern SECKEYPublicKey * |
134 SECKEY_ExtractPublicKey(const CERTSubjectPublicKeyInfo *); | 133 SECKEY_ExtractPublicKey(const CERTSubjectPublicKeyInfo *); |
135 | 134 |
136 /* | 135 /* |
137 ** Destroy a private key object. | 136 ** Destroy a private key object. |
138 ** "key" the object | 137 ** "key" the object |
139 */ | 138 */ |
140 extern void SECKEY_DestroyPrivateKey(SECKEYPrivateKey *key); | 139 extern void SECKEY_DestroyPrivateKey(SECKEYPrivateKey *key); |
141 | 140 |
142 | |
143 /* | 141 /* |
144 ** Destroy a public key object. | 142 ** Destroy a public key object. |
145 ** "key" the object | 143 ** "key" the object |
146 */ | 144 */ |
147 extern void SECKEY_DestroyPublicKey(SECKEYPublicKey *key); | 145 extern void SECKEY_DestroyPublicKey(SECKEYPublicKey *key); |
148 | 146 |
149 /* Destroy and zero out a private key info structure. for now this | 147 /* Destroy and zero out a private key info structure. for now this |
150 * function zero's out memory allocated in an arena for the key | 148 * function zero's out memory allocated in an arena for the key |
151 * since PORT_FreeArena does not currently do this. | 149 * since PORT_FreeArena does not currently do this. |
152 * | 150 * |
153 * NOTE -- If a private key info is allocated in an arena, one should | 151 * NOTE -- If a private key info is allocated in an arena, one should |
154 * not call this function with freeit = PR_FALSE. The function should | 152 * not call this function with freeit = PR_FALSE. The function should |
155 * destroy the arena. | 153 * destroy the arena. |
156 */ | 154 */ |
157 extern void | 155 extern void |
158 SECKEY_DestroyPrivateKeyInfo(SECKEYPrivateKeyInfo *pvk, PRBool freeit); | 156 SECKEY_DestroyPrivateKeyInfo(SECKEYPrivateKeyInfo *pvk, PRBool freeit); |
159 | 157 |
160 /* Destroy and zero out an encrypted private key info. | 158 /* Destroy and zero out an encrypted private key info. |
161 * | 159 * |
162 * NOTE -- If a encrypted private key info is allocated in an arena, one should | 160 * NOTE -- If a encrypted private key info is allocated in an arena, one should |
163 * not call this function with freeit = PR_FALSE. The function should | 161 * not call this function with freeit = PR_FALSE. The function should |
164 * destroy the arena. | 162 * destroy the arena. |
165 */ | 163 */ |
166 extern void | 164 extern void |
167 SECKEY_DestroyEncryptedPrivateKeyInfo(SECKEYEncryptedPrivateKeyInfo *epki, | 165 SECKEY_DestroyEncryptedPrivateKeyInfo(SECKEYEncryptedPrivateKeyInfo *epki, |
168 » » » » PRBool freeit); | 166 PRBool freeit); |
169 | 167 |
170 /* Copy private key info structure. | 168 /* Copy private key info structure. |
171 * poolp is the arena into which the contents of from is to be copied. | 169 * poolp is the arena into which the contents of from is to be copied. |
172 * NULL is a valid entry. | 170 * NULL is a valid entry. |
173 * to is the destination private key info | 171 * to is the destination private key info |
174 * from is the source private key info | 172 * from is the source private key info |
175 * if either from or to is NULL or an error occurs, SECFailure is | 173 * if either from or to is NULL or an error occurs, SECFailure is |
176 * returned. otherwise, SECSuccess is returned. | 174 * returned. otherwise, SECSuccess is returned. |
177 */ | 175 */ |
178 extern SECStatus | 176 extern SECStatus |
179 SECKEY_CopyPrivateKeyInfo(PLArenaPool *poolp, | 177 SECKEY_CopyPrivateKeyInfo(PLArenaPool *poolp, |
180 » » » SECKEYPrivateKeyInfo *to, | 178 SECKEYPrivateKeyInfo *to, |
181 » » » const SECKEYPrivateKeyInfo *from); | 179 const SECKEYPrivateKeyInfo *from); |
182 | 180 |
183 extern SECStatus | 181 extern SECStatus |
184 SECKEY_CacheStaticFlags(SECKEYPrivateKey* key); | 182 SECKEY_CacheStaticFlags(SECKEYPrivateKey *key); |
185 | 183 |
186 /* Copy encrypted private key info structure. | 184 /* Copy encrypted private key info structure. |
187 * poolp is the arena into which the contents of from is to be copied. | 185 * poolp is the arena into which the contents of from is to be copied. |
188 * NULL is a valid entry. | 186 * NULL is a valid entry. |
189 * to is the destination encrypted private key info | 187 * to is the destination encrypted private key info |
190 * from is the source encrypted private key info | 188 * from is the source encrypted private key info |
191 * if either from or to is NULL or an error occurs, SECFailure is | 189 * if either from or to is NULL or an error occurs, SECFailure is |
192 * returned. otherwise, SECSuccess is returned. | 190 * returned. otherwise, SECSuccess is returned. |
193 */ | 191 */ |
194 extern SECStatus | 192 extern SECStatus |
195 SECKEY_CopyEncryptedPrivateKeyInfo(PLArenaPool *poolp, | 193 SECKEY_CopyEncryptedPrivateKeyInfo(PLArenaPool *poolp, |
196 » » » » SECKEYEncryptedPrivateKeyInfo *to, | 194 SECKEYEncryptedPrivateKeyInfo *to, |
197 » » » » const SECKEYEncryptedPrivateKeyInfo *from); | 195 const SECKEYEncryptedPrivateKeyInfo *from); |
198 /* | 196 /* |
199 * Accessor functions for key type of public and private keys. | 197 * Accessor functions for key type of public and private keys. |
200 */ | 198 */ |
201 KeyType SECKEY_GetPrivateKeyType(const SECKEYPrivateKey *privKey); | 199 KeyType SECKEY_GetPrivateKeyType(const SECKEYPrivateKey *privKey); |
202 KeyType SECKEY_GetPublicKeyType(const SECKEYPublicKey *pubKey); | 200 KeyType SECKEY_GetPublicKeyType(const SECKEYPublicKey *pubKey); |
203 | 201 |
204 /* | 202 /* |
205 * Creates a PublicKey from its DER encoding. | 203 * Creates a PublicKey from its DER encoding. |
206 * Currently only supports RSA, DSA, and DH keys. | 204 * Currently only supports RSA, DSA, and DH keys. |
207 */ | 205 */ |
208 SECKEYPublicKey* | 206 SECKEYPublicKey * |
209 SECKEY_ImportDERPublicKey(const SECItem *derKey, CK_KEY_TYPE type); | 207 SECKEY_ImportDERPublicKey(const SECItem *derKey, CK_KEY_TYPE type); |
210 | 208 |
211 SECKEYPrivateKeyList* | 209 SECKEYPrivateKeyList * |
212 SECKEY_NewPrivateKeyList(void); | 210 SECKEY_NewPrivateKeyList(void); |
213 | 211 |
214 void | 212 void |
215 SECKEY_DestroyPrivateKeyList(SECKEYPrivateKeyList *keys); | 213 SECKEY_DestroyPrivateKeyList(SECKEYPrivateKeyList *keys); |
216 | 214 |
217 void | 215 void |
218 SECKEY_RemovePrivateKeyListNode(SECKEYPrivateKeyListNode *node); | 216 SECKEY_RemovePrivateKeyListNode(SECKEYPrivateKeyListNode *node); |
219 | 217 |
220 SECStatus | 218 SECStatus |
221 SECKEY_AddPrivateKeyToListTail( SECKEYPrivateKeyList *list, | 219 SECKEY_AddPrivateKeyToListTail(SECKEYPrivateKeyList *list, |
222 SECKEYPrivateKey *key); | 220 SECKEYPrivateKey *key); |
223 | 221 |
224 #define PRIVKEY_LIST_HEAD(l) ((SECKEYPrivateKeyListNode*)PR_LIST_HEAD(&l->list)) | 222 #define PRIVKEY_LIST_HEAD(l) ((SECKEYPrivateKeyListNode *)PR_LIST_HEAD(&l->list)
) |
225 #define PRIVKEY_LIST_NEXT(n) ((SECKEYPrivateKeyListNode *)n->links.next) | 223 #define PRIVKEY_LIST_NEXT(n) ((SECKEYPrivateKeyListNode *)n->links.next) |
226 #define PRIVKEY_LIST_END(n,l) (((void *)n) == ((void *)&l->list)) | 224 #define PRIVKEY_LIST_END(n, l) (((void *)n) == ((void *)&l->list)) |
227 | 225 |
228 SECKEYPublicKeyList* | 226 SECKEYPublicKeyList * |
229 SECKEY_NewPublicKeyList(void); | 227 SECKEY_NewPublicKeyList(void); |
230 | 228 |
231 void | 229 void |
232 SECKEY_DestroyPublicKeyList(SECKEYPublicKeyList *keys); | 230 SECKEY_DestroyPublicKeyList(SECKEYPublicKeyList *keys); |
233 | 231 |
234 void | 232 void |
235 SECKEY_RemovePublicKeyListNode(SECKEYPublicKeyListNode *node); | 233 SECKEY_RemovePublicKeyListNode(SECKEYPublicKeyListNode *node); |
236 | 234 |
237 SECStatus | 235 SECStatus |
238 SECKEY_AddPublicKeyToListTail( SECKEYPublicKeyList *list, | 236 SECKEY_AddPublicKeyToListTail(SECKEYPublicKeyList *list, |
239 SECKEYPublicKey *key); | 237 SECKEYPublicKey *key); |
240 | 238 |
241 #define PUBKEY_LIST_HEAD(l) ((SECKEYPublicKeyListNode*)PR_LIST_HEAD(&l->list)) | 239 #define PUBKEY_LIST_HEAD(l) ((SECKEYPublicKeyListNode *)PR_LIST_HEAD(&l->list)) |
242 #define PUBKEY_LIST_NEXT(n) ((SECKEYPublicKeyListNode *)n->links.next) | 240 #define PUBKEY_LIST_NEXT(n) ((SECKEYPublicKeyListNode *)n->links.next) |
243 #define PUBKEY_LIST_END(n,l) (((void *)n) == ((void *)&l->list)) | 241 #define PUBKEY_LIST_END(n, l) (((void *)n) == ((void *)&l->list)) |
244 | 242 |
245 /* | 243 /* |
246 * Length in bits of the EC's field size. This is also the length of | 244 * Length in bits of the EC's field size. This is also the length of |
247 * the x and y coordinates of EC points, such as EC public keys and | 245 * the x and y coordinates of EC points, such as EC public keys and |
248 * base points. | 246 * base points. |
249 * | 247 * |
250 * Return 0 on failure (unknown EC domain parameters). | 248 * Return 0 on failure (unknown EC domain parameters). |
251 */ | 249 */ |
252 extern int SECKEY_ECParamsToKeySize(const SECItem *params); | 250 extern int SECKEY_ECParamsToKeySize(const SECItem *params); |
253 | 251 |
254 /* | 252 /* |
255 * Length in bits of the EC base point order, usually denoted n. This | 253 * Length in bits of the EC base point order, usually denoted n. This |
256 * is also the length of EC private keys and ECDSA signature components | 254 * is also the length of EC private keys and ECDSA signature components |
257 * r and s. | 255 * r and s. |
258 * | 256 * |
259 * Return 0 on failure (unknown EC domain parameters). | 257 * Return 0 on failure (unknown EC domain parameters). |
260 */ | 258 */ |
261 extern int SECKEY_ECParamsToBasePointOrderLen(const SECItem *params); | 259 extern int SECKEY_ECParamsToBasePointOrderLen(const SECItem *params); |
262 | 260 |
263 /* | 261 /* |
264 * Returns the object identifier of the curve, of the provided | 262 * Returns the object identifier of the curve, of the provided |
265 * elliptic curve parameters structures. | 263 * elliptic curve parameters structures. |
266 * | 264 * |
267 * Return 0 on failure (unknown EC domain parameters). | 265 * Return 0 on failure (unknown EC domain parameters). |
268 */ | 266 */ |
269 SECOidTag SECKEY_GetECCOid(const SECKEYECParams * params); | 267 SECOidTag SECKEY_GetECCOid(const SECKEYECParams *params); |
270 | 268 |
271 SEC_END_PROTOS | 269 SEC_END_PROTOS |
272 | 270 |
273 #endif /* _KEYHI_H_ */ | 271 #endif /* _KEYHI_H_ */ |
OLD | NEW |