From 20ae076b801ec1b1868ce63f3aa8dfbc5c5e6ba2 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Tue, 7 Feb 2023 11:29:53 +1000 Subject: [PATCH] integer.c: fast mod reduce fix When using small stack, not enough memory uas being allocated in fast_mp_montgomery_reduce(). Allocate the required space and memset all used memory. --- wolfcrypt/src/integer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index 9a7cc485b..42f5848f2 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -2512,13 +2512,13 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho) } #ifdef WOLFSSL_SMALL_STACK - W = (mp_word*)XMALLOC(sizeof(mp_word) * (n->used * 2 + 1), NULL, + W = (mp_word*)XMALLOC(sizeof(mp_word) * (n->used * 2 + 2), NULL, DYNAMIC_TYPE_BIGINT); if (W == NULL) return MP_MEM; #endif - XMEMSET(W, 0, sizeof(mp_word) * (n->used * 2 + 1)); + XMEMSET(W, 0, sizeof(mp_word) * (n->used * 2 + 2)); /* first we have to get the digits of the input into * an array of double precision words W[...]