diff options
author | lloyd <[email protected]> | 2010-03-05 17:40:45 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-05 17:40:45 +0000 |
commit | be9d7d1031bba2cd4f415d114389a1f50c61d44b (patch) | |
tree | c6714d8c40ac685c98e4b8bfbacdd14d99d64a63 /src/pubkey | |
parent | cdd1a1509ffc74c74bd902d55a7a85ab9e2afe78 (diff) |
Remove IF_Core
Diffstat (limited to 'src/pubkey')
-rw-r--r-- | src/pubkey/if_algo/if_algo.cpp | 4 | ||||
-rw-r--r-- | src/pubkey/if_algo/if_algo.h | 3 | ||||
-rw-r--r-- | src/pubkey/if_algo/if_core.cpp | 83 | ||||
-rw-r--r-- | src/pubkey/if_algo/if_core.h | 45 | ||||
-rw-r--r-- | src/pubkey/if_algo/if_op.cpp | 47 | ||||
-rw-r--r-- | src/pubkey/if_algo/if_op.h | 52 | ||||
-rw-r--r-- | src/pubkey/if_algo/info.txt | 12 | ||||
-rw-r--r-- | src/pubkey/rsa/rsa.cpp | 45 | ||||
-rw-r--r-- | src/pubkey/rsa/rsa.h | 9 | ||||
-rw-r--r-- | src/pubkey/rw/rw.cpp | 2 | ||||
-rw-r--r-- | src/pubkey/rw/rw.h | 9 |
11 files changed, 7 insertions, 304 deletions
diff --git a/src/pubkey/if_algo/if_algo.cpp b/src/pubkey/if_algo/if_algo.cpp index 1acbad02c..759c30c61 100644 --- a/src/pubkey/if_algo/if_algo.cpp +++ b/src/pubkey/if_algo/if_algo.cpp @@ -78,8 +78,6 @@ IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(RandomNumberGenerator& rng, if(version != 0) throw Decoding_Error("Unknown PKCS #1 key format version"); - core = IF_Core(rng, e, n, d, p, q, d1, d2, c); - load_check(rng); } @@ -109,8 +107,6 @@ IF_Scheme_PrivateKey::IF_Scheme_PrivateKey(RandomNumberGenerator& rng, d2 = d % (q - 1); c = inverse_mod(q, p); - core = IF_Core(rng, e, n, d, p, q, d1, d2, c); - load_check(rng); } diff --git a/src/pubkey/if_algo/if_algo.h b/src/pubkey/if_algo/if_algo.h index d35c8245f..65bb8aed4 100644 --- a/src/pubkey/if_algo/if_algo.h +++ b/src/pubkey/if_algo/if_algo.h @@ -8,7 +8,7 @@ #ifndef BOTAN_IF_ALGO_H__ #define BOTAN_IF_ALGO_H__ -#include <botan/if_core.h> +#include <botan/bigint.h> #include <botan/x509_key.h> #include <botan/pkcs8.h> #include <botan/pk_ops.h> @@ -52,7 +52,6 @@ class BOTAN_DLL IF_Scheme_PublicKey : public virtual Public_Key IF_Scheme_PublicKey() {} BigInt n, e; - IF_Core core; }; /** diff --git a/src/pubkey/if_algo/if_core.cpp b/src/pubkey/if_algo/if_core.cpp deleted file mode 100644 index 41ebfe8dd..000000000 --- a/src/pubkey/if_algo/if_core.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* -* IF Algorithm Core -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/if_core.h> -#include <botan/numthry.h> -#include <botan/internal/pk_engine.h> -#include <botan/parsing.h> -#include <algorithm> - -namespace Botan { - -/* -* 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) - { - const u32bit BLINDING_BITS = BOTAN_PRIVATE_KEY_OP_BLINDING_BITS; - - 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/pubkey/if_algo/if_core.h b/src/pubkey/if_algo/if_core.h deleted file mode 100644 index b7f487706..000000000 --- a/src/pubkey/if_algo/if_core.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -* IF Algorithm Core -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_IF_CORE_H__ -#define BOTAN_IF_CORE_H__ - -#include <botan/if_op.h> -#include <botan/blinding.h> - -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/pubkey/if_algo/if_op.cpp b/src/pubkey/if_algo/if_op.cpp deleted file mode 100644 index 27aef453e..000000000 --- a/src/pubkey/if_algo/if_op.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* -* IF (RSA/RW) Operation -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/if_op.h> -#include <botan/numthry.h> - -namespace Botan { - -/* -* Default_IF_Op Constructor -*/ -Default_IF_Op::Default_IF_Op(const BigInt& e, const BigInt& n, const BigInt&, - const BigInt& p, const BigInt& q, - const BigInt& d1, const BigInt& d2, - const BigInt& c) - { - powermod_e_n = Fixed_Exponent_Power_Mod(e, n); - - if(d1 != 0 && d2 != 0 && p != 0 && q != 0) - { - powermod_d1_p = Fixed_Exponent_Power_Mod(d1, p); - powermod_d2_q = Fixed_Exponent_Power_Mod(d2, q); - reducer = Modular_Reducer(p); - this->c = c; - this->q = q; - } - } - -/* -* Default IF Private Operation -*/ -BigInt Default_IF_Op::private_op(const BigInt& i) const - { - if(q == 0) - throw Internal_Error("Default_IF_Op::private_op: No private key"); - - BigInt j1 = powermod_d1_p(i); - BigInt j2 = powermod_d2_q(i); - j1 = reducer.reduce(sub_mul(j1, j2, c)); - return mul_add(j1, q, j2); - } - -} diff --git a/src/pubkey/if_algo/if_op.h b/src/pubkey/if_algo/if_op.h deleted file mode 100644 index 516902fd9..000000000 --- a/src/pubkey/if_algo/if_op.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -* IF Operations -* (C) 1999-2008 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_IF_OP_H__ -#define BOTAN_IF_OP_H__ - -#include <botan/bigint.h> -#include <botan/pow_mod.h> -#include <botan/reducer.h> - -namespace Botan { - -/* -* IF Operation -*/ -class BOTAN_DLL IF_Operation - { - public: - virtual BigInt public_op(const BigInt&) const = 0; - virtual BigInt private_op(const BigInt&) const = 0; - virtual IF_Operation* clone() const = 0; - virtual ~IF_Operation() {} - }; - -/* -* Default IF Operation -*/ -class BOTAN_DLL Default_IF_Op : public IF_Operation - { - public: - BigInt public_op(const BigInt& i) const - { return powermod_e_n(i); } - BigInt private_op(const BigInt&) const; - - IF_Operation* clone() const { return new Default_IF_Op(*this); } - - Default_IF_Op(const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&, const BigInt&, - const BigInt&, const BigInt&); - private: - Fixed_Exponent_Power_Mod powermod_e_n, powermod_d1_p, powermod_d2_q; - Modular_Reducer reducer; - BigInt c, q; - }; - -} - -#endif diff --git a/src/pubkey/if_algo/info.txt b/src/pubkey/if_algo/info.txt index c0914cd15..32e50e684 100644 --- a/src/pubkey/if_algo/info.txt +++ b/src/pubkey/if_algo/info.txt @@ -2,18 +2,6 @@ define IF_PUBLIC_KEY_FAMILY load_on dep -<header:public> -if_algo.h -if_core.h -if_op.h -</header:public> - -<source> -if_algo.cpp -if_core.cpp -if_op.cpp -</source> - <requires> asn1 bigint diff --git a/src/pubkey/rsa/rsa.cpp b/src/pubkey/rsa/rsa.cpp index 13ac1c318..dc182f36a 100644 --- a/src/pubkey/rsa/rsa.cpp +++ b/src/pubkey/rsa/rsa.cpp @@ -14,26 +14,6 @@ namespace Botan { /* -* RSA Public Operation -*/ -BigInt RSA_PublicKey::public_op(const BigInt& i) const - { - if(i >= n) - throw Invalid_Argument(algo_name() + "::public_op: input is too large"); - return core.public_op(i); - } - -/* -* RSA Encryption Function -*/ -SecureVector<byte> RSA_PublicKey::encrypt(const byte in[], u32bit len, - RandomNumberGenerator&) const - { - BigInt i(in, len); - return BigInt::encode_1363(public_op(i), n.bytes()); - } - -/* * Create a RSA private key */ RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng, @@ -58,35 +38,10 @@ RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng, d2 = d % (q - 1); c = inverse_mod(q, p); - core = IF_Core(rng, e, n, d, p, q, d1, d2, c); - gen_check(rng); } /* -* RSA Private Operation -*/ -BigInt RSA_PrivateKey::private_op(const byte in[], u32bit length) const - { - BigInt i(in, length); - if(i >= n) - throw Invalid_Argument(algo_name() + "::private_op: input is too large"); - - BigInt r = core.private_op(i); - if(i != public_op(r)) - throw Self_Test_Failure(algo_name() + " private operation check failed"); - return r; - } - -/* -* RSA Decryption Operation -*/ -SecureVector<byte> RSA_PrivateKey::decrypt(const byte in[], u32bit len) const - { - return BigInt::encode(private_op(in, len)); - } - -/* * Check Private RSA Parameters */ bool RSA_PrivateKey::check_key(RandomNumberGenerator& rng, bool strong) const diff --git a/src/pubkey/rsa/rsa.h b/src/pubkey/rsa/rsa.h index 794352dce..73c3c347d 100644 --- a/src/pubkey/rsa/rsa.h +++ b/src/pubkey/rsa/rsa.h @@ -9,6 +9,7 @@ #define BOTAN_RSA_H__ #include <botan/if_algo.h> +#include <botan/reducer.h> namespace Botan { @@ -28,9 +29,7 @@ class BOTAN_DLL RSA_PublicKey : public PK_Encrypting_Key, RSA_PublicKey(const AlgorithmIdentifier& alg_id, const MemoryRegion<byte>& key_bits) : IF_Scheme_PublicKey(alg_id, key_bits) - { - core = IF_Core(e, n); - } + {} /** * Create a RSA_PublicKey @@ -39,9 +38,7 @@ class BOTAN_DLL RSA_PublicKey : public PK_Encrypting_Key, */ RSA_PublicKey(const BigInt& n, const BigInt& e) : IF_Scheme_PublicKey(n, e) - { - core = IF_Core(e, n); - } + {} protected: RSA_PublicKey() {} diff --git a/src/pubkey/rw/rw.cpp b/src/pubkey/rw/rw.cpp index bf66898b2..7b87ce7df 100644 --- a/src/pubkey/rw/rw.cpp +++ b/src/pubkey/rw/rw.cpp @@ -40,8 +40,6 @@ RW_PrivateKey::RW_PrivateKey(RandomNumberGenerator& rng, d2 = d % (q - 1); c = inverse_mod(q, p); - core = IF_Core(rng, e, n, d, p, q, d1, d2, c); - gen_check(rng); } diff --git a/src/pubkey/rw/rw.h b/src/pubkey/rw/rw.h index 059ba7d48..7d614cf5a 100644 --- a/src/pubkey/rw/rw.h +++ b/src/pubkey/rw/rw.h @@ -9,6 +9,7 @@ #define BOTAN_RW_H__ #include <botan/if_algo.h> +#include <botan/reducer.h> namespace Botan { @@ -24,15 +25,11 @@ class BOTAN_DLL RW_PublicKey : public PK_Verifying_with_MR_Key, RW_PublicKey(const AlgorithmIdentifier& alg_id, const MemoryRegion<byte>& key_bits) : IF_Scheme_PublicKey(alg_id, key_bits) - { - core = IF_Core(e, n); - } + {} RW_PublicKey(const BigInt& mod, const BigInt& exponent) : IF_Scheme_PublicKey(mod, exponent) - { - core = IF_Core(e, n); - } + {} protected: RW_PublicKey() {} |