[Patch] Enabling entropy gathering with Tool Help on Windows 2000
Sami Tolvanen
sami@tolvanen.com
Tue Jun 26 19:34:01 2001
GnuPG uses the Tool Help library for gathering entropy only when
running on Windows 9x. However, this API is also available on Windows
NT 5.0 and later. The following patch (against 1.0.6)
o Renames the function slow_gatherer_windows95 to
slow_gatherer_toolhelp
o Calls slow_gatherer_toolhelp in addition to
slow_gatherer_windowsNT if NT version >= 5
I am not sure how much this helps, but I suppose collecting more
entropy cannot hurt.
--
Sami Tolvanen
http://www.tolvanen.com/sami/
--- rndw32.c.orig Tue Jun 26 06:55:33 2001
+++ rndw32.c Tue Jun 26 06:57:06 2001
@@ -372,8 +372,7 @@
-/* Type definitions for function pointers to call Toolhelp32 functions
- * used with the windows95 gatherer */
+/* Type definitions for function pointers to call Toolhelp32 functions */
typedef BOOL (WINAPI * MODULEWALK) (HANDLE hSnapshot, MODULEENTRY32 *lpme);
typedef BOOL (WINAPI * THREADWALK) (HANDLE hSnapshot, THREADENTRY32 *lpte);
typedef BOOL (WINAPI * PROCESSWALK) (HANDLE hSnapshot, PROCESSENTRY32 *lppe);
@@ -401,7 +400,7 @@
static void
-slow_gatherer_windows95( void (*add)(const void*, size_t, int), int requester )
+slow_gatherer_toolhelp( void (*add)(const void*, size_t, int), int requester )
{
static CREATESNAPSHOT pCreateToolhelp32Snapshot = NULL;
static MODULEWALK pModule32First = NULL;
@@ -422,7 +421,7 @@
HANDLE hKernel;
if ( debug_me )
- log_debug ("rndw32#slow_gatherer_95: init toolkit\n" );
+ log_debug ("rndw32#slow_gatherer_toolhelp: init toolkit\n" );
/* Obtain the module handle of the kernel to retrieve the addresses
* of the Toolhelp32 functions */
@@ -469,7 +468,7 @@
hl32.dwSize = sizeof (HEAPLIST32);
if (pHeap32ListFirst (hSnapshot, &hl32)) {
if ( debug_me )
- log_debug ("rndw32#slow_gatherer_95: walk heap\n" );
+ log_debug ("rndw32#slow_gatherer_toolhelp: walk heap\n" );
do {
HEAPENTRY32 he32;
@@ -494,7 +493,7 @@
pe32.dwSize = sizeof (PROCESSENTRY32);
if (pProcess32First (hSnapshot, &pe32)) {
if ( debug_me )
- log_debug ("rndw32#slow_gatherer_95: walk processes\n" );
+ log_debug ("rndw32#slow_gatherer_toolhelp: walk processes\n" );
do {
(*add) ( &pe32, sizeof (pe32), requester );
} while (pProcess32Next (hSnapshot, &pe32));
@@ -506,7 +505,7 @@
te32.dwSize = sizeof (THREADENTRY32);
if (pThread32First (hSnapshot, &te32)) {
if ( debug_me )
- log_debug ("rndw32#slow_gatherer_95: walk threads\n" );
+ log_debug ("rndw32#slow_gatherer_toolhelp: walk threads\n" );
do {
(*add) ( &te32, sizeof (te32), requester );
} while (pThread32Next (hSnapshot, &te32));
@@ -518,7 +517,7 @@
me32.dwSize = sizeof (MODULEENTRY32);
if (pModule32First (hSnapshot, &me32)) {
if ( debug_me )
- log_debug ("rndw32#slow_gatherer_95: walk modules\n" );
+ log_debug ("rndw32#slow_gatherer_toolhelp: walk modules\n" );
do {
(*add) ( &me32, sizeof (me32), requester );
} while (pModule32Next (hSnapshot, &me32));
@@ -729,7 +728,8 @@
size_t length, int level )
{
static int is_initialized;
- static int is_windows95;
+ static int is_windowsNT;
+ static int has_toolhelp;
if( !level )
@@ -747,7 +747,10 @@
GetVersionEx( &osvi );
platform = osvi.dwPlatformId;
- is_windows95 = platform == VER_PLATFORM_WIN32_WINDOWS;
+
+ is_windowsNT = platform == VER_PLATFORM_WIN32_NT;
+ has_toolhelp = ( platform == VER_PLATFORM_WIN32_WINDOWS ||
+ ( is_windowsNT && osvi.dwMajorVersion >= 5 ) );
if ( platform == VER_PLATFORM_WIN32s ) {
g10_log_fatal("can't run on a W32s platform\n" );
@@ -762,10 +765,10 @@
log_debug ("rndw32#gather_random: req=%d len=%u lvl=%d\n",
requester, (unsigned int)length, level );
- if (is_windows95 ) {
- slow_gatherer_windows95( add, requester );
- }
- else {
+ if ( has_toolhelp ) {
+ slow_gatherer_toolhelp( add, requester );
+ }
+ if ( is_windowsNT ) {
slow_gatherer_windowsNT( add, requester );
}