Latest update.
This commit is contained in:
+14
-6
@@ -28,7 +28,7 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
|
||||
EVP_MD_CTX *ctx;
|
||||
unsigned char md_tmp[EVP_MAX_MD_SIZE];
|
||||
unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
|
||||
int i;
|
||||
int i, ivl, kl;
|
||||
PBEPARAM *pbe;
|
||||
int saltlen, iter;
|
||||
unsigned char *salt;
|
||||
@@ -48,6 +48,17 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
ivl = EVP_CIPHER_iv_length(cipher);
|
||||
if (ivl < 0 || ivl > 16) {
|
||||
EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN, EVP_R_INVALID_IV_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
kl = EVP_CIPHER_key_length(cipher);
|
||||
if (kl < 0 || kl > (int)sizeof(md_tmp)) {
|
||||
EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN, EVP_R_INVALID_KEY_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!pbe->iter)
|
||||
iter = 1;
|
||||
else
|
||||
@@ -86,11 +97,8 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
|
||||
if (!EVP_DigestFinal_ex(ctx, md_tmp, NULL))
|
||||
goto err;
|
||||
}
|
||||
OPENSSL_assert(EVP_CIPHER_key_length(cipher) <= (int)sizeof(md_tmp));
|
||||
memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher));
|
||||
OPENSSL_assert(EVP_CIPHER_iv_length(cipher) <= 16);
|
||||
memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
|
||||
EVP_CIPHER_iv_length(cipher));
|
||||
memcpy(key, md_tmp, kl);
|
||||
memcpy(iv, md_tmp + (16 - ivl), ivl);
|
||||
if (!EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de))
|
||||
goto err;
|
||||
OPENSSL_cleanse(md_tmp, EVP_MAX_MD_SIZE);
|
||||
|
||||
Reference in New Issue
Block a user