aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/ecc_key/ecc_key.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pubkey/ecc_key/ecc_key.cpp')
-rw-r--r--src/pubkey/ecc_key/ecc_key.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp
index f80e2bb15..4c91672d3 100644
--- a/src/pubkey/ecc_key/ecc_key.cpp
+++ b/src/pubkey/ecc_key/ecc_key.cpp
@@ -139,6 +139,29 @@ MemoryVector<byte> EC_PrivateKey::pkcs8_private_key() const
.get_contents();
}
+EC_PrivateKey::EC_PrivateKey(const AlgorithmIdentifier& alg_id,
+ const MemoryRegion<byte>& key_bits)
+ {
+ domain_params = EC_Domain_Params(alg_id.parameters);
+
+ u32bit version;
+ SecureVector<byte> octstr_secret;
+
+ BER_Decoder(key_bits)
+ .start_cons(SEQUENCE)
+ .decode(version)
+ .decode(octstr_secret, OCTET_STRING)
+ .verify_end()
+ .end_cons();
+
+ if(version != 1)
+ throw Decoding_Error("Wrong key format version for EC key");
+
+ private_key = BigInt::decode(octstr_secret, octstr_secret.size());
+
+ public_key = domain().get_base_point() * private_key;
+ }
+
/**
* Return the PKCS #8 public key decoder
*/