rshb: handle cases of shift amount being multiple of DIGIT_BIT

tfm.c and integer.c fixed
This commit is contained in:
Sean Parkinson
2020-11-11 09:41:47 +10:00
parent 68209f91fb
commit f5561b926c
2 changed files with 9 additions and 0 deletions

View File

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

View File

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