diff options
author | markus <> | 2002-09-05 12:51:52 +0000 |
---|---|---|
committer | markus <> | 2002-09-05 12:51:52 +0000 |
commit | 5514995a9d5ed91db089875adb509c7781357c0e (patch) | |
tree | 2484410a46ba6c05ef94c253da36fbceef990b64 /src/lib/libcrypto/rand/rand_win.c | |
parent | fd9566423b542798f5c8b06e68101a9ea5bb9885 (diff) | |
download | openbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.gz openbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.bz2 openbsd-5514995a9d5ed91db089875adb509c7781357c0e.zip |
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/rand/rand_win.c')
-rw-r--r-- | src/lib/libcrypto/rand/rand_win.c | 67 |
1 files changed, 14 insertions, 53 deletions
diff --git a/src/lib/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c index 9f2dcff9a9..c1b955b06f 100644 --- a/src/lib/libcrypto/rand/rand_win.c +++ b/src/lib/libcrypto/rand/rand_win.c | |||
@@ -113,7 +113,7 @@ | |||
113 | #include <openssl/rand.h> | 113 | #include <openssl/rand.h> |
114 | #include "rand_lcl.h" | 114 | #include "rand_lcl.h" |
115 | 115 | ||
116 | #if defined(WINDOWS) || defined(WIN32) | 116 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) |
117 | #include <windows.h> | 117 | #include <windows.h> |
118 | #ifndef _WIN32_WINNT | 118 | #ifndef _WIN32_WINNT |
119 | # define _WIN32_WINNT 0x0400 | 119 | # define _WIN32_WINNT 0x0400 |
@@ -254,6 +254,10 @@ int RAND_poll(void) | |||
254 | * at random times on Windows 2000. Reported by Jeffrey Altman. | 254 | * at random times on Windows 2000. Reported by Jeffrey Altman. |
255 | * Only use it on NT. | 255 | * Only use it on NT. |
256 | */ | 256 | */ |
257 | /* Wolfgang Marczy <WMarczy@topcall.co.at> reports that | ||
258 | * the RegQueryValueEx call below can hang on NT4.0 (SP6). | ||
259 | * So we don't use this at all for now. */ | ||
260 | #if 0 | ||
257 | if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT && | 261 | if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT && |
258 | osverinfo.dwMajorVersion < 5) | 262 | osverinfo.dwMajorVersion < 5) |
259 | { | 263 | { |
@@ -290,6 +294,7 @@ int RAND_poll(void) | |||
290 | if (buf) | 294 | if (buf) |
291 | free(buf); | 295 | free(buf); |
292 | } | 296 | } |
297 | #endif | ||
293 | 298 | ||
294 | if (advapi) | 299 | if (advapi) |
295 | { | 300 | { |
@@ -310,8 +315,8 @@ int RAND_poll(void) | |||
310 | { | 315 | { |
311 | if (gen(hProvider, sizeof(buf), buf) != 0) | 316 | if (gen(hProvider, sizeof(buf), buf) != 0) |
312 | { | 317 | { |
313 | RAND_add(buf, sizeof(buf), sizeof(buf)); | 318 | RAND_add(buf, sizeof(buf), 0); |
314 | #ifdef DEBUG | 319 | #if 0 |
315 | printf("randomness from PROV_RSA_FULL\n"); | 320 | printf("randomness from PROV_RSA_FULL\n"); |
316 | #endif | 321 | #endif |
317 | } | 322 | } |
@@ -324,7 +329,7 @@ int RAND_poll(void) | |||
324 | if (gen(hProvider, sizeof(buf), buf) != 0) | 329 | if (gen(hProvider, sizeof(buf), buf) != 0) |
325 | { | 330 | { |
326 | RAND_add(buf, sizeof(buf), sizeof(buf)); | 331 | RAND_add(buf, sizeof(buf), sizeof(buf)); |
327 | #ifdef DEBUG | 332 | #if 0 |
328 | printf("randomness from PROV_INTEL_SEC\n"); | 333 | printf("randomness from PROV_INTEL_SEC\n"); |
329 | #endif | 334 | #endif |
330 | } | 335 | } |
@@ -461,7 +466,7 @@ int RAND_poll(void) | |||
461 | hlist.th32ProcessID, | 466 | hlist.th32ProcessID, |
462 | hlist.th32HeapID)) | 467 | hlist.th32HeapID)) |
463 | { | 468 | { |
464 | int entrycnt = 50; | 469 | int entrycnt = 80; |
465 | do | 470 | do |
466 | RAND_add(&hentry, | 471 | RAND_add(&hentry, |
467 | hentry.dwSize, 5); | 472 | hentry.dwSize, 5); |
@@ -510,7 +515,7 @@ int RAND_poll(void) | |||
510 | FreeLibrary(kernel); | 515 | FreeLibrary(kernel); |
511 | } | 516 | } |
512 | 517 | ||
513 | #ifdef DEBUG | 518 | #if 0 |
514 | printf("Exiting RAND_poll\n"); | 519 | printf("Exiting RAND_poll\n"); |
515 | #endif | 520 | #endif |
516 | 521 | ||
@@ -570,14 +575,15 @@ static void readtimer(void) | |||
570 | DWORD w; | 575 | DWORD w; |
571 | LARGE_INTEGER l; | 576 | LARGE_INTEGER l; |
572 | static int have_perfc = 1; | 577 | static int have_perfc = 1; |
573 | #ifndef __GNUC__ | 578 | #ifdef _MSC_VER |
574 | static int have_tsc = 1; | 579 | static int have_tsc = 1; |
575 | DWORD cyclecount; | 580 | DWORD cyclecount; |
576 | 581 | ||
577 | if (have_tsc) { | 582 | if (have_tsc) { |
578 | __try { | 583 | __try { |
579 | __asm { | 584 | __asm { |
580 | rdtsc | 585 | _emit 0x0f |
586 | _emit 0x31 | ||
581 | mov cyclecount, eax | 587 | mov cyclecount, eax |
582 | } | 588 | } |
583 | RAND_add(&cyclecount, sizeof(cyclecount), 1); | 589 | RAND_add(&cyclecount, sizeof(cyclecount), 1); |
@@ -684,49 +690,4 @@ static void readscreen(void) | |||
684 | DeleteDC(hScrDC); | 690 | DeleteDC(hScrDC); |
685 | } | 691 | } |
686 | 692 | ||
687 | #else /* Unix version */ | ||
688 | |||
689 | #include <time.h> | ||
690 | |||
691 | int RAND_poll(void) | ||
692 | { | ||
693 | unsigned long l; | ||
694 | pid_t curr_pid = getpid(); | ||
695 | #ifdef DEVRANDOM | ||
696 | FILE *fh; | ||
697 | #endif | ||
698 | |||
699 | #ifdef DEVRANDOM | ||
700 | /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD | ||
701 | * have this. Use /dev/urandom if you can as /dev/random may block | ||
702 | * if it runs out of random entries. */ | ||
703 | |||
704 | if ((fh = fopen(DEVRANDOM, "r")) != NULL) | ||
705 | { | ||
706 | unsigned char tmpbuf[ENTROPY_NEEDED]; | ||
707 | int n; | ||
708 | |||
709 | setvbuf(fh, NULL, _IONBF, 0); | ||
710 | n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh); | ||
711 | fclose(fh); | ||
712 | RAND_add(tmpbuf,sizeof tmpbuf,n); | ||
713 | memset(tmpbuf,0,n); | ||
714 | } | ||
715 | #endif | ||
716 | |||
717 | /* put in some default random data, we need more than just this */ | ||
718 | l=curr_pid; | ||
719 | RAND_add(&l,sizeof(l),0); | ||
720 | l=getuid(); | ||
721 | RAND_add(&l,sizeof(l),0); | ||
722 | |||
723 | l=time(NULL); | ||
724 | RAND_add(&l,sizeof(l),0); | ||
725 | |||
726 | #ifdef DEVRANDOM | ||
727 | return 1; | ||
728 | #endif | ||
729 | return 0; | ||
730 | } | ||
731 | |||
732 | #endif | 693 | #endif |