aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-02-25 18:18:49 -0500
committerJack Lloyd <[email protected]>2018-02-25 18:18:49 -0500
commit2ccc0c1efb44c8756b346ba5874c219790b606cf (patch)
tree61b9f3aa1cdfc7a62fa758d2b4604a2a3b964d1b
parent8c3ce8fba6802b821ce1307e3ca10b06d82a04ce (diff)
Use reduce_below in PointGFp
Improves ECDSA times by 2-3%
-rw-r--r--src/lib/math/bigint/bigint.cpp2
-rw-r--r--src/lib/math/ec_gfp/point_gfp.cpp12
2 files changed, 6 insertions, 8 deletions
diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp
index 50e93c38d..c822a94e1 100644
--- a/src/lib/math/bigint/bigint.cpp
+++ b/src/lib/math/bigint/bigint.cpp
@@ -260,6 +260,8 @@ void BigInt::reduce_below(const BigInt& p, secure_vector<word>& ws)
if(ws.size() < p_words + 1)
ws.resize(p_words + 1);
+ clear_mem(ws.data(), ws.size());
+
for(;;)
{
word borrow = bigint_sub3(ws.data(), data(), p_words + 1, p.data(), p_words);
diff --git a/src/lib/math/ec_gfp/point_gfp.cpp b/src/lib/math/ec_gfp/point_gfp.cpp
index 407da9dbe..f054c51ff 100644
--- a/src/lib/math/ec_gfp/point_gfp.cpp
+++ b/src/lib/math/ec_gfp/point_gfp.cpp
@@ -203,8 +203,7 @@ void PointGFp::mult2(std::vector<BigInt>& ws_bn)
m_curve.mul(S, m_coord_x, y_2, monty_ws);
S <<= 2; // * 4
- while(S >= p)
- S -= p;
+ S.reduce_below(p, monty_ws);
m_curve.sqr(a_z4, m_coord_z, monty_ws); // z^2
m_curve.sqr(tmp, a_z4, monty_ws); // z^4
@@ -213,8 +212,7 @@ void PointGFp::mult2(std::vector<BigInt>& ws_bn)
m_curve.sqr(M, m_coord_x, monty_ws);
M *= 3;
M += a_z4;
- while(M >= p)
- M -= p;
+ M.reduce_below(p, monty_ws);
m_curve.sqr(x, M, monty_ws);
x -= (S << 1);
@@ -223,8 +221,7 @@ void PointGFp::mult2(std::vector<BigInt>& ws_bn)
m_curve.sqr(U, y_2, monty_ws);
U <<= 3;
- while(U >= p)
- U -= p;
+ U.reduce_below(p, monty_ws);
S -= x;
while(S.is_negative())
@@ -237,8 +234,7 @@ void PointGFp::mult2(std::vector<BigInt>& ws_bn)
m_curve.mul(z, m_coord_y, m_coord_z, monty_ws);
z <<= 1;
- if(z >= p)
- z -= p;
+ z.reduce_below(p, monty_ws);
m_coord_x = x;
m_coord_y = y;