From cf8a6efaa5a70151a9842f698fb6d11fd49acb4f Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Wed, 6 Dec 2023 08:59:54 +1000 Subject: [PATCH] SP int neg sp_mont_red_ex: disallow negative numbers Don't support negative a or m with sp_mont_red_ex(). --- wolfcrypt/src/sp_int.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index 73da134ea..cb1364535 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -17524,6 +17524,11 @@ int sp_mont_red_ex(sp_int* a, const sp_int* m, sp_int_digit mp, int ct) if ((a == NULL) || (m == NULL) || sp_iszero(m)) { err = MP_VAL; } +#ifdef WOLFSSL_SP_INT_NEGATIVE + else if ((a->sign == MP_NEG) || (m->sign == MP_NEG)) { + err = MP_VAL; + } +#endif /* Ensure a has enough space for calculation. */ else if (a->size < m->used * 2 + 1) { err = MP_VAL;