From 74b3df4f6cf37c94831963f5bf38ed10a0e0f089 Mon Sep 17 00:00:00 2001 From: Tesfa Mael Date: Fri, 6 May 2022 16:14:47 -0700 Subject: [PATCH] Refactor tmpF in RsaMGF1 --- wolfcrypt/src/rsa.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index 6011b363b..58ee2b28e 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -855,12 +855,12 @@ static int RsaMGF1(enum wc_HashType hType, byte* seed, word32 seedSz, { #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) byte* tmp = NULL; + byte tmpF = 0; /* 1 if dynamic memory needs freed */ #else byte tmp[RSA_MAX_SIZE/8]; #endif /* needs to be large enough for seed size plus counter(4) */ byte tmpA[WC_MAX_DIGEST_SIZE + 4]; - byte tmpF = 0; /* 1 if dynamic memory needs freed */ word32 tmpSz = 0; int hLen; int ret; @@ -903,8 +903,8 @@ static int RsaMGF1(enum wc_HashType hType, byte* seed, word32 seedSz, #endif #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) tmp = tmpA; -#endif tmpF = 0; /* no need to free memory at end */ +#endif } #ifdef WOLFSSL_SMALL_STACK_CACHE @@ -959,11 +959,12 @@ static int RsaMGF1(enum wc_HashType hType, byte* seed, word32 seedSz, } counter++; } while (idx < outSz); - +#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) /* check for if dynamic memory was needed, then free */ if (tmpF) { XFREE(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER); } +#endif #ifdef WOLFSSL_SMALL_STACK_CACHE wc_HashFree(hash, hType); XFREE(hash, heap, DYNAMIC_TYPE_DIGEST);