aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2021-03-12 05:03:44 -0500
committerJack Lloyd <[email protected]>2021-03-12 05:03:44 -0500
commitf28b4f8fe96e32c31271eb36e19347b82ff9a568 (patch)
tree9cb3c16bf063089456cb4ae1ff3bf0db954065c2
parentb7655766c87b111aed4023657c162a8288f62b2b (diff)
Fix a case where EC_Groups were not merged as expected
Discussion in #2649
-rw-r--r--src/lib/pubkey/ec_group/ec_group.cpp16
-rw-r--r--src/tests/test_ec_group.cpp29
2 files changed, 45 insertions, 0 deletions
diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp
index 6ec68f7fa..df84a6219 100644
--- a/src/lib/pubkey/ec_group/ec_group.cpp
+++ b/src/lib/pubkey/ec_group/ec_group.cpp
@@ -64,6 +64,13 @@ class EC_Group_Data final
this->g_y() == g_y);
}
+ bool match(EC_Group_Data& other) const
+ {
+ return match(other.p(), other.a(), other.b(),
+ other.g_x(), other.g_y(),
+ other.order(), other.cofactor());
+ }
+
void set_oid(const OID& oid)
{
BOTAN_STATE_CHECK(m_oid.empty());
@@ -168,6 +175,15 @@ class EC_Group_Data_Map final
if(data)
{
+ for(auto curve : m_registered_curves)
+ {
+ if(curve->oid().empty() == true && curve->match(*data))
+ {
+ curve->set_oid(oid);
+ return curve;
+ }
+ }
+
m_registered_curves.push_back(data);
return data;
}
diff --git a/src/tests/test_ec_group.cpp b/src/tests/test_ec_group.cpp
index d13f01862..fbce81541 100644
--- a/src/tests/test_ec_group.cpp
+++ b/src/tests/test_ec_group.cpp
@@ -686,6 +686,34 @@ Test::Result test_ecc_registration()
return result;
}
+Test::Result test_ec_group_from_params()
+ {
+ Test::Result result("EC_Group from params");
+
+ Botan::EC_Group::clear_registered_curve_data();
+
+ // secp160r1 params
+ const Botan::BigInt p("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF");
+ const Botan::BigInt a("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC");
+ const Botan::BigInt b("0x1C97BEFC54BD7A8B65ACF89F81D4D4ADC565FA45");
+
+ const Botan::BigInt g_x("0x4A96B5688EF573284664698968C38BB913CBFC82");
+ const Botan::BigInt g_y("0x23A628553168947D59DCC912042351377AC5FB32");
+ const Botan::BigInt order("0x100000000000000000001F4C8F927AED3CA752257");
+
+ const Botan::OID oid("1.3.132.0.8");
+
+ Botan::EC_Group reg_group(p, a, b, g_x, g_y, order, 1);
+ // At this point the group may not have an OID depending on internal state
+
+ // But now we load the group from OID which causes the entries to merge
+ Botan::EC_Group group_from_oid(oid);
+
+ result.confirm("Group has correct OID", reg_group.get_curve_oid() == oid);
+
+ return result;
+ }
+
class ECC_Unit_Tests final : public Test
{
public:
@@ -705,6 +733,7 @@ class ECC_Unit_Tests final : public Test
results.push_back(test_enc_dec_uncompressed_112());
results.push_back(test_enc_dec_uncompressed_521());
results.push_back(test_ecc_registration());
+ results.push_back(test_ec_group_from_params());
return results;
}