diff options
author | lloyd <[email protected]> | 2008-06-28 14:28:27 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-06-28 14:28:27 +0000 |
commit | eeb6859df0be3034cefd81ccce20494b9f7bc308 (patch) | |
tree | 6251fe589c8de164904329385f49e71b4ca52ad5 | |
parent | 0071ad80fc8eafc607d31018da27640c80d52af2 (diff) |
Add interfaces for add_entropy_source and add_entropy to
RandomNumberGenerator, and make ANSI_X931_PRNG's implementations just
forward the arguments to the underlying RNG. This allows seeding the RNG
even if no entropy modules are loaded into the library. Also it allows
actually adding user-specified data; to do it otherwise would require
creating the RNG objects yourself and retaining a pointer to the Randpool,
which is pretty bogus.
Move Null_RNG to rng.h
-rw-r--r-- | checks/common.h | 18 | ||||
-rw-r--r-- | include/rng.h | 16 | ||||
-rw-r--r-- | include/x931_rng.h | 2 | ||||
-rw-r--r-- | src/pubkey.cpp | 8 | ||||
-rw-r--r-- | src/x931_rng.cpp | 16 |
5 files changed, 41 insertions, 19 deletions
diff --git a/checks/common.h b/checks/common.h index e42fa8e44..06cb638ee 100644 --- a/checks/common.h +++ b/checks/common.h @@ -78,21 +78,19 @@ class Fixed_Output_RNG : public Botan::RandomNumberGenerator std::string name() const { return "Fixed_Output_RNG"; } - void clear() throw() {} + void add_entropy_source(Botan::EntropySource* src) { delete src; } + void add_entropy(const byte[], u32bit) {}; - void add_randomness(const byte in[], u32bit len) throw() - { - buf.insert(buf.end(), in, in + len); - } + void clear() throw() {} - Fixed_Output_RNG(const Botan::SecureVector<byte>& x) + Fixed_Output_RNG(const Botan::SecureVector<byte>& in) { - add_randomness(x.begin(), x.size()); + buf.insert(buf.end(), in.begin(), in.begin() + in.size()); } - Fixed_Output_RNG(const std::string& in) + Fixed_Output_RNG(const std::string& in_str) { - Botan::SecureVector<byte> x = decode_hex(in); - add_randomness(x.begin(), x.size()); + Botan::SecureVector<byte> in = decode_hex(in_str); + buf.insert(buf.end(), in.begin(), in.begin() + in.size()); } Fixed_Output_RNG() {} diff --git a/include/rng.h b/include/rng.h index 78edc1554..e09a3e939 100644 --- a/include/rng.h +++ b/include/rng.h @@ -35,11 +35,25 @@ class BOTAN_DLL RandomNumberGenerator byte next_byte(); - virtual void reseed() {}; + virtual void reseed() {} + virtual void add_entropy_source(EntropySource*) = 0; + virtual void add_entropy(const byte[], u32bit) = 0; virtual ~RandomNumberGenerator() {} }; +/************************************************* +* Null Random Number Generator * +*************************************************/ +class BOTAN_DLL Null_RNG : public RandomNumberGenerator + { + public: + void randomize(byte[], u32bit) { throw PRNG_Unseeded("Null_RNG"); } + bool is_seeded() const { return false; } + void add_entropy(const byte[], u32bit) {} + void add_entropy_source(EntropySource* es) { delete es; } + }; + } #endif diff --git a/include/x931_rng.h b/include/x931_rng.h index 2ba39361d..7914b605d 100644 --- a/include/x931_rng.h +++ b/include/x931_rng.h @@ -23,6 +23,8 @@ class BOTAN_DLL ANSI_X931_RNG : public RandomNumberGenerator std::string name() const; void reseed(); + void add_entropy_source(EntropySource*); + void add_entropy(const byte[], u32bit); ANSI_X931_RNG(const std::string&, RandomNumberGenerator*); ~ANSI_X931_RNG(); diff --git a/src/pubkey.cpp b/src/pubkey.cpp index f52208b3d..06bb44bca 100644 --- a/src/pubkey.cpp +++ b/src/pubkey.cpp @@ -367,14 +367,6 @@ PK_Verifier_wo_MR::PK_Verifier_wo_MR(const PK_Verifying_wo_MR_Key& k, bool PK_Verifier_wo_MR::validate_signature(const MemoryRegion<byte>& msg, const byte sig[], u32bit sig_len) { - class Null_RNG : public RandomNumberGenerator - { - public: - void randomize(byte[], u32bit) { throw PRNG_Unseeded("Null_RNG"); } - bool is_seeded() const { return false; } - void add_randomness(const byte[], u32bit) {} - }; - Null_RNG rng; SecureVector<byte> encoded = diff --git a/src/x931_rng.cpp b/src/x931_rng.cpp index 68d633df4..8f454dcb8 100644 --- a/src/x931_rng.cpp +++ b/src/x931_rng.cpp @@ -70,6 +70,22 @@ void ANSI_X931_RNG::reseed() } /************************************************* +* Add a entropy source to the underlying PRNG * +*************************************************/ +void ANSI_X931_RNG::add_entropy_source(EntropySource* src) + { + prng->add_entropy_source(src); + } + +/************************************************* +* Add some entropy to the underlying PRNG * +*************************************************/ +void ANSI_X931_RNG::add_entropy(const byte input[], u32bit length) + { + prng->add_entropy(input, length); + } + +/************************************************* * Check if the the PRNG is seeded * *************************************************/ bool ANSI_X931_RNG::is_seeded() const |