PKCS#12 code fixes: initialize and cleanup digests and ciphers
properly.
This commit is contained in:
parent
b83eddc578
commit
3a3619b46a
@ -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;
|
||||
|
||||
}
|
||||
|
@ -165,6 +165,7 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
|
||||
OPENSSL_free (I);
|
||||
BN_free (Ij);
|
||||
BN_free (Bpl1);
|
||||
EVP_MD_CTX_cleanup(&ctx);
|
||||
#ifdef DEBUG_KEYGEN
|
||||
fprintf(stderr, "Output KEY (length %d)\n", tmpn);
|
||||
h__dump(tmpout, tmpn);
|
||||
@ -195,7 +196,6 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
|
||||
} else BN_bn2bin (Ij, I + j);
|
||||
}
|
||||
}
|
||||
EVP_MD_CTX_cleanup(&ctx);
|
||||
}
|
||||
#ifdef DEBUG_KEYGEN
|
||||
void h__dump (unsigned char *p, int len)
|
||||
|
Loading…
x
Reference in New Issue
Block a user