diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/n_pkey.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/n_pkey.c | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c index e251739933..e7d0439062 100644 --- a/src/lib/libcrypto/asn1/n_pkey.c +++ b/src/lib/libcrypto/asn1/n_pkey.c | |||
| @@ -129,7 +129,6 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
| 129 | unsigned char buf[256],*zz; | 129 | unsigned char buf[256],*zz; |
| 130 | unsigned char key[EVP_MAX_KEY_LENGTH]; | 130 | unsigned char key[EVP_MAX_KEY_LENGTH]; |
| 131 | EVP_CIPHER_CTX ctx; | 131 | EVP_CIPHER_CTX ctx; |
| 132 | EVP_CIPHER_CTX_init(&ctx); | ||
| 133 | 132 | ||
| 134 | if (a == NULL) return(0); | 133 | if (a == NULL) return(0); |
| 135 | 134 | ||
| @@ -207,28 +206,24 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, | |||
| 207 | i = strlen((char *)buf); | 206 | i = strlen((char *)buf); |
| 208 | /* If the key is used for SGC the algorithm is modified a little. */ | 207 | /* If the key is used for SGC the algorithm is modified a little. */ |
| 209 | if(sgckey) { | 208 | if(sgckey) { |
| 210 | if (!EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL)) | 209 | EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL); |
| 211 | goto err; | ||
| 212 | memcpy(buf + 16, "SGCKEYSALT", 10); | 210 | memcpy(buf + 16, "SGCKEYSALT", 10); |
| 213 | i = 26; | 211 | i = 26; |
| 214 | } | 212 | } |
| 215 | 213 | ||
| 216 | if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) | 214 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); |
| 217 | goto err; | ||
| 218 | OPENSSL_cleanse(buf,256); | 215 | OPENSSL_cleanse(buf,256); |
| 219 | 216 | ||
| 220 | /* Encrypt private key in place */ | 217 | /* Encrypt private key in place */ |
| 221 | zz = enckey->enckey->digest->data; | 218 | zz = enckey->enckey->digest->data; |
| 222 | if (!EVP_EncryptInit_ex(&ctx,EVP_rc4(),NULL,key,NULL)) | 219 | EVP_CIPHER_CTX_init(&ctx); |
| 223 | goto err; | 220 | EVP_EncryptInit_ex(&ctx,EVP_rc4(),NULL,key,NULL); |
| 224 | if (!EVP_EncryptUpdate(&ctx,zz,&i,zz,pkeylen)) | 221 | EVP_EncryptUpdate(&ctx,zz,&i,zz,pkeylen); |
| 225 | goto err; | 222 | EVP_EncryptFinal_ex(&ctx,zz + i,&j); |
| 226 | if (!EVP_EncryptFinal_ex(&ctx,zz + i,&j)) | 223 | EVP_CIPHER_CTX_cleanup(&ctx); |
| 227 | goto err; | ||
| 228 | 224 | ||
| 229 | ret = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, pp); | 225 | ret = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, pp); |
| 230 | err: | 226 | err: |
| 231 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 232 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | 227 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); |
| 233 | NETSCAPE_PKEY_free(pkey); | 228 | NETSCAPE_PKEY_free(pkey); |
| 234 | return(ret); | 229 | return(ret); |
| @@ -293,7 +288,6 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
| 293 | const unsigned char *zz; | 288 | const unsigned char *zz; |
| 294 | unsigned char key[EVP_MAX_KEY_LENGTH]; | 289 | unsigned char key[EVP_MAX_KEY_LENGTH]; |
| 295 | EVP_CIPHER_CTX ctx; | 290 | EVP_CIPHER_CTX ctx; |
| 296 | EVP_CIPHER_CTX_init(&ctx); | ||
| 297 | 291 | ||
| 298 | i=cb((char *)buf,256,"Enter Private Key password:",0); | 292 | i=cb((char *)buf,256,"Enter Private Key password:",0); |
| 299 | if (i != 0) | 293 | if (i != 0) |
| @@ -304,22 +298,19 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
| 304 | 298 | ||
| 305 | i = strlen((char *)buf); | 299 | i = strlen((char *)buf); |
| 306 | if(sgckey){ | 300 | if(sgckey){ |
| 307 | if (!EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL)) | 301 | EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL); |
| 308 | goto err; | ||
| 309 | memcpy(buf + 16, "SGCKEYSALT", 10); | 302 | memcpy(buf + 16, "SGCKEYSALT", 10); |
| 310 | i = 26; | 303 | i = 26; |
| 311 | } | 304 | } |
| 312 | 305 | ||
| 313 | if (!EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL)) | 306 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); |
| 314 | goto err; | ||
| 315 | OPENSSL_cleanse(buf,256); | 307 | OPENSSL_cleanse(buf,256); |
| 316 | 308 | ||
| 317 | if (!EVP_DecryptInit_ex(&ctx,EVP_rc4(),NULL, key,NULL)) | 309 | EVP_CIPHER_CTX_init(&ctx); |
| 318 | goto err; | 310 | EVP_DecryptInit_ex(&ctx,EVP_rc4(),NULL, key,NULL); |
| 319 | if (!EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length)) | 311 | EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length); |
| 320 | goto err; | 312 | EVP_DecryptFinal_ex(&ctx,&(os->data[i]),&j); |
| 321 | if (!EVP_DecryptFinal_ex(&ctx,&(os->data[i]),&j)) | 313 | EVP_CIPHER_CTX_cleanup(&ctx); |
| 322 | goto err; | ||
| 323 | os->length=i+j; | 314 | os->length=i+j; |
| 324 | 315 | ||
| 325 | zz=os->data; | 316 | zz=os->data; |
| @@ -337,7 +328,6 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
| 337 | goto err; | 328 | goto err; |
| 338 | } | 329 | } |
| 339 | err: | 330 | err: |
| 340 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
| 341 | NETSCAPE_PKEY_free(pkey); | 331 | NETSCAPE_PKEY_free(pkey); |
| 342 | return(ret); | 332 | return(ret); |
| 343 | } | 333 | } |
