diff options
-rw-r--r-- | src/lib/pubkey/ec_group/ec_group.cpp | 10 | ||||
-rw-r--r-- | src/lib/pubkey/ec_group/ec_group.h | 5 | ||||
-rw-r--r-- | src/tests/unit_ecc.cpp | 5 |
3 files changed, 19 insertions, 1 deletions
diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp index 1fb762e4b..d5a94c90c 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_oid(oid), m_p_bits(p.bits()), m_order_bits(order.bits()), - m_a_is_minus_3(a == p - 3) + m_a_is_minus_3(a == p - 3), + m_a_is_zero(a.is_zero()) { } @@ -79,6 +80,7 @@ class EC_Group_Data final const PointGFp& base_point() const { return m_base_point; } bool a_is_minus_3() const { return m_a_is_minus_3; } + bool a_is_zero() const { return m_a_is_zero; } BigInt mod_order(const BigInt& x) const { return m_mod_order.reduce(x); } @@ -108,6 +110,7 @@ class EC_Group_Data final size_t m_p_bits; size_t m_order_bits; bool m_a_is_minus_3; + bool m_a_is_zero; }; class EC_Group_Data_Map final @@ -399,6 +402,11 @@ bool EC_Group::a_is_minus_3() const return data().a_is_minus_3(); } +bool EC_Group::a_is_zero() const + { + return data().a_is_zero(); + } + 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 031e5cc34..8bb1a3044 100644 --- a/src/lib/pubkey/ec_group/ec_group.h +++ b/src/lib/pubkey/ec_group/ec_group.h @@ -132,6 +132,11 @@ class BOTAN_PUBLIC_API(2,0) EC_Group final bool a_is_minus_3() const; /** + * Return if a == 0 mod p + */ + bool a_is_zero() 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 6ec9be3e8..c980d4a24 100644 --- a/src/tests/unit_ecc.cpp +++ b/src/tests/unit_ecc.cpp @@ -298,6 +298,11 @@ class EC_Group_Tests : public Test else result.test_ne("Group " + group_name + " A does not equal -3", group.get_a(), group.get_p() - 3); + if(group.a_is_zero()) + result.test_eq("Group A is zero", group.get_a(), BigInt(0)); + else + result.test_ne("Group " + group_name + " A does not equal zero", group.get_a(), BigInt(0)); + // get a valid point Botan::PointGFp p = group.get_base_point() * Test::rng().next_nonzero_byte(); |