From 6156e00a49d610c4c72d70b34e4ba5cd15c7d82e Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Sat, 13 Jul 2024 19:27:45 -0400 Subject: [PATCH] Fix two ways we could end up with null internal states in the new ECC layer GH #4208 --- src/lib/pubkey/ec_group/ec_apoint.cpp | 7 +++++-- src/lib/pubkey/ec_group/ec_group.cpp | 12 +++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/lib/pubkey/ec_group/ec_apoint.cpp b/src/lib/pubkey/ec_group/ec_apoint.cpp index 1baa53bfc36..450e716ae34 100644 --- a/src/lib/pubkey/ec_group/ec_apoint.cpp +++ b/src/lib/pubkey/ec_group/ec_apoint.cpp @@ -65,8 +65,11 @@ EC_AffinePoint EC_AffinePoint::hash_to_curve_nu(const EC_Group& group, EC_AffinePoint::~EC_AffinePoint() = default; std::optional EC_AffinePoint::deserialize(const EC_Group& group, std::span bytes) { - auto pt = group._data()->point_deserialize(bytes); - return EC_AffinePoint(std::move(pt)); + if(auto pt = group._data()->point_deserialize(bytes)) { + return EC_AffinePoint(std::move(pt)); + } else { + return {}; + } } EC_AffinePoint EC_AffinePoint::g_mul(const EC_Scalar& scalar, RandomNumberGenerator& rng, std::vector& ws) { diff --git a/src/lib/pubkey/ec_group/ec_group.cpp b/src/lib/pubkey/ec_group/ec_group.cpp index a6ace709735..e7a7cbc265e 100644 --- a/src/lib/pubkey/ec_group/ec_group.cpp +++ b/src/lib/pubkey/ec_group/ec_group.cpp @@ -210,9 +210,15 @@ std::pair, bool> EC_Group::BER_decode_EC_group(st BER_Object obj = ber.get_next_object(); if(obj.type() == ASN1_Type::ObjectId) { - OID dom_par_oid; - BER_Decoder(bits).decode(dom_par_oid); - return std::make_pair(ec_group_data().lookup(dom_par_oid), false); + OID oid; + BER_Decoder(bits).decode(oid); + + auto data = ec_group_data().lookup(oid); + if(!data) { + throw Decoding_Error(fmt("Unknown namedCurve OID '{}'", oid.to_string())); + } + + return std::make_pair(data, false); } if(obj.type() == ASN1_Type::Sequence) {