Botan  1.11.33
Crypto and TLS for C++11
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

§ create()

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

Definition at line 41 of file entropy_srcs.cpp.

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

42  {
43  if(name == "rdrand")
44  {
45 #if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND)
46  return std::unique_ptr<Entropy_Source>(new Intel_Rdrand);
47 #endif
48  }
49 
50  if(name == "rdseed")
51  {
52 #if defined(BOTAN_HAS_ENTROPY_SRC_RDSEED)
53  return std::unique_ptr<Entropy_Source>(new Intel_Rdseed);
54 #endif
55  }
56 
57  if(name == "darwin_secrandom")
58  {
59 #if defined(BOTAN_HAS_ENTROPY_SRC_DARWIN_SECRANDOM)
60  return std::unique_ptr<Entropy_Source>(new Darwin_SecRandom);
61 #endif
62  }
63 
64  if(name == "dev_random")
65  {
66 #if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
67  return std::unique_ptr<Entropy_Source>(new Device_EntropySource(BOTAN_SYSTEM_RNG_POLL_DEVICES));
68 #endif
69  }
70 
71  if(name == "win32_cryptoapi")
72  {
73 #if defined(BOTAN_HAS_ENTROPY_SRC_CAPI)
74  return std::unique_ptr<Entropy_Source>(new Win32_CAPI_EntropySource("RSA_FULL"));
75 #endif
76  }
77 
78  if(name == "proc_walk")
79  {
80 #if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER)
81  const std::string root_dir = BOTAN_ENTROPY_PROC_FS_PATH;
82  if(!root_dir.empty())
83  return std::unique_ptr<Entropy_Source>(new ProcWalking_EntropySource(root_dir));
84 #endif
85  }
86 
87  if(name == "system_stats")
88  {
89 #if defined(BOTAN_HAS_ENTROPY_SRC_WIN32)
90  return std::unique_ptr<Entropy_Source>(new Win32_EntropySource);
91 #endif
92  }
93 
94  return std::unique_ptr<Entropy_Source>();
95  }
virtual std::string name() const =0

§ name()

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"; }

§ poll()

size_t Botan::Win32_EntropySource::poll ( RandomNumberGenerator rng)
overridevirtual

Win32 poll using stats functions including Tooltip32

Implements Botan::Entropy_Source.

Definition at line 18 of file es_win32.cpp.

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

Referenced by name().

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

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