diff options
Diffstat (limited to 'src/lib/libcrypto/rand')
-rw-r--r-- | src/lib/libcrypto/rand/Makefile | 196 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/md_rand.c | 9 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_egd.c | 10 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_unix.c | 35 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_vms.c | 5 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_win.c | 104 |
6 files changed, 303 insertions, 56 deletions
diff --git a/src/lib/libcrypto/rand/Makefile b/src/lib/libcrypto/rand/Makefile new file mode 100644 index 0000000000..665eaa18e5 --- /dev/null +++ b/src/lib/libcrypto/rand/Makefile | |||
@@ -0,0 +1,196 @@ | |||
1 | # | ||
2 | # SSLeay/crypto/rand/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= rand | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | INSTALL_PREFIX= | ||
11 | OPENSSLDIR= /usr/local/ssl | ||
12 | INSTALLTOP=/usr/local/ssl | ||
13 | MAKEDEPPROG= makedepend | ||
14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
15 | MAKEFILE= Makefile | ||
16 | AR= ar r | ||
17 | |||
18 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
19 | |||
20 | GENERAL=Makefile | ||
21 | TEST= randtest.c | ||
22 | APPS= | ||
23 | |||
24 | LIB=$(TOP)/libcrypto.a | ||
25 | LIBSRC=md_rand.c randfile.c rand_lib.c rand_err.c rand_egd.c \ | ||
26 | rand_win.c rand_unix.c rand_os2.c | ||
27 | LIBOBJ=md_rand.o randfile.o rand_lib.o rand_err.o rand_egd.o \ | ||
28 | rand_win.o rand_unix.o rand_os2.o | ||
29 | |||
30 | SRC= $(LIBSRC) | ||
31 | |||
32 | EXHEADER= rand.h | ||
33 | HEADER= $(EXHEADER) | ||
34 | |||
35 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
36 | |||
37 | top: | ||
38 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
39 | |||
40 | all: lib | ||
41 | |||
42 | lib: $(LIBOBJ) | ||
43 | $(AR) $(LIB) $(LIBOBJ) | ||
44 | $(RANLIB) $(LIB) || echo Never mind. | ||
45 | @touch lib | ||
46 | |||
47 | files: | ||
48 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
49 | |||
50 | links: | ||
51 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
52 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
53 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
54 | |||
55 | install: | ||
56 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
57 | do \ | ||
58 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
59 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
60 | done; | ||
61 | |||
62 | tags: | ||
63 | ctags $(SRC) | ||
64 | |||
65 | tests: | ||
66 | |||
67 | lint: | ||
68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
69 | |||
70 | depend: | ||
71 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
72 | |||
73 | dclean: | ||
74 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
75 | mv -f Makefile.new $(MAKEFILE) | ||
76 | |||
77 | clean: | ||
78 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
79 | |||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
81 | |||
82 | md_rand.o: ../../e_os.h ../../include/openssl/aes.h | ||
83 | md_rand.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
84 | md_rand.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
85 | md_rand.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h | ||
86 | md_rand.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
87 | md_rand.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
88 | md_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
89 | md_rand.o: ../../include/openssl/evp.h ../../include/openssl/fips.h | ||
90 | md_rand.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
91 | md_rand.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
92 | md_rand.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
93 | md_rand.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
94 | md_rand.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
95 | md_rand.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
96 | md_rand.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h | ||
97 | md_rand.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h | ||
98 | md_rand.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h | ||
99 | md_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
100 | md_rand.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
101 | md_rand.o: ../../include/openssl/ui_compat.h md_rand.c rand_lcl.h | ||
102 | rand_egd.o: ../../include/openssl/buffer.h ../../include/openssl/e_os2.h | ||
103 | rand_egd.o: ../../include/openssl/opensslconf.h | ||
104 | rand_egd.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
105 | rand_egd.o: rand_egd.c | ||
106 | rand_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
107 | rand_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
108 | rand_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
109 | rand_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
110 | rand_err.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
111 | rand_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
112 | rand_err.o: rand_err.c | ||
113 | rand_lib.o: ../../e_os.h ../../include/openssl/asn1.h | ||
114 | rand_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
115 | rand_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
116 | rand_lib.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
117 | rand_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
118 | rand_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
119 | rand_lib.o: ../../include/openssl/err.h ../../include/openssl/fips.h | ||
120 | rand_lib.o: ../../include/openssl/fips_rand.h ../../include/openssl/lhash.h | ||
121 | rand_lib.o: ../../include/openssl/opensslconf.h | ||
122 | rand_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
123 | rand_lib.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h | ||
124 | rand_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
125 | rand_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
126 | rand_lib.o: ../../include/openssl/ui_compat.h ../cryptlib.h rand_lib.c | ||
127 | rand_os2.o: ../../e_os.h ../../include/openssl/aes.h | ||
128 | rand_os2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
129 | rand_os2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
130 | rand_os2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
131 | rand_os2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
132 | rand_os2.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
133 | rand_os2.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
134 | rand_os2.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
135 | rand_os2.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
136 | rand_os2.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
137 | rand_os2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
138 | rand_os2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
139 | rand_os2.o: ../../include/openssl/opensslconf.h | ||
140 | rand_os2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
141 | rand_os2.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
142 | rand_os2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
143 | rand_os2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
144 | rand_os2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
145 | rand_os2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
146 | rand_os2.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
147 | rand_os2.o: ../cryptlib.h rand_lcl.h rand_os2.c | ||
148 | rand_unix.o: ../../e_os.h ../../include/openssl/aes.h | ||
149 | rand_unix.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
150 | rand_unix.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
151 | rand_unix.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
152 | rand_unix.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
153 | rand_unix.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
154 | rand_unix.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
155 | rand_unix.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
156 | rand_unix.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
157 | rand_unix.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
158 | rand_unix.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
159 | rand_unix.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
160 | rand_unix.o: ../../include/openssl/opensslconf.h | ||
161 | rand_unix.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
162 | rand_unix.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
163 | rand_unix.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
164 | rand_unix.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
165 | rand_unix.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
166 | rand_unix.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
167 | rand_unix.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
168 | rand_unix.o: ../cryptlib.h rand_lcl.h rand_unix.c | ||
169 | rand_win.o: ../../e_os.h ../../include/openssl/aes.h | ||
170 | rand_win.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
171 | rand_win.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
172 | rand_win.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h | ||
173 | rand_win.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
174 | rand_win.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h | ||
175 | rand_win.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h | ||
176 | rand_win.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
177 | rand_win.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h | ||
178 | rand_win.o: ../../include/openssl/md2.h ../../include/openssl/md4.h | ||
179 | rand_win.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h | ||
180 | rand_win.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
181 | rand_win.o: ../../include/openssl/opensslconf.h | ||
182 | rand_win.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
183 | rand_win.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
184 | rand_win.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
185 | rand_win.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
186 | rand_win.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
187 | rand_win.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
188 | rand_win.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
189 | rand_win.o: ../cryptlib.h rand_lcl.h rand_win.c | ||
190 | randfile.o: ../../e_os.h ../../include/openssl/buffer.h | ||
191 | randfile.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
192 | randfile.o: ../../include/openssl/opensslconf.h | ||
193 | randfile.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
194 | randfile.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
195 | randfile.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
196 | randfile.o: randfile.c | ||
diff --git a/src/lib/libcrypto/rand/md_rand.c b/src/lib/libcrypto/rand/md_rand.c index eeffc0df4c..c84968df88 100644 --- a/src/lib/libcrypto/rand/md_rand.c +++ b/src/lib/libcrypto/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/libcrypto/rand/rand_egd.c b/src/lib/libcrypto/rand/rand_egd.c index 6f742900a0..cd666abfcb 100644 --- a/src/lib/libcrypto/rand/rand_egd.c +++ b/src/lib/libcrypto/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/libcrypto/rand/rand_unix.c b/src/lib/libcrypto/rand/rand_unix.c index 0599719dd1..9376554fae 100644 --- a/src/lib/libcrypto/rand/rand_unix.c +++ b/src/lib/libcrypto/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/libcrypto/rand/rand_vms.c b/src/lib/libcrypto/rand/rand_vms.c index 29b2d7af0b..1267a3acae 100644 --- a/src/lib/libcrypto/rand/rand_vms.c +++ b/src/lib/libcrypto/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/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c index 3584842224..30c69161ef 100644 --- a/src/lib/libcrypto/rand/rand_win.c +++ b/src/lib/libcrypto/rand/rand_win.c | |||
@@ -125,7 +125,7 @@ | |||
125 | * http://developer.intel.com/design/security/rng/redist_license.htm | 125 | * http://developer.intel.com/design/security/rng/redist_license.htm |
126 | */ | 126 | */ |
127 | #define PROV_INTEL_SEC 22 | 127 | #define PROV_INTEL_SEC 22 |
128 | #define INTEL_DEF_PROV TEXT("Intel Hardware Cryptographic Service Provider") | 128 | #define INTEL_DEF_PROV L"Intel Hardware Cryptographic Service Provider" |
129 | 129 | ||
130 | static void readtimer(void); | 130 | static void readtimer(void); |
131 | static void readscreen(void); | 131 | static void readscreen(void); |
@@ -152,7 +152,7 @@ typedef struct tagCURSORINFO | |||
152 | #define CURSOR_SHOWING 0x00000001 | 152 | #define CURSOR_SHOWING 0x00000001 |
153 | #endif /* CURSOR_SHOWING */ | 153 | #endif /* CURSOR_SHOWING */ |
154 | 154 | ||
155 | typedef BOOL (WINAPI *CRYPTACQUIRECONTEXT)(HCRYPTPROV *, LPCTSTR, LPCTSTR, | 155 | typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTW)(HCRYPTPROV *, LPCWSTR, LPCWSTR, |
156 | DWORD, DWORD); | 156 | DWORD, DWORD); |
157 | typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV, DWORD, BYTE *); | 157 | typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV, DWORD, BYTE *); |
158 | typedef BOOL (WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV, DWORD); | 158 | typedef BOOL (WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV, DWORD); |
@@ -194,7 +194,7 @@ int RAND_poll(void) | |||
194 | HWND h; | 194 | HWND h; |
195 | 195 | ||
196 | HMODULE advapi, kernel, user, netapi; | 196 | HMODULE advapi, kernel, user, netapi; |
197 | CRYPTACQUIRECONTEXT acquire = 0; | 197 | CRYPTACQUIRECONTEXTW acquire = 0; |
198 | CRYPTGENRANDOM gen = 0; | 198 | CRYPTGENRANDOM gen = 0; |
199 | CRYPTRELEASECONTEXT release = 0; | 199 | CRYPTRELEASECONTEXT release = 0; |
200 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this | 200 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this |
@@ -213,6 +213,9 @@ int RAND_poll(void) | |||
213 | GetVersionEx( &osverinfo ) ; | 213 | GetVersionEx( &osverinfo ) ; |
214 | 214 | ||
215 | #if defined(OPENSSL_SYS_WINCE) && WCEPLATFORM!=MS_HPC_PRO | 215 | #if defined(OPENSSL_SYS_WINCE) && WCEPLATFORM!=MS_HPC_PRO |
216 | #ifndef CryptAcquireContext | ||
217 | #define CryptAcquireContext CryptAcquireContextW | ||
218 | #endif | ||
216 | /* poll the CryptoAPI PRNG */ | 219 | /* poll the CryptoAPI PRNG */ |
217 | /* The CryptoAPI returns sizeof(buf) bytes of randomness */ | 220 | /* The CryptoAPI returns sizeof(buf) bytes of randomness */ |
218 | if (CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) | 221 | if (CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) |
@@ -223,21 +226,35 @@ int RAND_poll(void) | |||
223 | } | 226 | } |
224 | #endif | 227 | #endif |
225 | 228 | ||
229 | #ifndef OPENSSL_SYS_WINCE | ||
230 | /* | ||
231 | * None of below libraries are present on Windows CE, which is | ||
232 | * why we #ifndef the whole section. This also excuses us from | ||
233 | * handling the GetProcAddress issue. The trouble is that in | ||
234 | * real Win32 API GetProcAddress is available in ANSI flavor | ||
235 | * only. In WinCE on the other hand GetProcAddress is a macro | ||
236 | * most commonly defined as GetProcAddressW, which accepts | ||
237 | * Unicode argument. If we were to call GetProcAddress under | ||
238 | * WinCE, I'd recommend to either redefine GetProcAddress as | ||
239 | * GetProcAddressA (there seem to be one in common CE spec) or | ||
240 | * implement own shim routine, which would accept ANSI argument | ||
241 | * and expand it to Unicode. | ||
242 | */ | ||
243 | |||
226 | /* load functions dynamically - not available on all systems */ | 244 | /* load functions dynamically - not available on all systems */ |
227 | advapi = LoadLibrary(TEXT("ADVAPI32.DLL")); | 245 | advapi = LoadLibrary(TEXT("ADVAPI32.DLL")); |
228 | kernel = LoadLibrary(TEXT("KERNEL32.DLL")); | 246 | kernel = LoadLibrary(TEXT("KERNEL32.DLL")); |
229 | user = LoadLibrary(TEXT("USER32.DLL")); | 247 | user = LoadLibrary(TEXT("USER32.DLL")); |
230 | netapi = LoadLibrary(TEXT("NETAPI32.DLL")); | 248 | netapi = LoadLibrary(TEXT("NETAPI32.DLL")); |
231 | 249 | ||
232 | #ifndef OPENSSL_SYS_WINCE | ||
233 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this | 250 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this |
234 | * section is still experimental, but if all goes well, this conditional | 251 | * section is still experimental, but if all goes well, this conditional |
235 | * will be removed | 252 | * will be removed |
236 | */ | 253 | */ |
237 | if (netapi) | 254 | if (netapi) |
238 | { | 255 | { |
239 | netstatget = (NETSTATGET) GetProcAddress(netapi,TEXT("NetStatisticsGet")); | 256 | netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet"); |
240 | netfree = (NETFREE) GetProcAddress(netapi,TEXT("NetApiBufferFree")); | 257 | netfree = (NETFREE) GetProcAddress(netapi,"NetApiBufferFree"); |
241 | } | 258 | } |
242 | 259 | ||
243 | if (netstatget && netfree) | 260 | if (netstatget && netfree) |
@@ -264,9 +281,7 @@ int RAND_poll(void) | |||
264 | if (netapi) | 281 | if (netapi) |
265 | FreeLibrary(netapi); | 282 | FreeLibrary(netapi); |
266 | #endif /* 1 */ | 283 | #endif /* 1 */ |
267 | #endif /* !OPENSSL_SYS_WINCE */ | 284 | |
268 | |||
269 | #ifndef OPENSSL_SYS_WINCE | ||
270 | /* It appears like this can cause an exception deep within ADVAPI32.DLL | 285 | /* It appears like this can cause an exception deep within ADVAPI32.DLL |
271 | * at random times on Windows 2000. Reported by Jeffrey Altman. | 286 | * at random times on Windows 2000. Reported by Jeffrey Altman. |
272 | * Only use it on NT. | 287 | * Only use it on NT. |
@@ -321,16 +336,20 @@ int RAND_poll(void) | |||
321 | free(buf); | 336 | free(buf); |
322 | } | 337 | } |
323 | #endif | 338 | #endif |
324 | #endif /* !OPENSSL_SYS_WINCE */ | ||
325 | 339 | ||
326 | if (advapi) | 340 | if (advapi) |
327 | { | 341 | { |
328 | acquire = (CRYPTACQUIRECONTEXT) GetProcAddress(advapi, | 342 | /* |
329 | TEXT("CryptAcquireContextA")); | 343 | * If it's available, then it's available in both ANSI |
344 | * and UNICODE flavors even in Win9x, documentation says. | ||
345 | * We favor Unicode... | ||
346 | */ | ||
347 | acquire = (CRYPTACQUIRECONTEXTW) GetProcAddress(advapi, | ||
348 | "CryptAcquireContextW"); | ||
330 | gen = (CRYPTGENRANDOM) GetProcAddress(advapi, | 349 | gen = (CRYPTGENRANDOM) GetProcAddress(advapi, |
331 | TEXT("CryptGenRandom")); | 350 | "CryptGenRandom"); |
332 | release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi, | 351 | release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi, |
333 | TEXT("CryptReleaseContext")); | 352 | "CryptReleaseContext"); |
334 | } | 353 | } |
335 | 354 | ||
336 | if (acquire && gen && release) | 355 | if (acquire && gen && release) |
@@ -367,26 +386,15 @@ int RAND_poll(void) | |||
367 | if (advapi) | 386 | if (advapi) |
368 | FreeLibrary(advapi); | 387 | FreeLibrary(advapi); |
369 | 388 | ||
370 | /* timer data */ | ||
371 | readtimer(); | ||
372 | |||
373 | /* memory usage statistics */ | ||
374 | GlobalMemoryStatus(&m); | ||
375 | RAND_add(&m, sizeof(m), 1); | ||
376 | |||
377 | /* process ID */ | ||
378 | w = GetCurrentProcessId(); | ||
379 | RAND_add(&w, sizeof(w), 1); | ||
380 | |||
381 | if (user) | 389 | if (user) |
382 | { | 390 | { |
383 | GETCURSORINFO cursor; | 391 | GETCURSORINFO cursor; |
384 | GETFOREGROUNDWINDOW win; | 392 | GETFOREGROUNDWINDOW win; |
385 | GETQUEUESTATUS queue; | 393 | GETQUEUESTATUS queue; |
386 | 394 | ||
387 | win = (GETFOREGROUNDWINDOW) GetProcAddress(user, TEXT("GetForegroundWindow")); | 395 | win = (GETFOREGROUNDWINDOW) GetProcAddress(user, "GetForegroundWindow"); |
388 | cursor = (GETCURSORINFO) GetProcAddress(user, TEXT("GetCursorInfo")); | 396 | cursor = (GETCURSORINFO) GetProcAddress(user, "GetCursorInfo"); |
389 | queue = (GETQUEUESTATUS) GetProcAddress(user, TEXT("GetQueueStatus")); | 397 | queue = (GETQUEUESTATUS) GetProcAddress(user, "GetQueueStatus"); |
390 | 398 | ||
391 | if (win) | 399 | if (win) |
392 | { | 400 | { |
@@ -458,19 +466,19 @@ int RAND_poll(void) | |||
458 | MODULEENTRY32 m; | 466 | MODULEENTRY32 m; |
459 | 467 | ||
460 | snap = (CREATETOOLHELP32SNAPSHOT) | 468 | snap = (CREATETOOLHELP32SNAPSHOT) |
461 | GetProcAddress(kernel, TEXT("CreateToolhelp32Snapshot")); | 469 | GetProcAddress(kernel, "CreateToolhelp32Snapshot"); |
462 | close_snap = (CLOSETOOLHELP32SNAPSHOT) | 470 | close_snap = (CLOSETOOLHELP32SNAPSHOT) |
463 | GetProcAddress(kernel, TEXT("CloseToolhelp32Snapshot")); | 471 | GetProcAddress(kernel, "CloseToolhelp32Snapshot"); |
464 | heap_first = (HEAP32FIRST) GetProcAddress(kernel, TEXT("Heap32First")); | 472 | heap_first = (HEAP32FIRST) GetProcAddress(kernel, "Heap32First"); |
465 | heap_next = (HEAP32NEXT) GetProcAddress(kernel, TEXT("Heap32Next")); | 473 | heap_next = (HEAP32NEXT) GetProcAddress(kernel, "Heap32Next"); |
466 | heaplist_first = (HEAP32LIST) GetProcAddress(kernel, TEXT("Heap32ListFirst")); | 474 | heaplist_first = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListFirst"); |
467 | heaplist_next = (HEAP32LIST) GetProcAddress(kernel, TEXT("Heap32ListNext")); | 475 | heaplist_next = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListNext"); |
468 | process_first = (PROCESS32) GetProcAddress(kernel, TEXT("Process32First")); | 476 | process_first = (PROCESS32) GetProcAddress(kernel, "Process32First"); |
469 | process_next = (PROCESS32) GetProcAddress(kernel, TEXT("Process32Next")); | 477 | process_next = (PROCESS32) GetProcAddress(kernel, "Process32Next"); |
470 | thread_first = (THREAD32) GetProcAddress(kernel, TEXT("Thread32First")); | 478 | thread_first = (THREAD32) GetProcAddress(kernel, "Thread32First"); |
471 | thread_next = (THREAD32) GetProcAddress(kernel, TEXT("Thread32Next")); | 479 | thread_next = (THREAD32) GetProcAddress(kernel, "Thread32Next"); |
472 | module_first = (MODULE32) GetProcAddress(kernel, TEXT("Module32First")); | 480 | module_first = (MODULE32) GetProcAddress(kernel, "Module32First"); |
473 | module_next = (MODULE32) GetProcAddress(kernel, TEXT("Module32Next")); | 481 | module_next = (MODULE32) GetProcAddress(kernel, "Module32Next"); |
474 | 482 | ||
475 | if (snap && heap_first && heap_next && heaplist_first && | 483 | if (snap && heap_first && heap_next && heaplist_first && |
476 | heaplist_next && process_first && process_next && | 484 | heaplist_next && process_first && process_next && |
@@ -546,6 +554,18 @@ int RAND_poll(void) | |||
546 | 554 | ||
547 | FreeLibrary(kernel); | 555 | FreeLibrary(kernel); |
548 | } | 556 | } |
557 | #endif /* !OPENSSL_SYS_WINCE */ | ||
558 | |||
559 | /* timer data */ | ||
560 | readtimer(); | ||
561 | |||
562 | /* memory usage statistics */ | ||
563 | GlobalMemoryStatus(&m); | ||
564 | RAND_add(&m, sizeof(m), 1); | ||
565 | |||
566 | /* process ID */ | ||
567 | w = GetCurrentProcessId(); | ||
568 | RAND_add(&w, sizeof(w), 1); | ||
549 | 569 | ||
550 | #if 0 | 570 | #if 0 |
551 | printf("Exiting RAND_poll\n"); | 571 | printf("Exiting RAND_poll\n"); |
@@ -607,7 +627,7 @@ static void readtimer(void) | |||
607 | DWORD w; | 627 | DWORD w; |
608 | LARGE_INTEGER l; | 628 | LARGE_INTEGER l; |
609 | static int have_perfc = 1; | 629 | static int have_perfc = 1; |
610 | #if defined(_MSC_VER) && !defined(OPENSSL_SYS_WINCE) | 630 | #if defined(_MSC_VER) && defined(_M_X86) |
611 | static int have_tsc = 1; | 631 | static int have_tsc = 1; |
612 | DWORD cyclecount; | 632 | DWORD cyclecount; |
613 | 633 | ||
@@ -660,7 +680,7 @@ static void readtimer(void) | |||
660 | 680 | ||
661 | static void readscreen(void) | 681 | static void readscreen(void) |
662 | { | 682 | { |
663 | #ifndef OPENSSL_SYS_WINCE | 683 | #if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) |
664 | HDC hScrDC; /* screen DC */ | 684 | HDC hScrDC; /* screen DC */ |
665 | HDC hMemDC; /* memory DC */ | 685 | HDC hMemDC; /* memory DC */ |
666 | HBITMAP hBitmap; /* handle for our bitmap */ | 686 | HBITMAP hBitmap; /* handle for our bitmap */ |