summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/n_pkey.c
diff options
context:
space:
mode:
authortedu <>2014-04-18 00:10:08 +0000
committertedu <>2014-04-18 00:10:08 +0000
commit07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d (patch)
tree6327d50d69a1982f840dc68fe928ea459e2c41e0 /src/lib/libcrypto/asn1/n_pkey.c
parent288a9e368d9d4a72792b12a00ad69e3592d94073 (diff)
downloadopenbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.tar.gz
openbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.tar.bz2
openbsd-07f5c09b19f56c323fa22ebd5efb5a4df9f5dc4d.zip
putting most of the braces in the right column is the very least we can do.
Diffstat (limited to 'src/lib/libcrypto/asn1/n_pkey.c')
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
index 97647d17e1..a59640582e 100644
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ b/src/lib/libcrypto/asn1/n_pkey.c
@@ -70,21 +70,21 @@
70#ifndef OPENSSL_NO_RC4 70#ifndef OPENSSL_NO_RC4
71 71
72typedef struct netscape_pkey_st 72typedef struct netscape_pkey_st
73 { 73{
74 long version; 74 long version;
75 X509_ALGOR *algor; 75 X509_ALGOR *algor;
76 ASN1_OCTET_STRING *private_key; 76 ASN1_OCTET_STRING *private_key;
77 } NETSCAPE_PKEY; 77} NETSCAPE_PKEY;
78 78
79typedef struct netscape_encrypted_pkey_st 79typedef struct netscape_encrypted_pkey_st
80 { 80{
81 ASN1_OCTET_STRING *os; 81 ASN1_OCTET_STRING *os;
82 /* This is the same structure as DigestInfo so use it: 82 /* This is the same structure as DigestInfo so use it:
83 * although this isn't really anything to do with 83 * although this isn't really anything to do with
84 * digests. 84 * digests.
85 */ 85 */
86 X509_SIG *enckey; 86 X509_SIG *enckey;
87 } NETSCAPE_ENCRYPTED_PKEY; 87} NETSCAPE_ENCRYPTED_PKEY;
88 88
89 89
90ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = { 90ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = {
@@ -121,7 +121,7 @@ int i2d_Netscape_RSA(const RSA *a, unsigned char **pp,
121int i2d_RSA_NET(const RSA *a, unsigned char **pp, 121int i2d_RSA_NET(const RSA *a, unsigned char **pp,
122 int (*cb)(char *buf, int len, const char *prompt, int verify), 122 int (*cb)(char *buf, int len, const char *prompt, int verify),
123 int sgckey) 123 int sgckey)
124 { 124{
125 int i, j, ret = 0; 125 int i, j, ret = 0;
126 int rsalen, pkeylen, olen; 126 int rsalen, pkeylen, olen;
127 NETSCAPE_PKEY *pkey = NULL; 127 NETSCAPE_PKEY *pkey = NULL;
@@ -160,36 +160,36 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp,
160 enckey->enckey->algor->parameter->type=V_ASN1_NULL; 160 enckey->enckey->algor->parameter->type=V_ASN1_NULL;
161 161
162 if (pp == NULL) 162 if (pp == NULL)
163 { 163 {
164 olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL); 164 olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL);
165 NETSCAPE_PKEY_free(pkey); 165 NETSCAPE_PKEY_free(pkey);
166 NETSCAPE_ENCRYPTED_PKEY_free(enckey); 166 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
167 return olen; 167 return olen;
168 } 168 }
169 169
170 170
171 /* Since its RC4 encrypted length is actual length */ 171 /* Since its RC4 encrypted length is actual length */
172 if ((zz=(unsigned char *)malloc(rsalen)) == NULL) 172 if ((zz=(unsigned char *)malloc(rsalen)) == NULL)
173 { 173 {
174 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); 174 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
175 goto err; 175 goto err;
176 } 176 }
177 177
178 pkey->private_key->data = zz; 178 pkey->private_key->data = zz;
179 /* Write out private key encoding */ 179 /* Write out private key encoding */
180 i2d_RSAPrivateKey(a,&zz); 180 i2d_RSAPrivateKey(a,&zz);
181 181
182 if ((zz=malloc(pkeylen)) == NULL) 182 if ((zz=malloc(pkeylen)) == NULL)
183 { 183 {
184 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); 184 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
185 goto err; 185 goto err;
186 } 186 }
187 187
188 if (!ASN1_STRING_set(enckey->os, "private-key", -1)) 188 if (!ASN1_STRING_set(enckey->os, "private-key", -1))
189 { 189 {
190 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); 190 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
191 goto err; 191 goto err;
192 } 192 }
193 enckey->enckey->digest->data = zz; 193 enckey->enckey->digest->data = zz;
194 i2d_NETSCAPE_PKEY(pkey,&zz); 194 i2d_NETSCAPE_PKEY(pkey,&zz);
195 195
@@ -200,10 +200,10 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp,
200 cb=EVP_read_pw_string; 200 cb=EVP_read_pw_string;
201 i=cb((char *)buf,256,"Enter Private Key password:",1); 201 i=cb((char *)buf,256,"Enter Private Key password:",1);
202 if (i != 0) 202 if (i != 0)
203 { 203 {
204 ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ); 204 ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ);
205 goto err; 205 goto err;
206 } 206 }
207 i = strlen((char *)buf); 207 i = strlen((char *)buf);
208 /* If the key is used for SGC the algorithm is modified a little. */ 208 /* If the key is used for SGC the algorithm is modified a little. */
209 if(sgckey) { 209 if(sgckey) {
@@ -211,7 +211,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp,
211 goto err; 211 goto err;
212 memcpy(buf + 16, "SGCKEYSALT", 10); 212 memcpy(buf + 16, "SGCKEYSALT", 10);
213 i = 26; 213 i = 26;
214 } 214}
215 215
216 if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) 216 if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL))
217 goto err; 217 goto err;
@@ -232,7 +232,7 @@ err:
232 NETSCAPE_ENCRYPTED_PKEY_free(enckey); 232 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
233 NETSCAPE_PKEY_free(pkey); 233 NETSCAPE_PKEY_free(pkey);
234 return(ret); 234 return(ret);
235 } 235}
236 236
237 237
238RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, 238RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length,
@@ -245,7 +245,7 @@ RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length,
245RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, 245RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,
246 int (*cb)(char *buf, int len, const char *prompt, int verify), 246 int (*cb)(char *buf, int len, const char *prompt, int verify),
247 int sgckey) 247 int sgckey)
248 { 248{
249 RSA *ret=NULL; 249 RSA *ret=NULL;
250 const unsigned char *p; 250 const unsigned char *p;
251 NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; 251 NETSCAPE_ENCRYPTED_PKEY *enckey = NULL;
@@ -256,20 +256,20 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,
256 if(!enckey) { 256 if(!enckey) {
257 ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_DECODING_ERROR); 257 ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_DECODING_ERROR);
258 return NULL; 258 return NULL;
259 } 259}
260 260
261 if ((enckey->os->length != 11) || (strncmp("private-key", 261 if ((enckey->os->length != 11) || (strncmp("private-key",
262 (char *)enckey->os->data,11) != 0)) 262 (char *)enckey->os->data,11) != 0))
263 { 263 {
264 ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING); 264 ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
265 NETSCAPE_ENCRYPTED_PKEY_free(enckey); 265 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
266 return NULL; 266 return NULL;
267 } 267 }
268 if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) 268 if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4)
269 { 269 {
270 ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); 270 ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
271 goto err; 271 goto err;
272 } 272}
273 if (cb == NULL) 273 if (cb == NULL)
274 cb=EVP_read_pw_string; 274 cb=EVP_read_pw_string;
275 if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err; 275 if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err;
@@ -280,12 +280,12 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,
280 NETSCAPE_ENCRYPTED_PKEY_free(enckey); 280 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
281 return ret; 281 return ret;
282 282
283 } 283}
284 284
285static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, 285static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
286 int (*cb)(char *buf, int len, const char *prompt, 286 int (*cb)(char *buf, int len, const char *prompt,
287 int verify), int sgckey) 287 int verify), int sgckey)
288 { 288{
289 NETSCAPE_PKEY *pkey=NULL; 289 NETSCAPE_PKEY *pkey=NULL;
290 RSA *ret=NULL; 290 RSA *ret=NULL;
291 int i,j; 291 int i,j;
@@ -297,10 +297,10 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
297 297
298 i=cb((char *)buf,256,"Enter Private Key password:",0); 298 i=cb((char *)buf,256,"Enter Private Key password:",0);
299 if (i != 0) 299 if (i != 0)
300 { 300 {
301 ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ); 301 ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ);
302 goto err; 302 goto err;
303 } 303 }
304 304
305 i = strlen((char *)buf); 305 i = strlen((char *)buf);
306 if(sgckey){ 306 if(sgckey){
@@ -308,7 +308,7 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
308 goto err; 308 goto err;
309 memcpy(buf + 16, "SGCKEYSALT", 10); 309 memcpy(buf + 16, "SGCKEYSALT", 10);
310 i = 26; 310 i = 26;
311 } 311}
312 312
313 if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) 313 if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL))
314 goto err; 314 goto err;
@@ -325,22 +325,22 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
325 zz=os->data; 325 zz=os->data;
326 326
327 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) 327 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
328 { 328 {
329 ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); 329 ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
330 goto err; 330 goto err;
331 } 331 }
332 332
333 zz=pkey->private_key->data; 333 zz=pkey->private_key->data;
334 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) 334 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
335 { 335 {
336 ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); 336 ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
337 goto err; 337 goto err;
338 } 338 }
339err: 339err:
340 EVP_CIPHER_CTX_cleanup(&ctx); 340 EVP_CIPHER_CTX_cleanup(&ctx);
341 NETSCAPE_PKEY_free(pkey); 341 NETSCAPE_PKEY_free(pkey);
342 return(ret); 342 return(ret);
343 } 343}
344 344
345#endif /* OPENSSL_NO_RC4 */ 345#endif /* OPENSSL_NO_RC4 */
346 346