Botan  1.11.15
Classes | Public Member Functions | Static Public Member Functions
Botan::EGD_EntropySource Class Reference

#include <es_egd.h>

Inheritance diagram for Botan::EGD_EntropySource:
Botan::EntropySource

List of all members.

Classes

class  EGD_Socket

Public Member Functions

 EGD_EntropySource (const std::vector< std::string > &)
std::string name () const
void poll (Entropy_Accumulator &accum)
 ~EGD_EntropySource ()

Static Public Member Functions

static void poll_available_sources (class Entropy_Accumulator &accum)

Detailed Description

EGD Entropy Source

Definition at line 21 of file es_egd.h.


Constructor & Destructor Documentation

Botan::EGD_EntropySource::EGD_EntropySource ( const std::vector< std::string > &  paths)

EGD_EntropySource constructor

Definition at line 122 of file es_egd.cpp.

   {
   for(size_t i = 0; i != paths.size(); ++i)
      sockets.push_back(EGD_Socket(paths[i]));
   }

Definition at line 128 of file es_egd.cpp.

   {
   for(size_t i = 0; i != sockets.size(); ++i)
      sockets[i].close();
   sockets.clear();
   }

Member Function Documentation

std::string Botan::EGD_EntropySource::name ( ) const [inline, virtual]
Returns:
name identifying this entropy source

Implements Botan::EntropySource.

Definition at line 24 of file es_egd.h.

{ return "EGD/PRNGD"; }

Gather Entropy from EGD

Implements Botan::EntropySource.

Definition at line 138 of file es_egd.cpp.

References Botan::Entropy_Accumulator::add(), and Botan::Entropy_Accumulator::get_io_buffer().

   {
   const size_t READ_ATTEMPT = 32;

   std::lock_guard<std::mutex> lock(m_mutex);

   secure_vector<byte>& io_buffer = accum.get_io_buffer(READ_ATTEMPT);

   for(size_t i = 0; i != sockets.size(); ++i)
      {
      size_t got = sockets[i].read(&io_buffer[0], io_buffer.size());

      if(got)
         {
         accum.add(&io_buffer[0], got, 6);
         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;
      }
   }

The documentation for this class was generated from the following files: