Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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:

## Public Member Functions
std::string | name () const override
size_t | poll (RandomNumberGenerator &rng) override

## Static Public Member Functions
static std::unique_ptr< Entropy_Source > | create (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 | ) |
| static inherited

Return a new entropy source of a particular type, or null Each entropy source may require substantial resources (eg, a file handle or socket instance), so try to share them among multiple RNGs, or just use the preconfigured global list accessed by Entropy_Sources::global_sources()

Definition at line 45 of file entropy_srcs.cpp.

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

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

std::string Botan::Win32_EntropySource::name | ( |  | ) | const
| inline override virtual

Returns
  name identifying this entropy source

Implements Botan::Entropy_Source.

Definition at line 21 of file es_win32.h.

21 { return "system_stats"; }

size_t Botan::Win32_EntropySource::poll | ( | RandomNumberGenerator & | rng | ) |
| override virtual

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.

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 }
TOOLHELP32_ITER
#define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT)

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

- src/lib/entropy/win32_stats/es_win32.h
- src/lib/entropy/win32_stats/es_win32.cpp