summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/rand/rand_win.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/rand/rand_win.c')
-rw-r--r--src/lib/libcrypto/rand/rand_win.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/lib/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c
index 113b58678f..263068d256 100644
--- a/src/lib/libcrypto/rand/rand_win.c
+++ b/src/lib/libcrypto/rand/rand_win.c
@@ -162,6 +162,7 @@ typedef BOOL (WINAPI *GETCURSORINFO)(PCURSORINFO);
162typedef DWORD (WINAPI *GETQUEUESTATUS)(UINT); 162typedef DWORD (WINAPI *GETQUEUESTATUS)(UINT);
163 163
164typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD); 164typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD);
165typedef BOOL (WINAPI *CLOSETOOLHELP32SNAPSHOT)(HANDLE);
165typedef BOOL (WINAPI *HEAP32FIRST)(LPHEAPENTRY32, DWORD, DWORD); 166typedef BOOL (WINAPI *HEAP32FIRST)(LPHEAPENTRY32, DWORD, DWORD);
166typedef BOOL (WINAPI *HEAP32NEXT)(LPHEAPENTRY32); 167typedef BOOL (WINAPI *HEAP32NEXT)(LPHEAPENTRY32);
167typedef BOOL (WINAPI *HEAP32LIST)(HANDLE, LPHEAPLIST32); 168typedef BOOL (WINAPI *HEAP32LIST)(HANDLE, LPHEAPLIST32);
@@ -431,7 +432,7 @@ int RAND_poll(void)
431 * This seeding method was proposed in Peter Gutmann, Software 432 * This seeding method was proposed in Peter Gutmann, Software
432 * Generation of Practically Strong Random Numbers, 433 * Generation of Practically Strong Random Numbers,
433 * http://www.usenix.org/publications/library/proceedings/sec98/gutmann.html 434 * http://www.usenix.org/publications/library/proceedings/sec98/gutmann.html
434 * revised version at http://www.cryptoengines.com/~peter/06_random.pdf 435 * revised version at http://www.cryptoengines.com/~peter/06_random.pdf
435 * (The assignment of entropy estimates below is arbitrary, but based 436 * (The assignment of entropy estimates below is arbitrary, but based
436 * on Peter's analysis the full poll appears to be safe. Additional 437 * on Peter's analysis the full poll appears to be safe. Additional
437 * interactive seeding is encouraged.) 438 * interactive seeding is encouraged.)
@@ -440,6 +441,7 @@ int RAND_poll(void)
440 if (kernel) 441 if (kernel)
441 { 442 {
442 CREATETOOLHELP32SNAPSHOT snap; 443 CREATETOOLHELP32SNAPSHOT snap;
444 CLOSETOOLHELP32SNAPSHOT close_snap;
443 HANDLE handle; 445 HANDLE handle;
444 446
445 HEAP32FIRST heap_first; 447 HEAP32FIRST heap_first;
@@ -457,6 +459,8 @@ int RAND_poll(void)
457 459
458 snap = (CREATETOOLHELP32SNAPSHOT) 460 snap = (CREATETOOLHELP32SNAPSHOT)
459 GetProcAddress(kernel, TEXT("CreateToolhelp32Snapshot")); 461 GetProcAddress(kernel, TEXT("CreateToolhelp32Snapshot"));
462 close_snap = (CLOSETOOLHELP32SNAPSHOT)
463 GetProcAddress(kernel, TEXT("CloseToolhelp32Snapshot"));
460 heap_first = (HEAP32FIRST) GetProcAddress(kernel, TEXT("Heap32First")); 464 heap_first = (HEAP32FIRST) GetProcAddress(kernel, TEXT("Heap32First"));
461 heap_next = (HEAP32NEXT) GetProcAddress(kernel, TEXT("Heap32Next")); 465 heap_next = (HEAP32NEXT) GetProcAddress(kernel, TEXT("Heap32Next"));
462 heaplist_first = (HEAP32LIST) GetProcAddress(kernel, TEXT("Heap32ListFirst")); 466 heaplist_first = (HEAP32LIST) GetProcAddress(kernel, TEXT("Heap32ListFirst"));
@@ -472,7 +476,7 @@ int RAND_poll(void)
472 heaplist_next && process_first && process_next && 476 heaplist_next && process_first && process_next &&
473 thread_first && thread_next && module_first && 477 thread_first && thread_next && module_first &&
474 module_next && (handle = snap(TH32CS_SNAPALL,0)) 478 module_next && (handle = snap(TH32CS_SNAPALL,0))
475 != NULL) 479 != INVALID_HANDLE_VALUE)
476 { 480 {
477 /* heap list and heap walking */ 481 /* heap list and heap walking */
478 /* HEAPLIST32 contains 3 fields that will change with 482 /* HEAPLIST32 contains 3 fields that will change with
@@ -534,8 +538,10 @@ int RAND_poll(void)
534 do 538 do
535 RAND_add(&m, m.dwSize, 9); 539 RAND_add(&m, m.dwSize, 9);
536 while (module_next(handle, &m)); 540 while (module_next(handle, &m));
537 541 if (close_snap)
538 CloseHandle(handle); 542 close_snap(handle);
543 else
544 CloseHandle(handle);
539 } 545 }
540 546
541 FreeLibrary(kernel); 547 FreeLibrary(kernel);