Botan  1.11.34
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 45 of file entropy_srcs.cpp.

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

46  {
47  if(name == "timestamp")
48  {
49 #if defined(BOTAN_HAS_ENTROPY_SRC_HIGH_RESOLUTION_TIMER)
50  return std::unique_ptr<Entropy_Source>(new High_Resolution_Timestamp);
51 #endif
52  }
53 
54  if(name == "rdrand")
55  {
56 #if defined(BOTAN_HAS_ENTROPY_SRC_RDRAND)
57  return std::unique_ptr<Entropy_Source>(new Intel_Rdrand);
58 #endif
59  }
60 
61  if(name == "rdseed")
62  {
63 #if defined(BOTAN_HAS_ENTROPY_SRC_RDSEED)
64  return std::unique_ptr<Entropy_Source>(new Intel_Rdseed);
65 #endif
66  }
67 
68  if(name == "proc_info")
69  {
70 #if defined(BOTAN_HAS_ENTROPY_SRC_UNIX_PROCESS_RUNNER)
71  return std::unique_ptr<Entropy_Source>(new UnixProcessInfo_EntropySource);
72 #endif
73  }
74 
75  if(name == "darwin_secrandom")
76  {
77 #if defined(BOTAN_HAS_ENTROPY_SRC_DARWIN_SECRANDOM)
78  return std::unique_ptr<Entropy_Source>(new Darwin_SecRandom);
79 #endif
80  }
81 
82  if(name == "dev_random")
83  {
84 #if defined(BOTAN_HAS_ENTROPY_SRC_DEV_RANDOM)
85  return std::unique_ptr<Entropy_Source>(new Device_EntropySource(BOTAN_SYSTEM_RNG_POLL_DEVICES));
86 #endif
87  }
88 
89  if(name == "win32_cryptoapi")
90  {
91 #if defined(BOTAN_HAS_ENTROPY_SRC_CAPI)
92  return std::unique_ptr<Entropy_Source>(new Win32_CAPI_EntropySource("RSA_FULL"));
93 #endif
94  }
95 
96  if(name == "proc_walk")
97  {
98 #if defined(BOTAN_HAS_ENTROPY_SRC_PROC_WALKER)
99  const std::string root_dir = BOTAN_ENTROPY_PROC_FS_PATH;
100  if(!root_dir.empty())
101  return std::unique_ptr<Entropy_Source>(new ProcWalking_EntropySource(root_dir));
102 #endif
103  }
104 
105  if(name == "system_stats")
106  {
107 #if defined(BOTAN_HAS_ENTROPY_SRC_WIN32)
108  return std::unique_ptr<Entropy_Source>(new Win32_EntropySource);
109 #endif
110  }
111 
112  return std::unique_ptr<Entropy_Source>();
113  }
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: