diff options
author | lloyd <[email protected]> | 2010-03-02 02:23:52 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-02 02:23:52 +0000 |
commit | 9c2131c935f052f3c783e3fd35e13f2908d02a98 (patch) | |
tree | 444176986153ed98216bc60c177bf49ef6606ef8 /src/pubkey/eckaeg/eckaeg.cpp | |
parent | 3435b04adf83c714d9907e85135db30a0e1d07c4 (diff) |
Remove auto_ptr from ECC key types
Diffstat (limited to 'src/pubkey/eckaeg/eckaeg.cpp')
-rw-r--r-- | src/pubkey/eckaeg/eckaeg.cpp | 109 |
1 files changed, 17 insertions, 92 deletions
diff --git a/src/pubkey/eckaeg/eckaeg.cpp b/src/pubkey/eckaeg/eckaeg.cpp index fe47e3c31..639060f33 100644 --- a/src/pubkey/eckaeg/eckaeg.cpp +++ b/src/pubkey/eckaeg/eckaeg.cpp @@ -16,113 +16,41 @@ namespace Botan { -/* -* ECKAEG_PublicKey -*/ - -void ECKAEG_PublicKey::affirm_init() const // virtual - { - EC_PublicKey::affirm_init(); - } - -void ECKAEG_PublicKey::set_all_values(ECKAEG_PublicKey const& other) - { - m_param_enc = other.m_param_enc; - m_eckaeg_core = other.m_eckaeg_core; - - if(other.mp_dom_pars.get()) - { - mp_dom_pars.reset(new EC_Domain_Params(*(other.mp_dom_pars))); - } - if(other.mp_public_point.get()) - { - mp_public_point.reset(new PointGFp(*(other.mp_public_point))); - } - } - -ECKAEG_PublicKey::ECKAEG_PublicKey(ECKAEG_PublicKey const& other) - : Public_Key(), - EC_PublicKey() - { - set_all_values(other); - } - -ECKAEG_PublicKey const& ECKAEG_PublicKey::operator=(ECKAEG_PublicKey const& rhs) - { - set_all_values(rhs); - return *this; - } - void ECKAEG_PublicKey::X509_load_hook() { EC_PublicKey::X509_load_hook(); - EC_PublicKey::affirm_init(); - m_eckaeg_core = ECKAEG_Core(*mp_dom_pars, BigInt(0), *mp_public_point); + m_eckaeg_core = ECKAEG_Core(domain(), 0, public_point()); } -ECKAEG_PublicKey::ECKAEG_PublicKey(EC_Domain_Params const& dom_par, PointGFp const& public_point) +ECKAEG_PublicKey::ECKAEG_PublicKey(const EC_Domain_Params& dom_par, + const PointGFp& pub_point) { - mp_dom_pars = std::auto_ptr<EC_Domain_Params>(new EC_Domain_Params(dom_par)); - mp_public_point = std::auto_ptr<PointGFp>(new PointGFp(public_point)); - if(mp_public_point->get_curve() != mp_dom_pars->get_curve()) - { - throw Invalid_Argument("ECKAEG_PublicKey(): curve of arg. point and curve of arg. domain parameters are different"); - } - EC_PublicKey::affirm_init(); - m_eckaeg_core = ECKAEG_Core(*mp_dom_pars, BigInt(0), *mp_public_point); - } + domain_params = dom_par; + public_key = pub_point; -/* -* ECKAEG_PrivateKey -*/ -void ECKAEG_PrivateKey::affirm_init() const // virtual - { - EC_PrivateKey::affirm_init(); + if(domain().get_curve() != pub_point.get_curve()) + throw Invalid_Argument("ECKAEG_PublicKey: curve mismatch in constructor"); + + m_eckaeg_core = ECKAEG_Core(domain(), 0, public_point()); } void ECKAEG_PrivateKey::PKCS8_load_hook(bool generated) { EC_PrivateKey::PKCS8_load_hook(generated); - EC_PrivateKey::affirm_init(); - m_eckaeg_core = ECKAEG_Core(*mp_dom_pars, m_private_value, *mp_public_point); - } - -void ECKAEG_PrivateKey::set_all_values(ECKAEG_PrivateKey const& other) - { - m_private_value = other.m_private_value; - m_param_enc = other.m_param_enc; - m_eckaeg_core = other.m_eckaeg_core; - - if(other.mp_dom_pars.get()) - { - mp_dom_pars.reset(new EC_Domain_Params(*(other.mp_dom_pars))); - } - if(other.mp_public_point.get()) - { - mp_public_point.reset(new PointGFp(*(other.mp_public_point))); - } + m_eckaeg_core = ECKAEG_Core(domain(), private_value(), public_point()); } -ECKAEG_PrivateKey::ECKAEG_PrivateKey(ECKAEG_PrivateKey const& other) - : Public_Key(), - EC_PublicKey(), - Private_Key(), - ECKAEG_PublicKey(), - EC_PrivateKey(), - PK_Key_Agreement_Key() - { - set_all_values(other); - } - -ECKAEG_PrivateKey const& ECKAEG_PrivateKey::operator= (ECKAEG_PrivateKey const& rhs) +MemoryVector<byte> ECKAEG_PrivateKey::public_value() const { - set_all_values(rhs); - return *this; + return EC2OSP(public_point(), PointGFp::UNCOMPRESSED); } -MemoryVector<byte> ECKAEG_PrivateKey::public_value() const +ECKAEG_PrivateKey::ECKAEG_PrivateKey(RandomNumberGenerator& rng, + const EC_Domain_Params& dom_pars) { - return EC2OSP(public_point(), PointGFp::UNCOMPRESSED); + domain_params = dom_pars; + generate_private_key(rng); + m_eckaeg_core = ECKAEG_Core(domain(), private_value(), public_point()); } /** @@ -142,9 +70,6 @@ SecureVector<byte> ECKAEG_PrivateKey::derive_key(const byte key[], */ SecureVector<byte> ECKAEG_PrivateKey::derive_key(const ECKAEG_PublicKey& key) const { - affirm_init(); - key.affirm_init(); - return m_eckaeg_core.agree(key.public_point()); } |