diff options
author | lloyd <[email protected]> | 2010-03-02 04:01:18 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-02 04:01:18 +0000 |
commit | b822cc605b324bf449fb3e0a2185b83cd4a157e3 (patch) | |
tree | f59b57f65e30a0c025c0c4265e591a9f507ac0ff /src/pubkey/ecc_key/ecc_key.cpp | |
parent | 510128ffd3789301305c7f1fe52a11b238a6a60b (diff) |
Add some simple constructors to the EC_ base key types to simplify
the various implementations
Diffstat (limited to 'src/pubkey/ecc_key/ecc_key.cpp')
-rw-r--r-- | src/pubkey/ecc_key/ecc_key.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/src/pubkey/ecc_key/ecc_key.cpp b/src/pubkey/ecc_key/ecc_key.cpp index 8273256cf..10968fa7e 100644 --- a/src/pubkey/ecc_key/ecc_key.cpp +++ b/src/pubkey/ecc_key/ecc_key.cpp @@ -17,6 +17,24 @@ namespace Botan { +EC_PublicKey::EC_PublicKey(const EC_Domain_Params& dom_par, + const PointGFp& pub_point) : + domain_params(dom_par), public_key(pub_point), + domain_encoding(EC_DOMPAR_ENC_EXPLICIT) + { + if(domain().get_curve() != public_point().get_curve()) + throw Invalid_Argument("EC_PublicKey: curve mismatch in constructor"); + + try + { + public_key.check_invariants(); + } + catch(Illegal_Point) + { + throw Invalid_State("Public key failed invariant check"); + } + } + void EC_PublicKey::X509_load_hook() { try @@ -97,7 +115,7 @@ void EC_PublicKey::set_parameter_encoding(EC_Domain_Params_Encoding form) const BigInt& EC_PrivateKey::private_value() const { if(private_key == 0) - throw Invalid_State("cannot use EC_PrivateKey when private key is uninitialized"); + throw Invalid_State("EC_PrivateKey::private_value - uninitialized"); return private_key; } @@ -105,10 +123,20 @@ const BigInt& EC_PrivateKey::private_value() const /** * EC_PrivateKey generator **/ -void EC_PrivateKey::generate_private_key(RandomNumberGenerator& rng) +EC_PrivateKey::EC_PrivateKey(const EC_Domain_Params& dom_par, + const BigInt& priv_key) : + EC_PublicKey(dom_par, dom_par.get_base_point() * private_key), + private_key(priv_key) + { + } + +/** +* EC_PrivateKey generator +**/ +EC_PrivateKey::EC_PrivateKey(RandomNumberGenerator& rng, + const EC_Domain_Params& dom_par) { - if(!domain().initialized()) - throw Invalid_State("Cannot generate new EC key, domain unset"); + domain_params = dom_par; private_key = BigInt::random_integer(rng, 1, domain().get_order()); public_key = domain().get_base_point() * private_key; @@ -119,7 +147,7 @@ void EC_PrivateKey::generate_private_key(RandomNumberGenerator& rng) } catch(Illegal_Point& e) { - throw Invalid_State(algo_name() + " key generation failed"); + throw Internal_Error("ECC private key generation failed"); } } |