From 53a4903e2fef7ebc01550eb832027ad94ce809e5 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Tue, 18 Jan 2022 16:17:27 +1000 Subject: [PATCH] SP math neg: Mont Reduce fix Compare the absolute value for negatives. --- wolfcrypt/src/sp_int.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index e838a0d79..f47795b34 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -12171,7 +12171,7 @@ static int _sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp) sp_clamp(a); sp_rshb(a, bits, a); - if (_sp_cmp(a, m) != MP_LT) { + if (_sp_cmp_abs(a, m) != MP_LT) { _sp_sub_off(a, m, a, 0); } @@ -12370,7 +12370,7 @@ static int _sp_mont_red(sp_int* a, sp_int* m, sp_int_digit mp) sp_clamp(a); sp_rshb(a, bits, a); - if (_sp_cmp(a, m) != MP_LT) { + if (_sp_cmp_abs(a, m) != MP_LT) { sp_sub(a, m, a); }