diff options
-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; |