diff options
-rw-r--r-- | src/lib/math/bigint/bigint.cpp | 2 | ||||
-rw-r--r-- | src/lib/math/ec_gfp/point_gfp.cpp | 12 |
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; |