wolfcrypt: wc_encrypt: add missing wc_AesFree()

This commit is contained in:
Marco Oliverio
2021-12-29 16:25:08 +01:00
parent 933065d696
commit 2679c386ae

View File

@@ -625,6 +625,8 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
case PBE_AES256_CBC: case PBE_AES256_CBC:
case PBE_AES128_CBC: case PBE_AES128_CBC:
{ {
int free_aes;
#ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SMALL_STACK
Aes *aes; Aes *aes;
aes = (Aes *)XMALLOC(sizeof *aes, NULL, DYNAMIC_TYPE_AES); aes = (Aes *)XMALLOC(sizeof *aes, NULL, DYNAMIC_TYPE_AES);
@@ -633,8 +635,10 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
#else #else
Aes aes[1]; Aes aes[1];
#endif #endif
free_aes = 0;
ret = wc_AesInit(aes, NULL, INVALID_DEVID); ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret == 0) { if (ret == 0) {
free_aes = 1;
if (enc) { if (enc) {
ret = wc_AesSetKey(aes, key, derivedLen, cbcIv, ret = wc_AesSetKey(aes, key, derivedLen, cbcIv,
AES_ENCRYPTION); AES_ENCRYPTION);
@@ -650,6 +654,8 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
else else
ret = wc_AesCbcDecrypt(aes, input, input, length); ret = wc_AesCbcDecrypt(aes, input, input, length);
} }
if (free_aes)
wc_AesFree(aes);
ForceZero(aes, sizeof(Aes)); ForceZero(aes, sizeof(Aes));
#ifdef WOLFSSL_SMALL_STACK #ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_AES); XFREE(aes, NULL, DYNAMIC_TYPE_AES);