aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/eckaeg/eckaeg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pubkey/eckaeg/eckaeg.cpp')
-rw-r--r--src/pubkey/eckaeg/eckaeg.cpp50
1 files changed, 21 insertions, 29 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());
}
}