Botan  1.11.15
Public Member Functions | Static Public Member Functions
Botan::UnixProcessInfo_EntropySource Class Reference

#include <unix_procs.h>

Inheritance diagram for Botan::UnixProcessInfo_EntropySource:
Botan::EntropySource

List of all members.

Public Member Functions

std::string name () const
void poll (Entropy_Accumulator &accum)

Static Public Member Functions

static void poll_available_sources (class Entropy_Accumulator &accum)

Detailed Description

Definition at line 80 of file unix_procs.h.


Member Function Documentation

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

Implements Botan::EntropySource.

Definition at line 83 of file unix_procs.h.

{ return "Unix Process Info"; }

Perform an entropy gathering poll

Parameters:
accumis an accumulator object that will be given entropy

Implements Botan::EntropySource.

Definition at line 69 of file unix_procs.cpp.

References Botan::Entropy_Accumulator::add().

   {
   static std::atomic<int> last_pid;

   int pid = ::getpid();

   accum.add(pid, 0.0);

   if(pid != last_pid)
      {
      last_pid = pid;
      accum.add(::getppid(), 0.0);
      accum.add(::getuid(),  0.0);
      accum.add(::getgid(),  0.0);
      accum.add(::getsid(0),  0.0);
      accum.add(::getpgrp(), 0.0);
      }

   struct ::rusage usage;
   ::getrusage(RUSAGE_SELF, &usage);
   accum.add(usage, 0.0);
   }
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: