diff options
author | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
commit | a2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch) | |
tree | ad3d6c4fcc8dd0f403f8105598943616246fe172 /modules/es_win32 |
Initial checkin1.5.6
Diffstat (limited to 'modules/es_win32')
-rw-r--r-- | modules/es_win32/es_win32.cpp | 105 | ||||
-rw-r--r-- | modules/es_win32/es_win32.h | 25 | ||||
-rw-r--r-- | modules/es_win32/modinfo.txt | 18 |
3 files changed, 148 insertions, 0 deletions
diff --git a/modules/es_win32/es_win32.cpp b/modules/es_win32/es_win32.cpp new file mode 100644 index 000000000..fda02effe --- /dev/null +++ b/modules/es_win32/es_win32.cpp @@ -0,0 +1,105 @@ +/************************************************* +* Win32 EntropySource Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include <botan/es_win32.h> +#include <windows.h> +#include <tlhelp32.h> + +namespace Botan { + +/************************************************* +* Win32 Slow Poll * +*************************************************/ +void Win32_EntropySource::do_slow_poll() + { + const u32bit MAX_ITEMS = 256; + + do_fast_poll(); + + HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); + +#define TOOLHELP32_ITER(DATA_TYPE, FUNC_FIRST, FUNC_NEXT) \ + { \ + u32bit items = 0; \ + DATA_TYPE info; \ + info.dwSize = sizeof(DATA_TYPE); \ + if(FUNC_FIRST(snapshot, &info)) \ + { \ + do \ + { \ + if(items++ > MAX_ITEMS) break; \ + add_bytes(&info, sizeof(info)); \ + } while(FUNC_NEXT(snapshot, &info)); \ + } \ + } + + TOOLHELP32_ITER(MODULEENTRY32, Module32First, Module32Next); + TOOLHELP32_ITER(PROCESSENTRY32, Process32First, Process32Next); + TOOLHELP32_ITER(THREADENTRY32, Thread32First, Thread32Next); + +#undef TOOLHELP32_ITER + + u32bit heap_lists_found = 0; + HEAPLIST32 heap_list; + heap_list.dwSize = sizeof(HEAPLIST32); + + const u32bit HEAP_LISTS_MAX = 32; + const u32bit HEAP_OBJS_PER_LIST = 128; + if(Heap32ListFirst(snapshot, &heap_list)) + { + do + { + add_bytes(&heap_list, sizeof(HEAPLIST32)); + + if(heap_lists_found++ > HEAP_LISTS_MAX) + break; + + u32bit heap_objs_found = 0; + HEAPENTRY32 heap_entry; + heap_entry.dwSize = sizeof(HEAPENTRY32); + if(Heap32First(&heap_entry, heap_list.th32ProcessID, + heap_list.th32HeapID)) + { + do + { + if(heap_objs_found++ > HEAP_OBJS_PER_LIST) + break; + add_bytes(&heap_entry, sizeof(HEAPENTRY32)); + } while(Heap32Next(&heap_entry)); + } + } while(Heap32ListNext(snapshot, &heap_list)); + } + + CloseHandle(snapshot); + } + +/************************************************* +* Win32 Fast Poll * +*************************************************/ +void Win32_EntropySource::do_fast_poll() + { + add_bytes(GetTickCount()); + add_bytes(GetMessagePos()); + add_bytes(GetMessageTime()); + add_bytes(GetInputState()); + add_bytes(GetCurrentProcessId()); + add_bytes(GetCurrentThreadId()); + + SYSTEM_INFO sys_info; + GetSystemInfo(&sys_info); + add_bytes(&sys_info, sizeof(sys_info)); + + MEMORYSTATUS mem_info; + GlobalMemoryStatus(&mem_info); + add_bytes(&mem_info, sizeof(mem_info)); + + POINT point; + GetCursorPos(&point); + add_bytes(&point, sizeof(point)); + GetCaretPos(&point); + add_bytes(&point, sizeof(point)); + } + +} diff --git a/modules/es_win32/es_win32.h b/modules/es_win32/es_win32.h new file mode 100644 index 000000000..7ca9f1285 --- /dev/null +++ b/modules/es_win32/es_win32.h @@ -0,0 +1,25 @@ +/************************************************* +* Win32 EntropySource Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_EXT_ENTROPY_SRC_WIN32_H__ +#define BOTAN_EXT_ENTROPY_SRC_WIN32_H__ + +#include <botan/buf_es.h> + +namespace Botan { + +/************************************************* +* Win32 Entropy Source * +*************************************************/ +class Win32_EntropySource : public Buffered_EntropySource + { + private: + void do_fast_poll(); + void do_slow_poll(); + }; + +} + +#endif diff --git a/modules/es_win32/modinfo.txt b/modules/es_win32/modinfo.txt new file mode 100644 index 000000000..67e1a6ec0 --- /dev/null +++ b/modules/es_win32/modinfo.txt @@ -0,0 +1,18 @@ +realname "MS Windows Entropy Source" + +# Probably not much of an issue anymore +#note "This module will not run under NT4" + +define ENTROPY_SRC_WIN32 + +add_file es_win32.h +add_file es_win32.cpp + +<os> +windows +cygwin +</os> + +<libs> +windows -> user32 +</libs> |