From 344c3338a955b6118f8a92e2d09868f21bc941c0 Mon Sep 17 00:00:00 2001 From: John Bland Date: Thu, 18 May 2023 20:31:05 -0400 Subject: [PATCH] add check to sp_invmod_mont_ct to make sure the result integer can hold the range of the modulus --- wolfcrypt/src/sp_int.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index df16fa6eb..2e43da048 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -12445,6 +12445,10 @@ int sp_invmod_mont_ct(const sp_int* a, const sp_int* m, sp_int* r, else if (m->used * 2 >= SP_INT_DIGITS) { err = MP_VAL; } + /* check that r can hold the range of the modulus result */ + else if (m->used > r->size) { + err = MP_VAL; + } /* 0 != n*m + 1 (+ve m), r*a mod 0 is always 0 (never 1) */ if ((err == MP_OKAY) && (sp_iszero(a) || sp_iszero(m) ||