Merge pull request #3552 from tmael/shiftNeg

Check shift value
This commit is contained in:
Sean Parkinson
2020-12-11 10:19:27 +10:00
committed by GitHub
2 changed files with 9 additions and 3 deletions

View File

@ -684,8 +684,10 @@ int mp_mod_2d (mp_int * a, int b, mp_int * c)
c->dp[x] = 0;
}
/* clear the digit that is not completely outside/inside the modulus */
c->dp[b / DIGIT_BIT] &= (mp_digit) ((((mp_digit) 1) <<
(((mp_digit) b) % DIGIT_BIT)) - ((mp_digit) 1));
x = DIGIT_BIT - (b % DIGIT_BIT);
if (x != DIGIT_BIT) {
c->dp[b / DIGIT_BIT] &= ~((mp_digit)0) >> x;
}
mp_clamp (c);
return MP_OKAY;
}

View File

@ -1027,7 +1027,11 @@ void fp_mod_2d(fp_int *a, int b, fp_int *c)
c->dp[x] = 0;
}
/* clear the digit that is not completely outside/inside the modulus */
c->dp[b / DIGIT_BIT] &= ~((fp_digit)0) >> (DIGIT_BIT - b);
x = DIGIT_BIT - (b % DIGIT_BIT);
if (x != DIGIT_BIT) {
c->dp[b / DIGIT_BIT] &= ~((fp_digit)0) >> x;
}
fp_clamp (c);
}