diff options
author | Jack Lloyd <[email protected]> | 2018-03-04 09:54:25 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-03-04 09:54:25 -0500 |
commit | ce637bf9b4010d33f8f7de5370beb8c4e247b8fe (patch) | |
tree | a3f9d2037689efadbc9e9b1b0b6a70c18566bd6a | |
parent | 86614915b55393a07686e58814a6a28a91e87113 (diff) |
Use Barrett instead of repeated divisions by p here
Doesn't matter much since its a one time setup cost but can't hurt.
-rw-r--r-- | src/lib/pubkey/ec_group/curve_gfp.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/lib/pubkey/ec_group/curve_gfp.cpp b/src/lib/pubkey/ec_group/curve_gfp.cpp index caaca0a9a..216f2a894 100644 --- a/src/lib/pubkey/ec_group/curve_gfp.cpp +++ b/src/lib/pubkey/ec_group/curve_gfp.cpp @@ -9,6 +9,7 @@ #include <botan/curve_gfp.h> #include <botan/curve_nistp.h> #include <botan/numthry.h> +#include <botan/reducer.h> #include <botan/internal/mp_core.h> #include <botan/internal/mp_asmi.h> @@ -26,9 +27,11 @@ class CurveGFp_Montgomery final : public CurveGFp_Repr { const BigInt r = BigInt::power_of_2(m_p_words * BOTAN_MP_WORD_BITS); - m_r2 = (r * r) % p; - m_a_r = (m_a * r) % p; - m_b_r = (m_b * r) % p; + Modular_Reducer mod_p(m_p); + + m_r2 = mod_p.square(r); + m_a_r = mod_p.multiply(r, m_a); + m_b_r = mod_p.multiply(r, m_b); } const BigInt& get_a() const override { return m_a; } |