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