rshb check range of n

This commit is contained in:
Sean Parkinson
2020-07-13 15:24:59 +10:00
parent fbe0c8cba7
commit 52d363390a
3 changed files with 40 additions and 11 deletions

View File

@@ -562,6 +562,17 @@ void mp_rshb (mp_int *c, int x)
mp_digit r, rr;
mp_digit D = x;
/* shifting by a negative number not supported */
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;
}
/* zero shifted is always zero */
if (mp_iszero(c)) return;
/* mask */