From f5561b926c3782e65d55778287b32561e774b3bb Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Wed, 11 Nov 2020 09:41:47 +1000 Subject: [PATCH] rshb: handle cases of shift amount being multiple of DIGIT_BIT tfm.c and integer.c fixed --- wolfcrypt/src/integer.c | 4 ++++ wolfcrypt/src/tfm.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/wolfcrypt/src/integer.c b/wolfcrypt/src/integer.c index 913b66ff5..640c2ddab 100644 --- a/wolfcrypt/src/integer.c +++ b/wolfcrypt/src/integer.c @@ -564,12 +564,16 @@ void mp_rshb (mp_int *c, int x) /* shifting by a negative number not supported */ if (x < 0) return; + /* shifting by zero changes nothing */ + if (x == 0) return; /* shift digits first if needed */ if (x >= DIGIT_BIT) { mp_rshd(c, x / DIGIT_BIT); /* recalculate number of bits to shift */ D = x % DIGIT_BIT; + /* check if any more shifting needed */ + if (D == 0) return; } /* zero shifted is always zero */ diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index 9b1a35151..cb50e74e1 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -3871,12 +3871,17 @@ void fp_rshb(fp_int *c, int x) /* shifting by a negative number not supported */ if (x < 0) return; + /* shifting by zero changes nothing */ + if (x == 0) return; /* shift digits first if needed */ if (x >= DIGIT_BIT) { fp_rshd(c, x / DIGIT_BIT); /* recalculate number of bits to shift */ D = x % DIGIT_BIT; + /* check if any more shifting needed */ + if (D == 0) return; + } /* zero shifted is always zero */