From 3e953ddfac173bc54010eea92bbce917f9a32432 Mon Sep 17 00:00:00 2001 From: Patrick Wildt Date: Fri, 30 Jun 2017 11:12:54 +0200 Subject: ECC: use OID encoding if possible Instead of explicitly encoding the domain, encode them with the OID if the OID is available. This makes the ecdsa_sign test run with OpenSSL, since OpenSSL needs the OID explicitly set. --- src/lib/pubkey/ecc_key/ecc_key.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/lib/pubkey/ecc_key/ecc_key.cpp') diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp index 0c59c75fd..ad62f6ae3 100644 --- a/src/lib/pubkey/ecc_key/ecc_key.cpp +++ b/src/lib/pubkey/ecc_key/ecc_key.cpp @@ -30,9 +30,12 @@ size_t EC_PublicKey::estimated_strength() const EC_PublicKey::EC_PublicKey(const EC_Group& dom_par, const PointGFp& pub_point) : - m_domain_params(dom_par), m_public_key(pub_point), - m_domain_encoding(EC_DOMPAR_ENC_EXPLICIT) + m_domain_params(dom_par), m_public_key(pub_point) { + if (!dom_par.get_oid().empty()) + m_domain_encoding = EC_DOMPAR_ENC_OID; + else + m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT; if(domain().get_curve() != public_point().get_curve()) throw Invalid_Argument("EC_PublicKey: curve mismatch in constructor"); } @@ -40,9 +43,13 @@ EC_PublicKey::EC_PublicKey(const EC_Group& dom_par, EC_PublicKey::EC_PublicKey(const AlgorithmIdentifier& alg_id, const std::vector& key_bits) : m_domain_params{EC_Group(alg_id.parameters)}, - m_public_key{OS2ECP(key_bits, domain().get_curve())}, - m_domain_encoding{EC_DOMPAR_ENC_EXPLICIT} - {} + m_public_key{OS2ECP(key_bits, domain().get_curve())} + { + if (!domain().get_oid().empty()) + m_domain_encoding = EC_DOMPAR_ENC_OID; + else + m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT; + } bool EC_PublicKey::check_key(RandomNumberGenerator& rng, bool) const @@ -120,7 +127,10 @@ EC_PrivateKey::EC_PrivateKey(RandomNumberGenerator& rng, bool with_modular_inverse) { m_domain_params = ec_group; - m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT; + if (!ec_group.get_oid().empty()) + m_domain_encoding = EC_DOMPAR_ENC_OID; + else + m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT; if(x == 0) { -- cgit v1.2.3