diff options
author | lloyd <[email protected]> | 2010-03-02 03:06:13 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-02 03:06:13 +0000 |
commit | 19e77947ee00b4db6b732ef3dabfdbb9ee2adfd6 (patch) | |
tree | 72e857635ad0f88d1229f598e8c2ae2f8a052755 | |
parent | 1fac460e94edf5c4dda296588a87476195f08c24 (diff) |
Kill ECKAEG_Op
-rw-r--r-- | src/engine/def_engine/def_pk_ops.cpp | 16 | ||||
-rw-r--r-- | src/engine/def_engine/default_engine.h | 6 | ||||
-rw-r--r-- | src/engine/engine.h | 12 | ||||
-rw-r--r-- | src/libstate/pk_engine.cpp | 21 | ||||
-rw-r--r-- | src/libstate/pk_engine.h | 11 | ||||
-rw-r--r-- | src/pubkey/ecdsa/info.txt | 2 | ||||
-rw-r--r-- | src/pubkey/eckaeg/eckaeg.cpp | 50 | ||||
-rw-r--r-- | src/pubkey/eckaeg/eckaeg.h | 23 | ||||
-rw-r--r-- | src/pubkey/eckaeg/eckaeg_core.cpp | 60 | ||||
-rw-r--r-- | src/pubkey/eckaeg/eckaeg_core.h | 44 | ||||
-rw-r--r-- | src/pubkey/eckaeg/eckaeg_op.cpp | 39 | ||||
-rw-r--r-- | src/pubkey/eckaeg/eckaeg_op.h | 49 |
12 files changed, 32 insertions, 301 deletions
diff --git a/src/engine/def_engine/def_pk_ops.cpp b/src/engine/def_engine/def_pk_ops.cpp index 177040805..e1040142e 100644 --- a/src/engine/def_engine/def_pk_ops.cpp +++ b/src/engine/def_engine/def_pk_ops.cpp @@ -27,10 +27,6 @@ #include <botan/dh_op.h> #endif -#if defined(BOTAN_HAS_ECKAEG) - #include <botan/eckaeg_op.h> -#endif - namespace Botan { #if defined(BOTAN_HAS_IF_PUBLIC_KEY_FAMILY) @@ -90,16 +86,4 @@ DH_Operation* Default_Engine::dh_op(const DL_Group& group, } #endif -#if defined(BOTAN_HAS_ECKAEG) -/* -* Acquire a ECKAEG op -*/ -ECKAEG_Operation* Default_Engine::eckaeg_op(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key) const - { - return new Default_ECKAEG_Op(dom_pars, priv_key, pub_key); - } -#endif - } diff --git a/src/engine/def_engine/default_engine.h b/src/engine/def_engine/default_engine.h index 5fe4c373b..aa753fadb 100644 --- a/src/engine/def_engine/default_engine.h +++ b/src/engine/def_engine/default_engine.h @@ -44,12 +44,6 @@ class Default_Engine : public Engine DH_Operation* dh_op(const DL_Group&, const BigInt&) const; #endif -#if defined(BOTAN_HAS_ECKAEG) - virtual ECKAEG_Operation* eckaeg_op(const EC_Domain_Params&, - const BigInt&, - const PointGFp&) const; -#endif - Modular_Exponentiator* mod_exp(const BigInt&, Power_Mod::Usage_Hints) const; diff --git a/src/engine/engine.h b/src/engine/engine.h index 8c1b9dd5f..ba5f95c27 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -39,11 +39,6 @@ #include <botan/elg_op.h> #endif -#if defined(BOTAN_HAS_ECKAEG) - #include <botan/eckaeg_op.h> - #include <botan/ec_dompar.h> -#endif - namespace Botan { class Algorithm_Factory; @@ -114,13 +109,6 @@ class BOTAN_DLL Engine virtual DH_Operation* dh_op(const DL_Group&, const BigInt&) const { return 0; } #endif - -#if defined(BOTAN_HAS_ECKAEG) - virtual ECKAEG_Operation* eckaeg_op(const EC_Domain_Params&, - const BigInt&, - const PointGFp&) const - { return 0; } -#endif }; } diff --git a/src/libstate/pk_engine.cpp b/src/libstate/pk_engine.cpp index 38fe17d73..ac2fa68b0 100644 --- a/src/libstate/pk_engine.cpp +++ b/src/libstate/pk_engine.cpp @@ -110,27 +110,6 @@ DH_Operation* dh_op(const DL_Group& group, const BigInt& x) } #endif -#if defined(BOTAN_HAS_ECKAEG) -/* -* Acquire a ECKAEG op -*/ -ECKAEG_Operation* eckaeg_op(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key) - { - Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory()); - - while(const Engine* engine = i.next()) - { - ECKAEG_Operation* op = engine->eckaeg_op(dom_pars, priv_key, pub_key); - if(op) - return op; - } - - throw Lookup_Error("Engine_Core::eckaeg_op: Unable to find a working engine"); - } -#endif - /* * Acquire a modular exponentiator */ diff --git a/src/libstate/pk_engine.h b/src/libstate/pk_engine.h index 6c45c3fca..25f326ef0 100644 --- a/src/libstate/pk_engine.h +++ b/src/libstate/pk_engine.h @@ -31,11 +31,6 @@ #include <botan/elg_op.h> #endif -#if defined(BOTAN_HAS_ECKAEG) - #include <botan/eckaeg_op.h> - #include <botan/ec_dompar.h> -#endif - namespace Botan { class Algorithm_Factory; @@ -71,12 +66,6 @@ ELG_Operation* elg_op(const DL_Group&, const BigInt&, const BigInt&); DH_Operation* dh_op(const DL_Group&, const BigInt&); #endif -#if defined(BOTAN_HAS_ECKAEG) -ECKAEG_Operation* eckaeg_op(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key); -#endif - } } diff --git a/src/pubkey/ecdsa/info.txt b/src/pubkey/ecdsa/info.txt index 799fff32f..ca2694ad1 100644 --- a/src/pubkey/ecdsa/info.txt +++ b/src/pubkey/ecdsa/info.txt @@ -1,11 +1,9 @@ define ECDSA <requires> -alloc asn1 ec_dompar ecc_key -libstate numbertheory rng </requires> diff --git a/src/pubkey/eckaeg/eckaeg.cpp b/src/pubkey/eckaeg/eckaeg.cpp index 639060f33..95b5afdbb 100644 --- a/src/pubkey/eckaeg/eckaeg.cpp +++ b/src/pubkey/eckaeg/eckaeg.cpp @@ -2,47 +2,23 @@ * ECKAEG implemenation * (C) 2007 Manuel Hartl, FlexSecure GmbH * 2007 Falko Strenzke, FlexSecure GmbH -* 2008 Jack Lloyd +* 2008-2010 Jack Lloyd * * Distributed under the terms of the Botan license */ #include <botan/eckaeg.h> -#include <botan/numthry.h> -#include <botan/der_enc.h> -#include <botan/ber_dec.h> -#include <botan/secmem.h> -#include <botan/point_gfp.h> namespace Botan { -void ECKAEG_PublicKey::X509_load_hook() - { - EC_PublicKey::X509_load_hook(); - m_eckaeg_core = ECKAEG_Core(domain(), 0, public_point()); - } - ECKAEG_PublicKey::ECKAEG_PublicKey(const EC_Domain_Params& dom_par, const PointGFp& pub_point) { domain_params = dom_par; public_key = pub_point; - if(domain().get_curve() != pub_point.get_curve()) + if(domain().get_curve() != public_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); - m_eckaeg_core = ECKAEG_Core(domain(), private_value(), public_point()); - } - -MemoryVector<byte> ECKAEG_PrivateKey::public_value() const - { - return EC2OSP(public_point(), PointGFp::UNCOMPRESSED); } ECKAEG_PrivateKey::ECKAEG_PrivateKey(RandomNumberGenerator& rng, @@ -50,7 +26,6 @@ ECKAEG_PrivateKey::ECKAEG_PrivateKey(RandomNumberGenerator& rng, { domain_params = dom_pars; generate_private_key(rng); - m_eckaeg_core = ECKAEG_Core(domain(), private_value(), public_point()); } /** @@ -62,7 +37,7 @@ SecureVector<byte> ECKAEG_PrivateKey::derive_key(const byte key[], MemoryVector<byte> key_x(key, key_len); // FIXME: nasty/slow PointGFp point = OS2ECP(key_x, public_point().get_curve()); - return m_eckaeg_core.agree(point); + return derive_key(point); } /** @@ -70,7 +45,24 @@ SecureVector<byte> ECKAEG_PrivateKey::derive_key(const byte key[], */ SecureVector<byte> ECKAEG_PrivateKey::derive_key(const ECKAEG_PublicKey& key) const { - return m_eckaeg_core.agree(key.public_point()); + return derive_key(key.public_point()); + } + +/** +* Derive a key +*/ +SecureVector<byte> ECKAEG_PrivateKey::derive_key(const PointGFp& point) const + { + const BigInt& cofactor = domain().get_cofactor(); + const BigInt& n = domain().get_order(); + + BigInt l = inverse_mod(cofactor, n); // can precompute this + + PointGFp S = (cofactor * point) * (private_value() * l); + S.check_invariants(); + + return BigInt::encode_1363(S.get_affine_x(), + point.get_curve().get_p().bytes()); } } diff --git a/src/pubkey/eckaeg/eckaeg.h b/src/pubkey/eckaeg/eckaeg.h index fbd263e82..6bc4340ac 100644 --- a/src/pubkey/eckaeg/eckaeg.h +++ b/src/pubkey/eckaeg/eckaeg.h @@ -2,7 +2,7 @@ * ECKAEG * (C) 2007 Falko Strenzke, FlexSecure GmbH * Manuel Hartl, FlexSecure GmbH -* (C) 2008 Jack Lloyd +* (C) 2008-2010 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -11,7 +11,6 @@ #define BOTAN_ECKAEG_KEY_H__ #include <botan/ecc_key.h> -#include <botan/eckaeg_core.h> namespace Botan { @@ -49,11 +48,6 @@ class BOTAN_DLL ECKAEG_PublicKey : public virtual EC_PublicKey * @result the maximum number of input bits */ u32bit max_input_bits() const { return domain().get_order().bits(); } - - protected: - void X509_load_hook(); - - ECKAEG_Core m_eckaeg_core; }; /** @@ -78,22 +72,27 @@ class BOTAN_DLL ECKAEG_PrivateKey : public ECKAEG_PublicKey, */ ECKAEG_PrivateKey() {} - MemoryVector<byte> public_value() const; - - void PKCS8_load_hook(bool = false); + MemoryVector<byte> public_value() const + { return EC2OSP(public_point(), PointGFp::UNCOMPRESSED); } /** - * Derive a shared key with the other partys public key. + * Derive a shared key with the other parties public key. * @param key the other partys public key * @param key_len the other partys public key */ SecureVector<byte> derive_key(const byte key[], u32bit key_len) const; /** - * Derive a shared key with the other partys public key. + * Derive a shared key with the other parties public key. * @param other the other partys public key */ SecureVector<byte> derive_key(const ECKAEG_PublicKey& other) const; + + /** + * Derive a shared key with the other parties public key. + * @param point the public point of the other parties key + */ + SecureVector<byte> derive_key(const PointGFp& point) const; }; } diff --git a/src/pubkey/eckaeg/eckaeg_core.cpp b/src/pubkey/eckaeg/eckaeg_core.cpp deleted file mode 100644 index e22a6dcfe..000000000 --- a/src/pubkey/eckaeg/eckaeg_core.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* -* ECKAEG Core -* (C) 1999-2010 Jack Lloyd -* (C) 2007 FlexSecure GmbH -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/eckaeg_core.h> -#include <botan/numthry.h> -#include <botan/internal/pk_engine.h> -#include <botan/parsing.h> -#include <algorithm> - -namespace Botan { - -/* -* ECKAEG_Core Constructor -*/ -ECKAEG_Core::ECKAEG_Core(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key) - { - op = Engine_Core::eckaeg_op(dom_pars, priv_key, pub_key); - } - -/* -* ECKAEG_Core Copy Constructor -*/ -ECKAEG_Core::ECKAEG_Core(const ECKAEG_Core& core) - { - op = 0; - if(core.op) - op = core.op->clone(); - blinder = core.blinder; - } - -/* -* ECKAEG_Core Assignment Operator -*/ -ECKAEG_Core& ECKAEG_Core::operator=(const ECKAEG_Core& core) - { - delete op; - if(core.op) - op = core.op->clone(); - blinder = core.blinder; - return (*this); - } - -/* -* ECKAEG Operation -*/ -SecureVector<byte> ECKAEG_Core::agree(const PointGFp& otherKey) const - { - if(op == 0) - throw Invalid_State("ECKAEG_Core: uninitialized"); - return op->agree(otherKey); - } - -} diff --git a/src/pubkey/eckaeg/eckaeg_core.h b/src/pubkey/eckaeg/eckaeg_core.h deleted file mode 100644 index d632c9451..000000000 --- a/src/pubkey/eckaeg/eckaeg_core.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -* ECKAEG Core -* (C) 1999-2007 Jack Lloyd -* (C) 2007 FlexSecure GmbH -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_ECKAEG_CORE_H__ -#define BOTAN_ECKAEG_CORE_H__ - -#include <botan/eckaeg_op.h> -#include <botan/blinding.h> -#include <botan/ec_dompar.h> - -namespace Botan { - -/* -* ECKAEG Core -*/ -class BOTAN_DLL ECKAEG_Core - { - public: - SecureVector<byte> agree(const PointGFp&) const; - - ECKAEG_Core& operator=(const ECKAEG_Core&); - - ECKAEG_Core() { op = 0; } - - ECKAEG_Core(const ECKAEG_Core&); - - ECKAEG_Core(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - PointGFp const& pub_key); - - ~ECKAEG_Core() { delete op; } - private: - ECKAEG_Operation* op; - Blinder blinder; - }; - -} - -#endif diff --git a/src/pubkey/eckaeg/eckaeg_op.cpp b/src/pubkey/eckaeg/eckaeg_op.cpp deleted file mode 100644 index 4fb0a23eb..000000000 --- a/src/pubkey/eckaeg/eckaeg_op.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -* ECKAEG Operation -* (C) 2007 FlexSecure GmbH -* 2008-2010 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/eckaeg_op.h> -#include <botan/numthry.h> - -namespace Botan { - -Default_ECKAEG_Op::Default_ECKAEG_Op(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key) - : m_dom_pars(dom_pars), - m_pub_key(pub_key), - m_priv_key(priv_key) - { - } - -SecureVector<byte> Default_ECKAEG_Op::agree(const PointGFp& i) const - { - BigInt cofactor = m_dom_pars.get_cofactor(); - BigInt n = m_dom_pars.get_order(); - - BigInt l = inverse_mod(cofactor, n); - - PointGFp S = cofactor * i; - S *= (m_priv_key * l) % n; - - S.check_invariants(); - - return BigInt::encode_1363(S.get_affine_x(), - S.get_curve().get_p().bytes()); - } - -} diff --git a/src/pubkey/eckaeg/eckaeg_op.h b/src/pubkey/eckaeg/eckaeg_op.h deleted file mode 100644 index 27cf4f367..000000000 --- a/src/pubkey/eckaeg/eckaeg_op.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -* ECKAEG Operations -* (C) 1999-2008 Jack Lloyd -* 2007 FlexSecure GmbH -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_ECKAEG_OPERATIONS_H__ -#define BOTAN_ECKAEG_OPERATIONS_H__ - -#include <botan/ec_dompar.h> - -namespace Botan { - -/* -* ECKAEG Operation -*/ -class BOTAN_DLL ECKAEG_Operation - { - public: - virtual SecureVector<byte> agree(const PointGFp&) const = 0; - virtual ECKAEG_Operation* clone() const = 0; - virtual ~ECKAEG_Operation() {} - }; - -/* -* Default ECKAEG operation -*/ -class BOTAN_DLL Default_ECKAEG_Op : public ECKAEG_Operation - { - public: - SecureVector<byte> agree(const PointGFp& i) const; - - ECKAEG_Operation* clone() const { return new Default_ECKAEG_Op(*this); } - - Default_ECKAEG_Op(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key); - private: - EC_Domain_Params m_dom_pars; - PointGFp m_pub_key; - BigInt m_priv_key; - }; - - -} - -#endif |