From 9042843e425180dfc6baf17c341f0907aaaf9746 Mon Sep 17 00:00:00 2001 From: Tesfa Mael Date: Thu, 10 Dec 2020 16:13:30 -0800 Subject: [PATCH] Fix shift and clear digits --- wolfcrypt/src/integer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index 95c894353..cd021e7f9 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -684,8 +684,10 @@ int mp_mod_2d (mp_int * a, int b, mp_int * c) c->dp[x] = 0; } /* clear the digit that is not completely outside/inside the modulus */ - c->dp[b / DIGIT_BIT] &= (mp_digit) ((((mp_digit) 1) << - (((mp_digit) b) % DIGIT_BIT)) - ((mp_digit) 1)); + x = DIGIT_BIT - (b % DIGIT_BIT); + if (x != DIGIT_BIT) { + c->dp[b / DIGIT_BIT] &= ~((mp_digit)0) >> x; + } mp_clamp (c); return MP_OKAY; }