8 #include <botan/randpool.h>
9 #include <botan/get_byte.h>
10 #include <botan/internal/xor_buf.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);
117 xor_buf(pool, mac_val, mac_val.size());
130 xor_buf(pool, mac_val, mac_val.size());
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 ||
188 cipher->
name() +
"/" + mac->
name());
191 buffer.resize(BLOCK_SIZE);
192 pool.resize(POOL_BLOCKS * BLOCK_SIZE);
205 for(
auto i = entropy_sources.begin(); i != entropy_sources.end(); ++i)