diff options
Diffstat (limited to 'src/lib/pubkey/ec_group/ec_group.cpp')
-rw-r--r-- | src/lib/pubkey/ec_group/ec_group.cpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp index a8d5136c8..942e7401a 100644 --- a/src/lib/pubkey/ec_group/ec_group.cpp +++ b/src/lib/pubkey/ec_group/ec_group.cpp @@ -37,6 +37,8 @@ class EC_Group_Data final const OID& oid) : m_curve(p, a, b), m_base_point(m_curve, g_x, g_y), + m_g_x(g_x), + m_g_y(g_y), m_order(order), m_cofactor(cofactor), m_mod_order(order), @@ -70,8 +72,8 @@ class EC_Group_Data final const BigInt& b() const { return m_curve.get_b(); } const BigInt& order() const { return m_order; } const BigInt& cofactor() const { return m_cofactor; } - BigInt g_x() const { return m_base_point.get_affine_x(); } - BigInt g_y() const { return m_base_point.get_affine_y(); } + const BigInt& g_x() const { return m_g_x; } + const BigInt& g_y() const { return m_g_y; } size_t p_bits() const { return m_p_bits; } size_t p_bytes() const { return (m_p_bits + 7) / 8; } @@ -101,6 +103,9 @@ class EC_Group_Data final private: CurveGFp m_curve; PointGFp m_base_point; + + BigInt m_g_x; + BigInt m_g_y; BigInt m_order; BigInt m_cofactor; Modular_Reducer m_mod_order; @@ -423,6 +428,16 @@ const BigInt& EC_Group::get_order() const return data().order(); } +const BigInt& EC_Group::get_g_x() const + { + return data().g_x(); + } + +const BigInt& EC_Group::get_g_y() const + { + return data().g_y(); + } + const BigInt& EC_Group::get_cofactor() const { return data().cofactor(); @@ -477,7 +492,7 @@ EC_Group::DER_encode(EC_Group_Encoding form) const if(form == EC_DOMPAR_ENC_EXPLICIT) { const size_t ecpVers1 = 1; - OID curve_type("1.2.840.10045.1.1"); // prime field + const OID curve_type("1.2.840.10045.1.1"); // prime field const size_t p_bytes = get_p_bytes(); @@ -533,7 +548,8 @@ bool EC_Group::operator==(const EC_Group& other) const return (get_p() == other.get_p() && get_a() == other.get_a() && get_b() == other.get_b() && - get_base_point() == other.get_base_point()); + get_g_x() == other.get_g_x() && + get_g_y() == other.get_g_y()); } bool EC_Group::verify_public_element(const PointGFp& point) const @@ -577,22 +593,28 @@ bool EC_Group::verify_group(RandomNumberGenerator& rng, { return false; } + + const PointGFp base_point = get_base_point(); + //check if the base point is on the curve - if(!get_base_point().on_the_curve()) + if(!base_point.on_the_curve()) { return false; } - if((get_base_point() * get_cofactor()).is_zero()) + if((base_point * get_cofactor()).is_zero()) { return false; } + + const BigInt& order = get_order(); + //check if order is prime - if(!is_prime(get_order(), rng, 128)) + if(!is_prime(order, rng, 128)) { return false; } //check if order of the base point is correct - if(!(get_base_point() * get_order()).is_zero()) + if(!(base_point * order).is_zero()) { return false; } |