|
Botan
1.11.15
|
#include <proc_walk.h>
Public Member Functions | |
| std::string | name () const |
| void | poll (Entropy_Accumulator &accum) |
| ProcWalking_EntropySource (const std::string &root_dir) | |
Static Public Member Functions | |
| static void | poll_available_sources (class Entropy_Accumulator &accum) |
File Tree Walking Entropy Source
Definition at line 26 of file proc_walk.h.
| Botan::ProcWalking_EntropySource::ProcWalking_EntropySource | ( | const std::string & | root_dir | ) | [inline] |
Definition at line 33 of file proc_walk.h.
:
m_path(root_dir), m_dir(nullptr) {}
| std::string Botan::ProcWalking_EntropySource::name | ( | ) | const [inline, virtual] |
Implements Botan::EntropySource.
Definition at line 29 of file proc_walk.h.
{ return "Proc Walker"; }
| void Botan::ProcWalking_EntropySource::poll | ( | Entropy_Accumulator & | accum | ) | [virtual] |
Perform an entropy gathering poll
| accum | is an accumulator object that will be given entropy |
Implements Botan::EntropySource.
Definition at line 113 of file proc_walk.cpp.
References Botan::Entropy_Accumulator::add(), Botan::Entropy_Accumulator::get_io_buffer(), m_mutex, and Botan::Entropy_Accumulator::polling_goal_achieved().
{
const size_t MAX_FILES_READ_PER_POLL = 2048;
const double ENTROPY_ESTIMATE = 1.0 / (8*1024);
std::lock_guard<std::mutex> lock(m_mutex);
if(!m_dir)
m_dir.reset(new Directory_Walker(m_path));
secure_vector<byte>& io_buffer = accum.get_io_buffer(4096);
for(size_t i = 0; i != MAX_FILES_READ_PER_POLL; ++i)
{
int fd = m_dir->next_fd();
// If we've exhaused this walk of the directory, halt the poll
if(fd == -1)
{
m_dir.reset();
break;
}
ssize_t got = ::read(fd, &io_buffer[0], io_buffer.size());
::close(fd);
if(got > 0)
accum.add(&io_buffer[0], got, ENTROPY_ESTIMATE);
if(accum.polling_goal_achieved())
break;
}
}
| void Botan::EntropySource::poll_available_sources | ( | class Entropy_Accumulator & | accum | ) | [static, inherited] |
Definition at line 108 of file entropy_srcs.cpp.
References Botan::Entropy_Accumulator::polling_goal_achieved().
Referenced by Botan::HMAC_RNG::reseed().
{
static std::vector<std::unique_ptr<EntropySource>> g_sources(get_default_entropy_sources());
if(g_sources.empty())
throw std::runtime_error("No entropy sources enabled at build time, poll failed");
size_t poll_attempt = 0;
while(!accum.polling_goal_achieved() && poll_attempt < 16)
{
const size_t src_idx = poll_attempt % g_sources.size();
g_sources[src_idx]->poll(accum);
++poll_attempt;
}
}
1.7.6.1