aboutsummaryrefslogtreecommitdiffstats
path: root/src/rng/x931_rng/x931_rng.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-01-31 10:48:07 +0000
committerlloyd <[email protected]>2009-01-31 10:48:07 +0000
commit716176904747020267858f4b8b2c04675d76c873 (patch)
treec5bcf2d7efdea8945c4daae75b48c8bea140523e /src/rng/x931_rng/x931_rng.cpp
parent89b72bf90264acc6cb84ee424e29ec4bd0e7539e (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/rng/x931_rng/x931_rng.cpp')
-rw-r--r--src/rng/x931_rng/x931_rng.cpp82
1 files changed, 45 insertions, 37 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;