Botan  1.11.26
Public Member Functions | Static Public Member Functions | List of all members
Botan::Win32_EntropySource Class Referencefinal

#include <es_win32.h>

Inheritance diagram for Botan::Win32_EntropySource:
Botan::Entropy_Source

Public Member Functions

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

Static Public Member Functions

static std::unique_ptr< Entropy_Sourcecreate (const std::string &type)
 

Detailed Description

Win32 Entropy Source

Definition at line 18 of file es_win32.h.

Member Function Documentation

std::unique_ptr< Entropy_Source > Botan::Entropy_Source::create ( const std::string &  type)
staticinherited

Definition at line 56 of file entropy_srcs.cpp.

Referenced by Botan::Entropy_Sources::Entropy_Sources().

57  {
58  if(name == "timestamp")
59  {
60 #if defined(BOTAN_HAS_ENTROPY_SRC_HIGH_RESOLUTION_TIMER)
61  return std::unique_ptr<Entropy_Source>(new High_Resolution_Timestamp);
62 #endif
63  }
64 
65  if(name == "rdrand")
66  {
67 #if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND)
68  return std::unique_ptr<Entropy_Source>(new Intel_Rdrand);
69 #endif
70  }
71 
72  if(name == "rdseed")
73  {
74 #if defined(BOTAN_HAS_ENTROPY_SRC_RDSEED)
75  return std::unique_ptr<Entropy_Source>(new Intel_Rdseed);
76 #endif
77  }
78 
79  if(name == "proc_info")
80  {
81 #if defined(BOTAN_HAS_ENTROPY_SRC_UNIX_PROCESS_RUNNER)
82  return std::unique_ptr<Entropy_Source>(new UnixProcessInfo_EntropySource);
83 #endif
84  }
85 
86  if(name == "darwin_secrandom")
87  {
88 #if defined(BOTAN_HAS_ENTROPY_SRC_DARWIN_SECRANDOM)
89  return std::unique_ptr<Entropy_Source>(new Darwin_SecRandom);
90 #endif
91  }
92 
93  if(name == "dev_random")
94  {
95 #if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
96  return std::unique_ptr<Entropy_Source>(new Device_EntropySource(BOTAN_SYSTEM_RNG_POLL_DEVICES));
97  }
98 
99  if(name == "win32_cryptoapi")
100  {
101 #elif defined(BOTAN_HAS_ENTROPY_SRC_CAPI)
102  return std::unique_ptr<Entropy_Source>(new Win32_CAPI_EntropySource);
103 #endif
104  }
105 
106  if(name == "proc_walk")
107  {
108 #if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER)
109  return std::unique_ptr<Entropy_Source>(new ProcWalking_EntropySource("/proc"));
110 #endif
111  }
112 
113  if(name == "system_stats")
114  {
115 #if defined(BOTAN_HAS_ENTROPY_SRC_WIN32)
116  return std::unique_ptr<Entropy_Source>(new Win32_EntropySource);
117 #elif defined(BOTAN_HAS_ENTROPY_SRC_BEOS)
118  return std::unique_ptr<Entropy_Source>(new BeOS_EntropySource);
119 #endif
120  }
121 
122  if(name == "unix_procs")
123  {
124 #if defined(BOTAN_HAS_ENTROPY_SRC_UNIX_PROCESS_RUNNER)
125  return std::unique_ptr<Entropy_Source>(new Unix_EntropySource(BOTAN_ENTROPY_SAFE_PATHS));
126 #endif
127  }
128 
129  if(name == "egd")
130  {
131 #if defined(BOTAN_HAS_ENTROPY_SRC_EGD)
132  return std::unique_ptr<Entropy_Source>(new EGD_EntropySource(BOTAN_ENTROPY_EGD_PATHS));
133 #endif
134  }
135 
136  return std::unique_ptr<Entropy_Source>();
137  }
virtual std::string name() const =0
std::string Botan::Win32_EntropySource::name ( ) const
inlineoverridevirtual
Returns
name identifying this entropy source

Implements Botan::Entropy_Source.

Definition at line 21 of file es_win32.h.

References poll().

21 { return "system_stats"; }
void Botan::Win32_EntropySource::poll ( Entropy_Accumulator accum)
overridevirtual

Win32 poll using stats functions including Tooltip32

Implements Botan::Entropy_Source.

Definition at line 17 of file es_win32.cpp.

References Botan::Entropy_Accumulator::add(), Botan::Entropy_Accumulator::polling_finished(), and TOOLHELP32_ITER.

Referenced by name().

18  {
19  /*
20  First query a bunch of basic statistical stuff, though
21  don't count it for much in terms of contributed entropy.
22  */
23  accum.add(GetTickCount64(), BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
24  accum.add(GetMessagePos(), BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
25  accum.add(GetMessageTime(), BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
26  accum.add(GetInputState(), BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
27 
28  accum.add(GetCurrentProcessId(), BOTAN_ENTROPY_ESTIMATE_STATIC_SYSTEM_DATA);
29  accum.add(GetCurrentThreadId(), BOTAN_ENTROPY_ESTIMATE_STATIC_SYSTEM_DATA);
30 
31  SYSTEM_INFO sys_info;
32  GetSystemInfo(&sys_info);
33  accum.add(sys_info, BOTAN_ENTROPY_ESTIMATE_STATIC_SYSTEM_DATA);
34 
35  MEMORYSTATUSEX mem_info;
36  GlobalMemoryStatusEx(&mem_info);
37  accum.add(mem_info, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
38 
39  POINT point;
40  GetCursorPos(&point);
41  accum.add(point, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
42 
43  GetCaretPos(&point);
44  accum.add(point, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
45 
46  LARGE_INTEGER perf_counter;
47  QueryPerformanceCounter(&perf_counter);
48  accum.add(perf_counter, BOTAN_ENTROPY_ESTIMATE_TIMESTAMPS);
49 
50  /*
51  Now use the Tooltip library to iterate throug various objects on
52  the system, including processes, threads, and heap objects.
53  */
54 
55  HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
56 
57 #define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \
58  if(!accum.polling_finished()) \
59  { \
60  DATA_TYPE info; \
61  info.dwSize = sizeof(DATA_TYPE); \
62  if(FUNC_FIRST(snapshot, &info)) \
63  { \
64  do \
65  { \
66  accum.add(info, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA); \
67  } while(FUNC_NEXT(snapshot, &info)); \
68  } \
69  }
70 
71  TOOLHELP32_ITER(MODULEENTRY32, Module32First, Module32Next);
72  TOOLHELP32_ITER(PROCESSENTRY32, Process32First, Process32Next);
73  TOOLHELP32_ITER(THREADENTRY32, Thread32First, Thread32Next);
74 
75 #undef TOOLHELP32_ITER
76 
77  if(!accum.polling_finished())
78  {
79  size_t heap_lists_found = 0;
80  HEAPLIST32 heap_list;
81  heap_list.dwSize = sizeof(HEAPLIST32);
82 
83  const size_t HEAP_LISTS_MAX = 32;
84  const size_t HEAP_OBJS_PER_LIST = 128;
85 
86  if(Heap32ListFirst(snapshot, &heap_list))
87  {
88  do
89  {
90  accum.add(heap_list, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
91 
92  if(++heap_lists_found > HEAP_LISTS_MAX)
93  break;
94 
95  size_t heap_objs_found = 0;
96  HEAPENTRY32 heap_entry;
97  heap_entry.dwSize = sizeof(HEAPENTRY32);
98  if(Heap32First(&heap_entry, heap_list.th32ProcessID,
99  heap_list.th32HeapID))
100  {
101  do
102  {
103  if(heap_objs_found++ > HEAP_OBJS_PER_LIST)
104  break;
105  accum.add(heap_entry, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
106  } while(Heap32Next(&heap_entry));
107  }
108 
109  if(accum.polling_finished())
110  break;
111 
112  } while(Heap32ListNext(snapshot, &heap_list));
113  }
114  }
115 
116  CloseHandle(snapshot);
117  }
#define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT)

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