Botan 1.10.17

Public Member Functions | List of all members
Botan::Unix_EntropySource Class Reference

`#include <es_unix.h>`

Inheritance diagram for Botan::Unix_EntropySource:

## Public Member Functions
void | add_sources (const Unix_Program[], size_t)
std::string | name () const
void | poll (Entropy_Accumulator &accum)
| Unix_EntropySource (const std::vector< std::string > &path)

## Detailed Description

Unix Entropy Source

Definition at line 20 of file es_unix.h.

## Constructor & Destructor Documentation

## ◆ Unix_EntropySource()

Botan::Unix_EntropySource::Unix_EntropySource | ( | const std::vector< std::string > & | path | ) |

Unix_EntropySource Constructor

Definition at line 38 of file es_unix.cpp.

References add_sources().

38 :
39 PATH(path)
40 {
41 std::vector<Unix_Program> default_sources = get_default_sources();
42 add_sources(&default_sources[0], default_sources.size());
43 }
Botan::Unix_EntropySource::add_sources
void add_sources(const Unix_Program[], size_t)
Definition: es_unix.cpp:48

## Member Function Documentation

## ◆ add_sources()

void Botan::Unix_EntropySource::add_sources | ( | const Unix_Program | srcs[],
|  | size_t | count
| ) |  |

Add sources to the list

Definition at line 48 of file es_unix.cpp.

Referenced by Unix_EntropySource().

49 {
50 sources.insert(sources.end(), srcs, srcs + count);
51 std::sort(sources.begin(), sources.end(), Unix_Program_Cmp);
52 }

## ◆ name()

std::string Botan::Unix_EntropySource::name | ( |  | ) | const
| inline virtual

Returns
  name identifying this entropy source

Implements Botan::EntropySource.

Definition at line 23 of file es_unix.h.

23 { return "Unix Entropy Source"; }

## ◆ poll()

void Botan::Unix_EntropySource::poll | ( | Entropy_Accumulator & | accum | ) |
| virtual

Poll for entropy on a generic Unix system, first by grabbing various statistics (stat on common files, getrusage, etc), and then, if more is required, by exec'ing various programs like uname and rpcinfo and reading the output.

Implements Botan::EntropySource.

Definition at line 60 of file es_unix.cpp.

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

61 {
62 const char* stat_targets[] = {
63 "/",
64 "/tmp",
65 "/var/tmp",
66 "/usr",
67 "/home",
68 "/etc/passwd",
69 ".",
70 "..",
71 0 };
72
73 for(size_t i = 0; stat_targets[i]; i++)
74 {
75 struct stat statbuf;
76 clear_mem(&statbuf, 1);
77 if(::stat(stat_targets[i], &statbuf) == 0)
78 accum.add(&statbuf, sizeof(statbuf), .005);
79 }
80
81 accum.add(::getpid(), 0);
82 accum.add(::getppid(), 0);
83 accum.add(::getuid(), 0);
84 accum.add(::getgid(), 0);
85 accum.add(::getpgrp(), 0);
86
87 struct ::rusage usage;
88 ::getrusage(RUSAGE_SELF, &usage);
89 accum.add(usage, .005);
90
91 ::getrusage(RUSAGE_CHILDREN, &usage);
92 accum.add(usage, .005);
93
94 const size_t MINIMAL_WORKING = 16;
95
96 MemoryRegion<byte>& io_buffer = accum.get_io_buffer(DEFAULT_BUFFERSIZE);
97
98 for(size_t i = 0; i != sources.size(); i++)
99 {
100 DataSource_Command pipe(sources[i].name_and_args, PATH);
101
102 size_t got_from_src = 0;
103
104 while(!pipe.end_of_data())
105 {
106 size_t got_this_loop = pipe.read(&io_buffer[0], io_buffer.size());
107 got_from_src += got_this_loop;
108
109 accum.add(&io_buffer[0], got_this_loop, .005);
110 }
111
112 sources[i].working = (got_from_src >= MINIMAL_WORKING) ? true : false;
113
114 if(accum.polling_goal_achieved())
115 break;
116 }
117 }
Botan::clear_mem
void clear_mem(T *ptr, size_t n)
Definition: mem_ops.h:32

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

- src/entropy/unix_procs/es_unix.h
- src/entropy/unix_procs/es_unix.cpp
- src/entropy/unix_procs/unix_src.cpp