Merge pull request #3483 from SparkiDev/mp_rshb_word

rshb: handle cases of shift amount being multiple of DIGIT_BIT
This commit is contained in:
toddouska
2020-11-18 16:07:57 -08:00
committed by GitHub
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 */