aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/eckaeg
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-02 03:06:13 +0000
committerlloyd <[email protected]>2010-03-02 03:06:13 +0000
commit19e77947ee00b4db6b732ef3dabfdbb9ee2adfd6 (patch)
tree72e857635ad0f88d1229f598e8c2ae2f8a052755 /src/pubkey/eckaeg
parent1fac460e94edf5c4dda296588a87476195f08c24 (diff)
Kill ECKAEG_Op
Diffstat (limited to 'src/pubkey/eckaeg')
-rw-r--r--src/pubkey/eckaeg/eckaeg.cpp50
-rw-r--r--src/pubkey/eckaeg/eckaeg.h23
-rw-r--r--src/pubkey/eckaeg/eckaeg_core.cpp60
-rw-r--r--src/pubkey/eckaeg/eckaeg_core.h44
-rw-r--r--src/pubkey/eckaeg/eckaeg_op.cpp39
-rw-r--r--src/pubkey/eckaeg/eckaeg_op.h49
6 files changed, 32 insertions, 233 deletions
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