aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--checks/pk_bench.cpp78
-rw-r--r--doc/log.txt2
-rw-r--r--src/pubkey/eckaeg/eckaeg.cpp82
-rw-r--r--src/pubkey/eckaeg/eckaeg.h13
4 files changed, 133 insertions, 42 deletions
diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp
index 2a26a6071..31c718421 100644
--- a/checks/pk_bench.cpp
+++ b/checks/pk_bench.cpp
@@ -36,6 +36,10 @@
#include <botan/ecdsa.h>
#endif
+#if defined(BOTAN_HAS_ECKAEG)
+ #include <botan/eckaeg.h>
+#endif
+
using namespace Botan;
#include "common.h"
@@ -297,6 +301,70 @@ void benchmark_ecdsa(RandomNumberGenerator& rng,
#endif
+#if defined(BOTAN_HAS_ECKAEG)
+
+void benchmark_eckaeg(RandomNumberGenerator& rng,
+ double seconds,
+ Benchmark_Report& report)
+ {
+ const char* domains[] = { "1.3.132.0.6", // secp112r1
+ "1.3.132.0.28", // secp128r1
+ "1.3.132.0.30", // secp160r2
+ "1.3.132.0.33", // secp224r1
+ "1.3.132.0.34", // secp384r1
+ "1.3.132.0.35", // secp512r1
+ NULL };
+
+ for(size_t j = 0; domains[j]; j++)
+ {
+ EC_Domain_Params params = get_EC_Dom_Pars_by_oid(domains[j]);
+
+ u32bit pbits = params.get_curve().get_p().bits();
+
+ Timer keygen_timer("keygen");
+ Timer kex_timer("kex");
+
+ while(kex_timer.seconds() < seconds)
+ {
+ keygen_timer.start();
+ ECKAEG_PrivateKey eckaeg1(rng, params);
+ keygen_timer.stop();
+
+ keygen_timer.start();
+ ECKAEG_PrivateKey eckaeg2(rng, params);
+ keygen_timer.stop();
+
+ ECKAEG_PublicKey pub1(eckaeg1);
+ ECKAEG_PublicKey pub2(eckaeg2);
+
+ SecureVector<byte> secret1, secret2;
+
+ for(u32bit i = 0; i != 1000; ++i)
+ {
+ if(kex_timer.seconds() > seconds)
+ break;
+
+ kex_timer.start();
+ secret1 = eckaeg1.derive_key(pub2);
+ kex_timer.stop();
+
+ kex_timer.start();
+ secret2 = eckaeg2.derive_key(pub1);
+ kex_timer.stop();
+
+ if(secret1 != secret2)
+ std::cerr << "ECKAEG secrets did not match, bug in the library!?!\n";
+ }
+ }
+
+ const std::string nm = "ECKAEG-" + to_string(pbits);
+ report.report(nm, keygen_timer);
+ report.report(nm, kex_timer);
+ }
+ }
+
+#endif
+
template<typename PRIV_KEY_TYPE>
void benchmark_dsa_nr(RandomNumberGenerator& rng,
double seconds,
@@ -352,7 +420,6 @@ void benchmark_dh(RandomNumberGenerator& rng,
Benchmark_Report& report)
{
#ifdef BOTAN_HAS_DIFFIE_HELLMAN
-
const char* domains[] = { "modp/ietf/768",
"modp/ietf/1024",
"modp/ietf/2048",
@@ -398,12 +465,8 @@ void benchmark_dh(RandomNumberGenerator& rng,
kex_timer.stop();
if(secret1 != secret2)
- {
std::cerr << "DH secrets did not match, bug in the library!?!\n";
- }
-
}
-
}
const std::string nm = "DH-" + split_on(domains[j], '/')[2];
@@ -512,6 +575,11 @@ void bench_pk(RandomNumberGenerator& rng,
benchmark_ecdsa(rng, seconds, report);
#endif
+#if defined(BOTAN_HAS_ECKAEG)
+ if(algo == "All" || algo == "ECKAEG")
+ benchmark_eckaeg(rng, seconds, report);
+#endif
+
if(algo == "All" || algo == "DH")
benchmark_dh(rng, seconds, report);
diff --git a/doc/log.txt b/doc/log.txt
index bd539ad1e..9a46a9bcc 100644
--- a/doc/log.txt
+++ b/doc/log.txt
@@ -1,7 +1,7 @@
* 1.7.18, ????-??-??
- - Add ECDSA benchmark
- Add Doxygen comments from InSiTo
+ - Add ECDSA and ECKAEG benchmarks
- Add configure.pl switch --with-tr1-implementation
- Fix configure.pl's --with-endian and --with-unaligned-mem options
- Optimize byteswap with x86 inline asm for Visual C++ by Yves Jerschow
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());
}
}
diff --git a/src/pubkey/eckaeg/eckaeg.h b/src/pubkey/eckaeg/eckaeg.h
index 609b13d79..9b0cd492c 100644
--- a/src/pubkey/eckaeg/eckaeg.h
+++ b/src/pubkey/eckaeg/eckaeg.h
@@ -101,13 +101,22 @@ class BOTAN_DLL ECKAEG_PrivateKey : public ECKAEG_PublicKey,
ECKAEG_PrivateKey(ECKAEG_PrivateKey const& other);
ECKAEG_PrivateKey const& operator=(ECKAEG_PrivateKey const& rhs);
+ MemoryVector<byte> public_value() const;
+
void PKCS8_load_hook(bool = false);
/**
* Derive a shared key with the other partys public key.
- * @param pub_key the other partys 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.
+ * @param other the other partys public key
*/
- SecureVector<byte> derive_key(const Public_Key& pub_key) const;
+ SecureVector<byte> derive_key(const ECKAEG_PublicKey& other) const;
/**
* Make sure that the public key parts of this object are set