Botan  1.11.31
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
 
size_t poll (RandomNumberGenerator &rng) 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 57 of file entropy_srcs.cpp.

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

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

Win32 poll using stats functions including Tooltip32

Implements Botan::Entropy_Source.

Definition at line 17 of file es_win32.cpp.

References Botan::RandomNumberGenerator::add_entropy_T(), and TOOLHELP32_ITER.

Referenced by name().

18  {
19  /*
20  First query a bunch of basic statistical stuff
21  */
22  rng.add_entropy_T(::GetTickCount());
23  rng.add_entropy_T(::GetMessagePos());
24  rng.add_entropy_T(::GetMessageTime());
25  rng.add_entropy_T(::GetInputState());
26 
27  rng.add_entropy_T(::GetCurrentProcessId());
28  rng.add_entropy_T(::GetCurrentThreadId());
29 
30  SYSTEM_INFO sys_info;
31  ::GetSystemInfo(&sys_info);
32  rng.add_entropy_T(sys_info);
33 
34  MEMORYSTATUSEX mem_info;
35  ::GlobalMemoryStatusEx(&mem_info);
36  rng.add_entropy_T(mem_info);
37 
38  POINT point;
39  ::GetCursorPos(&point);
40  rng.add_entropy_T(point);
41 
42  ::GetCaretPos(&point);
43  rng.add_entropy_T(point);
44 
45  /*
46  Now use the Tooltip library to iterate through various objects on
47  the system, including processes, threads, and heap objects.
48  */
49 
50  HANDLE snapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
51  size_t bits = 0;
52 
53 #define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \
54  if(bits < 256) \
55  { \
56  DATA_TYPE info; \
57  info.dwSize = sizeof(DATA_TYPE); \
58  if(FUNC_FIRST(snapshot, &info)) \
59  { \
60  do \
61  { \
62  rng.add_entropy_T(info); \
63  bits += 4; \
64  } while(FUNC_NEXT(snapshot, &info)); \
65  } \
66  }
67 
68  TOOLHELP32_ITER(MODULEENTRY32, ::Module32First, ::Module32Next);
69  TOOLHELP32_ITER(PROCESSENTRY32, ::Process32First, ::Process32Next);
70  TOOLHELP32_ITER(THREADENTRY32, ::Thread32First, ::Thread32Next);
71 
72 #undef TOOLHELP32_ITER
73 
74  if(bits <= 256)
75  {
76  HEAPLIST32 heap_list;
77  heap_list.dwSize = sizeof(HEAPLIST32);
78 
79  if(::Heap32ListFirst(snapshot, &heap_list))
80  {
81  do
82  {
83  rng.add_entropy_T(heap_list);
84 
85  HEAPENTRY32 heap_entry;
86  heap_entry.dwSize = sizeof(HEAPENTRY32);
87  if(::Heap32First(&heap_entry,
88  heap_list.th32ProcessID,
89  heap_list.th32HeapID))
90  {
91  do
92  {
93  rng.add_entropy_T(heap_entry);
94  bits += 4;
95  } while(::Heap32Next(&heap_entry));
96  }
97 
98  if(bits >= 256)
99  break;
100 
101  } while(::Heap32ListNext(snapshot, &heap_list));
102  }
103  }
104 
105  ::CloseHandle(snapshot);
106 
107  return bits;
108  }
#define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT)

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