diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2001-11-06 13:54:48 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2001-11-06 13:54:48 +0000 |
commit | 3a3619b46a08eea15076944288ac351c35836ce5 (patch) | |
tree | 1d1d4fe281f882efad4819fa0ecf9b00daf8505e /crypto/pkcs12/p12_decr.c | |
parent | b83eddc578dc37967700dc8ca04aad6fe49edfb3 (diff) |
PKCS#12 code fixes: initialize and cleanup digests and ciphers
properly.
Diffstat (limited to 'crypto/pkcs12/p12_decr.c')
-rw-r--r-- | crypto/pkcs12/p12_decr.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/crypto/pkcs12/p12_decr.c b/crypto/pkcs12/p12_decr.c index e0bbe4cff7..394af368f4 100644 --- a/crypto/pkcs12/p12_decr.c +++ b/crypto/pkcs12/p12_decr.c @@ -76,28 +76,32 @@ unsigned char * PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, int outlen, i; EVP_CIPHER_CTX ctx; + EVP_CIPHER_CTX_init(&ctx); /* Decrypt data */ - if (!EVP_PBE_CipherInit (algor->algorithm, pass, passlen, + if (!EVP_PBE_CipherInit(algor->algorithm, pass, passlen, algor->parameter, &ctx, en_de)) { PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_ALGOR_CIPHERINIT_ERROR); return NULL; } - if(!(out = OPENSSL_malloc (inlen + EVP_CIPHER_CTX_block_size(&ctx)))) { + if(!(out = OPENSSL_malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) { PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE); - return NULL; + goto err; } - EVP_CipherUpdate (&ctx, out, &i, in, inlen); + EVP_CipherUpdate(&ctx, out, &i, in, inlen); outlen = i; - if(!EVP_CipherFinal_ex (&ctx, out + i, &i)) { - OPENSSL_free (out); + if(!EVP_CipherFinal_ex(&ctx, out + i, &i)) { + OPENSSL_free(out); + out = NULL; PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR); - return NULL; + goto err; } outlen += i; if (datalen) *datalen = outlen; if (data) *data = out; + err: + EVP_CIPHER_CTX_cleanup(&ctx); return out; } |