diff options
author | lloyd <[email protected]> | 2010-03-04 03:49:35 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-04 03:49:35 +0000 |
commit | fe9aa5acece6c004f2c1c1aa4b23d7c44207672f (patch) | |
tree | 56bf2fc8378d965138e29074c23f645ed5d1a947 /src/pubkey/ecc_key/ecc_key.cpp | |
parent | de89566f633d5ed807ca57a59cc1071f79fdded3 (diff) |
Add similar decoding constructors to the private keys
Diffstat (limited to 'src/pubkey/ecc_key/ecc_key.cpp')
-rw-r--r-- | src/pubkey/ecc_key/ecc_key.cpp | 23 |
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 */ |