forked from wolfSSL/wolfssl
wolfcrypt/test/test.c: fix Aes init/free lifecycle in aes192_test() and aes256_test().
This commit is contained in:
@ -11888,6 +11888,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
|
|||||||
#else
|
#else
|
||||||
Aes enc[1];
|
Aes enc[1];
|
||||||
#endif
|
#endif
|
||||||
|
int enc_inited = 0;
|
||||||
byte cipher[AES_BLOCK_SIZE];
|
byte cipher[AES_BLOCK_SIZE];
|
||||||
#ifdef HAVE_AES_DECRYPT
|
#ifdef HAVE_AES_DECRYPT
|
||||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
||||||
@ -11895,6 +11896,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
|
|||||||
#else
|
#else
|
||||||
Aes dec[1];
|
Aes dec[1];
|
||||||
#endif
|
#endif
|
||||||
|
int dec_inited = 0;
|
||||||
byte plain[AES_BLOCK_SIZE];
|
byte plain[AES_BLOCK_SIZE];
|
||||||
#endif
|
#endif
|
||||||
#endif /* HAVE_AES_CBC */
|
#endif /* HAVE_AES_CBC */
|
||||||
@ -11937,11 +11939,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
|
|||||||
ret = wc_AesInit(enc, HEAP_HINT, devId);
|
ret = wc_AesInit(enc, HEAP_HINT, devId);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||||
|
enc_inited = 1;
|
||||||
#ifdef HAVE_AES_DECRYPT
|
#ifdef HAVE_AES_DECRYPT
|
||||||
ret = wc_AesInit(dec, HEAP_HINT, devId);
|
ret = wc_AesInit(dec, HEAP_HINT, devId);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||||
#endif
|
#endif
|
||||||
|
dec_inited = 1;
|
||||||
|
|
||||||
ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION);
|
ret = wc_AesSetKey(enc, key, (int) sizeof(key), iv, AES_ENCRYPTION);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
@ -11975,19 +11979,25 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes192_test(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wc_AesFree(enc);
|
|
||||||
#ifdef HAVE_AES_DECRYPT
|
|
||||||
wc_AesFree(dec);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
||||||
if (enc)
|
if (enc) {
|
||||||
|
if (enc_inited)
|
||||||
|
wc_AesFree(enc);
|
||||||
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
|
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
|
||||||
|
}
|
||||||
#ifdef HAVE_AES_DECRYPT
|
#ifdef HAVE_AES_DECRYPT
|
||||||
if (dec)
|
if (dec) {
|
||||||
|
if (dec_inited)
|
||||||
|
wc_AesFree(dec);
|
||||||
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
|
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
|
||||||
|
if (enc_inited)
|
||||||
|
wc_AesFree(enc);
|
||||||
|
if (dec_inited)
|
||||||
|
wc_AesFree(dec);
|
||||||
#endif
|
#endif
|
||||||
#endif /* HAVE_AES_CBC */
|
#endif /* HAVE_AES_CBC */
|
||||||
|
|
||||||
@ -12004,6 +12014,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
|
|||||||
#else
|
#else
|
||||||
Aes enc[1];
|
Aes enc[1];
|
||||||
#endif
|
#endif
|
||||||
|
int enc_inited = 0;
|
||||||
byte cipher[AES_BLOCK_SIZE];
|
byte cipher[AES_BLOCK_SIZE];
|
||||||
#ifdef HAVE_AES_DECRYPT
|
#ifdef HAVE_AES_DECRYPT
|
||||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
||||||
@ -12011,6 +12022,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
|
|||||||
#else
|
#else
|
||||||
Aes dec[1];
|
Aes dec[1];
|
||||||
#endif
|
#endif
|
||||||
|
int dec_inited = 0;
|
||||||
byte plain[AES_BLOCK_SIZE];
|
byte plain[AES_BLOCK_SIZE];
|
||||||
#endif
|
#endif
|
||||||
#endif /* HAVE_AES_CBC */
|
#endif /* HAVE_AES_CBC */
|
||||||
@ -12059,11 +12071,13 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
|
|||||||
ret = wc_AesInit(enc, HEAP_HINT, devId);
|
ret = wc_AesInit(enc, HEAP_HINT, devId);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||||
|
enc_inited = 1;
|
||||||
#ifdef HAVE_AES_DECRYPT
|
#ifdef HAVE_AES_DECRYPT
|
||||||
ret = wc_AesInit(dec, HEAP_HINT, devId);
|
ret = wc_AesInit(dec, HEAP_HINT, devId);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), out);
|
||||||
#endif
|
#endif
|
||||||
|
dec_inited = 1;
|
||||||
|
|
||||||
ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
|
ret = wc_AesSetKey(enc, key, keySz, iv, AES_ENCRYPTION);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
@ -12173,21 +12187,28 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t aes256_test(void)
|
|||||||
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
ERROR_OUT(WC_TEST_RET_ENC_NC, out);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wc_AesFree(enc);
|
#endif /* DEBUG_VECTOR_REGISTER_ACCESS && WC_AES_C_DYNAMIC_FALLBACK */
|
||||||
#ifdef HAVE_AES_DECRYPT
|
|
||||||
wc_AesFree(dec);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
||||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
||||||
if (enc)
|
if (enc) {
|
||||||
|
if (enc_inited)
|
||||||
|
wc_AesFree(enc);
|
||||||
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
|
XFREE(enc, HEAP_HINT, DYNAMIC_TYPE_AES);
|
||||||
|
}
|
||||||
#ifdef HAVE_AES_DECRYPT
|
#ifdef HAVE_AES_DECRYPT
|
||||||
if (dec)
|
if (dec) {
|
||||||
|
if (dec_inited)
|
||||||
|
wc_AesFree(dec);
|
||||||
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
|
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
|
||||||
|
if (enc_inited)
|
||||||
|
wc_AesFree(enc);
|
||||||
|
if (dec_inited)
|
||||||
|
wc_AesFree(dec);
|
||||||
#endif
|
#endif
|
||||||
#endif /* HAVE_AES_CBC */
|
#endif /* HAVE_AES_CBC */
|
||||||
|
|
||||||
@ -12326,7 +12347,7 @@ static wc_test_ret_t aesgcm_default_test_helper(byte* key, int keySz, byte* iv,
|
|||||||
wc_AesFree(dec);
|
wc_AesFree(dec);
|
||||||
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
|
XFREE(dec, HEAP_HINT, DYNAMIC_TYPE_AES);
|
||||||
}
|
}
|
||||||
#else
|
#else /* !WOLFSSL_SMALL_STACK || WOLFSSL_NO_MALLOC */
|
||||||
if (enc_inited)
|
if (enc_inited)
|
||||||
wc_AesFree(enc);
|
wc_AesFree(enc);
|
||||||
if (dec_inited)
|
if (dec_inited)
|
||||||
|
Reference in New Issue
Block a user