aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-06-15 13:40:46 -0400
committerJack Lloyd <[email protected]>2018-06-15 13:40:46 -0400
commitb434f6a7518b65fbe5eb1b8e042d2daf10d03671 (patch)
treea6c143e2a700decaf91b8dbfe6b6367f6b18cbcd /src
parenta8bbba27e89a7d21dc39020d8abeb9f9aff6f603 (diff)
parentd7df2981d3bfa16c36b5651ef2958a75ead0811a (diff)
Merge GH #1609 Avoid small side channel in ECC field mul
Diffstat (limited to 'src')
-rw-r--r--src/lib/pubkey/ec_group/curve_gfp.cpp37
1 files changed, 15 insertions, 22 deletions
diff --git a/src/lib/pubkey/ec_group/curve_gfp.cpp b/src/lib/pubkey/ec_group/curve_gfp.cpp
index 112213d6c..a9fa2d614 100644
--- a/src/lib/pubkey/ec_group/curve_gfp.cpp
+++ b/src/lib/pubkey/ec_group/curve_gfp.cpp
@@ -133,12 +133,9 @@ void CurveGFp_Montgomery::curve_mul(BigInt& z, const BigInt& x, const BigInt& y,
BOTAN_DEBUG_ASSERT(x.sig_words() <= m_p_words);
BOTAN_DEBUG_ASSERT(y.sig_words() <= m_p_words);
- const size_t x_words = (x.size() >= m_p_words) ? m_p_words : x.sig_words();
- const size_t y_words = (y.size() >= m_p_words) ? m_p_words : y.sig_words();
-
bigint_mul(z.mutable_data(), z.size(),
- x.data(), x.size(), x_words,
- y.data(), y.size(), y_words,
+ x.data(), x.size(), std::min(m_p_words, x.size()),
+ y.data(), y.size(), std::min(m_p_words, y.size()),
ws.data(), ws.size());
bigint_monty_redc(z.mutable_data(),
@@ -161,12 +158,9 @@ void CurveGFp_Montgomery::curve_mul_words(BigInt& z,
BOTAN_DEBUG_ASSERT(y.sig_words() <= m_p_words);
- const size_t x_words = (x_size >= m_p_words) ? m_p_words : x_size;
- const size_t y_words = (y.size() >= m_p_words) ? m_p_words : y.sig_words();
-
bigint_mul(z.mutable_data(), z.size(),
- x_w, x_size, x_words,
- y.data(), y.size(), y_words,
+ x_w, x_size, std::min(m_p_words, x_size),
+ y.data(), y.size(), std::min(m_p_words, y.size()),
ws.data(), ws.size());
bigint_monty_redc(z.mutable_data(),
@@ -184,10 +178,10 @@ void CurveGFp_Montgomery::curve_sqr(BigInt& z, const BigInt& x,
if(z.size() < output_size)
z.grow_to(output_size);
- const size_t x_words = (x.size() >= m_p_words) ? m_p_words : x.sig_words();
+ BOTAN_DEBUG_ASSERT(x.sig_words() <= m_p_words);
bigint_sqr(z.mutable_data(), z.size(),
- x.data(), x.size(), x_words,
+ x.data(), x.size(), std::min(m_p_words, x.size()),
ws.data(), ws.size());
bigint_monty_redc(z.mutable_data(),
@@ -279,12 +273,12 @@ void CurveGFp_NIST::curve_mul(BigInt& z, const BigInt& x, const BigInt& y,
if(z.size() < output_size)
z.grow_to(output_size);
- const size_t x_words = (x.size() >= m_p_words) ? m_p_words : x.sig_words();
- const size_t y_words = (y.size() >= m_p_words) ? m_p_words : y.sig_words();
+ BOTAN_DEBUG_ASSERT(x.sig_words() <= m_p_words);
+ BOTAN_DEBUG_ASSERT(y.sig_words() <= m_p_words);
bigint_mul(z.mutable_data(), z.size(),
- x.data(), x.size(), x_words,
- y.data(), y.size(), y_words,
+ x.data(), x.size(), std::min(m_p_words, x.size()),
+ y.data(), y.size(), std::min(m_p_words, y.size()),
ws.data(), ws.size());
this->redc(z, ws);
@@ -303,12 +297,11 @@ void CurveGFp_NIST::curve_mul_words(BigInt& z,
if(z.size() < output_size)
z.grow_to(output_size);
- const size_t x_words = (x_size >= m_p_words) ? m_p_words : x_size;
- const size_t y_words = (y.size() >= m_p_words) ? m_p_words : y.sig_words();
+ BOTAN_DEBUG_ASSERT(y.sig_words() <= m_p_words);
bigint_mul(z.mutable_data(), z.size(),
- x_w, x_size, x_words,
- y.data(), y.size(), y_words,
+ x_w, x_size, std::min(m_p_words, x_size),
+ y.data(), y.size(), std::min(m_p_words, y.size()),
ws.data(), ws.size());
this->redc(z, ws);
@@ -324,10 +317,10 @@ void CurveGFp_NIST::curve_sqr(BigInt& z, const BigInt& x,
if(z.size() < output_size)
z.grow_to(output_size);
- const size_t x_words = (x.size() >= m_p_words) ? m_p_words : x.sig_words();
+ BOTAN_DEBUG_ASSERT(x.sig_words() <= m_p_words);
bigint_sqr(z.mutable_data(), output_size,
- x.data(), x.size(), x_words,
+ x.data(), x.size(), std::min(m_p_words, x.size()),
ws.data(), ws.size());
this->redc(z, ws);