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 */