AES SIV: Allocate memory for AES as late as possbile

AES will be initialized if memory allocation succeeded.
This commit is contained in:
Sean Parkinson
2023-01-14 05:41:24 +10:00
parent 5311a8e673
commit 0a2ee6c530

View File

@@ -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) {