diff options
author | lloyd <[email protected]> | 2009-01-31 10:48:07 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-01-31 10:48:07 +0000 |
commit | 716176904747020267858f4b8b2c04675d76c873 (patch) | |
tree | c5bcf2d7efdea8945c4daae75b48c8bea140523e /src | |
parent | 89b72bf90264acc6cb84ee424e29ec4bd0e7539e (diff) |
In the X9.31 PRNG, move the code that rekeys the cipher and generates V to
a new member function rekey, calling it from both reseed and add_entropy.
Previously add_entropy worked without this because the PRNG would reseed
itself automatically if it was not at the point when randomize() was called,
but once this was removed it was necessary to ensure a rekey kicked off,
if appropriate, when calling add_entropy.
Diffstat (limited to 'src')
-rw-r--r-- | src/rng/x931_rng/x931_rng.cpp | 82 | ||||
-rw-r--r-- | src/rng/x931_rng/x931_rng.h | 15 |
2 files changed, 53 insertions, 44 deletions
diff --git a/src/rng/x931_rng/x931_rng.cpp b/src/rng/x931_rng/x931_rng.cpp index 4b33f4c5e..e77f04ae4 100644 --- a/src/rng/x931_rng/x931_rng.cpp +++ b/src/rng/x931_rng/x931_rng.cpp @@ -1,7 +1,7 @@ -/************************************************* -* ANSI X9.31 RNG Source File * -* (C) 1999-2008 Jack Lloyd * -*************************************************/ +/* +* ANSI X9.31 RNG Source File +* (C) 1999-2009 Jack Lloyd +*/ #include <botan/x931_rng.h> #include <botan/xor_buf.h> @@ -9,9 +9,9 @@ namespace Botan { -/************************************************* -* Generate a buffer of random bytes * -*************************************************/ +/** +* Generate a buffer of random bytes +*/ void ANSI_X931_RNG::randomize(byte out[], u32bit length) { if(!is_seeded()) @@ -31,9 +31,9 @@ void ANSI_X931_RNG::randomize(byte out[], u32bit length) } } -/************************************************* -* Refill the internal state * -*************************************************/ +/** +* Refill the internal state +*/ void ANSI_X931_RNG::update_buffer() { SecureVector<byte> DT(cipher->BLOCK_SIZE); @@ -50,13 +50,11 @@ void ANSI_X931_RNG::update_buffer() position = 0; } -/************************************************* -* Reseed the internal state * -*************************************************/ -void ANSI_X931_RNG::reseed(u32bit poll_bits) +/** +* Reset V and the cipher key with new values +*/ +void ANSI_X931_RNG::rekey() { - prng->reseed(poll_bits); - if(prng->is_seeded()) { SecureVector<byte> key(cipher->MAXIMUM_KEYLENGTH); @@ -71,33 +69,43 @@ void ANSI_X931_RNG::reseed(u32bit poll_bits) } } -/************************************************* -* Add a entropy source to the underlying PRNG * -*************************************************/ +/** +* Reseed the internal state +*/ +void ANSI_X931_RNG::reseed(u32bit poll_bits) + { + prng->reseed(poll_bits); + rekey(); + } + +/** +* 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 * -*************************************************/ +/** +* Add some entropy to the underlying PRNG +*/ void ANSI_X931_RNG::add_entropy(const byte input[], u32bit length) { prng->add_entropy(input, length); + rekey(); } -/************************************************* -* Check if the the PRNG is seeded * -*************************************************/ +/** +* Check if the the PRNG is seeded +*/ bool ANSI_X931_RNG::is_seeded() const { return V.has_items(); } -/************************************************* -* Clear memory of sensitive data * -*************************************************/ +/** +* Clear memory of sensitive data +*/ void ANSI_X931_RNG::clear() throw() { cipher->clear(); @@ -108,17 +116,17 @@ void ANSI_X931_RNG::clear() throw() position = 0; } -/************************************************* -* Return the name of this type * -*************************************************/ +/** +* Return the name of this type +*/ std::string ANSI_X931_RNG::name() const { return "X9.31(" + cipher->name() + ")"; } -/************************************************* -* ANSI X931 RNG Constructor * -*************************************************/ +/** +* ANSI X931 RNG Constructor +*/ ANSI_X931_RNG::ANSI_X931_RNG(BlockCipher* cipher_in, RandomNumberGenerator* prng_in) { @@ -132,9 +140,9 @@ ANSI_X931_RNG::ANSI_X931_RNG(BlockCipher* cipher_in, position = 0; } -/************************************************* -* ANSI X931 RNG Destructor * -*************************************************/ +/** +* ANSI X931 RNG Destructor +*/ ANSI_X931_RNG::~ANSI_X931_RNG() { delete cipher; diff --git a/src/rng/x931_rng/x931_rng.h b/src/rng/x931_rng/x931_rng.h index 2c68b9cb4..b1cef8df3 100644 --- a/src/rng/x931_rng/x931_rng.h +++ b/src/rng/x931_rng/x931_rng.h @@ -1,7 +1,7 @@ -/************************************************* -* ANSI X9.31 RNG Header File * -* (C) 1999-2008 Jack Lloyd * -*************************************************/ +/* +* ANSI X9.31 RNG Header File +* (C) 1999-2009 Jack Lloyd +*/ #ifndef BOTAN_ANSI_X931_RNG_H__ #define BOTAN_ANSI_X931_RNG_H__ @@ -11,9 +11,9 @@ namespace Botan { -/************************************************* -* ANSI X9.31 RNG * -*************************************************/ +/** +* ANSI X9.31 RNG +*/ class BOTAN_DLL ANSI_X931_RNG : public RandomNumberGenerator { public: @@ -29,6 +29,7 @@ class BOTAN_DLL ANSI_X931_RNG : public RandomNumberGenerator ANSI_X931_RNG(BlockCipher*, RandomNumberGenerator*); ~ANSI_X931_RNG(); private: + void rekey(); void update_buffer(); BlockCipher* cipher; |