diff options
Diffstat (limited to 'src/lib/libcrypto/rand/rand_win.c')
-rw-r--r-- | src/lib/libcrypto/rand/rand_win.c | 84 |
1 files changed, 56 insertions, 28 deletions
diff --git a/src/lib/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c index c1b955b06f..113b58678f 100644 --- a/src/lib/libcrypto/rand/rand_win.c +++ b/src/lib/libcrypto/rand/rand_win.c | |||
@@ -125,7 +125,7 @@ | |||
125 | * http://developer.intel.com/design/security/rng/redist_license.htm | 125 | * http://developer.intel.com/design/security/rng/redist_license.htm |
126 | */ | 126 | */ |
127 | #define PROV_INTEL_SEC 22 | 127 | #define PROV_INTEL_SEC 22 |
128 | #define INTEL_DEF_PROV "Intel Hardware Cryptographic Service Provider" | 128 | #define INTEL_DEF_PROV TEXT("Intel Hardware Cryptographic Service Provider") |
129 | 129 | ||
130 | static void readtimer(void); | 130 | static void readtimer(void); |
131 | static void readscreen(void); | 131 | static void readscreen(void); |
@@ -170,7 +170,9 @@ typedef BOOL (WINAPI *THREAD32)(HANDLE, LPTHREADENTRY32); | |||
170 | typedef BOOL (WINAPI *MODULE32)(HANDLE, LPMODULEENTRY32); | 170 | typedef BOOL (WINAPI *MODULE32)(HANDLE, LPMODULEENTRY32); |
171 | 171 | ||
172 | #include <lmcons.h> | 172 | #include <lmcons.h> |
173 | #ifndef OPENSSL_SYS_WINCE | ||
173 | #include <lmstats.h> | 174 | #include <lmstats.h> |
175 | #endif | ||
174 | #if 1 /* The NET API is Unicode only. It requires the use of the UNICODE | 176 | #if 1 /* The NET API is Unicode only. It requires the use of the UNICODE |
175 | * macro. When UNICODE is defined LPTSTR becomes LPWSTR. LMSTR was | 177 | * macro. When UNICODE is defined LPTSTR becomes LPWSTR. LMSTR was |
176 | * was added to the Platform SDK to allow the NET API to be used in | 178 | * was added to the Platform SDK to allow the NET API to be used in |
@@ -209,20 +211,32 @@ int RAND_poll(void) | |||
209 | osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ; | 211 | osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ; |
210 | GetVersionEx( &osverinfo ) ; | 212 | GetVersionEx( &osverinfo ) ; |
211 | 213 | ||
214 | #if defined(OPENSSL_SYS_WINCE) && WCEPLATFORM!=MS_HPC_PRO | ||
215 | /* poll the CryptoAPI PRNG */ | ||
216 | /* The CryptoAPI returns sizeof(buf) bytes of randomness */ | ||
217 | if (CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) | ||
218 | { | ||
219 | if (CryptGenRandom(hProvider, sizeof(buf), buf)) | ||
220 | RAND_add(buf, sizeof(buf), sizeof(buf)); | ||
221 | CryptReleaseContext(hProvider, 0); | ||
222 | } | ||
223 | #endif | ||
224 | |||
212 | /* load functions dynamically - not available on all systems */ | 225 | /* load functions dynamically - not available on all systems */ |
213 | advapi = LoadLibrary("ADVAPI32.DLL"); | 226 | advapi = LoadLibrary(TEXT("ADVAPI32.DLL")); |
214 | kernel = LoadLibrary("KERNEL32.DLL"); | 227 | kernel = LoadLibrary(TEXT("KERNEL32.DLL")); |
215 | user = LoadLibrary("USER32.DLL"); | 228 | user = LoadLibrary(TEXT("USER32.DLL")); |
216 | netapi = LoadLibrary("NETAPI32.DLL"); | 229 | netapi = LoadLibrary(TEXT("NETAPI32.DLL")); |
217 | 230 | ||
231 | #ifndef OPENSSL_SYS_WINCE | ||
218 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this | 232 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this |
219 | * section is still experimental, but if all goes well, this conditional | 233 | * section is still experimental, but if all goes well, this conditional |
220 | * will be removed | 234 | * will be removed |
221 | */ | 235 | */ |
222 | if (netapi) | 236 | if (netapi) |
223 | { | 237 | { |
224 | netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet"); | 238 | netstatget = (NETSTATGET) GetProcAddress(netapi,TEXT("NetStatisticsGet")); |
225 | netfree = (NETFREE) GetProcAddress(netapi,"NetApiBufferFree"); | 239 | netfree = (NETFREE) GetProcAddress(netapi,TEXT("NetApiBufferFree")); |
226 | } | 240 | } |
227 | 241 | ||
228 | if (netstatget && netfree) | 242 | if (netstatget && netfree) |
@@ -249,7 +263,9 @@ int RAND_poll(void) | |||
249 | if (netapi) | 263 | if (netapi) |
250 | FreeLibrary(netapi); | 264 | FreeLibrary(netapi); |
251 | #endif /* 1 */ | 265 | #endif /* 1 */ |
266 | #endif /* !OPENSSL_SYS_WINCE */ | ||
252 | 267 | ||
268 | #ifndef OPENSSL_SYS_WINCE | ||
253 | /* It appears like this can cause an exception deep within ADVAPI32.DLL | 269 | /* It appears like this can cause an exception deep within ADVAPI32.DLL |
254 | * at random times on Windows 2000. Reported by Jeffrey Altman. | 270 | * at random times on Windows 2000. Reported by Jeffrey Altman. |
255 | * Only use it on NT. | 271 | * Only use it on NT. |
@@ -280,30 +296,40 @@ int RAND_poll(void) | |||
280 | bufsz += 8192; | 296 | bufsz += 8192; |
281 | 297 | ||
282 | length = bufsz; | 298 | length = bufsz; |
283 | rc = RegQueryValueEx(HKEY_PERFORMANCE_DATA, "Global", | 299 | rc = RegQueryValueEx(HKEY_PERFORMANCE_DATA, TEXT("Global"), |
284 | NULL, NULL, buf, &length); | 300 | NULL, NULL, buf, &length); |
285 | } | 301 | } |
286 | if (rc == ERROR_SUCCESS) | 302 | if (rc == ERROR_SUCCESS) |
287 | { | 303 | { |
288 | /* For entropy count assume only least significant | 304 | /* For entropy count assume only least significant |
289 | * byte of each DWORD is random. | 305 | * byte of each DWORD is random. |
290 | */ | 306 | */ |
291 | RAND_add(&length, sizeof(length), 0); | 307 | RAND_add(&length, sizeof(length), 0); |
292 | RAND_add(buf, length, length / 4.0); | 308 | RAND_add(buf, length, length / 4.0); |
309 | |||
310 | /* Close the Registry Key to allow Windows to cleanup/close | ||
311 | * the open handle | ||
312 | * Note: The 'HKEY_PERFORMANCE_DATA' key is implicitly opened | ||
313 | * when the RegQueryValueEx above is done. However, if | ||
314 | * it is not explicitly closed, it can cause disk | ||
315 | * partition manipulation problems. | ||
316 | */ | ||
317 | RegCloseKey(HKEY_PERFORMANCE_DATA); | ||
293 | } | 318 | } |
294 | if (buf) | 319 | if (buf) |
295 | free(buf); | 320 | free(buf); |
296 | } | 321 | } |
297 | #endif | 322 | #endif |
323 | #endif /* !OPENSSL_SYS_WINCE */ | ||
298 | 324 | ||
299 | if (advapi) | 325 | if (advapi) |
300 | { | 326 | { |
301 | acquire = (CRYPTACQUIRECONTEXT) GetProcAddress(advapi, | 327 | acquire = (CRYPTACQUIRECONTEXT) GetProcAddress(advapi, |
302 | "CryptAcquireContextA"); | 328 | TEXT("CryptAcquireContextA")); |
303 | gen = (CRYPTGENRANDOM) GetProcAddress(advapi, | 329 | gen = (CRYPTGENRANDOM) GetProcAddress(advapi, |
304 | "CryptGenRandom"); | 330 | TEXT("CryptGenRandom")); |
305 | release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi, | 331 | release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi, |
306 | "CryptReleaseContext"); | 332 | TEXT("CryptReleaseContext")); |
307 | } | 333 | } |
308 | 334 | ||
309 | if (acquire && gen && release) | 335 | if (acquire && gen && release) |
@@ -357,9 +383,9 @@ int RAND_poll(void) | |||
357 | GETFOREGROUNDWINDOW win; | 383 | GETFOREGROUNDWINDOW win; |
358 | GETQUEUESTATUS queue; | 384 | GETQUEUESTATUS queue; |
359 | 385 | ||
360 | win = (GETFOREGROUNDWINDOW) GetProcAddress(user, "GetForegroundWindow"); | 386 | win = (GETFOREGROUNDWINDOW) GetProcAddress(user, TEXT("GetForegroundWindow")); |
361 | cursor = (GETCURSORINFO) GetProcAddress(user, "GetCursorInfo"); | 387 | cursor = (GETCURSORINFO) GetProcAddress(user, TEXT("GetCursorInfo")); |
362 | queue = (GETQUEUESTATUS) GetProcAddress(user, "GetQueueStatus"); | 388 | queue = (GETQUEUESTATUS) GetProcAddress(user, TEXT("GetQueueStatus")); |
363 | 389 | ||
364 | if (win) | 390 | if (win) |
365 | { | 391 | { |
@@ -430,17 +456,17 @@ int RAND_poll(void) | |||
430 | MODULEENTRY32 m; | 456 | MODULEENTRY32 m; |
431 | 457 | ||
432 | snap = (CREATETOOLHELP32SNAPSHOT) | 458 | snap = (CREATETOOLHELP32SNAPSHOT) |
433 | GetProcAddress(kernel, "CreateToolhelp32Snapshot"); | 459 | GetProcAddress(kernel, TEXT("CreateToolhelp32Snapshot")); |
434 | heap_first = (HEAP32FIRST) GetProcAddress(kernel, "Heap32First"); | 460 | heap_first = (HEAP32FIRST) GetProcAddress(kernel, TEXT("Heap32First")); |
435 | heap_next = (HEAP32NEXT) GetProcAddress(kernel, "Heap32Next"); | 461 | heap_next = (HEAP32NEXT) GetProcAddress(kernel, TEXT("Heap32Next")); |
436 | heaplist_first = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListFirst"); | 462 | heaplist_first = (HEAP32LIST) GetProcAddress(kernel, TEXT("Heap32ListFirst")); |
437 | heaplist_next = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListNext"); | 463 | heaplist_next = (HEAP32LIST) GetProcAddress(kernel, TEXT("Heap32ListNext")); |
438 | process_first = (PROCESS32) GetProcAddress(kernel, "Process32First"); | 464 | process_first = (PROCESS32) GetProcAddress(kernel, TEXT("Process32First")); |
439 | process_next = (PROCESS32) GetProcAddress(kernel, "Process32Next"); | 465 | process_next = (PROCESS32) GetProcAddress(kernel, TEXT("Process32Next")); |
440 | thread_first = (THREAD32) GetProcAddress(kernel, "Thread32First"); | 466 | thread_first = (THREAD32) GetProcAddress(kernel, TEXT("Thread32First")); |
441 | thread_next = (THREAD32) GetProcAddress(kernel, "Thread32Next"); | 467 | thread_next = (THREAD32) GetProcAddress(kernel, TEXT("Thread32Next")); |
442 | module_first = (MODULE32) GetProcAddress(kernel, "Module32First"); | 468 | module_first = (MODULE32) GetProcAddress(kernel, TEXT("Module32First")); |
443 | module_next = (MODULE32) GetProcAddress(kernel, "Module32Next"); | 469 | module_next = (MODULE32) GetProcAddress(kernel, TEXT("Module32Next")); |
444 | 470 | ||
445 | if (snap && heap_first && heap_next && heaplist_first && | 471 | if (snap && heap_first && heap_next && heaplist_first && |
446 | heaplist_next && process_first && process_next && | 472 | heaplist_next && process_first && process_next && |
@@ -575,7 +601,7 @@ static void readtimer(void) | |||
575 | DWORD w; | 601 | DWORD w; |
576 | LARGE_INTEGER l; | 602 | LARGE_INTEGER l; |
577 | static int have_perfc = 1; | 603 | static int have_perfc = 1; |
578 | #ifdef _MSC_VER | 604 | #if defined(_MSC_VER) && !defined(OPENSSL_SYS_WINCE) |
579 | static int have_tsc = 1; | 605 | static int have_tsc = 1; |
580 | DWORD cyclecount; | 606 | DWORD cyclecount; |
581 | 607 | ||
@@ -628,6 +654,7 @@ static void readtimer(void) | |||
628 | 654 | ||
629 | static void readscreen(void) | 655 | static void readscreen(void) |
630 | { | 656 | { |
657 | #ifndef OPENSSL_SYS_WINCE | ||
631 | HDC hScrDC; /* screen DC */ | 658 | HDC hScrDC; /* screen DC */ |
632 | HDC hMemDC; /* memory DC */ | 659 | HDC hMemDC; /* memory DC */ |
633 | HBITMAP hBitmap; /* handle for our bitmap */ | 660 | HBITMAP hBitmap; /* handle for our bitmap */ |
@@ -641,7 +668,7 @@ static void readscreen(void) | |||
641 | int n = 16; /* number of screen lines to grab at a time */ | 668 | int n = 16; /* number of screen lines to grab at a time */ |
642 | 669 | ||
643 | /* Create a screen DC and a memory DC compatible to screen DC */ | 670 | /* Create a screen DC and a memory DC compatible to screen DC */ |
644 | hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL); | 671 | hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); |
645 | hMemDC = CreateCompatibleDC(hScrDC); | 672 | hMemDC = CreateCompatibleDC(hScrDC); |
646 | 673 | ||
647 | /* Get screen resolution */ | 674 | /* Get screen resolution */ |
@@ -688,6 +715,7 @@ static void readscreen(void) | |||
688 | DeleteObject(hBitmap); | 715 | DeleteObject(hBitmap); |
689 | DeleteDC(hMemDC); | 716 | DeleteDC(hMemDC); |
690 | DeleteDC(hScrDC); | 717 | DeleteDC(hScrDC); |
718 | #endif /* !OPENSSL_SYS_WINCE */ | ||
691 | } | 719 | } |
692 | 720 | ||
693 | #endif | 721 | #endif |