aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorPatrick Wildt <[email protected]>2017-06-30 11:12:54 +0200
committerPatrick Wildt <[email protected]>2017-06-30 11:12:54 +0200
commit3e953ddfac173bc54010eea92bbce917f9a32432 (patch)
treec2c09737fbfddb57deeea61dd43511dcafc365b2 /src/lib
parent5b5a2cb5ceb3d160d04fd9f9a9ea670599e185cb (diff)
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.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/pubkey/ecc_key/ecc_key.cpp22
1 files changed, 16 insertions, 6 deletions
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<uint8_t>& 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)
{