From 7438e2c57df90ea379745790de243b4b30aeb3e9 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Oct 2008 14:26:06 +0000 Subject: Move more of the public key implementation code out of the shared pk/pubkey directory and into algorithm specific modules. Even now, disabling a public key algorithm does leave some 'residual' code, but much less than before. Mark if_algo to only load if needed (if RW or RSA is loaded). However there seems to be a bug in the dependency handling in configure.pl - even if rsa and rw are disabled with --disable-modules, if_algo continues to be built. Will have to look at this later. --- src/pk/dh/dh_core.cpp | 67 ++++++++++++++++++++++++++++++++ src/pk/dh/dh_core.h | 38 ++++++++++++++++++ src/pk/dh/info.txt | 2 + src/pk/dsa/dsa_core.cpp | 67 ++++++++++++++++++++++++++++++++ src/pk/dsa/dsa_core.h | 36 +++++++++++++++++ src/pk/dsa/info.txt | 2 + src/pk/ecdsa/ecc_core.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++ src/pk/ecdsa/ecc_core.h | 74 +++++++++++++++++++++++++++++++++++ src/pk/ecdsa/info.txt | 2 + src/pk/elgamal/elg_core.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++ src/pk/elgamal/elg_core.h | 43 ++++++++++++++++++++ src/pk/elgamal/info.txt | 2 + src/pk/if_algo/if_core.cpp | 85 ++++++++++++++++++++++++++++++++++++++++ src/pk/if_algo/if_core.h | 44 +++++++++++++++++++++ src/pk/if_algo/info.txt | 4 +- src/pk/nr/info.txt | 2 + src/pk/nr/nr_core.cpp | 60 ++++++++++++++++++++++++++++ src/pk/nr/nr_core.h | 36 +++++++++++++++++ src/pk/pubkey/dh_core.cpp | 67 -------------------------------- src/pk/pubkey/dh_core.h | 38 ------------------ src/pk/pubkey/dsa_core.cpp | 67 -------------------------------- src/pk/pubkey/dsa_core.h | 36 ----------------- src/pk/pubkey/ecc_core.cpp | 95 --------------------------------------------- src/pk/pubkey/ecc_core.h | 74 ----------------------------------- src/pk/pubkey/elg_core.cpp | 95 --------------------------------------------- src/pk/pubkey/elg_core.h | 43 -------------------- src/pk/pubkey/if_core.cpp | 85 ---------------------------------------- src/pk/pubkey/if_core.h | 44 --------------------- src/pk/pubkey/info.txt | 12 ------ src/pk/pubkey/nr_core.cpp | 60 ---------------------------- src/pk/pubkey/nr_core.h | 36 ----------------- 31 files changed, 753 insertions(+), 753 deletions(-) create mode 100644 src/pk/dh/dh_core.cpp create mode 100644 src/pk/dh/dh_core.h create mode 100644 src/pk/dsa/dsa_core.cpp create mode 100644 src/pk/dsa/dsa_core.h create mode 100644 src/pk/ecdsa/ecc_core.cpp create mode 100644 src/pk/ecdsa/ecc_core.h create mode 100644 src/pk/elgamal/elg_core.cpp create mode 100644 src/pk/elgamal/elg_core.h create mode 100644 src/pk/if_algo/if_core.cpp create mode 100644 src/pk/if_algo/if_core.h create mode 100644 src/pk/nr/nr_core.cpp create mode 100644 src/pk/nr/nr_core.h delete mode 100644 src/pk/pubkey/dh_core.cpp delete mode 100644 src/pk/pubkey/dh_core.h delete mode 100644 src/pk/pubkey/dsa_core.cpp delete mode 100644 src/pk/pubkey/dsa_core.h delete mode 100644 src/pk/pubkey/ecc_core.cpp delete mode 100644 src/pk/pubkey/ecc_core.h delete mode 100644 src/pk/pubkey/elg_core.cpp delete mode 100644 src/pk/pubkey/elg_core.h delete mode 100644 src/pk/pubkey/if_core.cpp delete mode 100644 src/pk/pubkey/if_core.h delete mode 100644 src/pk/pubkey/nr_core.cpp delete mode 100644 src/pk/pubkey/nr_core.h diff --git a/src/pk/dh/dh_core.cpp b/src/pk/dh/dh_core.cpp new file mode 100644 index 000000000..a0586c444 --- /dev/null +++ b/src/pk/dh/dh_core.cpp @@ -0,0 +1,67 @@ +/************************************************* +* PK Algorithm Core Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include +#include + +namespace Botan { + +namespace { + +const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS; + +} + +/************************************************* +* DH_Core Constructor * +*************************************************/ +DH_Core::DH_Core(RandomNumberGenerator& rng, + const DL_Group& group, const BigInt& x) + { + op = Engine_Core::dh_op(group, x); + + const BigInt& p = group.get_p(); + + BigInt k(rng, std::min(p.bits()-1, BLINDING_BITS)); + + if(k != 0) + blinder = Blinder(k, power_mod(inverse_mod(k, p), x, p), p); + } + +/************************************************* +* DH_Core Copy Constructor * +*************************************************/ +DH_Core::DH_Core(const DH_Core& core) + { + op = 0; + if(core.op) + op = core.op->clone(); + blinder = core.blinder; + } + +/************************************************* +* DH_Core Assignment Operator * +*************************************************/ +DH_Core& DH_Core::operator=(const DH_Core& core) + { + delete op; + if(core.op) + op = core.op->clone(); + blinder = core.blinder; + return (*this); + } + +/************************************************* +* DH Operation * +*************************************************/ +BigInt DH_Core::agree(const BigInt& i) const + { + return blinder.unblind(op->agree(blinder.blind(i))); + } + +} diff --git a/src/pk/dh/dh_core.h b/src/pk/dh/dh_core.h new file mode 100644 index 000000000..3735f31e1 --- /dev/null +++ b/src/pk/dh/dh_core.h @@ -0,0 +1,38 @@ +/************************************************* +* DH Core Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_DH_CORE_H__ +#define BOTAN_DH_CORE_H__ + +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* DH Core * +*************************************************/ +class BOTAN_DLL DH_Core + { + public: + BigInt agree(const BigInt&) const; + + DH_Core& operator=(const DH_Core&); + + DH_Core() { op = 0; } + DH_Core(const DH_Core&); + DH_Core(RandomNumberGenerator& rng, + const DL_Group&, const BigInt&); + ~DH_Core() { delete op; } + private: + DH_Operation* op; + Blinder blinder; + }; + +} + +#endif diff --git a/src/pk/dh/info.txt b/src/pk/dh/info.txt index 34e77ddb8..3765644c8 100644 --- a/src/pk/dh/info.txt +++ b/src/pk/dh/info.txt @@ -7,6 +7,8 @@ load_on auto dh.cpp dh.h +dh_core.cpp +dh_core.h diff --git a/src/pk/dsa/dsa_core.cpp b/src/pk/dsa/dsa_core.cpp new file mode 100644 index 000000000..aba1e61fb --- /dev/null +++ b/src/pk/dsa/dsa_core.cpp @@ -0,0 +1,67 @@ +/************************************************* +* DSA Core Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include +#include + +namespace Botan { + +namespace { + +const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS; + +} + +/************************************************* +* DSA_Core Constructor * +*************************************************/ +DSA_Core::DSA_Core(const DL_Group& group, const BigInt& y, const BigInt& x) + { + op = Engine_Core::dsa_op(group, y, x); + } + +/************************************************* +* DSA_Core Copy Constructor * +*************************************************/ +DSA_Core::DSA_Core(const DSA_Core& core) + { + op = 0; + if(core.op) + op = core.op->clone(); + } + +/************************************************* +* DSA_Core Assignment Operator * +*************************************************/ +DSA_Core& DSA_Core::operator=(const DSA_Core& core) + { + delete op; + if(core.op) + op = core.op->clone(); + return (*this); + } + +/************************************************* +* DSA Verification Operation * +*************************************************/ +bool DSA_Core::verify(const byte msg[], u32bit msg_length, + const byte sig[], u32bit sig_length) const + { + return op->verify(msg, msg_length, sig, sig_length); + } + +/************************************************* +* DSA Signature Operation * +*************************************************/ +SecureVector DSA_Core::sign(const byte in[], u32bit length, + const BigInt& k) const + { + return op->sign(in, length, k); + } + +} diff --git a/src/pk/dsa/dsa_core.h b/src/pk/dsa/dsa_core.h new file mode 100644 index 000000000..467f3c23f --- /dev/null +++ b/src/pk/dsa/dsa_core.h @@ -0,0 +1,36 @@ +/************************************************* +* DSA Core Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_DSA_CORE_H__ +#define BOTAN_DSA_CORE_H__ + +#include +#include +#include + +namespace Botan { + +/************************************************* +* DSA Core * +*************************************************/ +class BOTAN_DLL DSA_Core + { + public: + SecureVector sign(const byte[], u32bit, const BigInt&) const; + bool verify(const byte[], u32bit, const byte[], u32bit) const; + + DSA_Core& operator=(const DSA_Core&); + + DSA_Core() { op = 0; } + DSA_Core(const DSA_Core&); + DSA_Core(const DL_Group&, const BigInt&, const BigInt& = 0); + ~DSA_Core() { delete op; } + private: + DSA_Operation* op; + }; + +} + +#endif diff --git a/src/pk/dsa/info.txt b/src/pk/dsa/info.txt index 74cd08144..e98f33ca9 100644 --- a/src/pk/dsa/info.txt +++ b/src/pk/dsa/info.txt @@ -7,6 +7,8 @@ load_on auto dsa.cpp dsa.h +dsa_core.cpp +dsa_core.h diff --git a/src/pk/ecdsa/ecc_core.cpp b/src/pk/ecdsa/ecc_core.cpp new file mode 100644 index 000000000..8d1d48b49 --- /dev/null +++ b/src/pk/ecdsa/ecc_core.cpp @@ -0,0 +1,95 @@ +/************************************************* +* ECDSA/ECKAEG Core Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include +#include + +namespace Botan { + +#if defined(BOTAN_HAS_ECDSA) + +/************************************************* +* 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 ECKAEG_Core::agree(const PointGFp& otherKey) const + { + //assert(op.get()); + return op->agree(otherKey); + } + +/************************************************* +* ECDSA Operation * +*************************************************/ +bool ECDSA_Core::verify(const byte signature[], u32bit sig_len, + const byte message[], u32bit mess_len) const + { + //assert(op.get()); + return op->verify(signature, sig_len, message, mess_len); + } + +SecureVector ECDSA_Core::sign(const byte message[], u32bit mess_len) const + { + //assert(op.get()); + return op->sign(message, mess_len); + } + +ECDSA_Core& ECDSA_Core::operator=(const ECDSA_Core& core) + { + delete op; + if(core.op) + op = core.op->clone(); + return (*this); + } + +ECDSA_Core::ECDSA_Core(const ECDSA_Core& core) + { + op = 0; + if(core.op) + op = core.op->clone(); + } + +ECDSA_Core::ECDSA_Core(EC_Domain_Params const& dom_pars, const BigInt& priv_key, PointGFp const& pub_key) + { + op = Engine_Core::ecdsa_op(dom_pars, priv_key, pub_key); + } +#endif + +} diff --git a/src/pk/ecdsa/ecc_core.h b/src/pk/ecdsa/ecc_core.h new file mode 100644 index 000000000..1124eaa2f --- /dev/null +++ b/src/pk/ecdsa/ecc_core.h @@ -0,0 +1,74 @@ +/************************************************* +* ECC Core Header File * +* (C) 1999-2007 Jack Lloyd * +* (C) 2007 FlexSecure GmbH * +*************************************************/ + +#ifndef BOTAN_ECC_CORE_H__ +#define BOTAN_ECC_CORE_H__ + +#include +#include +#include + +#if defined(BOTAN_HAS_ECDSA) + #include +#endif + +namespace Botan { + +#if defined(BOTAN_HAS_ECDSA) +/************************************************* +* ECDSA Core * +*************************************************/ +class ECDSA_Core + { + public: + bool verify(const byte signature[], u32bit sig_len, + const byte message[], u32bit mess_len) const; + + SecureVector sign(const byte message[], u32bit mess_len) const; + + ECDSA_Core& operator=(const ECDSA_Core&); + + ECDSA_Core() { op = 0; } + + ECDSA_Core(const ECDSA_Core&); + + ECDSA_Core(const EC_Domain_Params& dom_pars, + const BigInt& priv_key, + const PointGFp& pub_key); + + ~ECDSA_Core() { delete op; } + private: + ECDSA_Operation* op; + }; + +/************************************************* +* ECKAEG Core * +*************************************************/ +class ECKAEG_Core + { + public: + SecureVector 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 + +} + +#endif diff --git a/src/pk/ecdsa/info.txt b/src/pk/ecdsa/info.txt index 19891d52b..699c62214 100644 --- a/src/pk/ecdsa/info.txt +++ b/src/pk/ecdsa/info.txt @@ -7,6 +7,8 @@ load_on auto ec.cpp ec.h +ecc_core.cpp +ecc_core.h ecdsa.cpp ecdsa.h diff --git a/src/pk/elgamal/elg_core.cpp b/src/pk/elgamal/elg_core.cpp new file mode 100644 index 000000000..1181e7534 --- /dev/null +++ b/src/pk/elgamal/elg_core.cpp @@ -0,0 +1,95 @@ +/************************************************* +* ElGamal Core Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include +#include + +namespace Botan { + +namespace { + +const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS; + +} + +/************************************************* +* ELG_Core Constructor * +*************************************************/ +ELG_Core::ELG_Core(const DL_Group& group, const BigInt& y) + { + op = Engine_Core::elg_op(group, y, 0); + p_bytes = 0; + } + +/************************************************* +* ELG_Core Constructor * +*************************************************/ +ELG_Core::ELG_Core(RandomNumberGenerator& rng, + const DL_Group& group, const BigInt& y, const BigInt& x) + { + op = Engine_Core::elg_op(group, y, x); + + const BigInt& p = group.get_p(); + p_bytes = p.bytes(); + + if(BLINDING_BITS) + { + BigInt k(rng, std::min(p.bits()-1, BLINDING_BITS)); + blinder = Blinder(k, power_mod(k, x, p), p); + } + } + +/************************************************* +* ELG_Core Copy Constructor * +*************************************************/ +ELG_Core::ELG_Core(const ELG_Core& core) + { + op = 0; + if(core.op) + op = core.op->clone(); + blinder = core.blinder; + p_bytes = core.p_bytes; + } + +/************************************************* +* ELG_Core Assignment Operator * +*************************************************/ +ELG_Core& ELG_Core::operator=(const ELG_Core& core) + { + delete op; + if(core.op) + op = core.op->clone(); + blinder = core.blinder; + p_bytes = core.p_bytes; + return (*this); + } + +/************************************************* +* ElGamal Encrypt Operation * +*************************************************/ +SecureVector ELG_Core::encrypt(const byte in[], u32bit length, + const BigInt& k) const + { + return op->encrypt(in, length, k); + } + +/************************************************* +* ElGamal Decrypt Operation * +*************************************************/ +SecureVector ELG_Core::decrypt(const byte in[], u32bit length) const + { + if(length != 2*p_bytes) + throw Invalid_Argument("ELG_Core::decrypt: Invalid message"); + + BigInt a(in, p_bytes); + BigInt b(in + p_bytes, p_bytes); + + return BigInt::encode(blinder.unblind(op->decrypt(blinder.blind(a), b))); + } + +} diff --git a/src/pk/elgamal/elg_core.h b/src/pk/elgamal/elg_core.h new file mode 100644 index 000000000..67966a452 --- /dev/null +++ b/src/pk/elgamal/elg_core.h @@ -0,0 +1,43 @@ +/************************************************* +* ElGamal Core Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_ELGAMAL_CORE_H__ +#define BOTAN_ELGAMAL_CORE_H__ + +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* ElGamal Core * +*************************************************/ +class BOTAN_DLL ELG_Core + { + public: + SecureVector encrypt(const byte[], u32bit, const BigInt&) const; + SecureVector decrypt(const byte[], u32bit) const; + + ELG_Core& operator=(const ELG_Core&); + + ELG_Core() { op = 0; } + ELG_Core(const ELG_Core&); + + ELG_Core(const DL_Group&, const BigInt&); + ELG_Core(RandomNumberGenerator&, const DL_Group&, + const BigInt&, const BigInt&); + + ~ELG_Core() { delete op; } + private: + ELG_Operation* op; + Blinder blinder; + u32bit p_bytes; + }; + +} + +#endif diff --git a/src/pk/elgamal/info.txt b/src/pk/elgamal/info.txt index 541c7905e..96586480b 100644 --- a/src/pk/elgamal/info.txt +++ b/src/pk/elgamal/info.txt @@ -7,6 +7,8 @@ load_on auto elgamal.cpp elgamal.h +elg_core.cpp +elg_core.h diff --git a/src/pk/if_algo/if_core.cpp b/src/pk/if_algo/if_core.cpp new file mode 100644 index 000000000..97cacf9d8 --- /dev/null +++ b/src/pk/if_algo/if_core.cpp @@ -0,0 +1,85 @@ +/************************************************* +* IF Algorithm Core Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include +#include + +namespace Botan { + +namespace { + +const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS; + +} + +/************************************************* +* IF_Core Constructor * +*************************************************/ +IF_Core::IF_Core(const BigInt& e, const BigInt& n) + { + op = Engine_Core::if_op(e, n, 0, 0, 0, 0, 0, 0); + } + + +/************************************************* +* IF_Core Constructor * +*************************************************/ +IF_Core::IF_Core(RandomNumberGenerator& rng, + const BigInt& e, const BigInt& n, const BigInt& d, + const BigInt& p, const BigInt& q, + const BigInt& d1, const BigInt& d2, const BigInt& c) + { + op = Engine_Core::if_op(e, n, d, p, q, d1, d2, c); + + if(BLINDING_BITS) + { + BigInt k(rng, std::min(n.bits()-1, BLINDING_BITS)); + blinder = Blinder(power_mod(k, e, n), inverse_mod(k, n), n); + } + } + +/************************************************* +* IF_Core Copy Constructor * +*************************************************/ +IF_Core::IF_Core(const IF_Core& core) + { + op = 0; + if(core.op) + op = core.op->clone(); + blinder = core.blinder; + } + +/************************************************* +* IF_Core Assignment Operator * +*************************************************/ +IF_Core& IF_Core::operator=(const IF_Core& core) + { + delete op; + if(core.op) + op = core.op->clone(); + blinder = core.blinder; + return (*this); + } + +/************************************************* +* IF Public Operation * +*************************************************/ +BigInt IF_Core::public_op(const BigInt& i) const + { + return op->public_op(i); + } + +/************************************************* +* IF Private Operation * +*************************************************/ +BigInt IF_Core::private_op(const BigInt& i) const + { + return blinder.unblind(op->private_op(blinder.blind(i))); + } + +} diff --git a/src/pk/if_algo/if_core.h b/src/pk/if_algo/if_core.h new file mode 100644 index 000000000..b6afad950 --- /dev/null +++ b/src/pk/if_algo/if_core.h @@ -0,0 +1,44 @@ +/************************************************* +* IF Algorithm Core Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_IF_CORE_H__ +#define BOTAN_IF_CORE_H__ + +#include +#include +#include + +namespace Botan { + +/************************************************* +* IF Core * +*************************************************/ +class BOTAN_DLL IF_Core + { + public: + BigInt public_op(const BigInt&) const; + BigInt private_op(const BigInt&) const; + + IF_Core& operator=(const IF_Core&); + + IF_Core() { op = 0; } + IF_Core(const IF_Core&); + + IF_Core(const BigInt&, const BigInt&); + + IF_Core(RandomNumberGenerator& rng, + const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&, + const BigInt&, const BigInt&, const BigInt&); + + ~IF_Core() { delete op; } + private: + IF_Operation* op; + Blinder blinder; + }; + +} + +#endif diff --git a/src/pk/if_algo/info.txt b/src/pk/if_algo/info.txt index e8d582c00..af1726414 100644 --- a/src/pk/if_algo/info.txt +++ b/src/pk/if_algo/info.txt @@ -2,11 +2,13 @@ realname "Integer Factorization Algorithms" define IF_PUBLIC_KEY_FAMILY -load_on auto +load_on required if_algo.cpp if_algo.h +if_core.cpp +if_core.h diff --git a/src/pk/nr/info.txt b/src/pk/nr/info.txt index 4032a9825..f7325d984 100644 --- a/src/pk/nr/info.txt +++ b/src/pk/nr/info.txt @@ -7,6 +7,8 @@ load_on auto nr.cpp nr.h +nr_core.cpp +nr_core.h diff --git a/src/pk/nr/nr_core.cpp b/src/pk/nr/nr_core.cpp new file mode 100644 index 000000000..f9dfa4024 --- /dev/null +++ b/src/pk/nr/nr_core.cpp @@ -0,0 +1,60 @@ +/************************************************* +* NR Core Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include +#include +#include +#include +#include + +namespace Botan { + +/************************************************* +* NR_Core Constructor * +*************************************************/ +NR_Core::NR_Core(const DL_Group& group, const BigInt& y, const BigInt& x) + { + op = Engine_Core::nr_op(group, y, x); + } + +/************************************************* +* NR_Core Copy Constructor * +*************************************************/ +NR_Core::NR_Core(const NR_Core& core) + { + op = 0; + if(core.op) + op = core.op->clone(); + } + +/************************************************* +* NR_Core Assignment Operator * +*************************************************/ +NR_Core& NR_Core::operator=(const NR_Core& core) + { + delete op; + if(core.op) + op = core.op->clone(); + return (*this); + } + +/************************************************* +* NR Verification Operation * +*************************************************/ +SecureVector NR_Core::verify(const byte in[], u32bit length) const + { + return op->verify(in, length); + } + +/************************************************* +* NR Signature Operation * +*************************************************/ +SecureVector NR_Core::sign(const byte in[], u32bit length, + const BigInt& k) const + { + return op->sign(in, length, k); + } + +} diff --git a/src/pk/nr/nr_core.h b/src/pk/nr/nr_core.h new file mode 100644 index 000000000..416e31619 --- /dev/null +++ b/src/pk/nr/nr_core.h @@ -0,0 +1,36 @@ +/************************************************* +* NR Core Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_NR_CORE_H__ +#define BOTAN_NR_CORE_H__ + +#include +#include +#include + +namespace Botan { + +/************************************************* +* NR Core * +*************************************************/ +class BOTAN_DLL NR_Core + { + public: + SecureVector sign(const byte[], u32bit, const BigInt&) const; + SecureVector verify(const byte[], u32bit) const; + + NR_Core& operator=(const NR_Core&); + + NR_Core() { op = 0; } + NR_Core(const NR_Core&); + NR_Core(const DL_Group&, const BigInt&, const BigInt& = 0); + ~NR_Core() { delete op; } + private: + NR_Operation* op; + }; + +} + +#endif diff --git a/src/pk/pubkey/dh_core.cpp b/src/pk/pubkey/dh_core.cpp deleted file mode 100644 index a0586c444..000000000 --- a/src/pk/pubkey/dh_core.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/************************************************* -* PK Algorithm Core Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include -#include - -namespace Botan { - -namespace { - -const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS; - -} - -/************************************************* -* DH_Core Constructor * -*************************************************/ -DH_Core::DH_Core(RandomNumberGenerator& rng, - const DL_Group& group, const BigInt& x) - { - op = Engine_Core::dh_op(group, x); - - const BigInt& p = group.get_p(); - - BigInt k(rng, std::min(p.bits()-1, BLINDING_BITS)); - - if(k != 0) - blinder = Blinder(k, power_mod(inverse_mod(k, p), x, p), p); - } - -/************************************************* -* DH_Core Copy Constructor * -*************************************************/ -DH_Core::DH_Core(const DH_Core& core) - { - op = 0; - if(core.op) - op = core.op->clone(); - blinder = core.blinder; - } - -/************************************************* -* DH_Core Assignment Operator * -*************************************************/ -DH_Core& DH_Core::operator=(const DH_Core& core) - { - delete op; - if(core.op) - op = core.op->clone(); - blinder = core.blinder; - return (*this); - } - -/************************************************* -* DH Operation * -*************************************************/ -BigInt DH_Core::agree(const BigInt& i) const - { - return blinder.unblind(op->agree(blinder.blind(i))); - } - -} diff --git a/src/pk/pubkey/dh_core.h b/src/pk/pubkey/dh_core.h deleted file mode 100644 index 3735f31e1..000000000 --- a/src/pk/pubkey/dh_core.h +++ /dev/null @@ -1,38 +0,0 @@ -/************************************************* -* DH Core Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_DH_CORE_H__ -#define BOTAN_DH_CORE_H__ - -#include -#include -#include -#include - -namespace Botan { - -/************************************************* -* DH Core * -*************************************************/ -class BOTAN_DLL DH_Core - { - public: - BigInt agree(const BigInt&) const; - - DH_Core& operator=(const DH_Core&); - - DH_Core() { op = 0; } - DH_Core(const DH_Core&); - DH_Core(RandomNumberGenerator& rng, - const DL_Group&, const BigInt&); - ~DH_Core() { delete op; } - private: - DH_Operation* op; - Blinder blinder; - }; - -} - -#endif diff --git a/src/pk/pubkey/dsa_core.cpp b/src/pk/pubkey/dsa_core.cpp deleted file mode 100644 index aba1e61fb..000000000 --- a/src/pk/pubkey/dsa_core.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/************************************************* -* DSA Core Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include -#include - -namespace Botan { - -namespace { - -const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS; - -} - -/************************************************* -* DSA_Core Constructor * -*************************************************/ -DSA_Core::DSA_Core(const DL_Group& group, const BigInt& y, const BigInt& x) - { - op = Engine_Core::dsa_op(group, y, x); - } - -/************************************************* -* DSA_Core Copy Constructor * -*************************************************/ -DSA_Core::DSA_Core(const DSA_Core& core) - { - op = 0; - if(core.op) - op = core.op->clone(); - } - -/************************************************* -* DSA_Core Assignment Operator * -*************************************************/ -DSA_Core& DSA_Core::operator=(const DSA_Core& core) - { - delete op; - if(core.op) - op = core.op->clone(); - return (*this); - } - -/************************************************* -* DSA Verification Operation * -*************************************************/ -bool DSA_Core::verify(const byte msg[], u32bit msg_length, - const byte sig[], u32bit sig_length) const - { - return op->verify(msg, msg_length, sig, sig_length); - } - -/************************************************* -* DSA Signature Operation * -*************************************************/ -SecureVector DSA_Core::sign(const byte in[], u32bit length, - const BigInt& k) const - { - return op->sign(in, length, k); - } - -} diff --git a/src/pk/pubkey/dsa_core.h b/src/pk/pubkey/dsa_core.h deleted file mode 100644 index 467f3c23f..000000000 --- a/src/pk/pubkey/dsa_core.h +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************* -* DSA Core Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_DSA_CORE_H__ -#define BOTAN_DSA_CORE_H__ - -#include -#include -#include - -namespace Botan { - -/************************************************* -* DSA Core * -*************************************************/ -class BOTAN_DLL DSA_Core - { - public: - SecureVector sign(const byte[], u32bit, const BigInt&) const; - bool verify(const byte[], u32bit, const byte[], u32bit) const; - - DSA_Core& operator=(const DSA_Core&); - - DSA_Core() { op = 0; } - DSA_Core(const DSA_Core&); - DSA_Core(const DL_Group&, const BigInt&, const BigInt& = 0); - ~DSA_Core() { delete op; } - private: - DSA_Operation* op; - }; - -} - -#endif diff --git a/src/pk/pubkey/ecc_core.cpp b/src/pk/pubkey/ecc_core.cpp deleted file mode 100644 index 8d1d48b49..000000000 --- a/src/pk/pubkey/ecc_core.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/************************************************* -* ECDSA/ECKAEG Core Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include -#include - -namespace Botan { - -#if defined(BOTAN_HAS_ECDSA) - -/************************************************* -* 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 ECKAEG_Core::agree(const PointGFp& otherKey) const - { - //assert(op.get()); - return op->agree(otherKey); - } - -/************************************************* -* ECDSA Operation * -*************************************************/ -bool ECDSA_Core::verify(const byte signature[], u32bit sig_len, - const byte message[], u32bit mess_len) const - { - //assert(op.get()); - return op->verify(signature, sig_len, message, mess_len); - } - -SecureVector ECDSA_Core::sign(const byte message[], u32bit mess_len) const - { - //assert(op.get()); - return op->sign(message, mess_len); - } - -ECDSA_Core& ECDSA_Core::operator=(const ECDSA_Core& core) - { - delete op; - if(core.op) - op = core.op->clone(); - return (*this); - } - -ECDSA_Core::ECDSA_Core(const ECDSA_Core& core) - { - op = 0; - if(core.op) - op = core.op->clone(); - } - -ECDSA_Core::ECDSA_Core(EC_Domain_Params const& dom_pars, const BigInt& priv_key, PointGFp const& pub_key) - { - op = Engine_Core::ecdsa_op(dom_pars, priv_key, pub_key); - } -#endif - -} diff --git a/src/pk/pubkey/ecc_core.h b/src/pk/pubkey/ecc_core.h deleted file mode 100644 index 1124eaa2f..000000000 --- a/src/pk/pubkey/ecc_core.h +++ /dev/null @@ -1,74 +0,0 @@ -/************************************************* -* ECC Core Header File * -* (C) 1999-2007 Jack Lloyd * -* (C) 2007 FlexSecure GmbH * -*************************************************/ - -#ifndef BOTAN_ECC_CORE_H__ -#define BOTAN_ECC_CORE_H__ - -#include -#include -#include - -#if defined(BOTAN_HAS_ECDSA) - #include -#endif - -namespace Botan { - -#if defined(BOTAN_HAS_ECDSA) -/************************************************* -* ECDSA Core * -*************************************************/ -class ECDSA_Core - { - public: - bool verify(const byte signature[], u32bit sig_len, - const byte message[], u32bit mess_len) const; - - SecureVector sign(const byte message[], u32bit mess_len) const; - - ECDSA_Core& operator=(const ECDSA_Core&); - - ECDSA_Core() { op = 0; } - - ECDSA_Core(const ECDSA_Core&); - - ECDSA_Core(const EC_Domain_Params& dom_pars, - const BigInt& priv_key, - const PointGFp& pub_key); - - ~ECDSA_Core() { delete op; } - private: - ECDSA_Operation* op; - }; - -/************************************************* -* ECKAEG Core * -*************************************************/ -class ECKAEG_Core - { - public: - SecureVector 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 - -} - -#endif diff --git a/src/pk/pubkey/elg_core.cpp b/src/pk/pubkey/elg_core.cpp deleted file mode 100644 index 1181e7534..000000000 --- a/src/pk/pubkey/elg_core.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/************************************************* -* ElGamal Core Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include -#include - -namespace Botan { - -namespace { - -const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS; - -} - -/************************************************* -* ELG_Core Constructor * -*************************************************/ -ELG_Core::ELG_Core(const DL_Group& group, const BigInt& y) - { - op = Engine_Core::elg_op(group, y, 0); - p_bytes = 0; - } - -/************************************************* -* ELG_Core Constructor * -*************************************************/ -ELG_Core::ELG_Core(RandomNumberGenerator& rng, - const DL_Group& group, const BigInt& y, const BigInt& x) - { - op = Engine_Core::elg_op(group, y, x); - - const BigInt& p = group.get_p(); - p_bytes = p.bytes(); - - if(BLINDING_BITS) - { - BigInt k(rng, std::min(p.bits()-1, BLINDING_BITS)); - blinder = Blinder(k, power_mod(k, x, p), p); - } - } - -/************************************************* -* ELG_Core Copy Constructor * -*************************************************/ -ELG_Core::ELG_Core(const ELG_Core& core) - { - op = 0; - if(core.op) - op = core.op->clone(); - blinder = core.blinder; - p_bytes = core.p_bytes; - } - -/************************************************* -* ELG_Core Assignment Operator * -*************************************************/ -ELG_Core& ELG_Core::operator=(const ELG_Core& core) - { - delete op; - if(core.op) - op = core.op->clone(); - blinder = core.blinder; - p_bytes = core.p_bytes; - return (*this); - } - -/************************************************* -* ElGamal Encrypt Operation * -*************************************************/ -SecureVector ELG_Core::encrypt(const byte in[], u32bit length, - const BigInt& k) const - { - return op->encrypt(in, length, k); - } - -/************************************************* -* ElGamal Decrypt Operation * -*************************************************/ -SecureVector ELG_Core::decrypt(const byte in[], u32bit length) const - { - if(length != 2*p_bytes) - throw Invalid_Argument("ELG_Core::decrypt: Invalid message"); - - BigInt a(in, p_bytes); - BigInt b(in + p_bytes, p_bytes); - - return BigInt::encode(blinder.unblind(op->decrypt(blinder.blind(a), b))); - } - -} diff --git a/src/pk/pubkey/elg_core.h b/src/pk/pubkey/elg_core.h deleted file mode 100644 index 67966a452..000000000 --- a/src/pk/pubkey/elg_core.h +++ /dev/null @@ -1,43 +0,0 @@ -/************************************************* -* ElGamal Core Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_ELGAMAL_CORE_H__ -#define BOTAN_ELGAMAL_CORE_H__ - -#include -#include -#include -#include - -namespace Botan { - -/************************************************* -* ElGamal Core * -*************************************************/ -class BOTAN_DLL ELG_Core - { - public: - SecureVector encrypt(const byte[], u32bit, const BigInt&) const; - SecureVector decrypt(const byte[], u32bit) const; - - ELG_Core& operator=(const ELG_Core&); - - ELG_Core() { op = 0; } - ELG_Core(const ELG_Core&); - - ELG_Core(const DL_Group&, const BigInt&); - ELG_Core(RandomNumberGenerator&, const DL_Group&, - const BigInt&, const BigInt&); - - ~ELG_Core() { delete op; } - private: - ELG_Operation* op; - Blinder blinder; - u32bit p_bytes; - }; - -} - -#endif diff --git a/src/pk/pubkey/if_core.cpp b/src/pk/pubkey/if_core.cpp deleted file mode 100644 index 97cacf9d8..000000000 --- a/src/pk/pubkey/if_core.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/************************************************* -* IF Algorithm Core Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include -#include - -namespace Botan { - -namespace { - -const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS; - -} - -/************************************************* -* IF_Core Constructor * -*************************************************/ -IF_Core::IF_Core(const BigInt& e, const BigInt& n) - { - op = Engine_Core::if_op(e, n, 0, 0, 0, 0, 0, 0); - } - - -/************************************************* -* IF_Core Constructor * -*************************************************/ -IF_Core::IF_Core(RandomNumberGenerator& rng, - const BigInt& e, const BigInt& n, const BigInt& d, - const BigInt& p, const BigInt& q, - const BigInt& d1, const BigInt& d2, const BigInt& c) - { - op = Engine_Core::if_op(e, n, d, p, q, d1, d2, c); - - if(BLINDING_BITS) - { - BigInt k(rng, std::min(n.bits()-1, BLINDING_BITS)); - blinder = Blinder(power_mod(k, e, n), inverse_mod(k, n), n); - } - } - -/************************************************* -* IF_Core Copy Constructor * -*************************************************/ -IF_Core::IF_Core(const IF_Core& core) - { - op = 0; - if(core.op) - op = core.op->clone(); - blinder = core.blinder; - } - -/************************************************* -* IF_Core Assignment Operator * -*************************************************/ -IF_Core& IF_Core::operator=(const IF_Core& core) - { - delete op; - if(core.op) - op = core.op->clone(); - blinder = core.blinder; - return (*this); - } - -/************************************************* -* IF Public Operation * -*************************************************/ -BigInt IF_Core::public_op(const BigInt& i) const - { - return op->public_op(i); - } - -/************************************************* -* IF Private Operation * -*************************************************/ -BigInt IF_Core::private_op(const BigInt& i) const - { - return blinder.unblind(op->private_op(blinder.blind(i))); - } - -} diff --git a/src/pk/pubkey/if_core.h b/src/pk/pubkey/if_core.h deleted file mode 100644 index b6afad950..000000000 --- a/src/pk/pubkey/if_core.h +++ /dev/null @@ -1,44 +0,0 @@ -/************************************************* -* IF Algorithm Core Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_IF_CORE_H__ -#define BOTAN_IF_CORE_H__ - -#include -#include -#include - -namespace Botan { - -/************************************************* -* IF Core * -*************************************************/ -class BOTAN_DLL IF_Core - { - public: - BigInt public_op(const BigInt&) const; - BigInt private_op(const BigInt&) const; - - IF_Core& operator=(const IF_Core&); - - IF_Core() { op = 0; } - IF_Core(const IF_Core&); - - IF_Core(const BigInt&, const BigInt&); - - IF_Core(RandomNumberGenerator& rng, - const BigInt&, const BigInt&, - const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&, const BigInt&); - - ~IF_Core() { delete op; } - private: - IF_Operation* op; - Blinder blinder; - }; - -} - -#endif diff --git a/src/pk/pubkey/info.txt b/src/pk/pubkey/info.txt index 1c58c0e89..8c97aa744 100644 --- a/src/pk/pubkey/info.txt +++ b/src/pk/pubkey/info.txt @@ -11,21 +11,9 @@ asn1 -dh_core.cpp -dh_core.h dh_op.cpp -dsa_core.cpp -dsa_core.h dsa_op.cpp -ecc_core.cpp -ecc_core.h -elg_core.cpp -elg_core.h elg_op.cpp -if_core.cpp -if_core.h -nr_core.cpp -nr_core.h nr_op.cpp pk_algs.cpp pk_algs.h diff --git a/src/pk/pubkey/nr_core.cpp b/src/pk/pubkey/nr_core.cpp deleted file mode 100644 index f9dfa4024..000000000 --- a/src/pk/pubkey/nr_core.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/************************************************* -* NR Core Source File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#include -#include -#include -#include -#include - -namespace Botan { - -/************************************************* -* NR_Core Constructor * -*************************************************/ -NR_Core::NR_Core(const DL_Group& group, const BigInt& y, const BigInt& x) - { - op = Engine_Core::nr_op(group, y, x); - } - -/************************************************* -* NR_Core Copy Constructor * -*************************************************/ -NR_Core::NR_Core(const NR_Core& core) - { - op = 0; - if(core.op) - op = core.op->clone(); - } - -/************************************************* -* NR_Core Assignment Operator * -*************************************************/ -NR_Core& NR_Core::operator=(const NR_Core& core) - { - delete op; - if(core.op) - op = core.op->clone(); - return (*this); - } - -/************************************************* -* NR Verification Operation * -*************************************************/ -SecureVector NR_Core::verify(const byte in[], u32bit length) const - { - return op->verify(in, length); - } - -/************************************************* -* NR Signature Operation * -*************************************************/ -SecureVector NR_Core::sign(const byte in[], u32bit length, - const BigInt& k) const - { - return op->sign(in, length, k); - } - -} diff --git a/src/pk/pubkey/nr_core.h b/src/pk/pubkey/nr_core.h deleted file mode 100644 index 416e31619..000000000 --- a/src/pk/pubkey/nr_core.h +++ /dev/null @@ -1,36 +0,0 @@ -/************************************************* -* NR Core Header File * -* (C) 1999-2007 Jack Lloyd * -*************************************************/ - -#ifndef BOTAN_NR_CORE_H__ -#define BOTAN_NR_CORE_H__ - -#include -#include -#include - -namespace Botan { - -/************************************************* -* NR Core * -*************************************************/ -class BOTAN_DLL NR_Core - { - public: - SecureVector sign(const byte[], u32bit, const BigInt&) const; - SecureVector verify(const byte[], u32bit) const; - - NR_Core& operator=(const NR_Core&); - - NR_Core() { op = 0; } - NR_Core(const NR_Core&); - NR_Core(const DL_Group&, const BigInt&, const BigInt& = 0); - ~NR_Core() { delete op; } - private: - NR_Operation* op; - }; - -} - -#endif -- cgit v1.2.3