8 #include <botan/randpool.h>
9 #include <botan/get_byte.h>
10 #include <botan/internal/xor_buf.h>
11 #include <botan/internal/stl_util.h>
21 enum RANDPOOL_PRF_TAG {
40 const size_t copied = std::min<size_t>(length, buffer.
size());
51 void Randpool::update_buffer()
53 for(
size_t i = 0; i != counter.
size(); ++i)
57 mac->
update(static_cast<byte>(GEN_OUTPUT));
61 for(
size_t i = 0; i != mac_val.
size(); ++i)
62 buffer[i % buffer.
size()] ^= mac_val[i];
65 if(counter[0] % ITERATIONS_BEFORE_RESEED == 0)
72 void Randpool::mix_pool()
74 const size_t BLOCK_SIZE = cipher->
block_size();
76 mac->
update(static_cast<byte>(MAC_KEY));
80 mac->
update(static_cast<byte>(CIPHER_KEY));
84 xor_buf(pool, buffer, BLOCK_SIZE);
86 for(
size_t i = 1; i != POOL_BLOCKS; ++i)
88 const byte* previous_block = &pool[BLOCK_SIZE*(i-1)];
89 byte* this_block = &pool[BLOCK_SIZE*i];
90 xor_buf(this_block, previous_block, BLOCK_SIZE);
104 if(!entropy_sources.empty())
106 size_t poll_attempt = 0;
110 entropy_sources[poll_attempt % entropy_sources.size()]->poll(accum);
142 entropy_sources.push_back(src);
163 return "Randpool(" + cipher->
name() +
"," + mac->
name() +
")";
172 size_t iter_before_reseed) :
173 ITERATIONS_BEFORE_RESEED(iter_before_reseed),
174 POOL_BLOCKS(pool_blocks),
178 const size_t BLOCK_SIZE = cipher->
block_size();
181 if(OUTPUT_LENGTH < BLOCK_SIZE ||
190 buffer.
resize(BLOCK_SIZE);
191 pool.
resize(POOL_BLOCKS * BLOCK_SIZE);
204 std::for_each(entropy_sources.begin(), entropy_sources.end(),
void add_entropy(const byte input[], size_t length)
void add_entropy_source(EntropySource *es)
Randpool(BlockCipher *cipher, MessageAuthenticationCode *mac, size_t pool_blocks=32, size_t iterations_before_reseed=128)
void randomize(byte[], size_t)
bool valid_keylength(size_t length) const
void set_key(const SymmetricKey &key)
virtual std::string name() const =0
MessageAuthenticationCode * mac
void update(const byte in[], size_t length)
bool polling_goal_achieved() const
SecureVector< byte > process(const byte in[], size_t length)
size_t bits_collected() const
void copy_mem(T *out, const T *in, size_t n)
virtual std::string name() const =0
void reseed(size_t bits_to_collect)
void encrypt(const byte in[], byte out[]) const
void xor_buf(byte out[], const byte in[], size_t length)
void zeroise(MemoryRegion< T > &vec)
virtual size_t block_size() const =0
virtual size_t output_length() const =0