aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-02-26 17:28:35 -0500
committerJack Lloyd <[email protected]>2018-02-26 17:28:35 -0500
commit5fcc1c70d7ae2b2bac8598629e576a7a484b770a (patch)
treef0b187bcfd635d721ac5c4a0245fbc3507d4292b /src/lib/pubkey
parent539d364a5d6e52ed28684ecf2ae04e93fd3c46d8 (diff)
Avoid unnecessary calls to BigInt::grow_to
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r--src/lib/pubkey/ec_group/curve_gfp.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/lib/pubkey/ec_group/curve_gfp.cpp b/src/lib/pubkey/ec_group/curve_gfp.cpp
index 83d1c841c..a55741fb0 100644
--- a/src/lib/pubkey/ec_group/curve_gfp.cpp
+++ b/src/lib/pubkey/ec_group/curve_gfp.cpp
@@ -85,7 +85,8 @@ void CurveGFp_Montgomery::curve_mul(BigInt& z, const BigInt& x, const BigInt& y,
const size_t output_size = 2*m_p_words + 1;
ws.resize(2*(m_p_words+2));
- z.grow_to(output_size);
+ if(z.size() < output_size)
+ z.grow_to(output_size);
z.clear();
bigint_monty_mul(z, x, y,
@@ -109,7 +110,8 @@ void CurveGFp_Montgomery::curve_sqr(BigInt& z, const BigInt& x,
ws.resize(2*(m_p_words+2));
- z.grow_to(output_size);
+ if(z.size() < output_size)
+ z.grow_to(output_size);
z.clear();
bigint_monty_sqr(z, x, m_p.data(), m_p_words, m_p_dash,
@@ -164,9 +166,11 @@ void CurveGFp_NIST::curve_mul(BigInt& z, const BigInt& x, const BigInt& y,
const size_t p_words = get_p_words();
const size_t output_size = 2*p_words + 1;
+
ws.resize(2*(p_words+2));
- z.grow_to(output_size);
+ if(z.size() < output_size)
+ z.grow_to(output_size);
z.clear();
bigint_mul(z, x, y, ws.data(), ws.size());
@@ -188,7 +192,8 @@ void CurveGFp_NIST::curve_sqr(BigInt& z, const BigInt& x,
ws.resize(2*(p_words+2));
- z.grow_to(output_size);
+ if(z.size() < output_size)
+ z.grow_to(output_size);
z.clear();
bigint_sqr(z.mutable_data(), output_size,