diff options
Diffstat (limited to 'src/lib/libcrypto/rand')
-rw-r--r-- | src/lib/libcrypto/rand/Makefile.ssl | 118 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/md_rand.c | 53 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand.h | 30 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_egd.c | 240 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_err.c | 5 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_lcl.h | 60 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_lib.c | 82 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_os2.c | 147 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_unix.c | 274 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_vms.c | 135 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_win.c | 63 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/randfile.c | 26 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/randtest.c | 9 |
13 files changed, 969 insertions, 273 deletions
diff --git a/src/lib/libcrypto/rand/Makefile.ssl b/src/lib/libcrypto/rand/Makefile.ssl index 707eaac678..42623d18d8 100644 --- a/src/lib/libcrypto/rand/Makefile.ssl +++ b/src/lib/libcrypto/rand/Makefile.ssl | |||
@@ -11,7 +11,8 @@ INSTALL_PREFIX= | |||
11 | OPENSSLDIR= /usr/local/ssl | 11 | OPENSSLDIR= /usr/local/ssl |
12 | INSTALLTOP=/usr/local/ssl | 12 | INSTALLTOP=/usr/local/ssl |
13 | MAKE= make -f Makefile.ssl | 13 | MAKE= make -f Makefile.ssl |
14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) | 14 | MAKEDEPPROG= makedepend |
15 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
15 | MAKEFILE= Makefile.ssl | 16 | MAKEFILE= Makefile.ssl |
16 | AR= ar r | 17 | AR= ar r |
17 | 18 | ||
@@ -22,8 +23,10 @@ TEST= randtest.c | |||
22 | APPS= | 23 | APPS= |
23 | 24 | ||
24 | LIB=$(TOP)/libcrypto.a | 25 | LIB=$(TOP)/libcrypto.a |
25 | LIBSRC=md_rand.c randfile.c rand_lib.c rand_err.c rand_egd.c rand_win.c | 26 | LIBSRC=md_rand.c randfile.c rand_lib.c rand_err.c rand_egd.c \ |
26 | LIBOBJ=md_rand.o randfile.o rand_lib.o rand_err.o rand_egd.o rand_win.o | 27 | rand_win.c rand_unix.c rand_os2.c |
28 | LIBOBJ=md_rand.o randfile.o rand_lib.o rand_err.o rand_egd.o \ | ||
29 | rand_win.o rand_unix.o rand_os2.o | ||
27 | 30 | ||
28 | SRC= $(LIBSRC) | 31 | SRC= $(LIBSRC) |
29 | 32 | ||
@@ -39,8 +42,7 @@ all: lib | |||
39 | 42 | ||
40 | lib: $(LIBOBJ) | 43 | lib: $(LIBOBJ) |
41 | $(AR) $(LIB) $(LIBOBJ) | 44 | $(AR) $(LIB) $(LIBOBJ) |
42 | @echo You may get an error following this line. Please ignore. | 45 | $(RANLIB) $(LIB) || echo Never mind. |
43 | - $(RANLIB) $(LIB) | ||
44 | @touch lib | 46 | @touch lib |
45 | 47 | ||
46 | files: | 48 | files: |
@@ -79,45 +81,77 @@ clean: | |||
79 | 81 | ||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 82 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
81 | 83 | ||
82 | md_rand.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | 84 | md_rand.o: ../../e_os.h ../../include/openssl/asn1.h |
83 | md_rand.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | 85 | md_rand.o: ../../include/openssl/bio.h ../../include/openssl/bn.h |
84 | md_rand.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | 86 | md_rand.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h |
85 | md_rand.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | 87 | md_rand.o: ../../include/openssl/err.h ../../include/openssl/evp.h |
88 | md_rand.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
89 | md_rand.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
90 | md_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
86 | md_rand.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | 91 | md_rand.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h |
87 | md_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | 92 | md_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h |
88 | md_rand.o: ../../include/openssl/symhacks.h rand_lcl.h | 93 | md_rand.o: ../../include/openssl/symhacks.h md_rand.c rand_lcl.h |
89 | rand_egd.o: ../../include/openssl/opensslconf.h ../../include/openssl/rand.h | 94 | rand_egd.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h |
95 | rand_egd.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
96 | rand_egd.o: rand_egd.c | ||
90 | rand_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | 97 | rand_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h |
91 | rand_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | 98 | rand_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
92 | rand_err.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h | 99 | rand_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h |
93 | rand_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | 100 | rand_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h |
94 | rand_err.o: ../../include/openssl/symhacks.h | 101 | rand_err.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h |
95 | rand_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | 102 | rand_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h |
96 | rand_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | 103 | rand_err.o: rand_err.c |
97 | rand_lib.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h | 104 | rand_lib.o: ../../e_os.h ../../include/openssl/asn1.h |
98 | rand_lib.o: ../../include/openssl/des.h ../../include/openssl/dh.h | 105 | rand_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h |
99 | rand_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | 106 | rand_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h |
100 | rand_lib.o: ../../include/openssl/engine.h ../../include/openssl/evp.h | 107 | rand_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h |
101 | rand_lib.o: ../../include/openssl/idea.h ../../include/openssl/md2.h | 108 | rand_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h |
102 | rand_lib.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | 109 | rand_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h |
103 | rand_lib.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | 110 | rand_lib.o: ../../include/openssl/opensslconf.h |
104 | rand_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | 111 | rand_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h |
105 | rand_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h | 112 | rand_lib.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h |
106 | rand_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | 113 | rand_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
107 | rand_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | 114 | rand_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h |
108 | rand_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | 115 | rand_lib.o: ../cryptlib.h rand_lib.c |
109 | rand_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | 116 | rand_os2.o: ../../e_os.h ../../include/openssl/asn1.h |
110 | rand_lib.o: ../../include/openssl/symhacks.h | 117 | rand_os2.o: ../../include/openssl/bio.h ../../include/openssl/bn.h |
111 | rand_win.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | 118 | rand_os2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h |
112 | rand_win.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 119 | rand_os2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
120 | rand_os2.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
121 | rand_os2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
122 | rand_os2.o: ../../include/openssl/opensslconf.h | ||
123 | rand_os2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
124 | rand_os2.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
125 | rand_os2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
126 | rand_os2.o: ../../include/openssl/symhacks.h ../cryptlib.h rand_lcl.h | ||
127 | rand_os2.o: rand_os2.c | ||
128 | rand_unix.o: ../../e_os.h ../../include/openssl/asn1.h | ||
129 | rand_unix.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
130 | rand_unix.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
131 | rand_unix.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
132 | rand_unix.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
133 | rand_unix.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
134 | rand_unix.o: ../../include/openssl/opensslconf.h | ||
135 | rand_unix.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
136 | rand_unix.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
137 | rand_unix.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
138 | rand_unix.o: ../../include/openssl/symhacks.h ../cryptlib.h rand_lcl.h | ||
139 | rand_unix.o: rand_unix.c | ||
140 | rand_win.o: ../../e_os.h ../../include/openssl/asn1.h | ||
141 | rand_win.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
142 | rand_win.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
113 | rand_win.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 143 | rand_win.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
114 | rand_win.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | 144 | rand_win.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h |
115 | rand_win.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h | 145 | rand_win.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h |
116 | rand_win.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | 146 | rand_win.o: ../../include/openssl/opensslconf.h |
117 | rand_win.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | 147 | rand_win.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h |
118 | rand_win.o: ../cryptlib.h rand_lcl.h | 148 | rand_win.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h |
119 | randfile.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | 149 | rand_win.o: ../../include/openssl/sha.h ../../include/openssl/stack.h |
150 | rand_win.o: ../../include/openssl/symhacks.h ../cryptlib.h rand_lcl.h | ||
151 | rand_win.o: rand_win.c | ||
152 | randfile.o: ../../e_os.h ../../include/openssl/crypto.h | ||
120 | randfile.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | 153 | randfile.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h |
121 | randfile.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h | 154 | randfile.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h |
122 | randfile.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | 155 | randfile.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h |
123 | randfile.o: ../../include/openssl/symhacks.h | 156 | randfile.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h |
157 | randfile.o: randfile.c | ||
diff --git a/src/lib/libcrypto/rand/md_rand.c b/src/lib/libcrypto/rand/md_rand.c index 04b9d695b0..a00ed70718 100644 --- a/src/lib/libcrypto/rand/md_rand.c +++ b/src/lib/libcrypto/rand/md_rand.c | |||
@@ -56,7 +56,7 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | /* ==================================================================== | 58 | /* ==================================================================== |
59 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | 59 | * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. |
60 | * | 60 | * |
61 | * Redistribution and use in source and binary forms, with or without | 61 | * Redistribution and use in source and binary forms, with or without |
62 | * modification, are permitted provided that the following conditions | 62 | * modification, are permitted provided that the following conditions |
@@ -119,7 +119,7 @@ | |||
119 | #include <stdio.h> | 119 | #include <stdio.h> |
120 | #include <string.h> | 120 | #include <string.h> |
121 | 121 | ||
122 | #include "openssl/e_os.h" | 122 | #include "e_os.h" |
123 | 123 | ||
124 | #include <openssl/rand.h> | 124 | #include <openssl/rand.h> |
125 | #include "rand_lcl.h" | 125 | #include "rand_lcl.h" |
@@ -144,6 +144,7 @@ static int initialized=0; | |||
144 | static unsigned int crypto_lock_rand = 0; /* may be set only when a thread | 144 | static unsigned int crypto_lock_rand = 0; /* may be set only when a thread |
145 | * holds CRYPTO_LOCK_RAND | 145 | * holds CRYPTO_LOCK_RAND |
146 | * (to prevent double locking) */ | 146 | * (to prevent double locking) */ |
147 | /* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */ | ||
147 | static unsigned long locking_thread = 0; /* valid iff crypto_lock_rand is set */ | 148 | static unsigned long locking_thread = 0; /* valid iff crypto_lock_rand is set */ |
148 | 149 | ||
149 | 150 | ||
@@ -191,7 +192,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) | |||
191 | int i,j,k,st_idx; | 192 | int i,j,k,st_idx; |
192 | long md_c[2]; | 193 | long md_c[2]; |
193 | unsigned char local_md[MD_DIGEST_LENGTH]; | 194 | unsigned char local_md[MD_DIGEST_LENGTH]; |
194 | MD_CTX m; | 195 | EVP_MD_CTX m; |
195 | int do_not_lock; | 196 | int do_not_lock; |
196 | 197 | ||
197 | /* | 198 | /* |
@@ -210,7 +211,14 @@ static void ssleay_rand_add(const void *buf, int num, double add) | |||
210 | */ | 211 | */ |
211 | 212 | ||
212 | /* check if we already have the lock */ | 213 | /* check if we already have the lock */ |
213 | do_not_lock = crypto_lock_rand && (locking_thread == CRYPTO_thread_id()); | 214 | if (crypto_lock_rand) |
215 | { | ||
216 | CRYPTO_r_lock(CRYPTO_LOCK_RAND2); | ||
217 | do_not_lock = (locking_thread == CRYPTO_thread_id()); | ||
218 | CRYPTO_r_unlock(CRYPTO_LOCK_RAND2); | ||
219 | } | ||
220 | else | ||
221 | do_not_lock = 0; | ||
214 | 222 | ||
215 | if (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND); | 223 | if (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND); |
216 | st_idx=state_index; | 224 | st_idx=state_index; |
@@ -246,6 +254,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) | |||
246 | 254 | ||
247 | if (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | 255 | if (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND); |
248 | 256 | ||
257 | EVP_MD_CTX_init(&m); | ||
249 | for (i=0; i<num; i+=MD_DIGEST_LENGTH) | 258 | for (i=0; i<num; i+=MD_DIGEST_LENGTH) |
250 | { | 259 | { |
251 | j=(num-i); | 260 | j=(num-i); |
@@ -264,7 +273,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) | |||
264 | 273 | ||
265 | MD_Update(&m,buf,j); | 274 | MD_Update(&m,buf,j); |
266 | MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c)); | 275 | MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c)); |
267 | MD_Final(local_md,&m); | 276 | MD_Final(&m,local_md); |
268 | md_c[1]++; | 277 | md_c[1]++; |
269 | 278 | ||
270 | buf=(const char *)buf + j; | 279 | buf=(const char *)buf + j; |
@@ -284,7 +293,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) | |||
284 | st_idx=0; | 293 | st_idx=0; |
285 | } | 294 | } |
286 | } | 295 | } |
287 | memset((char *)&m,0,sizeof(m)); | 296 | EVP_MD_CTX_cleanup(&m); |
288 | 297 | ||
289 | if (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND); | 298 | if (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND); |
290 | /* Don't just copy back local_md into md -- this could mean that | 299 | /* Don't just copy back local_md into md -- this could mean that |
@@ -299,7 +308,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) | |||
299 | entropy += add; | 308 | entropy += add; |
300 | if (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | 309 | if (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND); |
301 | 310 | ||
302 | #if !defined(THREADS) && !defined(WIN32) | 311 | #if !defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32) |
303 | assert(md_c[1] == md_count[1]); | 312 | assert(md_c[1] == md_count[1]); |
304 | #endif | 313 | #endif |
305 | } | 314 | } |
@@ -317,7 +326,7 @@ static int ssleay_rand_bytes(unsigned char *buf, int num) | |||
317 | int ok; | 326 | int ok; |
318 | long md_c[2]; | 327 | long md_c[2]; |
319 | unsigned char local_md[MD_DIGEST_LENGTH]; | 328 | unsigned char local_md[MD_DIGEST_LENGTH]; |
320 | MD_CTX m; | 329 | EVP_MD_CTX m; |
321 | #ifndef GETPID_IS_MEANINGLESS | 330 | #ifndef GETPID_IS_MEANINGLESS |
322 | pid_t curr_pid = getpid(); | 331 | pid_t curr_pid = getpid(); |
323 | #endif | 332 | #endif |
@@ -336,7 +345,8 @@ static int ssleay_rand_bytes(unsigned char *buf, int num) | |||
336 | 345 | ||
337 | if (num <= 0) | 346 | if (num <= 0) |
338 | return 1; | 347 | return 1; |
339 | 348 | ||
349 | EVP_MD_CTX_init(&m); | ||
340 | /* round upwards to multiple of MD_DIGEST_LENGTH/2 */ | 350 | /* round upwards to multiple of MD_DIGEST_LENGTH/2 */ |
341 | num_ceil = (1 + (num-1)/(MD_DIGEST_LENGTH/2)) * (MD_DIGEST_LENGTH/2); | 351 | num_ceil = (1 + (num-1)/(MD_DIGEST_LENGTH/2)) * (MD_DIGEST_LENGTH/2); |
342 | 352 | ||
@@ -361,8 +371,10 @@ static int ssleay_rand_bytes(unsigned char *buf, int num) | |||
361 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | 371 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); |
362 | 372 | ||
363 | /* prevent ssleay_rand_bytes() from trying to obtain the lock again */ | 373 | /* prevent ssleay_rand_bytes() from trying to obtain the lock again */ |
364 | crypto_lock_rand = 1; | 374 | CRYPTO_w_lock(CRYPTO_LOCK_RAND2); |
365 | locking_thread = CRYPTO_thread_id(); | 375 | locking_thread = CRYPTO_thread_id(); |
376 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND2); | ||
377 | crypto_lock_rand = 1; | ||
366 | 378 | ||
367 | if (!initialized) | 379 | if (!initialized) |
368 | { | 380 | { |
@@ -435,7 +447,6 @@ static int ssleay_rand_bytes(unsigned char *buf, int num) | |||
435 | 447 | ||
436 | /* before unlocking, we must clear 'crypto_lock_rand' */ | 448 | /* before unlocking, we must clear 'crypto_lock_rand' */ |
437 | crypto_lock_rand = 0; | 449 | crypto_lock_rand = 0; |
438 | locking_thread = 0; | ||
439 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | 450 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); |
440 | 451 | ||
441 | while (num > 0) | 452 | while (num > 0) |
@@ -464,7 +475,7 @@ static int ssleay_rand_bytes(unsigned char *buf, int num) | |||
464 | } | 475 | } |
465 | else | 476 | else |
466 | MD_Update(&m,&(state[st_idx]),MD_DIGEST_LENGTH/2); | 477 | MD_Update(&m,&(state[st_idx]),MD_DIGEST_LENGTH/2); |
467 | MD_Final(local_md,&m); | 478 | MD_Final(&m,local_md); |
468 | 479 | ||
469 | for (i=0; i<MD_DIGEST_LENGTH/2; i++) | 480 | for (i=0; i<MD_DIGEST_LENGTH/2; i++) |
470 | { | 481 | { |
@@ -481,10 +492,10 @@ static int ssleay_rand_bytes(unsigned char *buf, int num) | |||
481 | MD_Update(&m,local_md,MD_DIGEST_LENGTH); | 492 | MD_Update(&m,local_md,MD_DIGEST_LENGTH); |
482 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | 493 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); |
483 | MD_Update(&m,md,MD_DIGEST_LENGTH); | 494 | MD_Update(&m,md,MD_DIGEST_LENGTH); |
484 | MD_Final(md,&m); | 495 | MD_Final(&m,md); |
485 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | 496 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); |
486 | 497 | ||
487 | memset(&m,0,sizeof(m)); | 498 | EVP_MD_CTX_cleanup(&m); |
488 | if (ok) | 499 | if (ok) |
489 | return(1); | 500 | return(1); |
490 | else | 501 | else |
@@ -521,15 +532,24 @@ static int ssleay_rand_status(void) | |||
521 | 532 | ||
522 | /* check if we already have the lock | 533 | /* check if we already have the lock |
523 | * (could happen if a RAND_poll() implementation calls RAND_status()) */ | 534 | * (could happen if a RAND_poll() implementation calls RAND_status()) */ |
524 | do_not_lock = crypto_lock_rand && (locking_thread == CRYPTO_thread_id()); | 535 | if (crypto_lock_rand) |
536 | { | ||
537 | CRYPTO_r_lock(CRYPTO_LOCK_RAND2); | ||
538 | do_not_lock = (locking_thread == CRYPTO_thread_id()); | ||
539 | CRYPTO_r_unlock(CRYPTO_LOCK_RAND2); | ||
540 | } | ||
541 | else | ||
542 | do_not_lock = 0; | ||
525 | 543 | ||
526 | if (!do_not_lock) | 544 | if (!do_not_lock) |
527 | { | 545 | { |
528 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | 546 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); |
529 | 547 | ||
530 | /* prevent ssleay_rand_bytes() from trying to obtain the lock again */ | 548 | /* prevent ssleay_rand_bytes() from trying to obtain the lock again */ |
531 | crypto_lock_rand = 1; | 549 | CRYPTO_w_lock(CRYPTO_LOCK_RAND2); |
532 | locking_thread = CRYPTO_thread_id(); | 550 | locking_thread = CRYPTO_thread_id(); |
551 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND2); | ||
552 | crypto_lock_rand = 1; | ||
533 | } | 553 | } |
534 | 554 | ||
535 | if (!initialized) | 555 | if (!initialized) |
@@ -544,7 +564,6 @@ static int ssleay_rand_status(void) | |||
544 | { | 564 | { |
545 | /* before unlocking, we must clear 'crypto_lock_rand' */ | 565 | /* before unlocking, we must clear 'crypto_lock_rand' */ |
546 | crypto_lock_rand = 0; | 566 | crypto_lock_rand = 0; |
547 | locking_thread = 0; | ||
548 | 567 | ||
549 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | 568 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); |
550 | } | 569 | } |
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h index 9c6052733e..e17aa7a9f7 100644 --- a/src/lib/libcrypto/rand/rand.h +++ b/src/lib/libcrypto/rand/rand.h | |||
@@ -60,6 +60,7 @@ | |||
60 | #define HEADER_RAND_H | 60 | #define HEADER_RAND_H |
61 | 61 | ||
62 | #include <stdlib.h> | 62 | #include <stdlib.h> |
63 | #include <openssl/ossl_typ.h> | ||
63 | 64 | ||
64 | #ifdef __cplusplus | 65 | #ifdef __cplusplus |
65 | extern "C" { | 66 | extern "C" { |
@@ -79,10 +80,9 @@ typedef struct rand_meth_st | |||
79 | extern int rand_predictable; | 80 | extern int rand_predictable; |
80 | #endif | 81 | #endif |
81 | 82 | ||
82 | struct engine_st; | 83 | int RAND_set_rand_method(const RAND_METHOD *meth); |
83 | 84 | const RAND_METHOD *RAND_get_rand_method(void); | |
84 | int RAND_set_rand_method(struct engine_st *meth); | 85 | int RAND_set_rand_engine(ENGINE *engine); |
85 | RAND_METHOD *RAND_get_rand_method(void ); | ||
86 | RAND_METHOD *RAND_SSLeay(void); | 86 | RAND_METHOD *RAND_SSLeay(void); |
87 | void RAND_cleanup(void ); | 87 | void RAND_cleanup(void ); |
88 | int RAND_bytes(unsigned char *buf,int num); | 88 | int RAND_bytes(unsigned char *buf,int num); |
@@ -93,42 +93,34 @@ int RAND_load_file(const char *file,long max_bytes); | |||
93 | int RAND_write_file(const char *file); | 93 | int RAND_write_file(const char *file); |
94 | const char *RAND_file_name(char *file,size_t num); | 94 | const char *RAND_file_name(char *file,size_t num); |
95 | int RAND_status(void); | 95 | int RAND_status(void); |
96 | int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes); | ||
96 | int RAND_egd(const char *path); | 97 | int RAND_egd(const char *path); |
97 | int RAND_egd_bytes(const char *path,int bytes); | 98 | int RAND_egd_bytes(const char *path,int bytes); |
98 | void ERR_load_RAND_strings(void); | ||
99 | int RAND_poll(void); | 99 | int RAND_poll(void); |
100 | 100 | ||
101 | #ifdef __cplusplus | 101 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) |
102 | } | ||
103 | #endif | ||
104 | |||
105 | #if defined(WINDOWS) || defined(WIN32) | ||
106 | #include <windows.h> | ||
107 | |||
108 | #ifdef __cplusplus | ||
109 | extern "C" { | ||
110 | #endif | ||
111 | 102 | ||
112 | void RAND_screen(void); | 103 | void RAND_screen(void); |
113 | int RAND_event(UINT, WPARAM, LPARAM); | 104 | int RAND_event(UINT, WPARAM, LPARAM); |
114 | 105 | ||
115 | #ifdef __cplusplus | ||
116 | } | ||
117 | #endif | ||
118 | #endif | 106 | #endif |
119 | 107 | ||
120 | /* BEGIN ERROR CODES */ | 108 | /* BEGIN ERROR CODES */ |
121 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 109 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
122 | * made after this point may be overwritten when the script is next run. | 110 | * made after this point may be overwritten when the script is next run. |
123 | */ | 111 | */ |
112 | void ERR_load_RAND_strings(void); | ||
124 | 113 | ||
125 | /* Error codes for the RAND functions. */ | 114 | /* Error codes for the RAND functions. */ |
126 | 115 | ||
127 | /* Function codes. */ | 116 | /* Function codes. */ |
117 | #define RAND_F_RAND_GET_RAND_METHOD 101 | ||
128 | #define RAND_F_SSLEAY_RAND_BYTES 100 | 118 | #define RAND_F_SSLEAY_RAND_BYTES 100 |
129 | 119 | ||
130 | /* Reason codes. */ | 120 | /* Reason codes. */ |
131 | #define RAND_R_PRNG_NOT_SEEDED 100 | 121 | #define RAND_R_PRNG_NOT_SEEDED 100 |
132 | 122 | ||
123 | #ifdef __cplusplus | ||
124 | } | ||
125 | #endif | ||
133 | #endif | 126 | #endif |
134 | |||
diff --git a/src/lib/libcrypto/rand/rand_egd.c b/src/lib/libcrypto/rand/rand_egd.c index 79b5e6fa57..dd490c8254 100644 --- a/src/lib/libcrypto/rand/rand_egd.c +++ b/src/lib/libcrypto/rand/rand_egd.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* crypto/rand/rand_egd.c */ | 1 | /* crypto/rand/rand_egd.c */ |
2 | /* Written by Ulf Moeller for the OpenSSL project. */ | 2 | /* Written by Ulf Moeller and Lutz Jaenicke for the OpenSSL project. */ |
3 | /* ==================================================================== | 3 | /* ==================================================================== |
4 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | 4 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. |
5 | * | 5 | * |
@@ -54,12 +54,51 @@ | |||
54 | * | 54 | * |
55 | */ | 55 | */ |
56 | 56 | ||
57 | #include <openssl/e_os2.h> | ||
57 | #include <openssl/rand.h> | 58 | #include <openssl/rand.h> |
58 | 59 | ||
59 | /* Query the EGD <URL: http://www.lothar.com/tech/crypto/>. | 60 | /* |
61 | * Query the EGD <URL: http://www.lothar.com/tech/crypto/>. | ||
62 | * | ||
63 | * This module supplies three routines: | ||
64 | * | ||
65 | * RAND_query_egd_bytes(path, buf, bytes) | ||
66 | * will actually query "bytes" bytes of entropy form the egd-socket located | ||
67 | * at path and will write them to buf (if supplied) or will directly feed | ||
68 | * it to RAND_seed() if buf==NULL. | ||
69 | * The number of bytes is not limited by the maximum chunk size of EGD, | ||
70 | * which is 255 bytes. If more than 255 bytes are wanted, several chunks | ||
71 | * of entropy bytes are requested. The connection is left open until the | ||
72 | * query is competed. | ||
73 | * RAND_query_egd_bytes() returns with | ||
74 | * -1 if an error occured during connection or communication. | ||
75 | * num the number of bytes read from the EGD socket. This number is either | ||
76 | * the number of bytes requested or smaller, if the EGD pool is | ||
77 | * drained and the daemon signals that the pool is empty. | ||
78 | * This routine does not touch any RAND_status(). This is necessary, since | ||
79 | * PRNG functions may call it during initialization. | ||
80 | * | ||
81 | * RAND_egd_bytes(path, bytes) will query "bytes" bytes and have them | ||
82 | * used to seed the PRNG. | ||
83 | * RAND_egd_bytes() is a wrapper for RAND_query_egd_bytes() with buf=NULL. | ||
84 | * Unlike RAND_query_egd_bytes(), RAND_status() is used to test the | ||
85 | * seed status so that the return value can reflect the seed state: | ||
86 | * -1 if an error occured during connection or communication _or_ | ||
87 | * if the PRNG has still not received the required seeding. | ||
88 | * num the number of bytes read from the EGD socket. This number is either | ||
89 | * the number of bytes requested or smaller, if the EGD pool is | ||
90 | * drained and the daemon signals that the pool is empty. | ||
91 | * | ||
92 | * RAND_egd(path) will query 255 bytes and use the bytes retreived to seed | ||
93 | * the PRNG. | ||
94 | * RAND_egd() is a wrapper for RAND_egd_bytes() with numbytes=255. | ||
60 | */ | 95 | */ |
61 | 96 | ||
62 | #if defined(WIN32) || defined(VMS) || defined(__VMS) | 97 | #if defined(OPENSSL_SYS_WIN32) || defined(VMS) || defined(__VMS) |
98 | int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes) | ||
99 | { | ||
100 | return(-1); | ||
101 | } | ||
63 | int RAND_egd(const char *path) | 102 | int RAND_egd(const char *path) |
64 | { | 103 | { |
65 | return(-1); | 104 | return(-1); |
@@ -75,7 +114,11 @@ int RAND_egd_bytes(const char *path,int bytes) | |||
75 | #include <sys/types.h> | 114 | #include <sys/types.h> |
76 | #include <sys/socket.h> | 115 | #include <sys/socket.h> |
77 | #ifndef NO_SYS_UN_H | 116 | #ifndef NO_SYS_UN_H |
78 | #include <sys/un.h> | 117 | # ifdef OPENSSL_SYS_VSWORKS |
118 | # include <streams/un.h> | ||
119 | # else | ||
120 | # include <sys/un.h> | ||
121 | # endif | ||
79 | #else | 122 | #else |
80 | struct sockaddr_un { | 123 | struct sockaddr_un { |
81 | short sun_family; /* AF_UNIX */ | 124 | short sun_family; /* AF_UNIX */ |
@@ -83,50 +126,20 @@ struct sockaddr_un { | |||
83 | }; | 126 | }; |
84 | #endif /* NO_SYS_UN_H */ | 127 | #endif /* NO_SYS_UN_H */ |
85 | #include <string.h> | 128 | #include <string.h> |
129 | #include <errno.h> | ||
86 | 130 | ||
87 | #ifndef offsetof | 131 | #ifndef offsetof |
88 | # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) | 132 | # define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) |
89 | #endif | 133 | #endif |
90 | 134 | ||
91 | int RAND_egd(const char *path) | 135 | int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes) |
92 | { | ||
93 | int ret = -1; | ||
94 | struct sockaddr_un addr; | ||
95 | int len, num; | ||
96 | int fd = -1; | ||
97 | unsigned char buf[256]; | ||
98 | |||
99 | memset(&addr, 0, sizeof(addr)); | ||
100 | addr.sun_family = AF_UNIX; | ||
101 | if (strlen(path) > sizeof(addr.sun_path)) | ||
102 | return (-1); | ||
103 | strcpy(addr.sun_path,path); | ||
104 | len = offsetof(struct sockaddr_un, sun_path) + strlen(path); | ||
105 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | ||
106 | if (fd == -1) return (-1); | ||
107 | if (connect(fd, (struct sockaddr *)&addr, len) == -1) goto err; | ||
108 | buf[0] = 1; | ||
109 | buf[1] = 255; | ||
110 | write(fd, buf, 2); | ||
111 | if (read(fd, buf, 1) != 1) goto err; | ||
112 | if (buf[0] == 0) goto err; | ||
113 | num = read(fd, buf, 255); | ||
114 | if (num < 1) goto err; | ||
115 | RAND_seed(buf, num); | ||
116 | if (RAND_status() == 1) | ||
117 | ret = num; | ||
118 | err: | ||
119 | if (fd != -1) close(fd); | ||
120 | return(ret); | ||
121 | } | ||
122 | |||
123 | int RAND_egd_bytes(const char *path,int bytes) | ||
124 | { | 136 | { |
125 | int ret = 0; | 137 | int ret = 0; |
126 | struct sockaddr_un addr; | 138 | struct sockaddr_un addr; |
127 | int len, num; | 139 | int len, num, numbytes; |
128 | int fd = -1; | 140 | int fd = -1; |
129 | unsigned char buf[255]; | 141 | int success; |
142 | unsigned char egdbuf[2], tempbuf[255], *retrievebuf; | ||
130 | 143 | ||
131 | memset(&addr, 0, sizeof(addr)); | 144 | memset(&addr, 0, sizeof(addr)); |
132 | addr.sun_family = AF_UNIX; | 145 | addr.sun_family = AF_UNIX; |
@@ -136,34 +149,126 @@ int RAND_egd_bytes(const char *path,int bytes) | |||
136 | len = offsetof(struct sockaddr_un, sun_path) + strlen(path); | 149 | len = offsetof(struct sockaddr_un, sun_path) + strlen(path); |
137 | fd = socket(AF_UNIX, SOCK_STREAM, 0); | 150 | fd = socket(AF_UNIX, SOCK_STREAM, 0); |
138 | if (fd == -1) return (-1); | 151 | if (fd == -1) return (-1); |
139 | if (connect(fd, (struct sockaddr *)&addr, len) == -1) goto err; | 152 | success = 0; |
153 | while (!success) | ||
154 | { | ||
155 | if (connect(fd, (struct sockaddr *)&addr, len) == 0) | ||
156 | success = 1; | ||
157 | else | ||
158 | { | ||
159 | switch (errno) | ||
160 | { | ||
161 | #ifdef EINTR | ||
162 | case EINTR: | ||
163 | #endif | ||
164 | #ifdef EAGAIN | ||
165 | case EAGAIN: | ||
166 | #endif | ||
167 | #ifdef EINPROGRESS | ||
168 | case EINPROGRESS: | ||
169 | #endif | ||
170 | #ifdef EALREADY | ||
171 | case EALREADY: | ||
172 | #endif | ||
173 | /* No error, try again */ | ||
174 | break; | ||
175 | #ifdef EISCONN | ||
176 | case EISCONN: | ||
177 | success = 1; | ||
178 | break; | ||
179 | #endif | ||
180 | default: | ||
181 | goto err; /* failure */ | ||
182 | } | ||
183 | } | ||
184 | } | ||
140 | 185 | ||
141 | while(bytes > 0) | 186 | while(bytes > 0) |
142 | { | 187 | { |
143 | buf[0] = 1; | 188 | egdbuf[0] = 1; |
144 | buf[1] = bytes < 255 ? bytes : 255; | 189 | egdbuf[1] = bytes < 255 ? bytes : 255; |
145 | write(fd, buf, 2); | 190 | numbytes = 0; |
146 | if (read(fd, buf, 1) != 1) | 191 | while (numbytes != 2) |
147 | { | 192 | { |
148 | ret=-1; | 193 | num = write(fd, egdbuf + numbytes, 2 - numbytes); |
149 | goto err; | 194 | if (num >= 0) |
195 | numbytes += num; | ||
196 | else | ||
197 | { | ||
198 | switch (errno) | ||
199 | { | ||
200 | #ifdef EINTR | ||
201 | case EINTR: | ||
202 | #endif | ||
203 | #ifdef EAGAIN | ||
204 | case EAGAIN: | ||
205 | #endif | ||
206 | /* No error, try again */ | ||
207 | break; | ||
208 | default: | ||
209 | ret = -1; | ||
210 | goto err; /* failure */ | ||
211 | } | ||
212 | } | ||
150 | } | 213 | } |
151 | if(buf[0] == 0) | 214 | numbytes = 0; |
152 | goto err; | 215 | while (numbytes != 1) |
153 | num = read(fd, buf, buf[0]); | ||
154 | if (num < 1) | ||
155 | { | 216 | { |
156 | ret=-1; | 217 | num = read(fd, egdbuf, 1); |
157 | goto err; | 218 | if (num >= 0) |
219 | numbytes += num; | ||
220 | else | ||
221 | { | ||
222 | switch (errno) | ||
223 | { | ||
224 | #ifdef EINTR | ||
225 | case EINTR: | ||
226 | #endif | ||
227 | #ifdef EAGAIN | ||
228 | case EAGAIN: | ||
229 | #endif | ||
230 | /* No error, try again */ | ||
231 | break; | ||
232 | default: | ||
233 | ret = -1; | ||
234 | goto err; /* failure */ | ||
235 | } | ||
236 | } | ||
158 | } | 237 | } |
159 | RAND_seed(buf, num); | 238 | if(egdbuf[0] == 0) |
160 | if (RAND_status() != 1) | ||
161 | { | ||
162 | ret=-1; | ||
163 | goto err; | 239 | goto err; |
240 | if (buf) | ||
241 | retrievebuf = buf + ret; | ||
242 | else | ||
243 | retrievebuf = tempbuf; | ||
244 | numbytes = 0; | ||
245 | while (numbytes != egdbuf[0]) | ||
246 | { | ||
247 | num = read(fd, retrievebuf + numbytes, egdbuf[0] - numbytes); | ||
248 | if (num >= 0) | ||
249 | numbytes += num; | ||
250 | else | ||
251 | { | ||
252 | switch (errno) | ||
253 | { | ||
254 | #ifdef EINTR | ||
255 | case EINTR: | ||
256 | #endif | ||
257 | #ifdef EAGAIN | ||
258 | case EAGAIN: | ||
259 | #endif | ||
260 | /* No error, try again */ | ||
261 | break; | ||
262 | default: | ||
263 | ret = -1; | ||
264 | goto err; /* failure */ | ||
265 | } | ||
266 | } | ||
164 | } | 267 | } |
165 | ret += num; | 268 | ret += egdbuf[0]; |
166 | bytes-=num; | 269 | bytes -= egdbuf[0]; |
270 | if (!buf) | ||
271 | RAND_seed(tempbuf, egdbuf[0]); | ||
167 | } | 272 | } |
168 | err: | 273 | err: |
169 | if (fd != -1) close(fd); | 274 | if (fd != -1) close(fd); |
@@ -171,4 +276,23 @@ int RAND_egd_bytes(const char *path,int bytes) | |||
171 | } | 276 | } |
172 | 277 | ||
173 | 278 | ||
279 | int RAND_egd_bytes(const char *path, int bytes) | ||
280 | { | ||
281 | int num, ret = 0; | ||
282 | |||
283 | num = RAND_query_egd_bytes(path, NULL, bytes); | ||
284 | if (num < 1) goto err; | ||
285 | if (RAND_status() == 1) | ||
286 | ret = num; | ||
287 | err: | ||
288 | return(ret); | ||
289 | } | ||
290 | |||
291 | |||
292 | int RAND_egd(const char *path) | ||
293 | { | ||
294 | return (RAND_egd_bytes(path, 255)); | ||
295 | } | ||
296 | |||
297 | |||
174 | #endif | 298 | #endif |
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c index 1af0aa0b8a..b77267e213 100644 --- a/src/lib/libcrypto/rand/rand_err.c +++ b/src/lib/libcrypto/rand/rand_err.c | |||
@@ -63,9 +63,10 @@ | |||
63 | #include <openssl/rand.h> | 63 | #include <openssl/rand.h> |
64 | 64 | ||
65 | /* BEGIN ERROR CODES */ | 65 | /* BEGIN ERROR CODES */ |
66 | #ifndef 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_RAND_GET_RAND_METHOD,0), "RAND_get_rand_method"}, | ||
69 | {ERR_PACK(0,RAND_F_SSLEAY_RAND_BYTES,0), "SSLEAY_RAND_BYTES"}, | 70 | {ERR_PACK(0,RAND_F_SSLEAY_RAND_BYTES,0), "SSLEAY_RAND_BYTES"}, |
70 | {0,NULL} | 71 | {0,NULL} |
71 | }; | 72 | }; |
@@ -85,7 +86,7 @@ void ERR_load_RAND_strings(void) | |||
85 | if (init) | 86 | if (init) |
86 | { | 87 | { |
87 | init=0; | 88 | init=0; |
88 | #ifndef NO_ERR | 89 | #ifndef OPENSSL_NO_ERR |
89 | ERR_load_strings(ERR_LIB_RAND,RAND_str_functs); | 90 | ERR_load_strings(ERR_LIB_RAND,RAND_str_functs); |
90 | ERR_load_strings(ERR_LIB_RAND,RAND_str_reasons); | 91 | ERR_load_strings(ERR_LIB_RAND,RAND_str_reasons); |
91 | #endif | 92 | #endif |
diff --git a/src/lib/libcrypto/rand/rand_lcl.h b/src/lib/libcrypto/rand/rand_lcl.h index 120e9366d2..618a8ec899 100644 --- a/src/lib/libcrypto/rand/rand_lcl.h +++ b/src/lib/libcrypto/rand/rand_lcl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* crypto/rand/md_rand.c */ | 1 | /* crypto/rand/rand_lcl.h */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -112,72 +112,46 @@ | |||
112 | #ifndef HEADER_RAND_LCL_H | 112 | #ifndef HEADER_RAND_LCL_H |
113 | #define HEADER_RAND_LCL_H | 113 | #define HEADER_RAND_LCL_H |
114 | 114 | ||
115 | #define ENTROPY_NEEDED 20 /* require 160 bits = 20 bytes of randomness */ | 115 | #define ENTROPY_NEEDED 32 /* require 256 bits = 32 bytes of randomness */ |
116 | 116 | ||
117 | 117 | ||
118 | #if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND) | 118 | #if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND) |
119 | #if !defined(NO_SHA) && !defined(NO_SHA1) | 119 | #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1) |
120 | #define USE_SHA1_RAND | 120 | #define USE_SHA1_RAND |
121 | #elif !defined(NO_MD5) | 121 | #elif !defined(OPENSSL_NO_MD5) |
122 | #define USE_MD5_RAND | 122 | #define USE_MD5_RAND |
123 | #elif !defined(NO_MDC2) && !defined(NO_DES) | 123 | #elif !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES) |
124 | #define USE_MDC2_RAND | 124 | #define USE_MDC2_RAND |
125 | #elif !defined(NO_MD2) | 125 | #elif !defined(OPENSSL_NO_MD2) |
126 | #define USE_MD2_RAND | 126 | #define USE_MD2_RAND |
127 | #else | 127 | #else |
128 | #error No message digest algorithm available | 128 | #error No message digest algorithm available |
129 | #endif | 129 | #endif |
130 | #endif | 130 | #endif |
131 | 131 | ||
132 | #include <openssl/evp.h> | ||
133 | #define MD_Update(a,b,c) EVP_DigestUpdate(a,b,c) | ||
134 | #define MD_Final(a,b) EVP_DigestFinal_ex(a,b,NULL) | ||
132 | #if defined(USE_MD5_RAND) | 135 | #if defined(USE_MD5_RAND) |
133 | #include <openssl/md5.h> | 136 | #include <openssl/md5.h> |
134 | #define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH | 137 | #define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH |
135 | #define MD(a,b,c) MD5(a,b,c) | 138 | #define MD_Init(a) EVP_DigestInit_ex(a,EVP_md5(), NULL) |
139 | #define MD(a,b,c) EVP_Digest(a,b,c,NULL,EVP_md5(), NULL) | ||
136 | #elif defined(USE_SHA1_RAND) | 140 | #elif defined(USE_SHA1_RAND) |
137 | #include <openssl/sha.h> | 141 | #include <openssl/sha.h> |
138 | #define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH | 142 | #define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH |
139 | #define MD(a,b,c) SHA1(a,b,c) | 143 | #define MD_Init(a) EVP_DigestInit_ex(a,EVP_sha1(), NULL) |
144 | #define MD(a,b,c) EVP_Digest(a,b,c,NULL,EVP_sha1(), NULL) | ||
140 | #elif defined(USE_MDC2_RAND) | 145 | #elif defined(USE_MDC2_RAND) |
141 | #include <openssl/mdc2.h> | 146 | #include <openssl/mdc2.h> |
142 | #define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH | 147 | #define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH |
143 | #define MD(a,b,c) MDC2(a,b,c) | 148 | #define MD_Init(a) EVP_DigestInit_ex(a,EVP_mdc2(), NULL) |
149 | #define MD(a,b,c) EVP_Digest(a,b,c,NULL,EVP_mdc2(), NULL) | ||
144 | #elif defined(USE_MD2_RAND) | 150 | #elif defined(USE_MD2_RAND) |
145 | #include <openssl/md2.h> | 151 | #include <openssl/md2.h> |
146 | #define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH | 152 | #define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH |
147 | #define MD(a,b,c) MD2(a,b,c) | 153 | #define MD_Init(a) EVP_DigestInit_ex(a,EVP_md2(), NULL) |
148 | #endif | 154 | #define MD(a,b,c) EVP_Digest(a,b,c,NULL,EVP_md2(), NULL) |
149 | #if defined(USE_MD5_RAND) | ||
150 | #include <openssl/md5.h> | ||
151 | #define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH | ||
152 | #define MD_CTX MD5_CTX | ||
153 | #define MD_Init(a) MD5_Init(a) | ||
154 | #define MD_Update(a,b,c) MD5_Update(a,b,c) | ||
155 | #define MD_Final(a,b) MD5_Final(a,b) | ||
156 | #define MD(a,b,c) MD5(a,b,c) | ||
157 | #elif defined(USE_SHA1_RAND) | ||
158 | #include <openssl/sha.h> | ||
159 | #define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH | ||
160 | #define MD_CTX SHA_CTX | ||
161 | #define MD_Init(a) SHA1_Init(a) | ||
162 | #define MD_Update(a,b,c) SHA1_Update(a,b,c) | ||
163 | #define MD_Final(a,b) SHA1_Final(a,b) | ||
164 | #define MD(a,b,c) SHA1(a,b,c) | ||
165 | #elif defined(USE_MDC2_RAND) | ||
166 | #include <openssl/mdc2.h> | ||
167 | #define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH | ||
168 | #define MD_CTX MDC2_CTX | ||
169 | #define MD_Init(a) MDC2_Init(a) | ||
170 | #define MD_Update(a,b,c) MDC2_Update(a,b,c) | ||
171 | #define MD_Final(a,b) MDC2_Final(a,b) | ||
172 | #define MD(a,b,c) MDC2(a,b,c) | ||
173 | #elif defined(USE_MD2_RAND) | ||
174 | #include <openssl/md2.h> | ||
175 | #define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH | ||
176 | #define MD_CTX MD2_CTX | ||
177 | #define MD_Init(a) MD2_Init(a) | ||
178 | #define MD_Update(a,b,c) MD2_Update(a,b,c) | ||
179 | #define MD_Final(a,b) MD2_Final(a,b) | ||
180 | #define MD(a,b,c) MD2(a,b,c) | ||
181 | #endif | 155 | #endif |
182 | 156 | ||
183 | 157 | ||
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c index 57eff0f132..5cf5dc1188 100644 --- a/src/lib/libcrypto/rand/rand_lib.c +++ b/src/lib/libcrypto/rand/rand_lib.c | |||
@@ -58,62 +58,92 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <time.h> | 60 | #include <time.h> |
61 | #include "cryptlib.h" | ||
61 | #include <openssl/rand.h> | 62 | #include <openssl/rand.h> |
62 | #include <openssl/engine.h> | 63 | #include <openssl/engine.h> |
63 | 64 | ||
64 | static ENGINE *rand_engine=NULL; | 65 | /* non-NULL if default_RAND_meth is ENGINE-provided */ |
66 | static ENGINE *funct_ref =NULL; | ||
67 | static const RAND_METHOD *default_RAND_meth = NULL; | ||
65 | 68 | ||
66 | #if 0 | 69 | int RAND_set_rand_method(const RAND_METHOD *meth) |
67 | void RAND_set_rand_method(RAND_METHOD *meth) | ||
68 | { | 70 | { |
69 | rand_meth=meth; | 71 | if(funct_ref) |
72 | { | ||
73 | ENGINE_finish(funct_ref); | ||
74 | funct_ref = NULL; | ||
75 | } | ||
76 | default_RAND_meth = meth; | ||
77 | return 1; | ||
70 | } | 78 | } |
71 | #else | 79 | |
72 | int RAND_set_rand_method(ENGINE *engine) | 80 | const RAND_METHOD *RAND_get_rand_method(void) |
73 | { | 81 | { |
74 | ENGINE *mtmp; | 82 | if (!default_RAND_meth) |
75 | mtmp = rand_engine; | 83 | { |
76 | if (!ENGINE_init(engine)) | 84 | ENGINE *e = ENGINE_get_default_RAND(); |
77 | return 0; | 85 | if(e) |
78 | rand_engine = engine; | 86 | { |
79 | /* SHOULD ERROR CHECK THIS!!! */ | 87 | default_RAND_meth = ENGINE_get_RAND(e); |
80 | ENGINE_finish(mtmp); | 88 | if(!default_RAND_meth) |
81 | return 1; | 89 | { |
90 | ENGINE_finish(e); | ||
91 | e = NULL; | ||
92 | } | ||
93 | } | ||
94 | if(e) | ||
95 | funct_ref = e; | ||
96 | else | ||
97 | default_RAND_meth = RAND_SSLeay(); | ||
98 | } | ||
99 | return default_RAND_meth; | ||
82 | } | 100 | } |
83 | #endif | ||
84 | 101 | ||
85 | RAND_METHOD *RAND_get_rand_method(void) | 102 | int RAND_set_rand_engine(ENGINE *engine) |
86 | { | 103 | { |
87 | if (rand_engine == NULL | 104 | const RAND_METHOD *tmp_meth = NULL; |
88 | && (rand_engine = ENGINE_get_default_RAND()) == NULL) | 105 | if(engine) |
89 | return NULL; | 106 | { |
90 | return ENGINE_get_RAND(rand_engine); | 107 | if(!ENGINE_init(engine)) |
108 | return 0; | ||
109 | tmp_meth = ENGINE_get_RAND(engine); | ||
110 | if(!tmp_meth) | ||
111 | { | ||
112 | ENGINE_finish(engine); | ||
113 | return 0; | ||
114 | } | ||
115 | } | ||
116 | /* This function releases any prior ENGINE so call it first */ | ||
117 | RAND_set_rand_method(tmp_meth); | ||
118 | funct_ref = engine; | ||
119 | return 1; | ||
91 | } | 120 | } |
92 | 121 | ||
93 | void RAND_cleanup(void) | 122 | void RAND_cleanup(void) |
94 | { | 123 | { |
95 | RAND_METHOD *meth = RAND_get_rand_method(); | 124 | const RAND_METHOD *meth = RAND_get_rand_method(); |
96 | if (meth && meth->cleanup) | 125 | if (meth && meth->cleanup) |
97 | meth->cleanup(); | 126 | meth->cleanup(); |
127 | RAND_set_rand_method(NULL); | ||
98 | } | 128 | } |
99 | 129 | ||
100 | void RAND_seed(const void *buf, int num) | 130 | void RAND_seed(const void *buf, int num) |
101 | { | 131 | { |
102 | RAND_METHOD *meth = RAND_get_rand_method(); | 132 | const RAND_METHOD *meth = RAND_get_rand_method(); |
103 | if (meth && meth->seed) | 133 | if (meth && meth->seed) |
104 | meth->seed(buf,num); | 134 | meth->seed(buf,num); |
105 | } | 135 | } |
106 | 136 | ||
107 | void RAND_add(const void *buf, int num, double entropy) | 137 | void RAND_add(const void *buf, int num, double entropy) |
108 | { | 138 | { |
109 | RAND_METHOD *meth = RAND_get_rand_method(); | 139 | const RAND_METHOD *meth = RAND_get_rand_method(); |
110 | if (meth && meth->add) | 140 | if (meth && meth->add) |
111 | meth->add(buf,num,entropy); | 141 | meth->add(buf,num,entropy); |
112 | } | 142 | } |
113 | 143 | ||
114 | int RAND_bytes(unsigned char *buf, int num) | 144 | int RAND_bytes(unsigned char *buf, int num) |
115 | { | 145 | { |
116 | RAND_METHOD *meth = RAND_get_rand_method(); | 146 | const RAND_METHOD *meth = RAND_get_rand_method(); |
117 | if (meth && meth->bytes) | 147 | if (meth && meth->bytes) |
118 | return meth->bytes(buf,num); | 148 | return meth->bytes(buf,num); |
119 | return(-1); | 149 | return(-1); |
@@ -121,7 +151,7 @@ int RAND_bytes(unsigned char *buf, int num) | |||
121 | 151 | ||
122 | int RAND_pseudo_bytes(unsigned char *buf, int num) | 152 | int RAND_pseudo_bytes(unsigned char *buf, int num) |
123 | { | 153 | { |
124 | RAND_METHOD *meth = RAND_get_rand_method(); | 154 | const RAND_METHOD *meth = RAND_get_rand_method(); |
125 | if (meth && meth->pseudorand) | 155 | if (meth && meth->pseudorand) |
126 | return meth->pseudorand(buf,num); | 156 | return meth->pseudorand(buf,num); |
127 | return(-1); | 157 | return(-1); |
@@ -129,7 +159,7 @@ int RAND_pseudo_bytes(unsigned char *buf, int num) | |||
129 | 159 | ||
130 | int RAND_status(void) | 160 | int RAND_status(void) |
131 | { | 161 | { |
132 | RAND_METHOD *meth = RAND_get_rand_method(); | 162 | const RAND_METHOD *meth = RAND_get_rand_method(); |
133 | if (meth && meth->status) | 163 | if (meth && meth->status) |
134 | return meth->status(); | 164 | return meth->status(); |
135 | return 0; | 165 | return 0; |
diff --git a/src/lib/libcrypto/rand/rand_os2.c b/src/lib/libcrypto/rand/rand_os2.c new file mode 100644 index 0000000000..c3e36d4e5e --- /dev/null +++ b/src/lib/libcrypto/rand/rand_os2.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* crypto/rand/rand_os2.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@openssl.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include "cryptlib.h" | ||
57 | #include <openssl/rand.h> | ||
58 | #include "rand_lcl.h" | ||
59 | |||
60 | #ifdef OPENSSL_SYS_OS2 | ||
61 | |||
62 | #define INCL_DOSPROCESS | ||
63 | #define INCL_DOSPROFILE | ||
64 | #define INCL_DOSMISC | ||
65 | #define INCL_DOSMODULEMGR | ||
66 | #include <os2.h> | ||
67 | |||
68 | #define CMD_KI_RDCNT (0x63) | ||
69 | |||
70 | typedef struct _CPUUTIL { | ||
71 | ULONG ulTimeLow; /* Low 32 bits of time stamp */ | ||
72 | ULONG ulTimeHigh; /* High 32 bits of time stamp */ | ||
73 | ULONG ulIdleLow; /* Low 32 bits of idle time */ | ||
74 | ULONG ulIdleHigh; /* High 32 bits of idle time */ | ||
75 | ULONG ulBusyLow; /* Low 32 bits of busy time */ | ||
76 | ULONG ulBusyHigh; /* High 32 bits of busy time */ | ||
77 | ULONG ulIntrLow; /* Low 32 bits of interrupt time */ | ||
78 | ULONG ulIntrHigh; /* High 32 bits of interrupt time */ | ||
79 | } CPUUTIL; | ||
80 | |||
81 | APIRET APIENTRY(*DosPerfSysCall) (ULONG ulCommand, ULONG ulParm1, ULONG ulParm2, ULONG ulParm3) = NULL; | ||
82 | APIRET APIENTRY(*DosQuerySysState) (ULONG func, ULONG arg1, ULONG pid, ULONG _res_, PVOID buf, ULONG bufsz) = NULL; | ||
83 | HMODULE hDoscalls = 0; | ||
84 | |||
85 | int RAND_poll(void) | ||
86 | { | ||
87 | char failed_module[20]; | ||
88 | QWORD qwTime; | ||
89 | ULONG SysVars[QSV_FOREGROUND_PROCESS]; | ||
90 | |||
91 | if (hDoscalls == 0) { | ||
92 | ULONG rc = DosLoadModule(failed_module, sizeof(failed_module), "DOSCALLS", &hDoscalls); | ||
93 | |||
94 | if (rc == 0) { | ||
95 | rc = DosQueryProcAddr(hDoscalls, 976, NULL, (PFN *)&DosPerfSysCall); | ||
96 | |||
97 | if (rc) | ||
98 | DosPerfSysCall = NULL; | ||
99 | |||
100 | rc = DosQueryProcAddr(hDoscalls, 368, NULL, (PFN *)&DosQuerySysState); | ||
101 | |||
102 | if (rc) | ||
103 | DosQuerySysState = NULL; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | /* Sample the hi-res timer, runs at around 1.1 MHz */ | ||
108 | DosTmrQueryTime(&qwTime); | ||
109 | RAND_add(&qwTime, sizeof(qwTime), 2); | ||
110 | |||
111 | /* Sample a bunch of system variables, includes various process & memory statistics */ | ||
112 | DosQuerySysInfo(1, QSV_FOREGROUND_PROCESS, SysVars, sizeof(SysVars)); | ||
113 | RAND_add(SysVars, sizeof(SysVars), 4); | ||
114 | |||
115 | /* If available, sample CPU registers that count at CPU MHz | ||
116 | * Only fairly new CPUs (PPro & K6 onwards) & OS/2 versions support this | ||
117 | */ | ||
118 | if (DosPerfSysCall) { | ||
119 | CPUUTIL util; | ||
120 | |||
121 | if (DosPerfSysCall(CMD_KI_RDCNT, (ULONG)&util, 0, 0) == 0) { | ||
122 | RAND_add(&util, sizeof(util), 10); | ||
123 | } | ||
124 | else { | ||
125 | DosPerfSysCall = NULL; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | /* DosQuerySysState() gives us a huge quantity of process, thread, memory & handle stats */ | ||
130 | if (DosQuerySysState) { | ||
131 | char *buffer = OPENSSL_malloc(256 * 1024); | ||
132 | |||
133 | if (DosQuerySysState(0x1F, 0, 0, 0, buffer, 256 * 1024) == 0) { | ||
134 | /* First 4 bytes in buffer is a pointer to the thread count | ||
135 | * there should be at least 1 byte of entropy per thread | ||
136 | */ | ||
137 | RAND_add(buffer, 256 * 1024, **(ULONG **)buffer); | ||
138 | } | ||
139 | |||
140 | OPENSSL_free(buffer); | ||
141 | return 1; | ||
142 | } | ||
143 | |||
144 | return 0; | ||
145 | } | ||
146 | |||
147 | #endif /* OPENSSL_SYS_OS2 */ | ||
diff --git a/src/lib/libcrypto/rand/rand_unix.c b/src/lib/libcrypto/rand/rand_unix.c new file mode 100644 index 0000000000..0b29235130 --- /dev/null +++ b/src/lib/libcrypto/rand/rand_unix.c | |||
@@ -0,0 +1,274 @@ | |||
1 | /* crypto/rand/rand_unix.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #include "cryptlib.h" | ||
113 | #include <openssl/rand.h> | ||
114 | #include "rand_lcl.h" | ||
115 | |||
116 | #if !(defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2)) | ||
117 | |||
118 | #include <sys/types.h> | ||
119 | #include <sys/time.h> | ||
120 | #include <sys/times.h> | ||
121 | #include <fcntl.h> | ||
122 | #include <unistd.h> | ||
123 | #include <time.h> | ||
124 | |||
125 | #ifdef __OpenBSD__ | ||
126 | #undef DEVRANDOM | ||
127 | #define DEVRANDOM "/dev/arandom" | ||
128 | int RAND_poll(void) | ||
129 | { | ||
130 | unsigned long l; | ||
131 | pid_t curr_pid = getpid(); | ||
132 | FILE *fh; | ||
133 | |||
134 | /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD | ||
135 | * have this. Use /dev/urandom if you can as /dev/random may block | ||
136 | * if it runs out of random entries. */ | ||
137 | |||
138 | if ((fh = fopen(DEVRANDOM, "r")) != NULL) | ||
139 | { | ||
140 | unsigned char tmpbuf[ENTROPY_NEEDED]; | ||
141 | int n; | ||
142 | |||
143 | setvbuf(fh, NULL, _IONBF, 0); | ||
144 | n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh); | ||
145 | fclose(fh); | ||
146 | RAND_add(tmpbuf,sizeof tmpbuf,n); | ||
147 | memset(tmpbuf,0,n); | ||
148 | } | ||
149 | |||
150 | /* put in some default random data, we need more than just this */ | ||
151 | l=curr_pid; | ||
152 | RAND_add(&l,sizeof(l),0); | ||
153 | l=getuid(); | ||
154 | RAND_add(&l,sizeof(l),0); | ||
155 | |||
156 | l=time(NULL); | ||
157 | RAND_add(&l,sizeof(l),0); | ||
158 | |||
159 | return 1; | ||
160 | } | ||
161 | #else | ||
162 | int RAND_poll(void) | ||
163 | { | ||
164 | unsigned long l; | ||
165 | pid_t curr_pid = getpid(); | ||
166 | #if defined(DEVRANDOM) || defined(DEVRANDOM_EGD) | ||
167 | unsigned char tmpbuf[ENTROPY_NEEDED]; | ||
168 | int n = 0; | ||
169 | #endif | ||
170 | #ifdef DEVRANDOM | ||
171 | static const char *randomfiles[] = { DEVRANDOM, NULL }; | ||
172 | const char **randomfile = NULL; | ||
173 | int fd; | ||
174 | #endif | ||
175 | #ifdef DEVRANDOM_EGD | ||
176 | static const char *egdsockets[] = { DEVRANDOM_EGD, NULL }; | ||
177 | const char **egdsocket = NULL; | ||
178 | #endif | ||
179 | |||
180 | #ifdef DEVRANDOM | ||
181 | /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD | ||
182 | * have this. Use /dev/urandom if you can as /dev/random may block | ||
183 | * if it runs out of random entries. */ | ||
184 | |||
185 | for (randomfile = randomfiles; *randomfile && n < ENTROPY_NEEDED; randomfile++) | ||
186 | { | ||
187 | if ((fd = open(*randomfile, O_RDONLY|O_NONBLOCK | ||
188 | #ifdef O_NOCTTY /* If it happens to be a TTY (god forbid), do not make it | ||
189 | our controlling tty */ | ||
190 | |O_NOCTTY | ||
191 | #endif | ||
192 | #ifdef O_NOFOLLOW /* Fail if the file is a symbolic link */ | ||
193 | |O_NOFOLLOW | ||
194 | #endif | ||
195 | )) >= 0) | ||
196 | { | ||
197 | struct timeval t = { 0, 10*1000 }; /* Spend 10ms on | ||
198 | each file. */ | ||
199 | int r; | ||
200 | fd_set fset; | ||
201 | |||
202 | do | ||
203 | { | ||
204 | FD_ZERO(&fset); | ||
205 | FD_SET(fd, &fset); | ||
206 | r = -1; | ||
207 | |||
208 | if (select(fd+1,&fset,NULL,NULL,&t) < 0) | ||
209 | t.tv_usec=0; | ||
210 | else if (FD_ISSET(fd, &fset)) | ||
211 | { | ||
212 | r=read(fd,(unsigned char *)tmpbuf+n, | ||
213 | ENTROPY_NEEDED-n); | ||
214 | if (r > 0) | ||
215 | n += r; | ||
216 | } | ||
217 | |||
218 | /* Some Unixen will update t, some | ||
219 | won't. For those who won't, give | ||
220 | up here, otherwise, we will do | ||
221 | this once again for the remaining | ||
222 | time. */ | ||
223 | if (t.tv_usec == 10*1000) | ||
224 | t.tv_usec=0; | ||
225 | } | ||
226 | while ((r > 0 || (errno == EINTR || errno == EAGAIN)) | ||
227 | && t.tv_usec != 0 && n < ENTROPY_NEEDED); | ||
228 | |||
229 | close(fd); | ||
230 | } | ||
231 | } | ||
232 | #endif | ||
233 | |||
234 | #ifdef DEVRANDOM_EGD | ||
235 | /* Use an EGD socket to read entropy from an EGD or PRNGD entropy | ||
236 | * collecting daemon. */ | ||
237 | |||
238 | for (egdsocket = egdsockets; *egdsocket && n < ENTROPY_NEEDED; egdsocket++) | ||
239 | { | ||
240 | int r; | ||
241 | |||
242 | r = RAND_query_egd_bytes(*egdsocket, (unsigned char *)tmpbuf+n, | ||
243 | ENTROPY_NEEDED-n); | ||
244 | if (r > 0) | ||
245 | n += r; | ||
246 | } | ||
247 | #endif | ||
248 | |||
249 | #if defined(DEVRANDOM) || defined(DEVRANDOM_EGD) | ||
250 | if (n > 0) | ||
251 | { | ||
252 | RAND_add(tmpbuf,sizeof tmpbuf,n); | ||
253 | memset(tmpbuf,0,n); | ||
254 | } | ||
255 | #endif | ||
256 | |||
257 | /* put in some default random data, we need more than just this */ | ||
258 | l=curr_pid; | ||
259 | RAND_add(&l,sizeof(l),0); | ||
260 | l=getuid(); | ||
261 | RAND_add(&l,sizeof(l),0); | ||
262 | |||
263 | l=time(NULL); | ||
264 | RAND_add(&l,sizeof(l),0); | ||
265 | |||
266 | #if defined(DEVRANDOM) || defined(DEVRANDOM_EGD) | ||
267 | return 1; | ||
268 | #else | ||
269 | return 0; | ||
270 | #endif | ||
271 | } | ||
272 | |||
273 | #endif | ||
274 | #endif | ||
diff --git a/src/lib/libcrypto/rand/rand_vms.c b/src/lib/libcrypto/rand/rand_vms.c new file mode 100644 index 0000000000..29b2d7af0b --- /dev/null +++ b/src/lib/libcrypto/rand/rand_vms.c | |||
@@ -0,0 +1,135 @@ | |||
1 | /* crypto/rand/rand_vms.c -*- mode:C; c-file-style: "eay" -*- */ | ||
2 | /* Written by Richard Levitte <richard@levitte.org> for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * openssl-core@openssl.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <openssl/rand.h> | ||
60 | #include "rand_lcl.h" | ||
61 | |||
62 | #if defined(OPENSSL_SYS_VMS) | ||
63 | |||
64 | #include <descrip.h> | ||
65 | #include <jpidef.h> | ||
66 | #include <ssdef.h> | ||
67 | #include <starlet.h> | ||
68 | #ifdef __DECC | ||
69 | # pragma message disable DOLLARID | ||
70 | #endif | ||
71 | |||
72 | static struct items_data_st | ||
73 | { | ||
74 | short length, code; /* length is amount of bytes */ | ||
75 | } items_data[] = | ||
76 | { { 4, JPI$_BUFIO }, | ||
77 | { 4, JPI$_CPUTIM }, | ||
78 | { 4, JPI$_DIRIO }, | ||
79 | { 8, JPI$_LOGINTIM }, | ||
80 | { 4, JPI$_PAGEFLTS }, | ||
81 | { 4, JPI$_PID }, | ||
82 | { 4, JPI$_WSSIZE }, | ||
83 | { 0, 0 } | ||
84 | }; | ||
85 | |||
86 | int RAND_poll(void) | ||
87 | { | ||
88 | long pid, iosb[2]; | ||
89 | int status = 0; | ||
90 | struct | ||
91 | { | ||
92 | short length, code; | ||
93 | long *buffer; | ||
94 | int *retlen; | ||
95 | } item[32], *pitem; | ||
96 | unsigned char data_buffer[256]; | ||
97 | short total_length = 0; | ||
98 | struct items_data_st *pitems_data; | ||
99 | |||
100 | pitems_data = items_data; | ||
101 | pitem = item; | ||
102 | |||
103 | /* Setup */ | ||
104 | while (pitems_data->length) | ||
105 | { | ||
106 | pitem->length = pitems_data->length; | ||
107 | pitem->code = pitems_data->code; | ||
108 | pitem->buffer = (long *)data_buffer[total_length]; | ||
109 | pitem->retlen = 0; | ||
110 | total_length += pitems_data->length; | ||
111 | pitems_data++; | ||
112 | pitem++; | ||
113 | } | ||
114 | pitem->length = pitem->code = 0; | ||
115 | |||
116 | /* | ||
117 | * Scan through all the processes in the system and add entropy with | ||
118 | * results from the processes that were possible to look at. | ||
119 | * However, view the information as only half trustable. | ||
120 | */ | ||
121 | pid = -1; /* search context */ | ||
122 | while ((status = sys$getjpiw(0, &pid, 0, item, iosb, 0, 0)) | ||
123 | != SS$_NOMOREPROC) | ||
124 | { | ||
125 | if (status == SS$_NORMAL) | ||
126 | { | ||
127 | RAND_add(data_buffer, total_length, total_length/2); | ||
128 | } | ||
129 | } | ||
130 | sys$gettim(iosb); | ||
131 | RAND_add((unsigned char *)iosb, sizeof(iosb), sizeof(iosb)/2); | ||
132 | return 1; | ||
133 | } | ||
134 | |||
135 | #endif | ||
diff --git a/src/lib/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c index 3d137badd0..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 | ||
@@ -685,50 +690,4 @@ static void readscreen(void) | |||
685 | DeleteDC(hScrDC); | 690 | DeleteDC(hScrDC); |
686 | } | 691 | } |
687 | 692 | ||
688 | #else /* Unix version */ | ||
689 | |||
690 | #include <time.h> | ||
691 | |||
692 | int RAND_poll(void) | ||
693 | { | ||
694 | unsigned long l; | ||
695 | pid_t curr_pid = getpid(); | ||
696 | #ifdef DEVRANDOM | ||
697 | FILE *fh; | ||
698 | #endif | ||
699 | |||
700 | #ifdef DEVRANDOM | ||
701 | /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD | ||
702 | * have this. Use /dev/urandom if you can as /dev/random may block | ||
703 | * if it runs out of random entries. */ | ||
704 | |||
705 | if ((fh = fopen(DEVRANDOM, "r")) != NULL) | ||
706 | { | ||
707 | unsigned char tmpbuf[ENTROPY_NEEDED]; | ||
708 | int n; | ||
709 | |||
710 | setvbuf(fh, NULL, _IONBF, 0); | ||
711 | n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh); | ||
712 | fclose(fh); | ||
713 | RAND_add(tmpbuf,sizeof tmpbuf,n); | ||
714 | memset(tmpbuf,0,n); | ||
715 | } | ||
716 | #endif | ||
717 | |||
718 | /* put in some default random data, we need more than just this */ | ||
719 | l=curr_pid; | ||
720 | RAND_add(&l,sizeof(l),0); | ||
721 | l=getuid(); | ||
722 | RAND_add(&l,sizeof(l),0); | ||
723 | |||
724 | l=time(NULL); | ||
725 | RAND_add(&l,sizeof(l),0); | ||
726 | |||
727 | #ifdef DEVRANDOM | ||
728 | return 1; | ||
729 | #else | ||
730 | return 0; | ||
731 | #endif | ||
732 | } | ||
733 | |||
734 | #endif | 693 | #endif |
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index c4eb79ac5f..4b221e08f5 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c | |||
@@ -61,7 +61,11 @@ | |||
61 | #include <stdlib.h> | 61 | #include <stdlib.h> |
62 | #include <string.h> | 62 | #include <string.h> |
63 | 63 | ||
64 | #ifdef VMS | 64 | #include "e_os.h" |
65 | #include <openssl/crypto.h> | ||
66 | #include <openssl/rand.h> | ||
67 | |||
68 | #ifdef OPENSSL_SYS_VMS | ||
65 | #include <unixio.h> | 69 | #include <unixio.h> |
66 | #endif | 70 | #endif |
67 | #ifndef NO_SYS_TYPES_H | 71 | #ifndef NO_SYS_TYPES_H |
@@ -73,10 +77,6 @@ | |||
73 | # include <sys/stat.h> | 77 | # include <sys/stat.h> |
74 | #endif | 78 | #endif |
75 | 79 | ||
76 | #include "openssl/e_os.h" | ||
77 | #include <openssl/crypto.h> | ||
78 | #include <openssl/rand.h> | ||
79 | |||
80 | #undef BUFSIZE | 80 | #undef BUFSIZE |
81 | #define BUFSIZE 1024 | 81 | #define BUFSIZE 1024 |
82 | #define RAND_DATA 1024 | 82 | #define RAND_DATA 1024 |
@@ -158,7 +158,7 @@ int RAND_write_file(const char *file) | |||
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
161 | #if defined(O_CREAT) && !defined(WIN32) | 161 | #if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) |
162 | /* For some reason Win32 can't write to files created this way */ | 162 | /* For some reason Win32 can't write to files created this way */ |
163 | 163 | ||
164 | /* chmod(..., 0600) is too late to protect the file, | 164 | /* chmod(..., 0600) is too late to protect the file, |
@@ -190,7 +190,7 @@ int RAND_write_file(const char *file) | |||
190 | ret+=i; | 190 | ret+=i; |
191 | if (n <= 0) break; | 191 | if (n <= 0) break; |
192 | } | 192 | } |
193 | #ifdef VMS | 193 | #ifdef OPENSSL_SYS_VMS |
194 | /* Try to delete older versions of the file, until there aren't | 194 | /* Try to delete older versions of the file, until there aren't |
195 | any */ | 195 | any */ |
196 | { | 196 | { |
@@ -208,7 +208,7 @@ int RAND_write_file(const char *file) | |||
208 | some point... */ | 208 | some point... */ |
209 | } | 209 | } |
210 | } | 210 | } |
211 | #endif /* VMS */ | 211 | #endif /* OPENSSL_SYS_VMS */ |
212 | 212 | ||
213 | fclose(out); | 213 | fclose(out); |
214 | memset(buf,0,BUFSIZE); | 214 | memset(buf,0,BUFSIZE); |
@@ -242,7 +242,7 @@ const char *RAND_file_name(char *buf, size_t size) | |||
242 | if (s && *s && strlen(s)+strlen(RFILE)+2 < size) | 242 | if (s && *s && strlen(s)+strlen(RFILE)+2 < size) |
243 | { | 243 | { |
244 | strlcpy(buf,s,size); | 244 | strlcpy(buf,s,size); |
245 | #ifndef VMS | 245 | #ifndef OPENSSL_SYS_VMS |
246 | strcat(buf,"/"); | 246 | strcat(buf,"/"); |
247 | #endif | 247 | #endif |
248 | strlcat(buf,RFILE,size); | 248 | strlcat(buf,RFILE,size); |
@@ -252,20 +252,20 @@ const char *RAND_file_name(char *buf, size_t size) | |||
252 | buf[0] = '\0'; /* no file name */ | 252 | buf[0] = '\0'; /* no file name */ |
253 | } | 253 | } |
254 | 254 | ||
255 | #ifdef DEVRANDOM | 255 | #ifdef __OpenBSD__ |
256 | /* given that all random loads just fail if the file can't be | 256 | /* given that all random loads just fail if the file can't be |
257 | * seen on a stat, we stat the file we're returning, if it | 257 | * seen on a stat, we stat the file we're returning, if it |
258 | * fails, use DEVRANDOM instead. this allows the user to | 258 | * fails, use /dev/arandom instead. this allows the user to |
259 | * use their own source for good random data, but defaults | 259 | * use their own source for good random data, but defaults |
260 | * to something hopefully decent if that isn't available. | 260 | * to something hopefully decent if that isn't available. |
261 | */ | 261 | */ |
262 | 262 | ||
263 | if (!ok) | 263 | if (!ok) |
264 | if (strlcpy(buf,DEVRANDOM,size) >= size) { | 264 | if (strlcpy(buf,"/dev/arandom",size) >= size) { |
265 | return(NULL); | 265 | return(NULL); |
266 | } | 266 | } |
267 | if (stat(buf,&sb) == -1) | 267 | if (stat(buf,&sb) == -1) |
268 | if (strlcpy(buf,DEVRANDOM,size) >= size) { | 268 | if (strlcpy(buf,"/dev/arandom",size) >= size) { |
269 | return(NULL); | 269 | return(NULL); |
270 | } | 270 | } |
271 | 271 | ||
diff --git a/src/lib/libcrypto/rand/randtest.c b/src/lib/libcrypto/rand/randtest.c index da96e3f695..b64de616db 100644 --- a/src/lib/libcrypto/rand/randtest.c +++ b/src/lib/libcrypto/rand/randtest.c | |||
@@ -73,7 +73,13 @@ int main() | |||
73 | /*double d; */ | 73 | /*double d; */ |
74 | long d; | 74 | long d; |
75 | 75 | ||
76 | RAND_pseudo_bytes(buf,2500); | 76 | i = RAND_pseudo_bytes(buf,2500); |
77 | if (i < 0) | ||
78 | { | ||
79 | printf ("init failed, the rand method is not properly installed\n"); | ||
80 | err++; | ||
81 | goto err; | ||
82 | } | ||
77 | 83 | ||
78 | n1=0; | 84 | n1=0; |
79 | for (i=0; i<16; i++) n2[i]=0; | 85 | for (i=0; i<16; i++) n2[i]=0; |
@@ -201,6 +207,7 @@ int main() | |||
201 | err++; | 207 | err++; |
202 | } | 208 | } |
203 | printf("test 4 done\n"); | 209 | printf("test 4 done\n"); |
210 | err: | ||
204 | err=((err)?1:0); | 211 | err=((err)?1:0); |
205 | exit(err); | 212 | exit(err); |
206 | return(err); | 213 | return(err); |