diff options
Diffstat (limited to 'src/lib/libcrypto/rand/rand_win.c')
| -rw-r--r-- | src/lib/libcrypto/rand/rand_win.c | 104 |
1 files changed, 62 insertions, 42 deletions
diff --git a/src/lib/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c index 3584842224..30c69161ef 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 TEXT("Intel Hardware Cryptographic Service Provider") | 128 | #define INTEL_DEF_PROV L"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); |
| @@ -152,7 +152,7 @@ typedef struct tagCURSORINFO | |||
| 152 | #define CURSOR_SHOWING 0x00000001 | 152 | #define CURSOR_SHOWING 0x00000001 |
| 153 | #endif /* CURSOR_SHOWING */ | 153 | #endif /* CURSOR_SHOWING */ |
| 154 | 154 | ||
| 155 | typedef BOOL (WINAPI *CRYPTACQUIRECONTEXT)(HCRYPTPROV *, LPCTSTR, LPCTSTR, | 155 | typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTW)(HCRYPTPROV *, LPCWSTR, LPCWSTR, |
| 156 | DWORD, DWORD); | 156 | DWORD, DWORD); |
| 157 | typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV, DWORD, BYTE *); | 157 | typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV, DWORD, BYTE *); |
| 158 | typedef BOOL (WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV, DWORD); | 158 | typedef BOOL (WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV, DWORD); |
| @@ -194,7 +194,7 @@ int RAND_poll(void) | |||
| 194 | HWND h; | 194 | HWND h; |
| 195 | 195 | ||
| 196 | HMODULE advapi, kernel, user, netapi; | 196 | HMODULE advapi, kernel, user, netapi; |
| 197 | CRYPTACQUIRECONTEXT acquire = 0; | 197 | CRYPTACQUIRECONTEXTW acquire = 0; |
| 198 | CRYPTGENRANDOM gen = 0; | 198 | CRYPTGENRANDOM gen = 0; |
| 199 | CRYPTRELEASECONTEXT release = 0; | 199 | CRYPTRELEASECONTEXT release = 0; |
| 200 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this | 200 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this |
| @@ -213,6 +213,9 @@ int RAND_poll(void) | |||
| 213 | GetVersionEx( &osverinfo ) ; | 213 | GetVersionEx( &osverinfo ) ; |
| 214 | 214 | ||
| 215 | #if defined(OPENSSL_SYS_WINCE) && WCEPLATFORM!=MS_HPC_PRO | 215 | #if defined(OPENSSL_SYS_WINCE) && WCEPLATFORM!=MS_HPC_PRO |
| 216 | #ifndef CryptAcquireContext | ||
| 217 | #define CryptAcquireContext CryptAcquireContextW | ||
| 218 | #endif | ||
| 216 | /* poll the CryptoAPI PRNG */ | 219 | /* poll the CryptoAPI PRNG */ |
| 217 | /* The CryptoAPI returns sizeof(buf) bytes of randomness */ | 220 | /* The CryptoAPI returns sizeof(buf) bytes of randomness */ |
| 218 | if (CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) | 221 | if (CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) |
| @@ -223,21 +226,35 @@ int RAND_poll(void) | |||
| 223 | } | 226 | } |
| 224 | #endif | 227 | #endif |
| 225 | 228 | ||
| 229 | #ifndef OPENSSL_SYS_WINCE | ||
| 230 | /* | ||
| 231 | * None of below libraries are present on Windows CE, which is | ||
| 232 | * why we #ifndef the whole section. This also excuses us from | ||
| 233 | * handling the GetProcAddress issue. The trouble is that in | ||
| 234 | * real Win32 API GetProcAddress is available in ANSI flavor | ||
| 235 | * only. In WinCE on the other hand GetProcAddress is a macro | ||
| 236 | * most commonly defined as GetProcAddressW, which accepts | ||
| 237 | * Unicode argument. If we were to call GetProcAddress under | ||
| 238 | * WinCE, I'd recommend to either redefine GetProcAddress as | ||
| 239 | * GetProcAddressA (there seem to be one in common CE spec) or | ||
| 240 | * implement own shim routine, which would accept ANSI argument | ||
| 241 | * and expand it to Unicode. | ||
| 242 | */ | ||
| 243 | |||
| 226 | /* load functions dynamically - not available on all systems */ | 244 | /* load functions dynamically - not available on all systems */ |
| 227 | advapi = LoadLibrary(TEXT("ADVAPI32.DLL")); | 245 | advapi = LoadLibrary(TEXT("ADVAPI32.DLL")); |
| 228 | kernel = LoadLibrary(TEXT("KERNEL32.DLL")); | 246 | kernel = LoadLibrary(TEXT("KERNEL32.DLL")); |
| 229 | user = LoadLibrary(TEXT("USER32.DLL")); | 247 | user = LoadLibrary(TEXT("USER32.DLL")); |
| 230 | netapi = LoadLibrary(TEXT("NETAPI32.DLL")); | 248 | netapi = LoadLibrary(TEXT("NETAPI32.DLL")); |
| 231 | 249 | ||
| 232 | #ifndef OPENSSL_SYS_WINCE | ||
| 233 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this | 250 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this |
| 234 | * section is still experimental, but if all goes well, this conditional | 251 | * section is still experimental, but if all goes well, this conditional |
| 235 | * will be removed | 252 | * will be removed |
| 236 | */ | 253 | */ |
| 237 | if (netapi) | 254 | if (netapi) |
| 238 | { | 255 | { |
| 239 | netstatget = (NETSTATGET) GetProcAddress(netapi,TEXT("NetStatisticsGet")); | 256 | netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet"); |
| 240 | netfree = (NETFREE) GetProcAddress(netapi,TEXT("NetApiBufferFree")); | 257 | netfree = (NETFREE) GetProcAddress(netapi,"NetApiBufferFree"); |
| 241 | } | 258 | } |
| 242 | 259 | ||
| 243 | if (netstatget && netfree) | 260 | if (netstatget && netfree) |
| @@ -264,9 +281,7 @@ int RAND_poll(void) | |||
| 264 | if (netapi) | 281 | if (netapi) |
| 265 | FreeLibrary(netapi); | 282 | FreeLibrary(netapi); |
| 266 | #endif /* 1 */ | 283 | #endif /* 1 */ |
| 267 | #endif /* !OPENSSL_SYS_WINCE */ | 284 | |
| 268 | |||
| 269 | #ifndef OPENSSL_SYS_WINCE | ||
| 270 | /* It appears like this can cause an exception deep within ADVAPI32.DLL | 285 | /* It appears like this can cause an exception deep within ADVAPI32.DLL |
| 271 | * at random times on Windows 2000. Reported by Jeffrey Altman. | 286 | * at random times on Windows 2000. Reported by Jeffrey Altman. |
| 272 | * Only use it on NT. | 287 | * Only use it on NT. |
| @@ -321,16 +336,20 @@ int RAND_poll(void) | |||
| 321 | free(buf); | 336 | free(buf); |
| 322 | } | 337 | } |
| 323 | #endif | 338 | #endif |
| 324 | #endif /* !OPENSSL_SYS_WINCE */ | ||
| 325 | 339 | ||
| 326 | if (advapi) | 340 | if (advapi) |
| 327 | { | 341 | { |
| 328 | acquire = (CRYPTACQUIRECONTEXT) GetProcAddress(advapi, | 342 | /* |
| 329 | TEXT("CryptAcquireContextA")); | 343 | * If it's available, then it's available in both ANSI |
| 344 | * and UNICODE flavors even in Win9x, documentation says. | ||
| 345 | * We favor Unicode... | ||
| 346 | */ | ||
| 347 | acquire = (CRYPTACQUIRECONTEXTW) GetProcAddress(advapi, | ||
| 348 | "CryptAcquireContextW"); | ||
| 330 | gen = (CRYPTGENRANDOM) GetProcAddress(advapi, | 349 | gen = (CRYPTGENRANDOM) GetProcAddress(advapi, |
| 331 | TEXT("CryptGenRandom")); | 350 | "CryptGenRandom"); |
| 332 | release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi, | 351 | release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi, |
| 333 | TEXT("CryptReleaseContext")); | 352 | "CryptReleaseContext"); |
| 334 | } | 353 | } |
| 335 | 354 | ||
| 336 | if (acquire && gen && release) | 355 | if (acquire && gen && release) |
| @@ -367,26 +386,15 @@ int RAND_poll(void) | |||
| 367 | if (advapi) | 386 | if (advapi) |
| 368 | FreeLibrary(advapi); | 387 | FreeLibrary(advapi); |
| 369 | 388 | ||
| 370 | /* timer data */ | ||
| 371 | readtimer(); | ||
| 372 | |||
| 373 | /* memory usage statistics */ | ||
| 374 | GlobalMemoryStatus(&m); | ||
| 375 | RAND_add(&m, sizeof(m), 1); | ||
| 376 | |||
| 377 | /* process ID */ | ||
| 378 | w = GetCurrentProcessId(); | ||
| 379 | RAND_add(&w, sizeof(w), 1); | ||
| 380 | |||
| 381 | if (user) | 389 | if (user) |
| 382 | { | 390 | { |
| 383 | GETCURSORINFO cursor; | 391 | GETCURSORINFO cursor; |
| 384 | GETFOREGROUNDWINDOW win; | 392 | GETFOREGROUNDWINDOW win; |
| 385 | GETQUEUESTATUS queue; | 393 | GETQUEUESTATUS queue; |
| 386 | 394 | ||
| 387 | win = (GETFOREGROUNDWINDOW) GetProcAddress(user, TEXT("GetForegroundWindow")); | 395 | win = (GETFOREGROUNDWINDOW) GetProcAddress(user, "GetForegroundWindow"); |
| 388 | cursor = (GETCURSORINFO) GetProcAddress(user, TEXT("GetCursorInfo")); | 396 | cursor = (GETCURSORINFO) GetProcAddress(user, "GetCursorInfo"); |
| 389 | queue = (GETQUEUESTATUS) GetProcAddress(user, TEXT("GetQueueStatus")); | 397 | queue = (GETQUEUESTATUS) GetProcAddress(user, "GetQueueStatus"); |
| 390 | 398 | ||
| 391 | if (win) | 399 | if (win) |
| 392 | { | 400 | { |
| @@ -458,19 +466,19 @@ int RAND_poll(void) | |||
| 458 | MODULEENTRY32 m; | 466 | MODULEENTRY32 m; |
| 459 | 467 | ||
| 460 | snap = (CREATETOOLHELP32SNAPSHOT) | 468 | snap = (CREATETOOLHELP32SNAPSHOT) |
| 461 | GetProcAddress(kernel, TEXT("CreateToolhelp32Snapshot")); | 469 | GetProcAddress(kernel, "CreateToolhelp32Snapshot"); |
| 462 | close_snap = (CLOSETOOLHELP32SNAPSHOT) | 470 | close_snap = (CLOSETOOLHELP32SNAPSHOT) |
| 463 | GetProcAddress(kernel, TEXT("CloseToolhelp32Snapshot")); | 471 | GetProcAddress(kernel, "CloseToolhelp32Snapshot"); |
| 464 | heap_first = (HEAP32FIRST) GetProcAddress(kernel, TEXT("Heap32First")); | 472 | heap_first = (HEAP32FIRST) GetProcAddress(kernel, "Heap32First"); |
| 465 | heap_next = (HEAP32NEXT) GetProcAddress(kernel, TEXT("Heap32Next")); | 473 | heap_next = (HEAP32NEXT) GetProcAddress(kernel, "Heap32Next"); |
| 466 | heaplist_first = (HEAP32LIST) GetProcAddress(kernel, TEXT("Heap32ListFirst")); | 474 | heaplist_first = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListFirst"); |
| 467 | heaplist_next = (HEAP32LIST) GetProcAddress(kernel, TEXT("Heap32ListNext")); | 475 | heaplist_next = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListNext"); |
| 468 | process_first = (PROCESS32) GetProcAddress(kernel, TEXT("Process32First")); | 476 | process_first = (PROCESS32) GetProcAddress(kernel, "Process32First"); |
| 469 | process_next = (PROCESS32) GetProcAddress(kernel, TEXT("Process32Next")); | 477 | process_next = (PROCESS32) GetProcAddress(kernel, "Process32Next"); |
| 470 | thread_first = (THREAD32) GetProcAddress(kernel, TEXT("Thread32First")); | 478 | thread_first = (THREAD32) GetProcAddress(kernel, "Thread32First"); |
| 471 | thread_next = (THREAD32) GetProcAddress(kernel, TEXT("Thread32Next")); | 479 | thread_next = (THREAD32) GetProcAddress(kernel, "Thread32Next"); |
| 472 | module_first = (MODULE32) GetProcAddress(kernel, TEXT("Module32First")); | 480 | module_first = (MODULE32) GetProcAddress(kernel, "Module32First"); |
| 473 | module_next = (MODULE32) GetProcAddress(kernel, TEXT("Module32Next")); | 481 | module_next = (MODULE32) GetProcAddress(kernel, "Module32Next"); |
| 474 | 482 | ||
| 475 | if (snap && heap_first && heap_next && heaplist_first && | 483 | if (snap && heap_first && heap_next && heaplist_first && |
| 476 | heaplist_next && process_first && process_next && | 484 | heaplist_next && process_first && process_next && |
| @@ -546,6 +554,18 @@ int RAND_poll(void) | |||
| 546 | 554 | ||
| 547 | FreeLibrary(kernel); | 555 | FreeLibrary(kernel); |
| 548 | } | 556 | } |
| 557 | #endif /* !OPENSSL_SYS_WINCE */ | ||
| 558 | |||
| 559 | /* timer data */ | ||
| 560 | readtimer(); | ||
| 561 | |||
| 562 | /* memory usage statistics */ | ||
| 563 | GlobalMemoryStatus(&m); | ||
| 564 | RAND_add(&m, sizeof(m), 1); | ||
| 565 | |||
| 566 | /* process ID */ | ||
| 567 | w = GetCurrentProcessId(); | ||
| 568 | RAND_add(&w, sizeof(w), 1); | ||
| 549 | 569 | ||
| 550 | #if 0 | 570 | #if 0 |
| 551 | printf("Exiting RAND_poll\n"); | 571 | printf("Exiting RAND_poll\n"); |
| @@ -607,7 +627,7 @@ static void readtimer(void) | |||
| 607 | DWORD w; | 627 | DWORD w; |
| 608 | LARGE_INTEGER l; | 628 | LARGE_INTEGER l; |
| 609 | static int have_perfc = 1; | 629 | static int have_perfc = 1; |
| 610 | #if defined(_MSC_VER) && !defined(OPENSSL_SYS_WINCE) | 630 | #if defined(_MSC_VER) && defined(_M_X86) |
| 611 | static int have_tsc = 1; | 631 | static int have_tsc = 1; |
| 612 | DWORD cyclecount; | 632 | DWORD cyclecount; |
| 613 | 633 | ||
| @@ -660,7 +680,7 @@ static void readtimer(void) | |||
| 660 | 680 | ||
| 661 | static void readscreen(void) | 681 | static void readscreen(void) |
| 662 | { | 682 | { |
| 663 | #ifndef OPENSSL_SYS_WINCE | 683 | #if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) |
| 664 | HDC hScrDC; /* screen DC */ | 684 | HDC hScrDC; /* screen DC */ |
| 665 | HDC hMemDC; /* memory DC */ | 685 | HDC hMemDC; /* memory DC */ |
| 666 | HBITMAP hBitmap; /* handle for our bitmap */ | 686 | HBITMAP hBitmap; /* handle for our bitmap */ |
