aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/eckaeg
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-02 02:23:52 +0000
committerlloyd <[email protected]>2010-03-02 02:23:52 +0000
commit9c2131c935f052f3c783e3fd35e13f2908d02a98 (patch)
tree444176986153ed98216bc60c177bf49ef6606ef8 /src/pubkey/eckaeg
parent3435b04adf83c714d9907e85135db30a0e1d07c4 (diff)
Remove auto_ptr from ECC key types
Diffstat (limited to 'src/pubkey/eckaeg')
-rw-r--r--src/pubkey/eckaeg/eckaeg.cpp109
-rw-r--r--src/pubkey/eckaeg/eckaeg.h53
-rw-r--r--src/pubkey/eckaeg/eckaeg_core.cpp5
3 files changed, 28 insertions, 139 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());
}
diff --git a/src/pubkey/eckaeg/eckaeg.h b/src/pubkey/eckaeg/eckaeg.h
index 7c4dfdb2d..fbd263e82 100644
--- a/src/pubkey/eckaeg/eckaeg.h
+++ b/src/pubkey/eckaeg/eckaeg.h
@@ -23,6 +23,12 @@ class BOTAN_DLL ECKAEG_PublicKey : public virtual EC_PublicKey
public:
/**
+ * Get this keys algorithm name.
+ * @result this keys algorithm name
+ */
+ std::string algo_name() const { return "ECKAEG"; }
+
+ /**
* Default constructor. Use this one if you want to later fill
* this object with data from an encoded key.
*/
@@ -37,41 +43,17 @@ class BOTAN_DLL ECKAEG_PublicKey : public virtual EC_PublicKey
const PointGFp& public_point);
/**
- * Get this keys algorithm name.
- * @result this keys algorithm name
- */
- std::string algo_name() const { return "ECKAEG"; }
-
- /**
* Get the maximum number of bits allowed to be fed to this key.
* This is the bitlength of the order of the base point.
* @result the maximum number of input bits
*/
- u32bit max_input_bits() const
- {
- if(!mp_dom_pars.get())
- throw Invalid_State("ECKAEG_PublicKey::max_input_bits(): domain parameters not set");
-
- return mp_dom_pars->get_order().bits();
- }
-
- ECKAEG_PublicKey(ECKAEG_PublicKey const& other);
- ECKAEG_PublicKey const& operator= (ECKAEG_PublicKey const& rhs);
-
- /**
- * Make sure that the public point and domain parameters of this
- * key are set.
- * @throw Invalid_State if either of the two data members is not set
- */
- virtual void affirm_init() const;
+ u32bit max_input_bits() const { return domain().get_order().bits(); }
protected:
void X509_load_hook();
ECKAEG_Core m_eckaeg_core;
- private:
- void set_all_values(const ECKAEG_PublicKey& other);
};
/**
@@ -88,21 +70,13 @@ class BOTAN_DLL ECKAEG_PrivateKey : public ECKAEG_PublicKey,
* @param the domain parameters to used for this key
*/
ECKAEG_PrivateKey(RandomNumberGenerator& rng,
- const EC_Domain_Params& dom_pars)
- {
- mp_dom_pars = std::auto_ptr<EC_Domain_Params>(new EC_Domain_Params(dom_pars));
- generate_private_key(rng);
- mp_public_point->check_invariants();
- m_eckaeg_core = ECKAEG_Core(*mp_dom_pars, m_private_value, *mp_public_point);
- }
+ const EC_Domain_Params& dom_pars);
/**
* Default constructor. Use this one if you want to later fill this object with data
* from an encoded key.
*/
ECKAEG_PrivateKey() {}
- ECKAEG_PrivateKey(ECKAEG_PrivateKey const& other);
- ECKAEG_PrivateKey const& operator=(ECKAEG_PrivateKey const& rhs);
MemoryVector<byte> public_value() const;
@@ -120,17 +94,6 @@ class BOTAN_DLL ECKAEG_PrivateKey : public ECKAEG_PublicKey,
* @param other the other partys public key
*/
SecureVector<byte> derive_key(const ECKAEG_PublicKey& other) const;
-
- /**
- * Make sure that the public key parts of this object are set
- * (calls EC_PublicKey::affirm_init()) as well as the private key
- * value.
- * @throw Invalid_State if the above conditions are not satisfied
- */
- virtual void affirm_init() const;
-
- private:
- void set_all_values(const ECKAEG_PrivateKey& other);
};
}
diff --git a/src/pubkey/eckaeg/eckaeg_core.cpp b/src/pubkey/eckaeg/eckaeg_core.cpp
index eaf467933..e22a6dcfe 100644
--- a/src/pubkey/eckaeg/eckaeg_core.cpp
+++ b/src/pubkey/eckaeg/eckaeg_core.cpp
@@ -1,6 +1,6 @@
/*
* ECKAEG Core
-* (C) 1999-2007 Jack Lloyd
+* (C) 1999-2010 Jack Lloyd
* (C) 2007 FlexSecure GmbH
*
* Distributed under the terms of the Botan license
@@ -52,7 +52,8 @@ ECKAEG_Core& ECKAEG_Core::operator=(const ECKAEG_Core& core)
*/
SecureVector<byte> ECKAEG_Core::agree(const PointGFp& otherKey) const
{
- //assert(op.get());
+ if(op == 0)
+ throw Invalid_State("ECKAEG_Core: uninitialized");
return op->agree(otherKey);
}