diff options
author | lloyd <[email protected]> | 2010-03-05 16:25:43 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-05 16:25:43 +0000 |
commit | c52cfb67263a9bb227c4b6fb0a0e37ab388f933a (patch) | |
tree | fdd87d05cae6e30e84c60d518ae1f99f80bbabff /src/pubkey | |
parent | df56028cad58fad04b9866326cb62700af8f2fbe (diff) |
Remove NR and DSA specific hooks
Diffstat (limited to 'src/pubkey')
-rw-r--r-- | src/pubkey/dsa/dsa.cpp | 13 | ||||
-rw-r--r-- | src/pubkey/dsa/dsa.h | 6 | ||||
-rw-r--r-- | src/pubkey/dsa/dsa_core.cpp | 63 | ||||
-rw-r--r-- | src/pubkey/dsa/dsa_core.h | 37 | ||||
-rw-r--r-- | src/pubkey/dsa/dsa_op.cpp | 73 | ||||
-rw-r--r-- | src/pubkey/dsa/dsa_op.h | 59 | ||||
-rw-r--r-- | src/pubkey/dsa/info.txt | 12 | ||||
-rw-r--r-- | src/pubkey/nr/nr.cpp | 15 | ||||
-rw-r--r-- | src/pubkey/nr/nr.h | 6 | ||||
-rw-r--r-- | src/pubkey/nr/nr_core.cpp | 62 | ||||
-rw-r--r-- | src/pubkey/nr/nr_core.h | 37 | ||||
-rw-r--r-- | src/pubkey/nr/nr_op.cpp | 71 | ||||
-rw-r--r-- | src/pubkey/nr/nr_op.h | 53 |
13 files changed, 2 insertions, 505 deletions
diff --git a/src/pubkey/dsa/dsa.cpp b/src/pubkey/dsa/dsa.cpp index 52df9827f..60414195d 100644 --- a/src/pubkey/dsa/dsa.cpp +++ b/src/pubkey/dsa/dsa.cpp @@ -19,16 +19,6 @@ DSA_PublicKey::DSA_PublicKey(const DL_Group& grp, const BigInt& y1) { group = grp; y = y1; - core = DSA_Core(group, y); - } - -/* -* DSA Verification Function -*/ -bool DSA_PublicKey::verify(const byte msg[], u32bit msg_len, - const byte sig[], u32bit sig_len) const - { - return core.verify(msg, msg_len, sig, sig_len); } /* @@ -46,8 +36,6 @@ DSA_PrivateKey::DSA_PrivateKey(RandomNumberGenerator& rng, y = power_mod(group_g(), x, group_p()); - core = DSA_Core(group, y, x); - if(x_arg == 0) gen_check(rng); else @@ -60,7 +48,6 @@ DSA_PrivateKey::DSA_PrivateKey(const AlgorithmIdentifier& alg_id, DL_Scheme_PrivateKey(alg_id, key_bits, DL_Group::ANSI_X9_57) { y = power_mod(group_g(), x, group_p()); - core = DSA_Core(group, y, x); load_check(rng); } diff --git a/src/pubkey/dsa/dsa.h b/src/pubkey/dsa/dsa.h index 68ae34235..f8db77a1b 100644 --- a/src/pubkey/dsa/dsa.h +++ b/src/pubkey/dsa/dsa.h @@ -12,7 +12,6 @@ #include <botan/pk_ops.h> #include <botan/reducer.h> #include <botan/pow_mod.h> -#include <botan/dsa_core.h> namespace Botan { @@ -30,20 +29,15 @@ class BOTAN_DLL DSA_PublicKey : public PK_Verifying_wo_MR_Key, u32bit message_part_size() const { return group_q().bytes(); } u32bit max_input_bits() const { return group_q().bits(); } - bool verify(const byte msg[], u32bit msg_len, - const byte sig[], u32bit sig_len) const; - DSA_PublicKey(const AlgorithmIdentifier& alg_id, const MemoryRegion<byte>& key_bits) : DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_57) { - core = DSA_Core(group, y); } DSA_PublicKey(const DL_Group& group, const BigInt& y); protected: DSA_PublicKey() {} - DSA_Core core; }; /* diff --git a/src/pubkey/dsa/dsa_core.cpp b/src/pubkey/dsa/dsa_core.cpp deleted file mode 100644 index d952e10eb..000000000 --- a/src/pubkey/dsa/dsa_core.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* -* DSA Core -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/dsa_core.h> -#include <botan/numthry.h> -#include <botan/internal/pk_engine.h> -#include <botan/parsing.h> -#include <algorithm> - -namespace Botan { - -/* -* 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<byte> DSA_Core::sign(const byte in[], u32bit length, - const BigInt& k) const - { - return op->sign(in, length, k); - } - -} diff --git a/src/pubkey/dsa/dsa_core.h b/src/pubkey/dsa/dsa_core.h deleted file mode 100644 index 8bb16211f..000000000 --- a/src/pubkey/dsa/dsa_core.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -* DSA Core -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_DSA_CORE_H__ -#define BOTAN_DSA_CORE_H__ - -#include <botan/dsa_op.h> -#include <botan/dl_group.h> - -namespace Botan { - -/* -* DSA Core -*/ -class BOTAN_DLL DSA_Core - { - public: - SecureVector<byte> 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/pubkey/dsa/dsa_op.cpp b/src/pubkey/dsa/dsa_op.cpp deleted file mode 100644 index 5b921441d..000000000 --- a/src/pubkey/dsa/dsa_op.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* -* DSA Operations -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/dsa_op.h> - -namespace Botan { - -/* -* Default_DSA_Op Constructor -*/ -Default_DSA_Op::Default_DSA_Op(const DL_Group& grp, const BigInt& y1, - const BigInt& x1) : x(x1), y(y1), group(grp) - { - powermod_g_p = Fixed_Base_Power_Mod(group.get_g(), group.get_p()); - powermod_y_p = Fixed_Base_Power_Mod(y, group.get_p()); - mod_p = Modular_Reducer(group.get_p()); - mod_q = Modular_Reducer(group.get_q()); - } - -/* -* Default DSA Verify Operation -*/ -bool Default_DSA_Op::verify(const byte msg[], u32bit msg_len, - const byte sig[], u32bit sig_len) const - { - const BigInt& q = group.get_q(); - - if(sig_len != 2*q.bytes() || msg_len > q.bytes()) - return false; - - BigInt r(sig, q.bytes()); - BigInt s(sig + q.bytes(), q.bytes()); - BigInt i(msg, msg_len); - - if(r <= 0 || r >= q || s <= 0 || s >= q) - return false; - - s = inverse_mod(s, q); - s = mod_p.multiply(powermod_g_p(mod_q.multiply(s, i)), - powermod_y_p(mod_q.multiply(s, r))); - - return (mod_q.reduce(s) == r); - } - -/* -* Default DSA Sign Operation -*/ -SecureVector<byte> Default_DSA_Op::sign(const byte in[], u32bit length, - const BigInt& k) const - { - if(x == 0) - throw Internal_Error("Default_DSA_Op::sign: No private key"); - - const BigInt& q = group.get_q(); - BigInt i(in, length); - - BigInt r = mod_q.reduce(powermod_g_p(k)); - BigInt s = mod_q.multiply(inverse_mod(k, q), mul_add(x, r, i)); - - if(r.is_zero() || s.is_zero()) - throw Internal_Error("Default_DSA_Op::sign: r or s was zero"); - - SecureVector<byte> output(2*q.bytes()); - r.binary_encode(output + (output.size() / 2 - r.bytes())); - s.binary_encode(output + (output.size() - s.bytes())); - return output; - } - -} diff --git a/src/pubkey/dsa/dsa_op.h b/src/pubkey/dsa/dsa_op.h deleted file mode 100644 index 47a9d09e1..000000000 --- a/src/pubkey/dsa/dsa_op.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -* DSA Operations -* (C) 1999-2008 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_DSA_OPS_H__ -#define BOTAN_DSA_OPS_H__ - -#include <botan/numthry.h> -#include <botan/pow_mod.h> -#include <botan/reducer.h> -#include <botan/dl_group.h> - -namespace Botan { - -/* -* DSA Operation -*/ -class BOTAN_DLL DSA_Operation - { - public: - virtual bool verify(const byte msg[], u32bit msg_len, - const byte sig[], u32bit sig_len) const = 0; - - virtual SecureVector<byte> sign(const byte msg[], u32bit msg_len, - const BigInt& k) const = 0; - - virtual DSA_Operation* clone() const = 0; - - virtual ~DSA_Operation() {} - }; - -/* -* Botan's Default DSA Operation -*/ -class BOTAN_DLL Default_DSA_Op : public DSA_Operation - { - public: - bool verify(const byte msg[], u32bit msg_len, - const byte sig[], u32bit sig_len) const; - - SecureVector<byte> sign(const byte msg[], u32bit msg_len, - const BigInt& k) const; - - DSA_Operation* clone() const { return new Default_DSA_Op(*this); } - - Default_DSA_Op(const DL_Group&, const BigInt&, const BigInt&); - private: - const BigInt x, y; - const DL_Group group; - Fixed_Base_Power_Mod powermod_g_p, powermod_y_p; - Modular_Reducer mod_p, mod_q; - }; - -} - -#endif diff --git a/src/pubkey/dsa/info.txt b/src/pubkey/dsa/info.txt index 1248cf68d..d59fe7aa7 100644 --- a/src/pubkey/dsa/info.txt +++ b/src/pubkey/dsa/info.txt @@ -1,17 +1,5 @@ define DSA -<header:public> -dsa.h -dsa_core.h -dsa_op.h -</header:public> - -<source> -dsa.cpp -dsa_core.cpp -dsa_op.cpp -</source> - <requires> dl_algo dl_group diff --git a/src/pubkey/nr/nr.cpp b/src/pubkey/nr/nr.cpp index 700e93092..540cfa281 100644 --- a/src/pubkey/nr/nr.cpp +++ b/src/pubkey/nr/nr.cpp @@ -16,7 +16,6 @@ NR_PublicKey::NR_PublicKey(const AlgorithmIdentifier& alg_id, const MemoryRegion<byte>& key_bits) : DL_Scheme_PublicKey(alg_id, key_bits, DL_Group::ANSI_X9_57) { - core = NR_Core(group, y); } /* @@ -26,16 +25,6 @@ NR_PublicKey::NR_PublicKey(const DL_Group& grp, const BigInt& y1) { group = grp; y = y1; - - core = NR_Core(group, y); - } - -/* -* Nyberg-Rueppel Verification Function -*/ -SecureVector<byte> NR_PublicKey::verify(const byte sig[], u32bit sig_len) const - { - return core.verify(sig, sig_len); } /* @@ -53,8 +42,6 @@ NR_PrivateKey::NR_PrivateKey(RandomNumberGenerator& rng, y = power_mod(group_g(), x, group_p()); - core = NR_Core(group, y, x); - if(x_arg == 0) gen_check(rng); else @@ -68,8 +55,6 @@ NR_PrivateKey::NR_PrivateKey(const AlgorithmIdentifier& alg_id, { y = power_mod(group_g(), x, group_p()); - core = NR_Core(group, y, x); - load_check(rng); } diff --git a/src/pubkey/nr/nr.h b/src/pubkey/nr/nr.h index 7a6aaf8fb..c6c7d871c 100644 --- a/src/pubkey/nr/nr.h +++ b/src/pubkey/nr/nr.h @@ -10,7 +10,8 @@ #include <botan/dl_algo.h> #include <botan/pk_ops.h> -#include <botan/nr_core.h> +#include <botan/numthry.h> +#include <botan/reducer.h> namespace Botan { @@ -23,8 +24,6 @@ class BOTAN_DLL NR_PublicKey : public PK_Verifying_with_MR_Key, public: std::string algo_name() const { return "NR"; } - SecureVector<byte> verify(const byte sig[], u32bit sig_len) const; - DL_Group::Format group_format() const { return DL_Group::ANSI_X9_57; } u32bit message_parts() const { return 2; } @@ -37,7 +36,6 @@ class BOTAN_DLL NR_PublicKey : public PK_Verifying_with_MR_Key, NR_PublicKey(const DL_Group& group, const BigInt& pub_key); protected: NR_PublicKey() {} - NR_Core core; }; /* diff --git a/src/pubkey/nr/nr_core.cpp b/src/pubkey/nr/nr_core.cpp deleted file mode 100644 index a87c32d60..000000000 --- a/src/pubkey/nr/nr_core.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* -* NR Core -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/nr_core.h> -#include <botan/numthry.h> -#include <botan/internal/pk_engine.h> -#include <botan/parsing.h> -#include <algorithm> - -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<byte> NR_Core::verify(const byte in[], u32bit length) const - { - return op->verify(in, length); - } - -/* -* NR Signature Operation -*/ -SecureVector<byte> NR_Core::sign(const byte in[], u32bit length, - const BigInt& k) const - { - return op->sign(in, length, k); - } - -} diff --git a/src/pubkey/nr/nr_core.h b/src/pubkey/nr/nr_core.h deleted file mode 100644 index 483773622..000000000 --- a/src/pubkey/nr/nr_core.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -* NR Core -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_NR_CORE_H__ -#define BOTAN_NR_CORE_H__ - -#include <botan/nr_op.h> -#include <botan/dl_group.h> - -namespace Botan { - -/* -* NR Core -*/ -class BOTAN_DLL NR_Core - { - public: - SecureVector<byte> sign(const byte[], u32bit, const BigInt&) const; - SecureVector<byte> 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/pubkey/nr/nr_op.cpp b/src/pubkey/nr/nr_op.cpp deleted file mode 100644 index b5efa3d37..000000000 --- a/src/pubkey/nr/nr_op.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* -* NR Operations -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include <botan/nr_op.h> - -namespace Botan { - -/* -* Default_NR_Op Constructor -*/ -Default_NR_Op::Default_NR_Op(const DL_Group& grp, const BigInt& y1, - const BigInt& x1) : x(x1), y(y1), group(grp) - { - powermod_g_p = Fixed_Base_Power_Mod(group.get_g(), group.get_p()); - powermod_y_p = Fixed_Base_Power_Mod(y, group.get_p()); - mod_p = Modular_Reducer(group.get_p()); - mod_q = Modular_Reducer(group.get_q()); - } - -/* -* Default NR Verify Operation -*/ -SecureVector<byte> Default_NR_Op::verify(const byte in[], u32bit length) const - { - const BigInt& q = group.get_q(); - - if(length != 2*q.bytes()) - return false; - - BigInt c(in, q.bytes()); - BigInt d(in + q.bytes(), q.bytes()); - - if(c.is_zero() || c >= q || d >= q) - throw Invalid_Argument("Default_NR_Op::verify: Invalid signature"); - - BigInt i = mod_p.multiply(powermod_g_p(d), powermod_y_p(c)); - return BigInt::encode(mod_q.reduce(c - i)); - } - -/* -* Default NR Sign Operation -*/ -SecureVector<byte> Default_NR_Op::sign(const byte in[], u32bit length, - const BigInt& k) const - { - if(x == 0) - throw Internal_Error("Default_NR_Op::sign: No private key"); - - const BigInt& q = group.get_q(); - - BigInt f(in, length); - - if(f >= q) - throw Invalid_Argument("Default_NR_Op::sign: Input is out of range"); - - BigInt c = mod_q.reduce(powermod_g_p(k) + f); - if(c.is_zero()) - throw Internal_Error("Default_NR_Op::sign: c was zero"); - BigInt d = mod_q.reduce(k - x * c); - - SecureVector<byte> output(2*q.bytes()); - c.binary_encode(output + (output.size() / 2 - c.bytes())); - d.binary_encode(output + (output.size() - d.bytes())); - return output; - } - -} diff --git a/src/pubkey/nr/nr_op.h b/src/pubkey/nr/nr_op.h deleted file mode 100644 index cba1465f2..000000000 --- a/src/pubkey/nr/nr_op.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -* NR Operations -* (C) 1999-2008 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_NR_OPS_H__ -#define BOTAN_NR_OPS_H__ - -#include <botan/pow_mod.h> -#include <botan/numthry.h> -#include <botan/reducer.h> -#include <botan/dl_group.h> - -namespace Botan { - -/* -* NR Operation -*/ -class BOTAN_DLL NR_Operation - { - public: - virtual SecureVector<byte> verify(const byte[], u32bit) const = 0; - virtual SecureVector<byte> sign(const byte[], u32bit, - const BigInt&) const = 0; - virtual NR_Operation* clone() const = 0; - virtual ~NR_Operation() {} - }; - -/* -* Botan's Default NR Operation -*/ -class BOTAN_DLL Default_NR_Op : public NR_Operation - { - public: - SecureVector<byte> verify(const byte[], u32bit) const; - SecureVector<byte> sign(const byte[], u32bit, const BigInt&) const; - - NR_Operation* clone() const { return new Default_NR_Op(*this); } - - Default_NR_Op(const DL_Group&, const BigInt&, const BigInt&); - private: - const BigInt x, y; - const DL_Group group; - Fixed_Base_Power_Mod powermod_g_p, powermod_y_p; - Modular_Reducer mod_p, mod_q; - }; - - -} - -#endif |