diff options
Diffstat (limited to 'src/lib/libssl/src/crypto/rand')
-rw-r--r-- | src/lib/libssl/src/crypto/rand/md_rand.c | 9 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/rand.h | 10 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/rand_egd.c | 10 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/rand_err.c | 8 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/rand_lib.c | 12 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/rand_unix.c | 35 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/rand_vms.c | 5 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/rand_win.c | 104 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/rand/randfile.c | 2 |
9 files changed, 138 insertions, 57 deletions
diff --git a/src/lib/libssl/src/crypto/rand/md_rand.c b/src/lib/libssl/src/crypto/rand/md_rand.c index eeffc0df4c..c84968df88 100644 --- a/src/lib/libssl/src/crypto/rand/md_rand.c +++ b/src/lib/libssl/src/crypto/rand/md_rand.c | |||
@@ -126,6 +126,7 @@ | |||
126 | 126 | ||
127 | #include <openssl/crypto.h> | 127 | #include <openssl/crypto.h> |
128 | #include <openssl/err.h> | 128 | #include <openssl/err.h> |
129 | #include <openssl/fips.h> | ||
129 | 130 | ||
130 | #ifdef BN_DEBUG | 131 | #ifdef BN_DEBUG |
131 | # define PREDICT | 132 | # define PREDICT |
@@ -332,6 +333,14 @@ static int ssleay_rand_bytes(unsigned char *buf, int num) | |||
332 | #endif | 333 | #endif |
333 | int do_stir_pool = 0; | 334 | int do_stir_pool = 0; |
334 | 335 | ||
336 | #ifdef OPENSSL_FIPS | ||
337 | if(FIPS_mode()) | ||
338 | { | ||
339 | FIPSerr(FIPS_F_SSLEAY_RAND_BYTES,FIPS_R_NON_FIPS_METHOD); | ||
340 | return 0; | ||
341 | } | ||
342 | #endif | ||
343 | |||
335 | #ifdef PREDICT | 344 | #ifdef PREDICT |
336 | if (rand_predictable) | 345 | if (rand_predictable) |
337 | { | 346 | { |
diff --git a/src/lib/libssl/src/crypto/rand/rand.h b/src/lib/libssl/src/crypto/rand/rand.h index 606382dd21..604df9be6c 100644 --- a/src/lib/libssl/src/crypto/rand/rand.h +++ b/src/lib/libssl/src/crypto/rand/rand.h | |||
@@ -71,6 +71,10 @@ | |||
71 | extern "C" { | 71 | extern "C" { |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | #if defined(OPENSSL_FIPS) | ||
75 | #define FIPS_RAND_SIZE_T int | ||
76 | #endif | ||
77 | |||
74 | typedef struct rand_meth_st | 78 | typedef struct rand_meth_st |
75 | { | 79 | { |
76 | void (*seed)(const void *buf, int num); | 80 | void (*seed)(const void *buf, int num); |
@@ -121,11 +125,17 @@ void ERR_load_RAND_strings(void); | |||
121 | /* Error codes for the RAND functions. */ | 125 | /* Error codes for the RAND functions. */ |
122 | 126 | ||
123 | /* Function codes. */ | 127 | /* Function codes. */ |
128 | #define RAND_F_FIPS_RAND_BYTES 102 | ||
124 | #define RAND_F_RAND_GET_RAND_METHOD 101 | 129 | #define RAND_F_RAND_GET_RAND_METHOD 101 |
125 | #define RAND_F_SSLEAY_RAND_BYTES 100 | 130 | #define RAND_F_SSLEAY_RAND_BYTES 100 |
126 | 131 | ||
127 | /* Reason codes. */ | 132 | /* Reason codes. */ |
133 | #define RAND_R_NON_FIPS_METHOD 101 | ||
134 | #define RAND_R_PRNG_ASKING_FOR_TOO_MUCH 105 | ||
135 | #define RAND_R_PRNG_NOT_REKEYED 103 | ||
136 | #define RAND_R_PRNG_NOT_RESEEDED 104 | ||
128 | #define RAND_R_PRNG_NOT_SEEDED 100 | 137 | #define RAND_R_PRNG_NOT_SEEDED 100 |
138 | #define RAND_R_PRNG_STUCK 102 | ||
129 | 139 | ||
130 | #ifdef __cplusplus | 140 | #ifdef __cplusplus |
131 | } | 141 | } |
diff --git a/src/lib/libssl/src/crypto/rand/rand_egd.c b/src/lib/libssl/src/crypto/rand/rand_egd.c index 6f742900a0..cd666abfcb 100644 --- a/src/lib/libssl/src/crypto/rand/rand_egd.c +++ b/src/lib/libssl/src/crypto/rand/rand_egd.c | |||
@@ -95,7 +95,7 @@ | |||
95 | * RAND_egd() is a wrapper for RAND_egd_bytes() with numbytes=255. | 95 | * RAND_egd() is a wrapper for RAND_egd_bytes() with numbytes=255. |
96 | */ | 96 | */ |
97 | 97 | ||
98 | #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) | 98 | #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_VOS) |
99 | int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes) | 99 | int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes) |
100 | { | 100 | { |
101 | return(-1); | 101 | return(-1); |
@@ -216,7 +216,9 @@ int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes) | |||
216 | while (numbytes != 1) | 216 | while (numbytes != 1) |
217 | { | 217 | { |
218 | num = read(fd, egdbuf, 1); | 218 | num = read(fd, egdbuf, 1); |
219 | if (num >= 0) | 219 | if (num == 0) |
220 | goto err; /* descriptor closed */ | ||
221 | else if (num > 0) | ||
220 | numbytes += num; | 222 | numbytes += num; |
221 | else | 223 | else |
222 | { | 224 | { |
@@ -246,7 +248,9 @@ int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes) | |||
246 | while (numbytes != egdbuf[0]) | 248 | while (numbytes != egdbuf[0]) |
247 | { | 249 | { |
248 | num = read(fd, retrievebuf + numbytes, egdbuf[0] - numbytes); | 250 | num = read(fd, retrievebuf + numbytes, egdbuf[0] - numbytes); |
249 | if (num >= 0) | 251 | if (num == 0) |
252 | goto err; /* descriptor closed */ | ||
253 | else if (num > 0) | ||
250 | numbytes += num; | 254 | numbytes += num; |
251 | else | 255 | else |
252 | { | 256 | { |
diff --git a/src/lib/libssl/src/crypto/rand/rand_err.c b/src/lib/libssl/src/crypto/rand/rand_err.c index b77267e213..95574659ac 100644 --- a/src/lib/libssl/src/crypto/rand/rand_err.c +++ b/src/lib/libssl/src/crypto/rand/rand_err.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* crypto/rand/rand_err.c */ | 1 | /* crypto/rand/rand_err.c */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
@@ -66,6 +66,7 @@ | |||
66 | #ifndef OPENSSL_NO_ERR | 66 | #ifndef OPENSSL_NO_ERR |
67 | static ERR_STRING_DATA RAND_str_functs[]= | 67 | static ERR_STRING_DATA RAND_str_functs[]= |
68 | { | 68 | { |
69 | {ERR_PACK(0,RAND_F_FIPS_RAND_BYTES,0), "FIPS_RAND_BYTES"}, | ||
69 | {ERR_PACK(0,RAND_F_RAND_GET_RAND_METHOD,0), "RAND_get_rand_method"}, | 70 | {ERR_PACK(0,RAND_F_RAND_GET_RAND_METHOD,0), "RAND_get_rand_method"}, |
70 | {ERR_PACK(0,RAND_F_SSLEAY_RAND_BYTES,0), "SSLEAY_RAND_BYTES"}, | 71 | {ERR_PACK(0,RAND_F_SSLEAY_RAND_BYTES,0), "SSLEAY_RAND_BYTES"}, |
71 | {0,NULL} | 72 | {0,NULL} |
@@ -73,7 +74,12 @@ static ERR_STRING_DATA RAND_str_functs[]= | |||
73 | 74 | ||
74 | static ERR_STRING_DATA RAND_str_reasons[]= | 75 | static ERR_STRING_DATA RAND_str_reasons[]= |
75 | { | 76 | { |
77 | {RAND_R_NON_FIPS_METHOD ,"non fips method"}, | ||
78 | {RAND_R_PRNG_ASKING_FOR_TOO_MUCH ,"prng asking for too much"}, | ||
79 | {RAND_R_PRNG_NOT_REKEYED ,"prng not rekeyed"}, | ||
80 | {RAND_R_PRNG_NOT_RESEEDED ,"prng not reseeded"}, | ||
76 | {RAND_R_PRNG_NOT_SEEDED ,"PRNG not seeded"}, | 81 | {RAND_R_PRNG_NOT_SEEDED ,"PRNG not seeded"}, |
82 | {RAND_R_PRNG_STUCK ,"prng stuck"}, | ||
77 | {0,NULL} | 83 | {0,NULL} |
78 | }; | 84 | }; |
79 | 85 | ||
diff --git a/src/lib/libssl/src/crypto/rand/rand_lib.c b/src/lib/libssl/src/crypto/rand/rand_lib.c index 513e338985..88f1b56d91 100644 --- a/src/lib/libssl/src/crypto/rand/rand_lib.c +++ b/src/lib/libssl/src/crypto/rand/rand_lib.c | |||
@@ -63,6 +63,8 @@ | |||
63 | #ifndef OPENSSL_NO_ENGINE | 63 | #ifndef OPENSSL_NO_ENGINE |
64 | #include <openssl/engine.h> | 64 | #include <openssl/engine.h> |
65 | #endif | 65 | #endif |
66 | #include <openssl/fips.h> | ||
67 | #include <openssl/fips_rand.h> | ||
66 | 68 | ||
67 | #ifndef OPENSSL_NO_ENGINE | 69 | #ifndef OPENSSL_NO_ENGINE |
68 | /* non-NULL if default_RAND_meth is ENGINE-provided */ | 70 | /* non-NULL if default_RAND_meth is ENGINE-provided */ |
@@ -85,6 +87,16 @@ int RAND_set_rand_method(const RAND_METHOD *meth) | |||
85 | 87 | ||
86 | const RAND_METHOD *RAND_get_rand_method(void) | 88 | const RAND_METHOD *RAND_get_rand_method(void) |
87 | { | 89 | { |
90 | #ifdef OPENSSL_FIPS | ||
91 | if(FIPS_mode() | ||
92 | && default_RAND_meth != FIPS_rand_check()) | ||
93 | { | ||
94 | RANDerr(RAND_F_RAND_GET_RAND_METHOD,RAND_R_NON_FIPS_METHOD); | ||
95 | return 0; | ||
96 | } | ||
97 | #endif | ||
98 | |||
99 | |||
88 | if (!default_RAND_meth) | 100 | if (!default_RAND_meth) |
89 | { | 101 | { |
90 | #ifndef OPENSSL_NO_ENGINE | 102 | #ifndef OPENSSL_NO_ENGINE |
diff --git a/src/lib/libssl/src/crypto/rand/rand_unix.c b/src/lib/libssl/src/crypto/rand/rand_unix.c index 0599719dd1..9376554fae 100644 --- a/src/lib/libssl/src/crypto/rand/rand_unix.c +++ b/src/lib/libssl/src/crypto/rand/rand_unix.c | |||
@@ -120,6 +120,7 @@ | |||
120 | #include <sys/types.h> | 120 | #include <sys/types.h> |
121 | #include <sys/time.h> | 121 | #include <sys/time.h> |
122 | #include <sys/times.h> | 122 | #include <sys/times.h> |
123 | #include <sys/stat.h> | ||
123 | #include <fcntl.h> | 124 | #include <fcntl.h> |
124 | #include <unistd.h> | 125 | #include <unistd.h> |
125 | #include <time.h> | 126 | #include <time.h> |
@@ -151,9 +152,9 @@ int RAND_poll(void) | |||
151 | int n = 0; | 152 | int n = 0; |
152 | #endif | 153 | #endif |
153 | #ifdef DEVRANDOM | 154 | #ifdef DEVRANDOM |
154 | static const char *randomfiles[] = { DEVRANDOM, NULL }; | 155 | static const char *randomfiles[] = { DEVRANDOM }; |
155 | const char **randomfile = NULL; | 156 | struct stat randomstats[sizeof(randomfiles)/sizeof(randomfiles[0])]; |
156 | int fd; | 157 | int fd,i; |
157 | #endif | 158 | #endif |
158 | #ifdef DEVRANDOM_EGD | 159 | #ifdef DEVRANDOM_EGD |
159 | static const char *egdsockets[] = { DEVRANDOM_EGD, NULL }; | 160 | static const char *egdsockets[] = { DEVRANDOM_EGD, NULL }; |
@@ -161,26 +162,42 @@ int RAND_poll(void) | |||
161 | #endif | 162 | #endif |
162 | 163 | ||
163 | #ifdef DEVRANDOM | 164 | #ifdef DEVRANDOM |
165 | memset(randomstats,0,sizeof(randomstats)); | ||
164 | /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD | 166 | /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD |
165 | * have this. Use /dev/urandom if you can as /dev/random may block | 167 | * have this. Use /dev/urandom if you can as /dev/random may block |
166 | * if it runs out of random entries. */ | 168 | * if it runs out of random entries. */ |
167 | 169 | ||
168 | for (randomfile = randomfiles; *randomfile && n < ENTROPY_NEEDED; randomfile++) | 170 | for (i=0; i<sizeof(randomfiles)/sizeof(randomfiles[0]) && n < ENTROPY_NEEDED; i++) |
169 | { | 171 | { |
170 | if ((fd = open(*randomfile, O_RDONLY|O_NONBLOCK | 172 | if ((fd = open(randomfiles[i], O_RDONLY |
173 | #ifdef O_NONBLOCK | ||
174 | |O_NONBLOCK | ||
175 | #endif | ||
176 | #ifdef O_BINARY | ||
177 | |O_BINARY | ||
178 | #endif | ||
171 | #ifdef O_NOCTTY /* If it happens to be a TTY (god forbid), do not make it | 179 | #ifdef O_NOCTTY /* If it happens to be a TTY (god forbid), do not make it |
172 | our controlling tty */ | 180 | our controlling tty */ |
173 | |O_NOCTTY | 181 | |O_NOCTTY |
174 | #endif | 182 | #endif |
175 | #ifdef O_NOFOLLOW /* Fail if the file is a symbolic link */ | ||
176 | |O_NOFOLLOW | ||
177 | #endif | ||
178 | )) >= 0) | 183 | )) >= 0) |
179 | { | 184 | { |
180 | struct timeval t = { 0, 10*1000 }; /* Spend 10ms on | 185 | struct timeval t = { 0, 10*1000 }; /* Spend 10ms on |
181 | each file. */ | 186 | each file. */ |
182 | int r; | 187 | int r,j; |
183 | fd_set fset; | 188 | fd_set fset; |
189 | struct stat *st=&randomstats[i]; | ||
190 | |||
191 | /* Avoid using same input... Used to be O_NOFOLLOW | ||
192 | * above, but it's not universally appropriate... */ | ||
193 | if (fstat(fd,st) != 0) { close(fd); continue; } | ||
194 | for (j=0;j<i;j++) | ||
195 | { | ||
196 | if (randomstats[j].st_ino==st->st_ino && | ||
197 | randomstats[j].st_dev==st->st_dev) | ||
198 | break; | ||
199 | } | ||
200 | if (j<i) { close(fd); continue; } | ||
184 | 201 | ||
185 | do | 202 | do |
186 | { | 203 | { |
diff --git a/src/lib/libssl/src/crypto/rand/rand_vms.c b/src/lib/libssl/src/crypto/rand/rand_vms.c index 29b2d7af0b..1267a3acae 100644 --- a/src/lib/libssl/src/crypto/rand/rand_vms.c +++ b/src/lib/libssl/src/crypto/rand/rand_vms.c | |||
@@ -101,11 +101,12 @@ int RAND_poll(void) | |||
101 | pitem = item; | 101 | pitem = item; |
102 | 102 | ||
103 | /* Setup */ | 103 | /* Setup */ |
104 | while (pitems_data->length) | 104 | while (pitems_data->length |
105 | && (total_length + pitems_data->length <= 256)) | ||
105 | { | 106 | { |
106 | pitem->length = pitems_data->length; | 107 | pitem->length = pitems_data->length; |
107 | pitem->code = pitems_data->code; | 108 | pitem->code = pitems_data->code; |
108 | pitem->buffer = (long *)data_buffer[total_length]; | 109 | pitem->buffer = (long *)&data_buffer[total_length]; |
109 | pitem->retlen = 0; | 110 | pitem->retlen = 0; |
110 | total_length += pitems_data->length; | 111 | total_length += pitems_data->length; |
111 | pitems_data++; | 112 | pitems_data++; |
diff --git a/src/lib/libssl/src/crypto/rand/rand_win.c b/src/lib/libssl/src/crypto/rand/rand_win.c index 3584842224..30c69161ef 100644 --- a/src/lib/libssl/src/crypto/rand/rand_win.c +++ b/src/lib/libssl/src/crypto/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 */ |
diff --git a/src/lib/libssl/src/crypto/rand/randfile.c b/src/lib/libssl/src/crypto/rand/randfile.c index d88ee0d780..9bd89ba495 100644 --- a/src/lib/libssl/src/crypto/rand/randfile.c +++ b/src/lib/libssl/src/crypto/rand/randfile.c | |||
@@ -166,6 +166,7 @@ int RAND_write_file(const char *file) | |||
166 | } | 166 | } |
167 | 167 | ||
168 | #if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) | 168 | #if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) |
169 | { | ||
169 | /* For some reason Win32 can't write to files created this way */ | 170 | /* For some reason Win32 can't write to files created this way */ |
170 | 171 | ||
171 | /* chmod(..., 0600) is too late to protect the file, | 172 | /* chmod(..., 0600) is too late to protect the file, |
@@ -173,6 +174,7 @@ int RAND_write_file(const char *file) | |||
173 | int fd = open(file, O_CREAT, 0600); | 174 | int fd = open(file, O_CREAT, 0600); |
174 | if (fd != -1) | 175 | if (fd != -1) |
175 | out = fdopen(fd, "wb"); | 176 | out = fdopen(fd, "wb"); |
177 | } | ||
176 | #endif | 178 | #endif |
177 | if (out == NULL) | 179 | if (out == NULL) |
178 | out = fopen(file,"wb"); | 180 | out = fopen(file,"wb"); |