aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/ec_group/curve_gfp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/pubkey/ec_group/curve_gfp.cpp')
-rw-r--r--src/lib/pubkey/ec_group/curve_gfp.cpp40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/lib/pubkey/ec_group/curve_gfp.cpp b/src/lib/pubkey/ec_group/curve_gfp.cpp
index d841437f3..b57b8d3ef 100644
--- a/src/lib/pubkey/ec_group/curve_gfp.cpp
+++ b/src/lib/pubkey/ec_group/curve_gfp.cpp
@@ -89,10 +89,18 @@ void CurveGFp_Montgomery::to_curve_rep(BigInt& x, secure_vector<word>& ws) const
curve_mul(x, tx, m_r2, ws);
}
-void CurveGFp_Montgomery::from_curve_rep(BigInt& x, secure_vector<word>& ws) const
+void CurveGFp_Montgomery::from_curve_rep(BigInt& z, secure_vector<word>& ws) const
{
- const BigInt tx = x;
- curve_mul(x, tx, 1, ws);
+ if(ws.size() < get_ws_size())
+ ws.resize(get_ws_size());
+
+ const size_t output_size = 2*m_p_words + 2;
+ if(z.size() < output_size)
+ z.grow_to(output_size);
+
+ bigint_monty_redc(z.mutable_data(),
+ m_p.data(), m_p_words, m_p_dash,
+ ws.data(), ws.size());
}
void CurveGFp_Montgomery::curve_mul(BigInt& z, const BigInt& x, const BigInt& y,
@@ -111,9 +119,12 @@ void CurveGFp_Montgomery::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();
+
bigint_mul(z.mutable_data(), z.size(),
- x.data(), x.size(), x.sig_words(),
- y.data(), y.size(), y.sig_words(),
+ x.data(), x.size(), x_words,
+ y.data(), y.size(), y_words,
ws.data(), ws.size());
bigint_monty_redc(z.mutable_data(),
@@ -130,19 +141,17 @@ void CurveGFp_Montgomery::curve_sqr(BigInt& z, const BigInt& x,
return;
}
- const size_t x_sw = x.sig_words();
- BOTAN_ASSERT(x_sw <= m_p_words, "Input in range");
-
if(ws.size() < get_ws_size())
ws.resize(get_ws_size());
const size_t output_size = 2*m_p_words + 2;
-
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();
+
bigint_sqr(z.mutable_data(), z.size(),
- x.data(), x.size(), x_sw,
+ x.data(), x.size(), x_words,
ws.data(), ws.size());
bigint_monty_redc(z.mutable_data(),
@@ -216,9 +225,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();
+
bigint_mul(z.mutable_data(), z.size(),
- x.data(), x.size(), x.sig_words(),
- y.data(), y.size(), y.sig_words(),
+ x.data(), x.size(), x_words,
+ y.data(), y.size(), y_words,
ws.data(), ws.size());
this->redc(z, ws);
@@ -240,8 +252,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();
+
bigint_sqr(z.mutable_data(), output_size,
- x.data(), x.size(), x.sig_words(),
+ x.data(), x.size(), x_words,
ws.data(), ws.size());
this->redc(z, ws);