aboutsummaryrefslogtreecommitdiffstats
path: root/src/rng/x931_rng
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-01-31 12:50:25 +0000
committerlloyd <[email protected]>2009-01-31 12:50:25 +0000
commitce8e30269816c042cbee8bea46cad7b2dd10e981 (patch)
tree67edbb9157721ce9777b3c235ed60666d3d71aa6 /src/rng/x931_rng
parent99a4f3a728648989878dd8fa6b7cc7188ebcbdad (diff)
parente2927df4522d7e588214f1a5195efa298a6f0d23 (diff)
merge of '93d8e162df445b607d3085d0f966f4e7b286108a'
and 'fc89152d6d99043fb9ed1e9f2569fde3fee419e5'
Diffstat (limited to 'src/rng/x931_rng')
-rw-r--r--src/rng/x931_rng/x931_rng.cpp82
-rw-r--r--src/rng/x931_rng/x931_rng.h15
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;