diff options
author | lloyd <[email protected]> | 2008-10-13 20:59:52 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-10-13 20:59:52 +0000 |
commit | c0850c0afb4c177413c6be72bc8e96ab300a76fc (patch) | |
tree | 907c168adf7b1543490f79229f82f4c90ce1c8f6 /src/pubkey/eckaeg/eckaeg.cpp | |
parent | 5cd53808f058ed209a767a8c5ca01be29b5eedc0 (diff) |
Add ECKAEG benchmark. Fix several problems found in ECKAEG key (had pure virtuals)
Diffstat (limited to 'src/pubkey/eckaeg/eckaeg.cpp')
-rw-r--r-- | src/pubkey/eckaeg/eckaeg.cpp | 82 |
1 files changed, 48 insertions, 34 deletions
diff --git a/src/pubkey/eckaeg/eckaeg.cpp b/src/pubkey/eckaeg/eckaeg.cpp index 424715ad8..a8a32d812 100644 --- a/src/pubkey/eckaeg/eckaeg.cpp +++ b/src/pubkey/eckaeg/eckaeg.cpp @@ -24,29 +24,31 @@ void ECKAEG_PublicKey::affirm_init() const // virtual EC_PublicKey::affirm_init(); } -void ECKAEG_PublicKey::set_all_values ( ECKAEG_PublicKey const& other ) +void ECKAEG_PublicKey::set_all_values(ECKAEG_PublicKey const& other) { m_param_enc = other.m_param_enc; m_eckaeg_core = other.m_eckaeg_core; m_enc_public_point = other.m_enc_public_point; - if ( other.mp_dom_pars.get() ) + if(other.mp_dom_pars.get()) { - mp_dom_pars.reset ( new EC_Domain_Params ( * ( other.mp_dom_pars ) ) ); + mp_dom_pars.reset(new EC_Domain_Params(*(other.mp_dom_pars))); } - if ( other.mp_public_point.get() ) + if(other.mp_public_point.get()) { - mp_public_point.reset ( new PointGFp ( * ( other.mp_public_point ) ) ); + mp_public_point.reset(new PointGFp(*(other.mp_public_point))); } } -ECKAEG_PublicKey::ECKAEG_PublicKey ( ECKAEG_PublicKey const& other ) + +ECKAEG_PublicKey::ECKAEG_PublicKey(ECKAEG_PublicKey const& other) : Public_Key(), EC_PublicKey() { - set_all_values ( other ); + set_all_values(other); } -ECKAEG_PublicKey const& ECKAEG_PublicKey::operator= ( ECKAEG_PublicKey const& rhs ) + +ECKAEG_PublicKey const& ECKAEG_PublicKey::operator=(ECKAEG_PublicKey const& rhs) { - set_all_values ( rhs ); + set_all_values(rhs); return *this; } @@ -54,48 +56,49 @@ 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(*mp_dom_pars, BigInt(0), *mp_public_point); } -ECKAEG_PublicKey::ECKAEG_PublicKey ( EC_Domain_Params const& dom_par, PointGFp const& public_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 ) ); +ECKAEG_PublicKey::ECKAEG_PublicKey(EC_Domain_Params const& dom_par, PointGFp const& public_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 ); + m_eckaeg_core = ECKAEG_Core(*mp_dom_pars, BigInt(0), *mp_public_point); } - /********************************* -* ECKAEG_PrivateKey * +* ECKAEG_PrivateKey * *********************************/ void ECKAEG_PrivateKey::affirm_init() const // virtual { EC_PrivateKey::affirm_init(); } -void ECKAEG_PrivateKey::PKCS8_load_hook ( bool generated ) + +void ECKAEG_PrivateKey::PKCS8_load_hook(bool generated) { - EC_PrivateKey::PKCS8_load_hook ( 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 ); + m_eckaeg_core = ECKAEG_Core(*mp_dom_pars, m_private_value, *mp_public_point); } -void ECKAEG_PrivateKey::set_all_values ( ECKAEG_PrivateKey const& other ) + +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; m_enc_public_point = other.m_enc_public_point; - if ( other.mp_dom_pars.get() ) + if(other.mp_dom_pars.get()) { - mp_dom_pars.reset ( new EC_Domain_Params ( * ( other.mp_dom_pars ) ) ); + mp_dom_pars.reset(new EC_Domain_Params(*(other.mp_dom_pars))); } - if ( other.mp_public_point.get() ) + if(other.mp_public_point.get()) { - mp_public_point.reset ( new PointGFp ( * ( other.mp_public_point ) ) ); + mp_public_point.reset(new PointGFp(*(other.mp_public_point))); } } @@ -106,30 +109,41 @@ ECKAEG_PrivateKey::ECKAEG_PrivateKey(ECKAEG_PrivateKey const& other) ECKAEG_PublicKey(), EC_PrivateKey(), PK_Key_Agreement_Key() - { set_all_values(other); } + ECKAEG_PrivateKey const& ECKAEG_PrivateKey::operator= (ECKAEG_PrivateKey const& rhs) { set_all_values(rhs); return *this; } +MemoryVector<byte> ECKAEG_PrivateKey::public_value() const + { + return EC2OSP(public_point(), PointGFp::UNCOMPRESSED); + } + /** * Derive a key */ -SecureVector<byte> ECKAEG_PrivateKey::derive_key(const Public_Key& key) const +SecureVector<byte> ECKAEG_PrivateKey::derive_key(const byte key[], u32bit key_len) const + { + MemoryVector<byte> key_x(key, key_len); // XXX fix this, nasty/slow + PointGFp point = OS2ECP(key_x, public_point().get_curve()); + + return m_eckaeg_core.agree(point); + } + +/** +* Derive a key +*/ +SecureVector<byte> ECKAEG_PrivateKey::derive_key(const ECKAEG_PublicKey& key) const { affirm_init(); + key.affirm_init(); - const EC_PublicKey * p_ec_pk = dynamic_cast<const EC_PublicKey*>(&key); - if(!p_ec_pk) - { - throw Invalid_Argument("ECKAEG_PrivateKey::derive_key(): argument must be an EC_PublicKey"); - } - p_ec_pk->affirm_init(); - return m_eckaeg_core.agree ( p_ec_pk->public_point() ); + return m_eckaeg_core.agree(key.public_point()); } } |