diff options
Diffstat (limited to 'src/lib/math')
-rw-r--r-- | src/lib/math/mp/mp_misc.cpp | 3 | ||||
-rw-r--r-- | src/lib/math/numbertheory/numthry.cpp | 3 | ||||
-rw-r--r-- | src/lib/math/numbertheory/powm_mnt.cpp | 1 |
3 files changed, 7 insertions, 0 deletions
diff --git a/src/lib/math/mp/mp_misc.cpp b/src/lib/math/mp/mp_misc.cpp index 4f24765bb..3b8be177e 100644 --- a/src/lib/math/mp/mp_misc.cpp +++ b/src/lib/math/mp/mp_misc.cpp @@ -43,6 +43,9 @@ s32bit bigint_cmp(const word x[], size_t x_size, */ word bigint_divop(word n1, word n0, word d) { + if(d == 0) + throw std::runtime_error("bigint_divop divide by zero"); + word high = n1 % d, quotient = 0; for(size_t i = 0; i != MP_WORD_BITS; ++i) diff --git a/src/lib/math/numbertheory/numthry.cpp b/src/lib/math/numbertheory/numthry.cpp index fe943cc6b..900e61724 100644 --- a/src/lib/math/numbertheory/numthry.cpp +++ b/src/lib/math/numbertheory/numthry.cpp @@ -176,6 +176,9 @@ BigInt inverse_mod(const BigInt& n, const BigInt& mod) word monty_inverse(word input) { + if(input == 0) + throw std::runtime_error("monty_inverse: divide by zero"); + word b = input; word x2 = 1, x1 = 0, y2 = 0, y1 = 1; diff --git a/src/lib/math/numbertheory/powm_mnt.cpp b/src/lib/math/numbertheory/powm_mnt.cpp index c8bf0928c..5e797b195 100644 --- a/src/lib/math/numbertheory/powm_mnt.cpp +++ b/src/lib/math/numbertheory/powm_mnt.cpp @@ -137,6 +137,7 @@ Montgomery_Exponentiator::Montgomery_Exponentiator(const BigInt& mod, const BigInt r = BigInt::power_of_2(m_mod_words * BOTAN_MP_WORD_BITS); m_R_mod = r % m_modulus; m_R2_mod = (m_R_mod * m_R_mod) % m_modulus; + m_exp_bits = 0; } } |