From 3fb831f2e24ec1e3d7f8902d4aa5adceaf366f01 Mon Sep 17 00:00:00 2001 From: lloyd Date: Mon, 1 Mar 2010 23:05:00 +0000 Subject: Kill get_EC_Dom_Pars_by_oid --- checks/pk_bench.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'checks/pk_bench.cpp') diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index a0ea1d1d3..124872866 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -296,7 +296,8 @@ void benchmark_ecdsa(RandomNumberGenerator& rng, for(size_t j = 0; domains[j]; j++) { - EC_Domain_Params params = get_EC_Dom_Pars_by_oid(domains[j]); + OID oid(domains[j]); + EC_Domain_Params params(oid); u32bit pbits = params.get_curve().get_p().bits(); @@ -353,7 +354,8 @@ void benchmark_eckaeg(RandomNumberGenerator& rng, for(size_t j = 0; domains[j]; j++) { - EC_Domain_Params params = get_EC_Dom_Pars_by_oid(domains[j]); + OID oid(domains[j]); + EC_Domain_Params params(oid); u32bit pbits = params.get_curve().get_p().bits(); -- cgit v1.2.3 From 70d72cc1a843bb5e60c5f6ab27f2f3226f1333a3 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 2 Mar 2010 03:34:51 +0000 Subject: Rename ECKAEG to ECDH. As far as I can tell they are the same algorithm, I'm not sure where the old name came from though as literally the only hits for it on Google are botan-related. --- checks/eckaeg.cpp | 84 ++++++++++++++++++------------------ checks/pk_bench.cpp | 22 +++++----- doc/credits.txt | 2 +- doc/log.txt | 1 + src/pubkey/ecdh/ecdh.cpp | 72 +++++++++++++++++++++++++++++++ src/pubkey/ecdh/ecdh.h | 100 +++++++++++++++++++++++++++++++++++++++++++ src/pubkey/ecdh/info.txt | 10 +++++ src/pubkey/eckaeg/eckaeg.cpp | 68 ----------------------------- src/pubkey/eckaeg/eckaeg.h | 100 ------------------------------------------- src/pubkey/eckaeg/info.txt | 10 ----- 10 files changed, 236 insertions(+), 233 deletions(-) create mode 100644 src/pubkey/ecdh/ecdh.cpp create mode 100644 src/pubkey/ecdh/ecdh.h create mode 100644 src/pubkey/ecdh/info.txt delete mode 100644 src/pubkey/eckaeg/eckaeg.cpp delete mode 100644 src/pubkey/eckaeg/eckaeg.h delete mode 100644 src/pubkey/eckaeg/info.txt (limited to 'checks/pk_bench.cpp') diff --git a/checks/eckaeg.cpp b/checks/eckaeg.cpp index d8a3f61d8..748663eb6 100644 --- a/checks/eckaeg.cpp +++ b/checks/eckaeg.cpp @@ -1,30 +1,28 @@ -/****************************************************** -* ECKAEG tests * -* * -* (C) 2007 Manuel Hartl * -* hartl@flexsecure.de * -* 2008 Jack Lloyd * -******************************************************/ +/* +* ECDH tests +* +* (C) 2007 Manuel Hartl (hartl@flexsecure.de) +* 2008 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ #include #include "validate.h" #include "common.h" -#if defined(BOTAN_HAS_ECKAEG) +#if defined(BOTAN_HAS_ECDH) #include #include #include #include -#include +#include #include #include -#include -#include - using namespace Botan; #define CHECK_MESSAGE(expr, print) try { if(!(expr)) std::cout << print << "\n"; } catch(std::exception& e) { std::cout << __FUNCTION__ << ": " << e.what() << "\n"; } @@ -64,17 +62,17 @@ void test_eckaeg_normal_derivation(RandomNumberGenerator& rng) Botan::EC_Domain_Params dom_pars = Botan::EC_Domain_Params(curve, p_G, order, cofactor); /** - * begin ECKAEG + * begin ECDH */ // alices key (a key constructed by domain parameters IS an ephimeral key!) - Botan::ECKAEG_PrivateKey private_a(rng, dom_pars); - Botan::ECKAEG_PublicKey public_a = private_a; // Bob gets this + Botan::ECDH_PrivateKey private_a(rng, dom_pars); + Botan::ECDH_PublicKey public_a = private_a; // Bob gets this // Bob creates a key with a matching group - Botan::ECKAEG_PrivateKey private_b(rng, dom_pars); //public_a.getCurve() + Botan::ECDH_PrivateKey private_b(rng, dom_pars); //public_a.getCurve() // Bob sends the key back to Alice - Botan::ECKAEG_PublicKey public_b = private_b; // Alice gets this + Botan::ECDH_PublicKey public_b = private_b; // Alice gets this // Both of them create a key using their private key and the other's // public key @@ -102,8 +100,8 @@ void test_eckaeg_some_dp(RandomNumberGenerator& rng) Botan::OID oid(oids[i]); Botan::EC_Domain_Params dom_pars(oid); - Botan::ECKAEG_PrivateKey private_a(rng, dom_pars); - Botan::ECKAEG_PublicKey public_a = private_a; + Botan::ECDH_PrivateKey private_a(rng, dom_pars); + Botan::ECDH_PublicKey public_a = private_a; /*auto_ptr x509_key_enc = public_a.x509_encoder(); Botan::MemoryVector enc_key_a = Botan::DER_Encoder() .start_cons(Botan::SEQUENCE) @@ -112,8 +110,8 @@ void test_eckaeg_some_dp(RandomNumberGenerator& rng) .end_cons() .get_contents();*/ - Botan::ECKAEG_PrivateKey private_b(rng, dom_pars); - Botan::ECKAEG_PublicKey public_b = private_b; + Botan::ECDH_PrivateKey private_b(rng, dom_pars); + Botan::ECDH_PublicKey public_b = private_b; // to test the equivalence, we // use the direct derivation method here @@ -140,11 +138,11 @@ void test_eckaeg_der_derivation(RandomNumberGenerator& rng) Botan::OID oid(oids[i]); Botan::EC_Domain_Params dom_pars(oid); - Botan::ECKAEG_PrivateKey private_a(rng, dom_pars); - Botan::ECKAEG_PublicKey public_a = private_a; + Botan::ECDH_PrivateKey private_a(rng, dom_pars); + Botan::ECDH_PublicKey public_a = private_a; - Botan::ECKAEG_PrivateKey private_b(rng, dom_pars); - Botan::ECKAEG_PublicKey public_b = private_b; + Botan::ECDH_PrivateKey private_b(rng, dom_pars); + Botan::ECDH_PublicKey public_b = private_b; Botan::MemoryVector key_der_a = private_a.public_value(); Botan::MemoryVector key_der_b = private_b.public_value(); @@ -174,26 +172,26 @@ void test_eckaeg_cp_ctor_as_op(RandomNumberGenerator& rng) Botan::EC_Domain_Params dom_pars = Botan::EC_Domain_Params(curve, p_G, order, cofactor); /** - * begin ECKAEG + * begin ECDH */ // alices key (a key constructed by domain parameters IS an ephimeral key!) - Botan::ECKAEG_PrivateKey private_a(rng, dom_pars); - Botan::ECKAEG_PrivateKey private_a2(private_a); - Botan::ECKAEG_PrivateKey private_a3; + Botan::ECDH_PrivateKey private_a(rng, dom_pars); + Botan::ECDH_PrivateKey private_a2(private_a); + Botan::ECDH_PrivateKey private_a3; private_a3 = private_a2; Botan::DH_PrivateKey dh_pr_empty; Botan::DH_PublicKey dh_pub_empty; - Botan::ECKAEG_PublicKey public_a = private_a; // Bob gets this - Botan::ECKAEG_PublicKey public_a2(public_a); - Botan::ECKAEG_PublicKey public_a3; + Botan::ECDH_PublicKey public_a = private_a; // Bob gets this + Botan::ECDH_PublicKey public_a2(public_a); + Botan::ECDH_PublicKey public_a3; public_a3 = public_a; // Bob creates a key with a matching group - Botan::ECKAEG_PrivateKey private_b(rng, dom_pars); //public_a.getCurve() + Botan::ECDH_PrivateKey private_b(rng, dom_pars); //public_a.getCurve() // Bob sends the key back to Alice - Botan::ECKAEG_PublicKey public_b = private_b; // Alice gets this + Botan::ECDH_PublicKey public_b = private_b; // Alice gets this // Both of them create a key using their private key and the other's // public key @@ -213,7 +211,7 @@ void test_eckaeg_cp_ctor_as_op(RandomNumberGenerator& rng) } /** -* The following test tests whether ECKAEG keys exhibit correct behaviour when it is +* The following test tests whether ECDH keys exhibit correct behaviour when it is * attempted to use them in an uninitialized state */ void test_non_init_eckaeg_keys(RandomNumberGenerator& rng) @@ -233,13 +231,13 @@ void test_non_init_eckaeg_keys(RandomNumberGenerator& rng) Botan::EC_Domain_Params dom_pars = Botan::EC_Domain_Params(curve, p_G, order, cofactor); // alices key (a key constructed by domain parameters IS an emphemeral key!) - Botan::ECKAEG_PrivateKey private_a(rng, dom_pars); - Botan::ECKAEG_PrivateKey private_b(rng, dom_pars); + Botan::ECDH_PrivateKey private_a(rng, dom_pars); + Botan::ECDH_PrivateKey private_b(rng, dom_pars); - Botan::ECKAEG_PublicKey public_b; + Botan::ECDH_PublicKey public_b; - Botan::ECKAEG_PrivateKey private_empty; - Botan::ECKAEG_PublicKey public_empty; + Botan::ECDH_PrivateKey private_empty; + Botan::ECDH_PublicKey public_empty; bool exc1 = false; try @@ -251,7 +249,7 @@ void test_non_init_eckaeg_keys(RandomNumberGenerator& rng) exc1 = true; } - CHECK_MESSAGE(exc1, "there was no exception thrown when attempting to use an uninitialized ECKAEG key"); + CHECK_MESSAGE(exc1, "there was no exception thrown when attempting to use an uninitialized ECDH key"); bool exc2 = false; try @@ -263,14 +261,14 @@ void test_non_init_eckaeg_keys(RandomNumberGenerator& rng) exc2 = true; } - CHECK_MESSAGE(exc2, "there was no exception thrown when attempting to use an uninitialized ECKAEG key"); + CHECK_MESSAGE(exc2, "there was no exception thrown when attempting to use an uninitialized ECDH key"); } } u32bit do_eckaeg_tests(Botan::RandomNumberGenerator& rng) { - std::cout << "Testing ECKAEG (InSiTo unit tests): "; + std::cout << "Testing ECDH (InSiTo unit tests): "; test_eckaeg_normal_derivation(rng); test_eckaeg_some_dp(rng); diff --git a/checks/pk_bench.cpp b/checks/pk_bench.cpp index 124872866..e0970ebfb 100644 --- a/checks/pk_bench.cpp +++ b/checks/pk_bench.cpp @@ -45,8 +45,8 @@ #include #endif -#if defined(BOTAN_HAS_ECKAEG) - #include +#if defined(BOTAN_HAS_ECDH) + #include #endif using namespace Botan; @@ -338,7 +338,7 @@ void benchmark_ecdsa(RandomNumberGenerator& rng, #endif -#if defined(BOTAN_HAS_ECKAEG) +#if defined(BOTAN_HAS_ECDH) void benchmark_eckaeg(RandomNumberGenerator& rng, double seconds, @@ -365,15 +365,15 @@ void benchmark_eckaeg(RandomNumberGenerator& rng, while(kex_timer.seconds() < seconds) { keygen_timer.start(); - ECKAEG_PrivateKey eckaeg1(rng, params); + ECDH_PrivateKey eckaeg1(rng, params); keygen_timer.stop(); keygen_timer.start(); - ECKAEG_PrivateKey eckaeg2(rng, params); + ECDH_PrivateKey eckaeg2(rng, params); keygen_timer.stop(); - ECKAEG_PublicKey pub1(eckaeg1); - ECKAEG_PublicKey pub2(eckaeg2); + ECDH_PublicKey pub1(eckaeg1); + ECDH_PublicKey pub2(eckaeg2); SecureVector secret1, secret2; @@ -391,11 +391,11 @@ void benchmark_eckaeg(RandomNumberGenerator& rng, kex_timer.stop(); if(secret1 != secret2) - std::cerr << "ECKAEG secrets did not match, bug in the library!?!\n"; + std::cerr << "ECDH secrets did not match, bug in the library!?!\n"; } } - const std::string nm = "ECKAEG-" + to_string(pbits); + const std::string nm = "ECDH-" + to_string(pbits); report.report(nm, keygen_timer); report.report(nm, kex_timer); } @@ -672,8 +672,8 @@ void bench_pk(RandomNumberGenerator& rng, benchmark_ecdsa(rng, seconds, report); #endif -#if defined(BOTAN_HAS_ECKAEG) - if(algo == "All" || algo == "ECKAEG") +#if defined(BOTAN_HAS_ECDH) + if(algo == "All" || algo == "ECDH") benchmark_eckaeg(rng, seconds, report); #endif diff --git a/doc/credits.txt b/doc/credits.txt index ef2ee6bc1..67b318842 100644 --- a/doc/credits.txt +++ b/doc/credits.txt @@ -29,7 +29,7 @@ D: Windows porting N: Manuel Hartl E: hartl@flexsecure.de W: http://www.flexsecure.de/ -D: ECDSA, ECKAEG +D: ECDSA, ECDH N: Yves Jerschow E: yves.jerschow@uni-duesseldorf.de diff --git a/doc/log.txt b/doc/log.txt index 09564a01f..da624f223 100644 --- a/doc/log.txt +++ b/doc/log.txt @@ -12,6 +12,7 @@ - Add support for Win32 high resolution system timers - Changed S2K interface: derive_key now takes salt, iteration count - Remove dependency on TR1 for ECC and CVC code + - Renamed ECKAEG to its more usual name, ECDH - Fix crash in GMP_Engine if library is shutdown and reinitialized - Fix an invalid memory read in MD4 - Remove Timer class entirely diff --git a/src/pubkey/ecdh/ecdh.cpp b/src/pubkey/ecdh/ecdh.cpp new file mode 100644 index 000000000..2ddc371b2 --- /dev/null +++ b/src/pubkey/ecdh/ecdh.cpp @@ -0,0 +1,72 @@ +/* +* ECDH implemenation +* (C) 2007 Manuel Hartl, FlexSecure GmbH +* 2007 Falko Strenzke, FlexSecure GmbH +* 2008-2010 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include + +#include + +namespace Botan { + +ECDH_PublicKey::ECDH_PublicKey(const EC_Domain_Params& dom_par, + const PointGFp& pub_point) + { + domain_params = dom_par; + public_key = pub_point; + + if(domain().get_curve() != public_point().get_curve()) + throw Invalid_Argument("ECDH_PublicKey: curve mismatch in constructor"); + } + +ECDH_PrivateKey::ECDH_PrivateKey(RandomNumberGenerator& rng, + const EC_Domain_Params& dom_pars) + { + domain_params = dom_pars; + generate_private_key(rng); + } + +/** +* Derive a key +*/ +SecureVector ECDH_PrivateKey::derive_key(const byte key[], + u32bit key_len) const + { + MemoryVector key_x(key, key_len); // FIXME: nasty/slow + PointGFp point = OS2ECP(key_x, public_point().get_curve()); + + return derive_key(point); + } + +/** +* Derive a key +*/ +SecureVector ECDH_PrivateKey::derive_key(const ECDH_PublicKey& key) const + { + return derive_key(key.public_point()); + } + +/** +* Derive a key +*/ +SecureVector ECDH_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(); + + //PointGFp S = point * private_value(); + + return BigInt::encode_1363(S.get_affine_x(), + point.get_curve().get_p().bytes()); + } + +} diff --git a/src/pubkey/ecdh/ecdh.h b/src/pubkey/ecdh/ecdh.h new file mode 100644 index 000000000..632083dcc --- /dev/null +++ b/src/pubkey/ecdh/ecdh.h @@ -0,0 +1,100 @@ +/* +* ECDH +* (C) 2007 Falko Strenzke, FlexSecure GmbH +* Manuel Hartl, FlexSecure GmbH +* (C) 2008-2010 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_ECDH_KEY_H__ +#define BOTAN_ECDH_KEY_H__ + +#include + +namespace Botan { + +/** +* This class represents ECDH Public Keys. +*/ +class BOTAN_DLL ECDH_PublicKey : public virtual EC_PublicKey + { + public: + + /** + * Get this keys algorithm name. + * @result this keys algorithm name + */ + std::string algo_name() const { return "ECDH"; } + + /** + * Default constructor. Use this one if you want to later fill + * this object with data from an encoded key. + */ + ECDH_PublicKey() {} + + /** + * Construct a public key from a given public point. + * @param dom_par the domain parameters associated with this key + * @param public_point the public point defining this key + */ + ECDH_PublicKey(const EC_Domain_Params& dom_par, + const PointGFp& public_point); + + /** + * 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 { return domain().get_order().bits(); } + }; + +/** +* This class represents ECDH Private Keys. +*/ +class BOTAN_DLL ECDH_PrivateKey : public ECDH_PublicKey, + public EC_PrivateKey, + public PK_Key_Agreement_Key + { + public: + + /** + * Generate a new private key + * @param the domain parameters to used for this key + */ + ECDH_PrivateKey(RandomNumberGenerator& rng, + 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. + */ + ECDH_PrivateKey() {} + + MemoryVector public_value() const + { return EC2OSP(public_point(), PointGFp::UNCOMPRESSED); } + + /** + * 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 derive_key(const byte key[], u32bit key_len) const; + + /** + * Derive a shared key with the other parties public key. + * @param other the other partys public key + */ + SecureVector derive_key(const ECDH_PublicKey& other) const; + + /** + * Derive a shared key with the other parties public key. + * @param point the public point of the other parties key + */ + SecureVector derive_key(const PointGFp& point) const; + }; + +} + +#endif diff --git a/src/pubkey/ecdh/info.txt b/src/pubkey/ecdh/info.txt new file mode 100644 index 000000000..12826c81b --- /dev/null +++ b/src/pubkey/ecdh/info.txt @@ -0,0 +1,10 @@ +define ECDH + + +alloc +asn1 +ec_dompar +ecc_key +libstate +numbertheory + diff --git a/src/pubkey/eckaeg/eckaeg.cpp b/src/pubkey/eckaeg/eckaeg.cpp deleted file mode 100644 index 95b5afdbb..000000000 --- a/src/pubkey/eckaeg/eckaeg.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* -* ECKAEG implemenation -* (C) 2007 Manuel Hartl, FlexSecure GmbH -* 2007 Falko Strenzke, FlexSecure GmbH -* 2008-2010 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include - -namespace Botan { - -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() != public_point().get_curve()) - throw Invalid_Argument("ECKAEG_PublicKey: curve mismatch in constructor"); - } - -ECKAEG_PrivateKey::ECKAEG_PrivateKey(RandomNumberGenerator& rng, - const EC_Domain_Params& dom_pars) - { - domain_params = dom_pars; - generate_private_key(rng); - } - -/** -* Derive a key -*/ -SecureVector ECKAEG_PrivateKey::derive_key(const byte key[], - u32bit key_len) const - { - MemoryVector key_x(key, key_len); // FIXME: nasty/slow - PointGFp point = OS2ECP(key_x, public_point().get_curve()); - - return derive_key(point); - } - -/** -* Derive a key -*/ -SecureVector ECKAEG_PrivateKey::derive_key(const ECKAEG_PublicKey& key) const - { - return derive_key(key.public_point()); - } - -/** -* Derive a key -*/ -SecureVector 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 deleted file mode 100644 index 6bc4340ac..000000000 --- a/src/pubkey/eckaeg/eckaeg.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -* ECKAEG -* (C) 2007 Falko Strenzke, FlexSecure GmbH -* Manuel Hartl, FlexSecure GmbH -* (C) 2008-2010 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_ECKAEG_KEY_H__ -#define BOTAN_ECKAEG_KEY_H__ - -#include - -namespace Botan { - -/** -* This class represents ECKAEG Public Keys. -*/ -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. - */ - ECKAEG_PublicKey() {} - - /** - * Construct a public key from a given public point. - * @param dom_par the domain parameters associated with this key - * @param public_point the public point defining this key - */ - ECKAEG_PublicKey(const EC_Domain_Params& dom_par, - const PointGFp& public_point); - - /** - * 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 { return domain().get_order().bits(); } - }; - -/** -* This class represents ECKAEG Private Keys. -*/ -class BOTAN_DLL ECKAEG_PrivateKey : public ECKAEG_PublicKey, - public EC_PrivateKey, - public PK_Key_Agreement_Key - { - public: - - /** - * Generate a new private key - * @param the domain parameters to used for this key - */ - ECKAEG_PrivateKey(RandomNumberGenerator& rng, - 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() {} - - MemoryVector public_value() const - { return EC2OSP(public_point(), PointGFp::UNCOMPRESSED); } - - /** - * 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 derive_key(const byte key[], u32bit key_len) const; - - /** - * Derive a shared key with the other parties public key. - * @param other the other partys public key - */ - SecureVector 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 derive_key(const PointGFp& point) const; - }; - -} - -#endif diff --git a/src/pubkey/eckaeg/info.txt b/src/pubkey/eckaeg/info.txt deleted file mode 100644 index cac352a2a..000000000 --- a/src/pubkey/eckaeg/info.txt +++ /dev/null @@ -1,10 +0,0 @@ -define ECKAEG - - -alloc -asn1 -ec_dompar -ecc_key -libstate -numbertheory - -- cgit v1.2.3