make sure fast_mp_montgomery_reduce() doesn't BOF

This fixes #63
This commit is contained in:
Steffen Jaeckel 2017-08-29 16:41:08 +02:00
parent e9ce32a16d
commit a4d905a030
2 changed files with 5 additions and 0 deletions

View File

@ -28,6 +28,10 @@ int fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
int ix, res, olduse;
mp_word W[MP_WARRAY];
if (x->used > MP_WARRAY) {
return MP_VAL;
}
/* get old used count */
olduse = x->used;

View File

@ -29,6 +29,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
*/
digs = (n->used * 2) + 1;
if ((digs < MP_WARRAY) &&
(x->used <= MP_WARRAY) &&
(n->used <
(1 << ((CHAR_BIT * sizeof(mp_word)) - (2 * DIGIT_BIT))))) {
return fast_mp_montgomery_reduce(x, n, rho);