diff --git a/extern/libtommath/bn_fast_s_mp_mul_digs.c b/extern/libtommath/bn_fast_s_mp_mul_digs.c index 04becfd3853..6d82d8cf403 100644 --- a/extern/libtommath/bn_fast_s_mp_mul_digs.c +++ b/extern/libtommath/bn_fast_s_mp_mul_digs.c @@ -37,6 +37,10 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) mp_digit W[MP_WARRAY]; register mp_word _W; + if (digs < 0) { + return MP_VAL; + } + /* grow the destination as required */ if (c->alloc < digs) { if ((res = mp_grow (c, digs)) != MP_OKAY) { diff --git a/extern/libtommath/bn_fast_s_mp_mul_high_digs.c b/extern/libtommath/bn_fast_s_mp_mul_high_digs.c index 98bee3755d7..19cc04b444e 100644 --- a/extern/libtommath/bn_fast_s_mp_mul_high_digs.c +++ b/extern/libtommath/bn_fast_s_mp_mul_high_digs.c @@ -30,6 +30,10 @@ int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) mp_digit W[MP_WARRAY]; mp_word _W; + if (digs < 0) { + return MP_VAL; + } + /* grow the destination as required */ pa = a->used + b->used; if (c->alloc < pa) { diff --git a/extern/libtommath/bn_mp_2expt.c b/extern/libtommath/bn_mp_2expt.c index 4774aab3813..6a699a3e49c 100644 --- a/extern/libtommath/bn_mp_2expt.c +++ b/extern/libtommath/bn_mp_2expt.c @@ -25,6 +25,10 @@ mp_2expt (mp_int * a, int b) { int res; + if (b < 0) { + return MP_VAL; + } + /* zero a as per default */ mp_zero (a); diff --git a/extern/libtommath/bn_mp_grow.c b/extern/libtommath/bn_mp_grow.c index f1c1cab54e1..3749c7226e1 100644 --- a/extern/libtommath/bn_mp_grow.c +++ b/extern/libtommath/bn_mp_grow.c @@ -21,6 +21,10 @@ int mp_grow (mp_int * a, int size) int i; mp_digit *tmp; + if (size < 0) { + return MP_VAL; + } + /* if the alloc size is smaller alloc more ram */ if (a->alloc < size) { /* ensure there are always at least MP_PREC digits extra on top */ diff --git a/extern/libtommath/bn_mp_init_size.c b/extern/libtommath/bn_mp_init_size.c index 69dd49cec15..c69024f488d 100644 --- a/extern/libtommath/bn_mp_init_size.c +++ b/extern/libtommath/bn_mp_init_size.c @@ -20,6 +20,10 @@ int mp_init_size (mp_int * a, int size) { int x; + if (size < 0) { + return MP_VAL; + } + /* pad size so there are always extra digits */ size += (MP_PREC * 2) - (size % MP_PREC); diff --git a/extern/libtommath/bn_mp_mul_2d.c b/extern/libtommath/bn_mp_mul_2d.c index 385ac5906ba..8f9fe69f39f 100644 --- a/extern/libtommath/bn_mp_mul_2d.c +++ b/extern/libtommath/bn_mp_mul_2d.c @@ -21,6 +21,10 @@ int mp_mul_2d (mp_int * a, int b, mp_int * c) mp_digit d; int res; + if (b < 0) { + return MP_VAL; + } + /* copy */ if (a != c) { if ((res = mp_copy (a, c)) != MP_OKAY) { diff --git a/extern/libtommath/bn_s_mp_mul_digs.c b/extern/libtommath/bn_s_mp_mul_digs.c index 86196bf5db3..9990ae0373b 100644 --- a/extern/libtommath/bn_s_mp_mul_digs.c +++ b/extern/libtommath/bn_s_mp_mul_digs.c @@ -27,6 +27,10 @@ int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs) mp_word r; mp_digit tmpx, *tmpt, *tmpy; + if (digs < 0) { + return MP_VAL; + } + /* can we use the fast multiplier? */ if (((digs) < MP_WARRAY) && MIN (a->used, b->used) < diff --git a/extern/libtommath/bn_s_mp_mul_high_digs.c b/extern/libtommath/bn_s_mp_mul_high_digs.c index 019014e71d7..ff200f28083 100644 --- a/extern/libtommath/bn_s_mp_mul_high_digs.c +++ b/extern/libtommath/bn_s_mp_mul_high_digs.c @@ -27,6 +27,10 @@ s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs) mp_word r; mp_digit tmpx, *tmpt, *tmpy; + if (digs < 0) { + return MP_VAL; + } + /* can we use the fast multiplier? */ #ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C if (((a->used + b->used + 1) < MP_WARRAY)