aboutsummaryrefslogtreecommitdiffstats
path: root/src/rng/randpool/randpool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rng/randpool/randpool.cpp')
-rw-r--r--src/rng/randpool/randpool.cpp44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/rng/randpool/randpool.cpp b/src/rng/randpool/randpool.cpp
index d75885a76..51354db12 100644
--- a/src/rng/randpool/randpool.cpp
+++ b/src/rng/randpool/randpool.cpp
@@ -29,7 +29,7 @@ enum RANDPOOL_PRF_TAG {
/*
* Generate a buffer of random bytes
*/
-void Randpool::randomize(byte out[], u32bit length)
+void Randpool::randomize(byte out[], size_t length)
{
if(!is_seeded())
throw PRNG_Unseeded(name());
@@ -37,8 +37,8 @@ void Randpool::randomize(byte out[], u32bit length)
update_buffer();
while(length)
{
- const u32bit copied = std::min(length, buffer.size());
- copy_mem(out, buffer.begin(), copied);
+ const size_t copied = std::min<size_t>(length, buffer.size());
+ copy_mem(out, &buffer[0], copied);
out += copied;
length -= copied;
update_buffer();
@@ -50,15 +50,15 @@ void Randpool::randomize(byte out[], u32bit length)
*/
void Randpool::update_buffer()
{
- for(u32bit i = 0; i != counter.size(); ++i)
+ for(size_t i = 0; i != counter.size(); ++i)
if(++counter[i])
break;
mac->update(static_cast<byte>(GEN_OUTPUT));
- mac->update(counter, counter.size());
+ mac->update(counter);
SecureVector<byte> mac_val = mac->final();
- for(u32bit i = 0; i != mac_val.size(); ++i)
+ for(size_t i = 0; i != mac_val.size(); ++i)
buffer[i % buffer.size()] ^= mac_val[i];
cipher->encrypt(buffer);
@@ -71,22 +71,22 @@ void Randpool::update_buffer()
*/
void Randpool::mix_pool()
{
- const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE;
+ const size_t BLOCK_SIZE = cipher->block_size();
mac->update(static_cast<byte>(MAC_KEY));
- mac->update(pool, pool.size());
+ mac->update(pool);
mac->set_key(mac->final());
mac->update(static_cast<byte>(CIPHER_KEY));
- mac->update(pool, pool.size());
+ mac->update(pool);
cipher->set_key(mac->final());
xor_buf(pool, buffer, BLOCK_SIZE);
cipher->encrypt(pool);
- for(u32bit i = 1; i != POOL_BLOCKS; ++i)
+ for(size_t i = 1; i != POOL_BLOCKS; ++i)
{
- const byte* previous_block = pool + BLOCK_SIZE*(i-1);
- byte* this_block = pool + BLOCK_SIZE*i;
+ const byte* previous_block = &pool[BLOCK_SIZE*(i-1)];
+ byte* this_block = &pool[BLOCK_SIZE*i];
xor_buf(this_block, previous_block, BLOCK_SIZE);
cipher->encrypt(this_block);
}
@@ -97,13 +97,13 @@ void Randpool::mix_pool()
/*
* Reseed the internal state
*/
-void Randpool::reseed(u32bit poll_bits)
+void Randpool::reseed(size_t poll_bits)
{
Entropy_Accumulator_BufferedComputation accum(*mac, poll_bits);
if(!entropy_sources.empty())
{
- u32bit poll_attempt = 0;
+ size_t poll_attempt = 0;
while(!accum.polling_goal_achieved() && poll_attempt < poll_bits)
{
@@ -124,7 +124,7 @@ void Randpool::reseed(u32bit poll_bits)
/*
* Add user-supplied entropy
*/
-void Randpool::add_entropy(const byte input[], u32bit length)
+void Randpool::add_entropy(const byte input[], size_t length)
{
SecureVector<byte> mac_val = mac->process(input, length);
xor_buf(pool, mac_val, mac_val.size());
@@ -149,9 +149,9 @@ void Randpool::clear()
{
cipher->clear();
mac->clear();
- pool.clear();
- buffer.clear();
- counter.clear();
+ zeroise(pool);
+ zeroise(buffer);
+ zeroise(counter);
seeded = false;
}
@@ -168,15 +168,15 @@ std::string Randpool::name() const
*/
Randpool::Randpool(BlockCipher* cipher_in,
MessageAuthenticationCode* mac_in,
- u32bit pool_blocks,
- u32bit iter_before_reseed) :
+ size_t pool_blocks,
+ size_t iter_before_reseed) :
ITERATIONS_BEFORE_RESEED(iter_before_reseed),
POOL_BLOCKS(pool_blocks),
cipher(cipher_in),
mac(mac_in)
{
- const u32bit BLOCK_SIZE = cipher->BLOCK_SIZE;
- const u32bit OUTPUT_LENGTH = mac->OUTPUT_LENGTH;
+ const size_t BLOCK_SIZE = cipher->block_size();
+ const size_t OUTPUT_LENGTH = mac->output_length();
if(OUTPUT_LENGTH < BLOCK_SIZE ||
!cipher->valid_keylength(OUTPUT_LENGTH) ||