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 | |
parent | de89566f633d5ed807ca57a59cc1071f79fdded3 (diff) |
Add similar decoding constructors to the private keys
Diffstat (limited to 'src/pubkey/ecc_key')
-rw-r--r-- | src/pubkey/ecc_key/ecc_key.cpp | 23 | ||||
-rw-r--r-- | src/pubkey/ecc_key/ecc_key.h | 11 |
2 files changed, 30 insertions, 4 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 */ diff --git a/src/pubkey/ecc_key/ecc_key.h b/src/pubkey/ecc_key/ecc_key.h index 1b8ac3ff5..283813236 100644 --- a/src/pubkey/ecc_key/ecc_key.h +++ b/src/pubkey/ecc_key/ecc_key.h @@ -32,8 +32,6 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key { public: - EC_PublicKey() : domain_encoding(EC_DOMPAR_ENC_EXPLICIT) {} - EC_PublicKey(const EC_Domain_Params& dom_par, const PointGFp& pub_point); @@ -82,6 +80,8 @@ class BOTAN_DLL EC_PublicKey : public virtual Public_Key EC_Domain_Params_Encoding domain_format() const { return domain_encoding; } protected: + EC_PublicKey() : domain_encoding(EC_DOMPAR_ENC_EXPLICIT) {} + virtual void X509_load_hook(); EC_Domain_Params domain_params; @@ -96,14 +96,15 @@ class BOTAN_DLL EC_PrivateKey : public virtual EC_PublicKey, public virtual Private_Key { public: - EC_PrivateKey() {} - EC_PrivateKey(const EC_Domain_Params& domain, const BigInt& private_key); EC_PrivateKey(RandomNumberGenerator& rng, const EC_Domain_Params& domain); + EC_PrivateKey(const AlgorithmIdentifier& alg_id, + const MemoryRegion<byte>& key_bits); + virtual ~EC_PrivateKey() {} MemoryVector<byte> pkcs8_private_key() const; @@ -121,6 +122,8 @@ class BOTAN_DLL EC_PrivateKey : public virtual EC_PublicKey, */ const BigInt& private_value() const; protected: + EC_PrivateKey() {} + virtual void PKCS8_load_hook(bool = false); BigInt private_key; |