diff options
Diffstat (limited to 'src/lib/libcrypto/pem/pem_lib.c')
-rw-r--r-- | src/lib/libcrypto/pem/pem_lib.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c index 5a421fc4b6..cfc89a9921 100644 --- a/src/lib/libcrypto/pem/pem_lib.c +++ b/src/lib/libcrypto/pem/pem_lib.c | |||
@@ -394,8 +394,7 @@ int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, | |||
394 | goto err; | 394 | goto err; |
395 | /* The 'iv' is used as the iv and as a salt. It is | 395 | /* The 'iv' is used as the iv and as a salt. It is |
396 | * NOT taken from the BytesToKey function */ | 396 | * NOT taken from the BytesToKey function */ |
397 | if (!EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL)) | 397 | EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL); |
398 | goto err; | ||
399 | 398 | ||
400 | if (kstr == (unsigned char *)buf) OPENSSL_cleanse(buf,PEM_BUFSIZE); | 399 | if (kstr == (unsigned char *)buf) OPENSSL_cleanse(buf,PEM_BUFSIZE); |
401 | 400 | ||
@@ -407,15 +406,12 @@ int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, | |||
407 | /* k=strlen(buf); */ | 406 | /* k=strlen(buf); */ |
408 | 407 | ||
409 | EVP_CIPHER_CTX_init(&ctx); | 408 | EVP_CIPHER_CTX_init(&ctx); |
410 | ret = 1; | 409 | EVP_EncryptInit_ex(&ctx,enc,NULL,key,iv); |
411 | if (!EVP_EncryptInit_ex(&ctx,enc,NULL,key,iv) | 410 | EVP_EncryptUpdate(&ctx,data,&j,data,i); |
412 | || !EVP_EncryptUpdate(&ctx,data,&j,data,i) | 411 | EVP_EncryptFinal_ex(&ctx,&(data[j]),&i); |
413 | || !EVP_EncryptFinal_ex(&ctx,&(data[j]),&i)) | ||
414 | ret = 0; | ||
415 | EVP_CIPHER_CTX_cleanup(&ctx); | 412 | EVP_CIPHER_CTX_cleanup(&ctx); |
416 | if (ret == 0) | ||
417 | goto err; | ||
418 | i+=j; | 413 | i+=j; |
414 | ret=1; | ||
419 | } | 415 | } |
420 | else | 416 | else |
421 | { | 417 | { |
@@ -463,17 +459,14 @@ int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen, | |||
463 | ebcdic2ascii(buf, buf, klen); | 459 | ebcdic2ascii(buf, buf, klen); |
464 | #endif | 460 | #endif |
465 | 461 | ||
466 | if (!EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]), | 462 | EVP_BytesToKey(cipher->cipher,EVP_md5(),&(cipher->iv[0]), |
467 | (unsigned char *)buf,klen,1,key,NULL)) | 463 | (unsigned char *)buf,klen,1,key,NULL); |
468 | return 0; | ||
469 | 464 | ||
470 | j=(int)len; | 465 | j=(int)len; |
471 | EVP_CIPHER_CTX_init(&ctx); | 466 | EVP_CIPHER_CTX_init(&ctx); |
472 | o = EVP_DecryptInit_ex(&ctx,cipher->cipher,NULL, key,&(cipher->iv[0])); | 467 | EVP_DecryptInit_ex(&ctx,cipher->cipher,NULL, key,&(cipher->iv[0])); |
473 | if (o) | 468 | EVP_DecryptUpdate(&ctx,data,&i,data,j); |
474 | o = EVP_DecryptUpdate(&ctx,data,&i,data,j); | 469 | o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j); |
475 | if (o) | ||
476 | o = EVP_DecryptFinal_ex(&ctx,&(data[i]),&j); | ||
477 | EVP_CIPHER_CTX_cleanup(&ctx); | 470 | EVP_CIPHER_CTX_cleanup(&ctx); |
478 | OPENSSL_cleanse((char *)buf,sizeof(buf)); | 471 | OPENSSL_cleanse((char *)buf,sizeof(buf)); |
479 | OPENSSL_cleanse((char *)key,sizeof(key)); | 472 | OPENSSL_cleanse((char *)key,sizeof(key)); |