From 9453f83d28df0300df366e74867fc1f0118352ae Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 30 Apr 2021 14:37:25 -0700 Subject: [PATCH] Fix bad logic flow in `WC_NO_RNG` case. --- wolfcrypt/src/port/nxp/ksdk_port.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wolfcrypt/src/port/nxp/ksdk_port.c b/wolfcrypt/src/port/nxp/ksdk_port.c index 4daf3d92f..492308a8d 100644 --- a/wolfcrypt/src/port/nxp/ksdk_port.c +++ b/wolfcrypt/src/port/nxp/ksdk_port.c @@ -560,20 +560,21 @@ int mp_prime_is_prime_ex(mp_int* a, int t, int* result, WC_RNG* rng) /* The base size is the number of bits / 8. One is added if the number * of bits isn't an even 8. */ sizeB = (sizeB / 8) + ((sizeB % 8) ? 1 : 0); - + ptrA = (uint8_t*)XMALLOC(LTC_MAX_INT_BYTES, NULL, DYNAMIC_TYPE_BIGINT); ptrB = (uint8_t*)XMALLOC(sizeB, NULL, DYNAMIC_TYPE_BIGINT); if (ptrA == NULL || ptrB == NULL) { res = MEMORY_E; } - #ifndef WC_NO_RNG - if (res == MP_OKAY && rng != NULL) { + if (res == MP_OKAY) { + #ifndef WC_NO_RNG + /* A NULL rng will return as bad function arg */ res = wc_RNG_GenerateBlock(rng, ptrB, sizeB); + #else + res = NOT_COMPILED_IN; + #endif } - #else - res = NOT_COMPILED_IN; - #endif if (res == MP_OKAY) { res = ltc_get_lsb_bin_from_mp_int(ptrA, a, &sizeA);