Botan  1.11.30
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(GetTickCount(), 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  /*
47  Now use the Tooltip library to iterate throug various objects on
48  the system, including processes, threads, and heap objects.
49  */
50 
51  HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
52 
53 #define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \
54  if(!accum.polling_finished()) \
55  { \
56  DATA_TYPE info; \
57  info.dwSize = sizeof(DATA_TYPE); \
58  if(FUNC_FIRST(snapshot, &info)) \
59  { \
60  do \
61  { \
62  accum.add(info, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA); \
63  } while(FUNC_NEXT(snapshot, &info)); \
64  } \
65  }
66 
67  TOOLHELP32_ITER(MODULEENTRY32, Module32First, Module32Next);
68  TOOLHELP32_ITER(PROCESSENTRY32, Process32First, Process32Next);
69  TOOLHELP32_ITER(THREADENTRY32, Thread32First, Thread32Next);
70 
71 #undef TOOLHELP32_ITER
72 
73  if(!accum.polling_finished())
74  {
75  HEAPLIST32 heap_list;
76  heap_list.dwSize = sizeof(HEAPLIST32);
77 
78  const size_t HEAP_LISTS_MAX = 32;
79  const size_t HEAP_OBJS_PER_LIST = 128;
80 
81  if(Heap32ListFirst(snapshot, &heap_list))
82  {
83  size_t heap_lists_found = 0;
84  do
85  {
86  accum.add(heap_list, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
87 
88  if(++heap_lists_found > HEAP_LISTS_MAX)
89  break;
90 
91  HEAPENTRY32 heap_entry;
92  heap_entry.dwSize = sizeof(HEAPENTRY32);
93  if(Heap32First(&heap_entry, heap_list.th32ProcessID,
94  heap_list.th32HeapID))
95  {
96  size_t heap_objs_found = 0;
97  do
98  {
99  if(heap_objs_found++ > HEAP_OBJS_PER_LIST)
100  break;
101  accum.add(heap_entry, BOTAN_ENTROPY_ESTIMATE_SYSTEM_DATA);
102  } while(Heap32Next(&heap_entry));
103  }
104 
105  if(accum.polling_finished())
106  break;
107 
108  } while(Heap32ListNext(snapshot, &heap_list));
109  }
110  }
111 
112  CloseHandle(snapshot);
113  }
#define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT)

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