aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/pubkey/ec_group/ec_group.cpp11
-rw-r--r--src/lib/pubkey/ec_group/ec_group.h5
-rw-r--r--src/tests/unit_ecc.cpp7
3 files changed, 22 insertions, 1 deletions
diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp
index a41a59b66..26af32a16 100644
--- a/src/lib/pubkey/ec_group/ec_group.cpp
+++ b/src/lib/pubkey/ec_group/ec_group.cpp
@@ -43,7 +43,8 @@ class EC_Group_Data final
m_base_mult(m_base_point, 5),
m_oid(oid),
m_p_bits(p.bits()),
- m_order_bits(order.bits())
+ m_order_bits(order.bits()),
+ m_a_is_minus_3(a == p - 3)
{
#if defined(BOTAN_HAS_SYSTEM_RNG)
m_base_mult.randomize(system_rng());
@@ -77,6 +78,8 @@ class EC_Group_Data final
const CurveGFp& curve() const { return m_curve; }
const PointGFp& base_point() const { return m_base_point; }
+ bool a_is_minus_3() const { return m_a_is_minus_3; }
+
BigInt mod_order(const BigInt& x) const { return m_mod_order.reduce(x); }
BigInt multiply_mod_order(const BigInt& x, const BigInt& y) const
@@ -101,6 +104,7 @@ class EC_Group_Data final
OID m_oid;
size_t m_p_bits;
size_t m_order_bits;
+ bool m_a_is_minus_3;
};
class EC_Group_Data_Map final
@@ -365,6 +369,11 @@ const CurveGFp& EC_Group::get_curve() const
return data().curve();
}
+bool EC_Group::a_is_minus_3() const
+ {
+ return data().a_is_minus_3();
+ }
+
size_t EC_Group::get_p_bits() const
{
return data().p_bits();
diff --git a/src/lib/pubkey/ec_group/ec_group.h b/src/lib/pubkey/ec_group/ec_group.h
index 0e5f352f2..16a6abe28 100644
--- a/src/lib/pubkey/ec_group/ec_group.h
+++ b/src/lib/pubkey/ec_group/ec_group.h
@@ -126,6 +126,11 @@ class BOTAN_PUBLIC_API(2,0) EC_Group final
BOTAN_DEPRECATED("Avoid CurveGFp") const CurveGFp& get_curve() const;
/**
+ * Return if a == -3 mod p
+ */
+ bool a_is_minus_3() const;
+
+ /**
* Return the size of p in bits (same as get_p().bits())
*/
size_t get_p_bits() const;
diff --git a/src/tests/unit_ecc.cpp b/src/tests/unit_ecc.cpp
index 1a2f1d61c..166dfcd14 100644
--- a/src/tests/unit_ecc.cpp
+++ b/src/tests/unit_ecc.cpp
@@ -281,6 +281,13 @@ Test::Result test_groups()
result.confirm("EC_Group is known", !group.get_curve_oid().empty());
result.test_eq("EC_Group has correct bit size", group.get_p().bits(), group.get_p_bits());
result.test_eq("EC_Group has byte size", group.get_p().bytes(), group.get_p_bytes());
+
+ bool a_is_minus_3 = group.a_is_minus_3();
+
+ if(a_is_minus_3)
+ result.test_eq("Group A equals -3", group.get_a(), group.get_p() - 3);
+ else
+ result.test_ne("Group " + group_name + " A does not equal -3", group.get_a(), group.get_p() - 3);
}
return result;
}