aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenĂ© Korthaus <[email protected]>2017-12-19 18:29:41 +0100
committerRenĂ© Korthaus <[email protected]>2017-12-19 18:29:41 +0100
commitf19ab7155d746fde5ce8b811576abb5a6ee0ff28 (patch)
tree4a24aec13ea45b76ab4bd6bc3f5a3180da42f927
parent1e9db1f1d3d4d04368a7f7da490230deb5b6431e (diff)
Always set domain encoding correctly when loading an ECC key
When loading an ECC key from file, the domain encoding was always set to explicit instead of depending on the encoded key file read. This resulted in different encodings and therefore different fingerprints of the same key when encoding the same key twice (once after generation, once after re-reading it).
-rw-r--r--src/lib/pubkey/ecc_key/ecc_key.cpp6
-rw-r--r--src/tests/unit_ecdsa.cpp2
2 files changed, 7 insertions, 1 deletions
diff --git a/src/lib/pubkey/ecc_key/ecc_key.cpp b/src/lib/pubkey/ecc_key/ecc_key.cpp
index 962cd3f45..6adb806ef 100644
--- a/src/lib/pubkey/ecc_key/ecc_key.cpp
+++ b/src/lib/pubkey/ecc_key/ecc_key.cpp
@@ -163,7 +163,11 @@ EC_PrivateKey::EC_PrivateKey(const AlgorithmIdentifier& alg_id,
bool with_modular_inverse)
{
m_domain_params = EC_Group(alg_id.parameters);
- m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
+
+ if (!domain().get_oid().empty())
+ m_domain_encoding = EC_DOMPAR_ENC_OID;
+ else
+ m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
OID key_parameters;
secure_vector<uint8_t> public_key_bits;
diff --git a/src/tests/unit_ecdsa.cpp b/src/tests/unit_ecdsa.cpp
index a406878fb..c8e879f97 100644
--- a/src/tests/unit_ecdsa.cpp
+++ b/src/tests/unit_ecdsa.cpp
@@ -216,6 +216,8 @@ Test::Result test_ecdsa_create_save_load()
std::unique_ptr<Botan::Private_Key> loaded_key(Botan::PKCS8::load_key(pem_src, Test::rng()));
Botan::ECDSA_PrivateKey* loaded_ec_key = dynamic_cast<Botan::ECDSA_PrivateKey*>(loaded_key.get());
result.confirm("the loaded key could be converted into an ECDSA_PrivateKey", loaded_ec_key);
+ result.confirm("the loaded key produces equal encoding",
+ (ecc_private_key_pem == Botan::PKCS8::PEM_encode(*loaded_ec_key)));
if(loaded_ec_key)
{