From d506b715c51cf3c609d5f61d47f025c050462c92 Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Mon, 3 Dec 2018 06:40:20 -0500 Subject: Use const time reductions in Barrett and LCM computations --- src/lib/math/numbertheory/numthry.cpp | 3 ++- src/lib/math/numbertheory/reducer.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/lib/math/numbertheory') diff --git a/src/lib/math/numbertheory/numthry.cpp b/src/lib/math/numbertheory/numthry.cpp index 399a49cea..eba924b7c 100644 --- a/src/lib/math/numbertheory/numthry.cpp +++ b/src/lib/math/numbertheory/numthry.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -83,7 +84,7 @@ BigInt gcd(const BigInt& a, const BigInt& b) */ BigInt lcm(const BigInt& a, const BigInt& b) { - return ((a * b) / gcd(a, b)); + return ct_divide(a * b, gcd(a, b)); } /* diff --git a/src/lib/math/numbertheory/reducer.cpp b/src/lib/math/numbertheory/reducer.cpp index a5321c47c..0468d004b 100644 --- a/src/lib/math/numbertheory/reducer.cpp +++ b/src/lib/math/numbertheory/reducer.cpp @@ -7,6 +7,7 @@ #include #include +#include namespace Botan { @@ -28,7 +29,7 @@ Modular_Reducer::Modular_Reducer(const BigInt& mod) m_modulus_2 = Botan::square(m_modulus); - m_mu = BigInt::power_of_2(2 * BOTAN_MP_WORD_BITS * m_mod_words) / m_modulus; + m_mu = ct_divide(BigInt::power_of_2(2 * BOTAN_MP_WORD_BITS * m_mod_words), m_modulus); } } @@ -51,8 +52,8 @@ void Modular_Reducer::reduce(BigInt& t1, const BigInt& x, secure_vector& w if(x_sw >= (2*m_mod_words - 1) && x.cmp(m_modulus_2, false) >= 0) { - // too big, fall back to normal division - t1 = x % m_modulus; + // too big, fall back to slow boat division + t1 = ct_modulo(x, m_modulus); return; } -- cgit v1.2.3