From 0a2ee6c530f7c50b84be1154d19863f573999c65 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Sat, 14 Jan 2023 05:41:24 +1000 Subject: [PATCH] AES SIV: Allocate memory for AES as late as possbile AES will be initialized if memory allocation succeeded. --- wolfcrypt/src/aes.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index b80138dd1..23ab79201 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -12345,15 +12345,6 @@ static WARN_UNUSED_RESULT int AesSivCipher( ret = BAD_FUNC_ARG; } -#ifdef WOLFSSL_SMALL_STACK - if (ret == 0) { - aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_AES); - if (aes == NULL) { - ret = MEMORY_E; - } - } -#endif - if (ret == 0) { if (enc == 1) { ret = S2V(key, keySz / 2, assoc, assocSz, nonce, nonceSz, data, @@ -12370,6 +12361,15 @@ static WARN_UNUSED_RESULT int AesSivCipher( } } +#ifdef WOLFSSL_SMALL_STACK + if (ret == 0) { + aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_AES); + if (aes == NULL) { + ret = MEMORY_E; + } + } +#endif + if (ret == 0) { ret = wc_AesInit(aes, NULL, INVALID_DEVID); if (ret != 0) {