diff options
author | Jack Lloyd <[email protected]> | 2018-02-26 17:27:21 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-02-26 17:27:21 -0500 |
commit | 539d364a5d6e52ed28684ecf2ae04e93fd3c46d8 (patch) | |
tree | 5e981074302159af8dbcc954351e2424dd690651 /src/lib/pubkey | |
parent | a89255d933d02bb388f9a9fa1093b189f389732d (diff) |
Avoid using monty workspace for reduce_below
If the workspace is swapped, then it is too small for the Montgomery
operation and will be reallocate on the next sqr/multiply operation.
Also use ws[9] consistently for the Montgomery workspace, otherwise
if add needs to pass off the mult2, the workspaces are not the expected
size and again a reallocation occurs.
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r-- | src/lib/pubkey/ec_group/point_gfp.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/pubkey/ec_group/point_gfp.cpp b/src/lib/pubkey/ec_group/point_gfp.cpp index 12a26f50c..20b4e0179 100644 --- a/src/lib/pubkey/ec_group/point_gfp.cpp +++ b/src/lib/pubkey/ec_group/point_gfp.cpp @@ -93,9 +93,9 @@ void PointGFp::add(const PointGFp& rhs, std::vector<BigInt>& ws_bn) BigInt& H = ws_bn[6]; BigInt& r = ws_bn[7]; - BigInt& tmp = ws_bn[9]; + BigInt& tmp = ws_bn[8]; - secure_vector<word>& monty_ws = ws_bn[8].get_word_vector(); + secure_vector<word>& monty_ws = ws_bn[9].get_word_vector(); /* https://hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#addition-add-1998-cmo-2 @@ -204,7 +204,7 @@ void PointGFp::mult2(std::vector<BigInt>& ws_bn) m_curve.mul(S, m_coord_x, y_2, monty_ws); S <<= 2; // * 4 - S.reduce_below(p, monty_ws); + S.reduce_below(p, tmp.get_word_vector()); m_curve.sqr(a_z4, m_coord_z, monty_ws); // z^2 m_curve.sqr(tmp, a_z4, monty_ws); // z^4 @@ -213,7 +213,7 @@ void PointGFp::mult2(std::vector<BigInt>& ws_bn) m_curve.sqr(M, m_coord_x, monty_ws); M *= 3; M += a_z4; - M.reduce_below(p, monty_ws); + M.reduce_below(p, tmp.get_word_vector()); m_curve.sqr(x, M, monty_ws); x -= S; @@ -223,7 +223,7 @@ void PointGFp::mult2(std::vector<BigInt>& ws_bn) m_curve.sqr(U, y_2, monty_ws); U <<= 3; - U.reduce_below(p, monty_ws); + U.reduce_below(p, tmp.get_word_vector()); S -= x; while(S.is_negative()) @@ -236,7 +236,7 @@ void PointGFp::mult2(std::vector<BigInt>& ws_bn) m_curve.mul(z, m_coord_y, m_coord_z, monty_ws); z <<= 1; - z.reduce_below(p, monty_ws); + z.reduce_below(p, tmp.get_word_vector()); m_coord_x = x; m_coord_y = y; |