diff options
Diffstat (limited to 'src/lib/libcrypto/rand')
| -rw-r--r-- | src/lib/libcrypto/rand/Makefile.ssl | 196 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/md_rand.c | 17 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/rand.h | 143 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/rand_egd.c | 2 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/rand_err.c | 105 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/rand_lib.c | 192 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/rand_nw.c | 183 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/rand_unix.c | 119 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/rand_win.c | 99 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/randfile.c | 285 | ||||
| -rw-r--r-- | src/lib/libcrypto/rand/randtest.c | 5 |
11 files changed, 1198 insertions, 148 deletions
diff --git a/src/lib/libcrypto/rand/Makefile.ssl b/src/lib/libcrypto/rand/Makefile.ssl new file mode 100644 index 0000000000..e5cbe5319c --- /dev/null +++ b/src/lib/libcrypto/rand/Makefile.ssl | |||
| @@ -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 | MAKE= make -f Makefile.ssl | ||
| 14 | MAKEDEPPROG= makedepend | ||
| 15 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
| 16 | MAKEFILE= Makefile.ssl | ||
| 17 | AR= ar r | ||
| 18 | |||
| 19 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 20 | |||
| 21 | GENERAL=Makefile | ||
| 22 | TEST= randtest.c | ||
| 23 | APPS= | ||
| 24 | |||
| 25 | LIB=$(TOP)/libcrypto.a | ||
| 26 | LIBSRC=md_rand.c randfile.c rand_lib.c rand_err.c rand_egd.c \ | ||
| 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 | ||
| 30 | |||
| 31 | SRC= $(LIBSRC) | ||
| 32 | |||
| 33 | EXHEADER= rand.h | ||
| 34 | HEADER= $(EXHEADER) | ||
| 35 | |||
| 36 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 37 | |||
| 38 | top: | ||
| 39 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 40 | |||
| 41 | all: lib | ||
| 42 | |||
| 43 | lib: $(LIBOBJ) | ||
| 44 | $(AR) $(LIB) $(LIBOBJ) | ||
| 45 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 46 | @touch lib | ||
| 47 | |||
| 48 | files: | ||
| 49 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
| 50 | |||
| 51 | links: | ||
| 52 | @sh $(TOP)/util/point.sh Makefile.ssl Makefile | ||
| 53 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 54 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 55 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 56 | |||
| 57 | install: | ||
| 58 | @for i in $(EXHEADER) ; \ | ||
| 59 | do \ | ||
| 60 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 61 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 62 | done; | ||
| 63 | |||
| 64 | tags: | ||
| 65 | ctags $(SRC) | ||
| 66 | |||
| 67 | tests: | ||
| 68 | |||
| 69 | lint: | ||
| 70 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 71 | |||
| 72 | depend: | ||
| 73 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 74 | |||
| 75 | dclean: | ||
| 76 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 77 | mv -f Makefile.new $(MAKEFILE) | ||
| 78 | |||
| 79 | clean: | ||
| 80 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 81 | |||
| 82 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 83 | |||
| 84 | md_rand.o: ../../e_os.h ../../include/openssl/aes.h | ||
| 85 | md_rand.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
| 86 | md_rand.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h | ||
| 87 | md_rand.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h | ||
| 88 | md_rand.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
| 89 | md_rand.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 90 | md_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 91 | md_rand.o: ../../include/openssl/evp.h ../../include/openssl/idea.h | ||
| 92 | md_rand.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h | ||
| 93 | md_rand.o: ../../include/openssl/md4.h ../../include/openssl/md5.h | ||
| 94 | md_rand.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h | ||
| 95 | md_rand.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
| 96 | md_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 97 | md_rand.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h | ||
| 98 | md_rand.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h | ||
| 99 | md_rand.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h | ||
| 100 | md_rand.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 101 | md_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 102 | md_rand.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 103 | md_rand.o: md_rand.c rand_lcl.h | ||
| 104 | rand_egd.o: ../../include/openssl/buffer.h ../../include/openssl/e_os2.h | ||
| 105 | rand_egd.o: ../../include/openssl/opensslconf.h | ||
| 106 | rand_egd.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
| 107 | rand_egd.o: rand_egd.c | ||
| 108 | rand_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 109 | rand_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 110 | rand_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 111 | rand_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 112 | rand_err.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
| 113 | rand_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 114 | rand_err.o: rand_err.c | ||
| 115 | rand_lib.o: ../../e_os.h ../../include/openssl/asn1.h | ||
| 116 | rand_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
| 117 | rand_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 118 | rand_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h | ||
| 119 | rand_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h | ||
| 120 | rand_lib.o: ../../include/openssl/err.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: ../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 9783d0c23e..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 |
| @@ -152,7 +153,7 @@ static unsigned long locking_thread = 0; /* valid iff crypto_lock_rand is set */ | |||
| 152 | int rand_predictable=0; | 153 | int rand_predictable=0; |
| 153 | #endif | 154 | #endif |
| 154 | 155 | ||
| 155 | const char RAND_version[]="RAND" OPENSSL_VERSION_PTEXT; | 156 | const char *RAND_version="RAND" OPENSSL_VERSION_PTEXT; |
| 156 | 157 | ||
| 157 | static void ssleay_rand_cleanup(void); | 158 | static void ssleay_rand_cleanup(void); |
| 158 | static void ssleay_rand_seed(const void *buf, int num); | 159 | static void ssleay_rand_seed(const void *buf, int num); |
| @@ -300,7 +301,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) | |||
| 300 | * other thread's seeding remains without effect (except for | 301 | * other thread's seeding remains without effect (except for |
| 301 | * the incremented counter). By XORing it we keep at least as | 302 | * the incremented counter). By XORing it we keep at least as |
| 302 | * much entropy as fits into md. */ | 303 | * much entropy as fits into md. */ |
| 303 | for (k = 0; k < (int)sizeof(md); k++) | 304 | for (k = 0; k < sizeof md; k++) |
| 304 | { | 305 | { |
| 305 | md[k] ^= local_md[k]; | 306 | md[k] ^= local_md[k]; |
| 306 | } | 307 | } |
| @@ -315,7 +316,7 @@ static void ssleay_rand_add(const void *buf, int num, double add) | |||
| 315 | 316 | ||
| 316 | static void ssleay_rand_seed(const void *buf, int num) | 317 | static void ssleay_rand_seed(const void *buf, int num) |
| 317 | { | 318 | { |
| 318 | ssleay_rand_add(buf, num, (double)num); | 319 | ssleay_rand_add(buf, num, num); |
| 319 | } | 320 | } |
| 320 | 321 | ||
| 321 | static int ssleay_rand_bytes(unsigned char *buf, int num) | 322 | static int ssleay_rand_bytes(unsigned char *buf, int num) |
| @@ -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 | { |
| @@ -520,7 +529,7 @@ static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num) | |||
| 520 | err = ERR_peek_error(); | 529 | err = ERR_peek_error(); |
| 521 | if (ERR_GET_LIB(err) == ERR_LIB_RAND && | 530 | if (ERR_GET_LIB(err) == ERR_LIB_RAND && |
| 522 | ERR_GET_REASON(err) == RAND_R_PRNG_NOT_SEEDED) | 531 | ERR_GET_REASON(err) == RAND_R_PRNG_NOT_SEEDED) |
| 523 | ERR_clear_error(); | 532 | (void)ERR_get_error(); |
| 524 | } | 533 | } |
| 525 | return (ret); | 534 | return (ret); |
| 526 | } | 535 | } |
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h new file mode 100644 index 0000000000..604df9be6c --- /dev/null +++ b/src/lib/libcrypto/rand/rand.h | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | /* crypto/rand/rand.h */ | ||
| 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 | #ifndef HEADER_RAND_H | ||
| 60 | #define HEADER_RAND_H | ||
| 61 | |||
| 62 | #include <stdlib.h> | ||
| 63 | #include <openssl/ossl_typ.h> | ||
| 64 | #include <openssl/e_os2.h> | ||
| 65 | |||
| 66 | #if defined(OPENSSL_SYS_WINDOWS) | ||
| 67 | #include <windows.h> | ||
| 68 | #endif | ||
| 69 | |||
| 70 | #ifdef __cplusplus | ||
| 71 | extern "C" { | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #if defined(OPENSSL_FIPS) | ||
| 75 | #define FIPS_RAND_SIZE_T int | ||
| 76 | #endif | ||
| 77 | |||
| 78 | typedef struct rand_meth_st | ||
| 79 | { | ||
| 80 | void (*seed)(const void *buf, int num); | ||
| 81 | int (*bytes)(unsigned char *buf, int num); | ||
| 82 | void (*cleanup)(void); | ||
| 83 | void (*add)(const void *buf, int num, double entropy); | ||
| 84 | int (*pseudorand)(unsigned char *buf, int num); | ||
| 85 | int (*status)(void); | ||
| 86 | } RAND_METHOD; | ||
| 87 | |||
| 88 | #ifdef BN_DEBUG | ||
| 89 | extern int rand_predictable; | ||
| 90 | #endif | ||
| 91 | |||
| 92 | int RAND_set_rand_method(const RAND_METHOD *meth); | ||
| 93 | const RAND_METHOD *RAND_get_rand_method(void); | ||
| 94 | #ifndef OPENSSL_NO_ENGINE | ||
| 95 | int RAND_set_rand_engine(ENGINE *engine); | ||
| 96 | #endif | ||
| 97 | RAND_METHOD *RAND_SSLeay(void); | ||
| 98 | void RAND_cleanup(void ); | ||
| 99 | int RAND_bytes(unsigned char *buf,int num); | ||
| 100 | int RAND_pseudo_bytes(unsigned char *buf,int num); | ||
| 101 | void RAND_seed(const void *buf,int num); | ||
| 102 | void RAND_add(const void *buf,int num,double entropy); | ||
| 103 | int RAND_load_file(const char *file,long max_bytes); | ||
| 104 | int RAND_write_file(const char *file); | ||
| 105 | const char *RAND_file_name(char *file,size_t num); | ||
| 106 | int RAND_status(void); | ||
| 107 | int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes); | ||
| 108 | int RAND_egd(const char *path); | ||
| 109 | int RAND_egd_bytes(const char *path,int bytes); | ||
| 110 | int RAND_poll(void); | ||
| 111 | |||
| 112 | #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) | ||
| 113 | |||
| 114 | void RAND_screen(void); | ||
| 115 | int RAND_event(UINT, WPARAM, LPARAM); | ||
| 116 | |||
| 117 | #endif | ||
| 118 | |||
| 119 | /* BEGIN ERROR CODES */ | ||
| 120 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 121 | * made after this point may be overwritten when the script is next run. | ||
| 122 | */ | ||
| 123 | void ERR_load_RAND_strings(void); | ||
| 124 | |||
| 125 | /* Error codes for the RAND functions. */ | ||
| 126 | |||
| 127 | /* Function codes. */ | ||
| 128 | #define RAND_F_FIPS_RAND_BYTES 102 | ||
| 129 | #define RAND_F_RAND_GET_RAND_METHOD 101 | ||
| 130 | #define RAND_F_SSLEAY_RAND_BYTES 100 | ||
| 131 | |||
| 132 | /* Reason codes. */ | ||
| 133 | #define RAND_R_NON_FIPS_METHOD 101 | ||
| 134 | #define RAND_R_PRNG_ASKING_FOR_TOO_MUCH 105 | ||
| 135 | #define RAND_R_PRNG_NOT_REKEYED 103 | ||
| 136 | #define RAND_R_PRNG_NOT_RESEEDED 104 | ||
| 137 | #define RAND_R_PRNG_NOT_SEEDED 100 | ||
| 138 | #define RAND_R_PRNG_STUCK 102 | ||
| 139 | |||
| 140 | #ifdef __cplusplus | ||
| 141 | } | ||
| 142 | #endif | ||
| 143 | #endif | ||
diff --git a/src/lib/libcrypto/rand/rand_egd.c b/src/lib/libcrypto/rand/rand_egd.c index 50bce6caba..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) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_VOS) | 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); |
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c new file mode 100644 index 0000000000..97f96e1aee --- /dev/null +++ b/src/lib/libcrypto/rand/rand_err.c | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | /* crypto/rand/rand_err.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1999-2005 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 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
| 57 | * made to it will be overwritten when the script next updates this file, | ||
| 58 | * only reason strings will be preserved. | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include <openssl/err.h> | ||
| 63 | #include <openssl/rand.h> | ||
| 64 | |||
| 65 | /* BEGIN ERROR CODES */ | ||
| 66 | #ifndef OPENSSL_NO_ERR | ||
| 67 | |||
| 68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_RAND,func,0) | ||
| 69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_RAND,0,reason) | ||
| 70 | |||
| 71 | static ERR_STRING_DATA RAND_str_functs[]= | ||
| 72 | { | ||
| 73 | {ERR_FUNC(RAND_F_FIPS_RAND_BYTES), "FIPS_RAND_BYTES"}, | ||
| 74 | {ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, | ||
| 75 | {ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, | ||
| 76 | {0,NULL} | ||
| 77 | }; | ||
| 78 | |||
| 79 | static ERR_STRING_DATA RAND_str_reasons[]= | ||
| 80 | { | ||
| 81 | {ERR_REASON(RAND_R_NON_FIPS_METHOD) ,"non fips method"}, | ||
| 82 | {ERR_REASON(RAND_R_PRNG_ASKING_FOR_TOO_MUCH),"prng asking for too much"}, | ||
| 83 | {ERR_REASON(RAND_R_PRNG_NOT_REKEYED) ,"prng not rekeyed"}, | ||
| 84 | {ERR_REASON(RAND_R_PRNG_NOT_RESEEDED) ,"prng not reseeded"}, | ||
| 85 | {ERR_REASON(RAND_R_PRNG_NOT_SEEDED) ,"PRNG not seeded"}, | ||
| 86 | {ERR_REASON(RAND_R_PRNG_STUCK) ,"prng stuck"}, | ||
| 87 | {0,NULL} | ||
| 88 | }; | ||
| 89 | |||
| 90 | #endif | ||
| 91 | |||
| 92 | void ERR_load_RAND_strings(void) | ||
| 93 | { | ||
| 94 | static int init=1; | ||
| 95 | |||
| 96 | if (init) | ||
| 97 | { | ||
| 98 | init=0; | ||
| 99 | #ifndef OPENSSL_NO_ERR | ||
| 100 | ERR_load_strings(0,RAND_str_functs); | ||
| 101 | ERR_load_strings(0,RAND_str_reasons); | ||
| 102 | #endif | ||
| 103 | |||
| 104 | } | ||
| 105 | } | ||
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c new file mode 100644 index 0000000000..a21bde79de --- /dev/null +++ b/src/lib/libcrypto/rand/rand_lib.c | |||
| @@ -0,0 +1,192 @@ | |||
| 1 | /* crypto/rand/rand_lib.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 | #include <stdio.h> | ||
| 60 | #include <time.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include <openssl/rand.h> | ||
| 63 | #ifndef OPENSSL_NO_ENGINE | ||
| 64 | #include <openssl/engine.h> | ||
| 65 | #endif | ||
| 66 | #include <openssl/fips.h> | ||
| 67 | #include <openssl/fips_rand.h> | ||
| 68 | |||
| 69 | #ifndef OPENSSL_NO_ENGINE | ||
| 70 | /* non-NULL if default_RAND_meth is ENGINE-provided */ | ||
| 71 | static ENGINE *funct_ref =NULL; | ||
| 72 | #endif | ||
| 73 | static const RAND_METHOD *default_RAND_meth = NULL; | ||
| 74 | |||
| 75 | int RAND_set_rand_method(const RAND_METHOD *meth) | ||
| 76 | { | ||
| 77 | #ifndef OPENSSL_NO_ENGINE | ||
| 78 | if(funct_ref) | ||
| 79 | { | ||
| 80 | ENGINE_finish(funct_ref); | ||
| 81 | funct_ref = NULL; | ||
| 82 | } | ||
| 83 | #endif | ||
| 84 | default_RAND_meth = meth; | ||
| 85 | return 1; | ||
| 86 | } | ||
| 87 | |||
| 88 | const RAND_METHOD *RAND_get_rand_method(void) | ||
| 89 | { | ||
| 90 | if (!default_RAND_meth) | ||
| 91 | { | ||
| 92 | #ifndef OPENSSL_NO_ENGINE | ||
| 93 | ENGINE *e = ENGINE_get_default_RAND(); | ||
| 94 | if(e) | ||
| 95 | { | ||
| 96 | default_RAND_meth = ENGINE_get_RAND(e); | ||
| 97 | if(!default_RAND_meth) | ||
| 98 | { | ||
| 99 | ENGINE_finish(e); | ||
| 100 | e = NULL; | ||
| 101 | } | ||
| 102 | } | ||
| 103 | if(e) | ||
| 104 | funct_ref = e; | ||
| 105 | else | ||
| 106 | #endif | ||
| 107 | #ifdef OPENSSL_FIPS | ||
| 108 | if(FIPS_mode()) | ||
| 109 | default_RAND_meth=FIPS_rand_method(); | ||
| 110 | else | ||
| 111 | #endif | ||
| 112 | default_RAND_meth = RAND_SSLeay(); | ||
| 113 | } | ||
| 114 | |||
| 115 | #ifdef OPENSSL_FIPS | ||
| 116 | if(FIPS_mode() | ||
| 117 | && default_RAND_meth != FIPS_rand_check()) | ||
| 118 | { | ||
| 119 | RANDerr(RAND_F_RAND_GET_RAND_METHOD,RAND_R_NON_FIPS_METHOD); | ||
| 120 | return 0; | ||
| 121 | } | ||
| 122 | #endif | ||
| 123 | return default_RAND_meth; | ||
| 124 | } | ||
| 125 | |||
| 126 | #ifndef OPENSSL_NO_ENGINE | ||
| 127 | int RAND_set_rand_engine(ENGINE *engine) | ||
| 128 | { | ||
| 129 | const RAND_METHOD *tmp_meth = NULL; | ||
| 130 | if(engine) | ||
| 131 | { | ||
| 132 | if(!ENGINE_init(engine)) | ||
| 133 | return 0; | ||
| 134 | tmp_meth = ENGINE_get_RAND(engine); | ||
| 135 | if(!tmp_meth) | ||
| 136 | { | ||
| 137 | ENGINE_finish(engine); | ||
| 138 | return 0; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | /* This function releases any prior ENGINE so call it first */ | ||
| 142 | RAND_set_rand_method(tmp_meth); | ||
| 143 | funct_ref = engine; | ||
| 144 | return 1; | ||
| 145 | } | ||
| 146 | #endif | ||
| 147 | |||
| 148 | void RAND_cleanup(void) | ||
| 149 | { | ||
| 150 | const RAND_METHOD *meth = RAND_get_rand_method(); | ||
| 151 | if (meth && meth->cleanup) | ||
| 152 | meth->cleanup(); | ||
| 153 | RAND_set_rand_method(NULL); | ||
| 154 | } | ||
| 155 | |||
| 156 | void RAND_seed(const void *buf, int num) | ||
| 157 | { | ||
| 158 | const RAND_METHOD *meth = RAND_get_rand_method(); | ||
| 159 | if (meth && meth->seed) | ||
| 160 | meth->seed(buf,num); | ||
| 161 | } | ||
| 162 | |||
| 163 | void RAND_add(const void *buf, int num, double entropy) | ||
| 164 | { | ||
| 165 | const RAND_METHOD *meth = RAND_get_rand_method(); | ||
| 166 | if (meth && meth->add) | ||
| 167 | meth->add(buf,num,entropy); | ||
| 168 | } | ||
| 169 | |||
| 170 | int RAND_bytes(unsigned char *buf, int num) | ||
| 171 | { | ||
| 172 | const RAND_METHOD *meth = RAND_get_rand_method(); | ||
| 173 | if (meth && meth->bytes) | ||
| 174 | return meth->bytes(buf,num); | ||
| 175 | return(-1); | ||
| 176 | } | ||
| 177 | |||
| 178 | int RAND_pseudo_bytes(unsigned char *buf, int num) | ||
| 179 | { | ||
| 180 | const RAND_METHOD *meth = RAND_get_rand_method(); | ||
| 181 | if (meth && meth->pseudorand) | ||
| 182 | return meth->pseudorand(buf,num); | ||
| 183 | return(-1); | ||
| 184 | } | ||
| 185 | |||
| 186 | int RAND_status(void) | ||
| 187 | { | ||
| 188 | const RAND_METHOD *meth = RAND_get_rand_method(); | ||
| 189 | if (meth && meth->status) | ||
| 190 | return meth->status(); | ||
| 191 | return 0; | ||
| 192 | } | ||
diff --git a/src/lib/libcrypto/rand/rand_nw.c b/src/lib/libcrypto/rand/rand_nw.c new file mode 100644 index 0000000000..f177ffbe82 --- /dev/null +++ b/src/lib/libcrypto/rand/rand_nw.c | |||
| @@ -0,0 +1,183 @@ | |||
| 1 | /* crypto/rand/rand_nw.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_NETWARE) | ||
| 117 | |||
| 118 | #if defined(NETWARE_LIBC) | ||
| 119 | #include <nks/thread.h> | ||
| 120 | #else | ||
| 121 | #include <nwthread.h> | ||
| 122 | #endif | ||
| 123 | |||
| 124 | extern int GetProcessSwitchCount(void); | ||
| 125 | #if !defined(NETWARE_LIBC) || (CURRENT_NDK_THRESHOLD < 509220000) | ||
| 126 | extern void *RunningProcess; /* declare here same as found in newer NDKs */ | ||
| 127 | extern unsigned long GetSuperHighResolutionTimer(void); | ||
| 128 | #endif | ||
| 129 | |||
| 130 | /* the FAQ indicates we need to provide at least 20 bytes (160 bits) of seed | ||
| 131 | */ | ||
| 132 | int RAND_poll(void) | ||
| 133 | { | ||
| 134 | unsigned long l; | ||
| 135 | unsigned long tsc; | ||
| 136 | int i; | ||
| 137 | |||
| 138 | /* There are several options to gather miscellaneous data | ||
| 139 | * but for now we will loop checking the time stamp counter (rdtsc) and | ||
| 140 | * the SuperHighResolutionTimer. Each iteration will collect 8 bytes | ||
| 141 | * of data but it is treated as only 1 byte of entropy. The call to | ||
| 142 | * ThreadSwitchWithDelay() will introduce additional variability into | ||
| 143 | * the data returned by rdtsc. | ||
| 144 | * | ||
| 145 | * Applications can agument the seed material by adding additional | ||
| 146 | * stuff with RAND_add() and should probably do so. | ||
| 147 | */ | ||
| 148 | l = GetProcessSwitchCount(); | ||
| 149 | RAND_add(&l,sizeof(l),1); | ||
| 150 | |||
| 151 | /* need to cast the void* to unsigned long here */ | ||
| 152 | l = (unsigned long)RunningProcess; | ||
| 153 | RAND_add(&l,sizeof(l),1); | ||
| 154 | |||
| 155 | for( i=2; i<ENTROPY_NEEDED; i++) | ||
| 156 | { | ||
| 157 | #ifdef __MWERKS__ | ||
| 158 | asm | ||
| 159 | { | ||
| 160 | rdtsc | ||
| 161 | mov tsc, eax | ||
| 162 | } | ||
| 163 | #else | ||
| 164 | asm volatile("rdtsc":"=A" (tsc)); | ||
| 165 | #endif | ||
| 166 | |||
| 167 | RAND_add(&tsc, sizeof(tsc), 1); | ||
| 168 | |||
| 169 | l = GetSuperHighResolutionTimer(); | ||
| 170 | RAND_add(&l, sizeof(l), 0); | ||
| 171 | |||
| 172 | # if defined(NETWARE_LIBC) | ||
| 173 | NXThreadYield(); | ||
| 174 | # else /* NETWARE_CLIB */ | ||
| 175 | ThreadSwitchWithDelay(); | ||
| 176 | # endif | ||
| 177 | } | ||
| 178 | |||
| 179 | return 1; | ||
| 180 | } | ||
| 181 | |||
| 182 | #endif | ||
| 183 | |||
diff --git a/src/lib/libcrypto/rand/rand_unix.c b/src/lib/libcrypto/rand/rand_unix.c index 6c2be5cb96..9376554fae 100644 --- a/src/lib/libcrypto/rand/rand_unix.c +++ b/src/lib/libcrypto/rand/rand_unix.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-2006 The OpenSSL Project. All rights reserved. | 59 | * Copyright (c) 1998-2000 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 |
| @@ -108,7 +108,6 @@ | |||
| 108 | * Hudson (tjh@cryptsoft.com). | 108 | * Hudson (tjh@cryptsoft.com). |
| 109 | * | 109 | * |
| 110 | */ | 110 | */ |
| 111 | #include <stdio.h> | ||
| 112 | 111 | ||
| 113 | #define USE_SOCKETS | 112 | #define USE_SOCKETS |
| 114 | #include "e_os.h" | 113 | #include "e_os.h" |
| @@ -116,7 +115,7 @@ | |||
| 116 | #include <openssl/rand.h> | 115 | #include <openssl/rand.h> |
| 117 | #include "rand_lcl.h" | 116 | #include "rand_lcl.h" |
| 118 | 117 | ||
| 119 | #if !(defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE)) | 118 | #if !(defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_VXWORKS)) |
| 120 | 119 | ||
| 121 | #include <sys/types.h> | 120 | #include <sys/types.h> |
| 122 | #include <sys/time.h> | 121 | #include <sys/time.h> |
| @@ -125,13 +124,6 @@ | |||
| 125 | #include <fcntl.h> | 124 | #include <fcntl.h> |
| 126 | #include <unistd.h> | 125 | #include <unistd.h> |
| 127 | #include <time.h> | 126 | #include <time.h> |
| 128 | #if defined(OPENSSL_SYS_LINUX) /* should actually be available virtually everywhere */ | ||
| 129 | # include <poll.h> | ||
| 130 | #endif | ||
| 131 | #include <limits.h> | ||
| 132 | #ifndef FD_SETSIZE | ||
| 133 | # define FD_SETSIZE (8*sizeof(fd_set)) | ||
| 134 | #endif | ||
| 135 | 127 | ||
| 136 | #ifdef __OpenBSD__ | 128 | #ifdef __OpenBSD__ |
| 137 | int RAND_poll(void) | 129 | int RAND_poll(void) |
| @@ -150,7 +142,7 @@ int RAND_poll(void) | |||
| 150 | 142 | ||
| 151 | return 1; | 143 | return 1; |
| 152 | } | 144 | } |
| 153 | #else /* !defined(__OpenBSD__) */ | 145 | #else |
| 154 | int RAND_poll(void) | 146 | int RAND_poll(void) |
| 155 | { | 147 | { |
| 156 | unsigned long l; | 148 | unsigned long l; |
| @@ -162,8 +154,7 @@ int RAND_poll(void) | |||
| 162 | #ifdef DEVRANDOM | 154 | #ifdef DEVRANDOM |
| 163 | static const char *randomfiles[] = { DEVRANDOM }; | 155 | static const char *randomfiles[] = { DEVRANDOM }; |
| 164 | struct stat randomstats[sizeof(randomfiles)/sizeof(randomfiles[0])]; | 156 | struct stat randomstats[sizeof(randomfiles)/sizeof(randomfiles[0])]; |
| 165 | int fd; | 157 | int fd,i; |
| 166 | size_t i; | ||
| 167 | #endif | 158 | #endif |
| 168 | #ifdef DEVRANDOM_EGD | 159 | #ifdef DEVRANDOM_EGD |
| 169 | static const char *egdsockets[] = { DEVRANDOM_EGD, NULL }; | 160 | static const char *egdsockets[] = { DEVRANDOM_EGD, NULL }; |
| @@ -191,9 +182,10 @@ int RAND_poll(void) | |||
| 191 | #endif | 182 | #endif |
| 192 | )) >= 0) | 183 | )) >= 0) |
| 193 | { | 184 | { |
| 194 | int usec = 10*1000; /* spend 10ms on each file */ | 185 | struct timeval t = { 0, 10*1000 }; /* Spend 10ms on |
| 195 | int r; | 186 | each file. */ |
| 196 | size_t j; | 187 | int r,j; |
| 188 | fd_set fset; | ||
| 197 | struct stat *st=&randomstats[i]; | 189 | struct stat *st=&randomstats[i]; |
| 198 | 190 | ||
| 199 | /* Avoid using same input... Used to be O_NOFOLLOW | 191 | /* Avoid using same input... Used to be O_NOFOLLOW |
| @@ -209,75 +201,35 @@ int RAND_poll(void) | |||
| 209 | 201 | ||
| 210 | do | 202 | do |
| 211 | { | 203 | { |
| 212 | int try_read = 0; | 204 | FD_ZERO(&fset); |
| 205 | FD_SET(fd, &fset); | ||
| 206 | r = -1; | ||
| 213 | 207 | ||
| 214 | #if defined(OPENSSL_SYS_LINUX) | 208 | if (select(fd+1,&fset,NULL,NULL,&t) < 0) |
| 215 | /* use poll() */ | 209 | t.tv_usec=0; |
| 216 | struct pollfd pset; | 210 | else if (FD_ISSET(fd, &fset)) |
| 217 | |||
| 218 | pset.fd = fd; | ||
| 219 | pset.events = POLLIN; | ||
| 220 | pset.revents = 0; | ||
| 221 | |||
| 222 | if (poll(&pset, 1, usec / 1000) < 0) | ||
| 223 | usec = 0; | ||
| 224 | else | ||
| 225 | try_read = (pset.revents & POLLIN) != 0; | ||
| 226 | |||
| 227 | #else | ||
| 228 | /* use select() */ | ||
| 229 | fd_set fset; | ||
| 230 | struct timeval t; | ||
| 231 | |||
| 232 | t.tv_sec = 0; | ||
| 233 | t.tv_usec = usec; | ||
| 234 | |||
| 235 | if (FD_SETSIZE > 0 && fd >= FD_SETSIZE) | ||
| 236 | { | ||
| 237 | /* can't use select, so just try to read once anyway */ | ||
| 238 | try_read = 1; | ||
| 239 | } | ||
| 240 | else | ||
| 241 | { | ||
| 242 | FD_ZERO(&fset); | ||
| 243 | FD_SET(fd, &fset); | ||
| 244 | |||
| 245 | if (select(fd+1,&fset,NULL,NULL,&t) >= 0) | ||
| 246 | { | ||
| 247 | usec = t.tv_usec; | ||
| 248 | if (FD_ISSET(fd, &fset)) | ||
| 249 | try_read = 1; | ||
| 250 | } | ||
| 251 | else | ||
| 252 | usec = 0; | ||
| 253 | } | ||
| 254 | #endif | ||
| 255 | |||
| 256 | if (try_read) | ||
| 257 | { | 211 | { |
| 258 | r = read(fd,(unsigned char *)tmpbuf+n, ENTROPY_NEEDED-n); | 212 | r=read(fd,(unsigned char *)tmpbuf+n, |
| 213 | ENTROPY_NEEDED-n); | ||
| 259 | if (r > 0) | 214 | if (r > 0) |
| 260 | n += r; | 215 | n += r; |
| 261 | } | 216 | } |
| 262 | else | 217 | |
| 263 | r = -1; | 218 | /* Some Unixen will update t, some |
| 264 | 219 | won't. For those who won't, give | |
| 265 | /* Some Unixen will update t in select(), some | 220 | up here, otherwise, we will do |
| 266 | won't. For those who won't, or if we | ||
| 267 | didn't use select() in the first place, | ||
| 268 | give up here, otherwise, we will do | ||
| 269 | this once again for the remaining | 221 | this once again for the remaining |
| 270 | time. */ | 222 | time. */ |
| 271 | if (usec == 10*1000) | 223 | if (t.tv_usec == 10*1000) |
| 272 | usec = 0; | 224 | t.tv_usec=0; |
| 273 | } | 225 | } |
| 274 | while ((r > 0 || | 226 | while ((r > 0 || (errno == EINTR || errno == EAGAIN)) |
| 275 | (errno == EINTR || errno == EAGAIN)) && usec != 0 && n < ENTROPY_NEEDED); | 227 | && t.tv_usec != 0 && n < ENTROPY_NEEDED); |
| 276 | 228 | ||
| 277 | close(fd); | 229 | close(fd); |
| 278 | } | 230 | } |
| 279 | } | 231 | } |
| 280 | #endif /* defined(DEVRANDOM) */ | 232 | #endif |
| 281 | 233 | ||
| 282 | #ifdef DEVRANDOM_EGD | 234 | #ifdef DEVRANDOM_EGD |
| 283 | /* Use an EGD socket to read entropy from an EGD or PRNGD entropy | 235 | /* Use an EGD socket to read entropy from an EGD or PRNGD entropy |
| @@ -292,24 +244,24 @@ int RAND_poll(void) | |||
| 292 | if (r > 0) | 244 | if (r > 0) |
| 293 | n += r; | 245 | n += r; |
| 294 | } | 246 | } |
| 295 | #endif /* defined(DEVRANDOM_EGD) */ | 247 | #endif |
| 296 | 248 | ||
| 297 | #if defined(DEVRANDOM) || defined(DEVRANDOM_EGD) | 249 | #if defined(DEVRANDOM) || defined(DEVRANDOM_EGD) |
| 298 | if (n > 0) | 250 | if (n > 0) |
| 299 | { | 251 | { |
| 300 | RAND_add(tmpbuf,sizeof tmpbuf,(double)n); | 252 | RAND_add(tmpbuf,sizeof tmpbuf,n); |
| 301 | OPENSSL_cleanse(tmpbuf,n); | 253 | OPENSSL_cleanse(tmpbuf,n); |
| 302 | } | 254 | } |
| 303 | #endif | 255 | #endif |
| 304 | 256 | ||
| 305 | /* put in some default random data, we need more than just this */ | 257 | /* put in some default random data, we need more than just this */ |
| 306 | l=curr_pid; | 258 | l=curr_pid; |
| 307 | RAND_add(&l,sizeof(l),0.0); | 259 | RAND_add(&l,sizeof(l),0); |
| 308 | l=getuid(); | 260 | l=getuid(); |
| 309 | RAND_add(&l,sizeof(l),0.0); | 261 | RAND_add(&l,sizeof(l),0); |
| 310 | 262 | ||
| 311 | l=time(NULL); | 263 | l=time(NULL); |
| 312 | RAND_add(&l,sizeof(l),0.0); | 264 | RAND_add(&l,sizeof(l),0); |
| 313 | 265 | ||
| 314 | #if defined(DEVRANDOM) || defined(DEVRANDOM_EGD) | 266 | #if defined(DEVRANDOM) || defined(DEVRANDOM_EGD) |
| 315 | return 1; | 267 | return 1; |
| @@ -318,13 +270,12 @@ int RAND_poll(void) | |||
| 318 | #endif | 270 | #endif |
| 319 | } | 271 | } |
| 320 | 272 | ||
| 321 | #endif /* defined(__OpenBSD__) */ | 273 | #endif |
| 322 | #endif /* !(defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE)) */ | 274 | #endif |
| 323 | |||
| 324 | 275 | ||
| 325 | #if defined(OPENSSL_SYS_VXWORKS) | 276 | #if defined(OPENSSL_SYS_VXWORKS) |
| 326 | int RAND_poll(void) | 277 | int RAND_poll(void) |
| 327 | { | 278 | { |
| 328 | return 0; | 279 | return 0; |
| 329 | } | 280 | } |
| 330 | #endif | 281 | #endif |
diff --git a/src/lib/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c index 00dbe4232c..30c69161ef 100644 --- a/src/lib/libcrypto/rand/rand_win.c +++ b/src/lib/libcrypto/rand/rand_win.c | |||
| @@ -121,10 +121,6 @@ | |||
| 121 | #include <wincrypt.h> | 121 | #include <wincrypt.h> |
| 122 | #include <tlhelp32.h> | 122 | #include <tlhelp32.h> |
| 123 | 123 | ||
| 124 | /* Limit the time spent walking through the heap, processes, threads and modules to | ||
| 125 | a maximum of 1000 miliseconds each, unless CryptoGenRandom failed */ | ||
| 126 | #define MAXDELAY 1000 | ||
| 127 | |||
| 128 | /* Intel hardware RNG CSP -- available from | 124 | /* Intel hardware RNG CSP -- available from |
| 129 | * http://developer.intel.com/design/security/rng/redist_license.htm | 125 | * http://developer.intel.com/design/security/rng/redist_license.htm |
| 130 | */ | 126 | */ |
| @@ -156,7 +152,6 @@ typedef struct tagCURSORINFO | |||
| 156 | #define CURSOR_SHOWING 0x00000001 | 152 | #define CURSOR_SHOWING 0x00000001 |
| 157 | #endif /* CURSOR_SHOWING */ | 153 | #endif /* CURSOR_SHOWING */ |
| 158 | 154 | ||
| 159 | #if !defined(OPENSSL_SYS_WINCE) | ||
| 160 | typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTW)(HCRYPTPROV *, LPCWSTR, LPCWSTR, | 155 | typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTW)(HCRYPTPROV *, LPCWSTR, LPCWSTR, |
| 161 | DWORD, DWORD); | 156 | DWORD, DWORD); |
| 162 | typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV, DWORD, BYTE *); | 157 | typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV, DWORD, BYTE *); |
| @@ -168,7 +163,7 @@ typedef DWORD (WINAPI *GETQUEUESTATUS)(UINT); | |||
| 168 | 163 | ||
| 169 | typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD); | 164 | typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD); |
| 170 | typedef BOOL (WINAPI *CLOSETOOLHELP32SNAPSHOT)(HANDLE); | 165 | typedef BOOL (WINAPI *CLOSETOOLHELP32SNAPSHOT)(HANDLE); |
| 171 | typedef BOOL (WINAPI *HEAP32FIRST)(LPHEAPENTRY32, DWORD, size_t); | 166 | typedef BOOL (WINAPI *HEAP32FIRST)(LPHEAPENTRY32, DWORD, DWORD); |
| 172 | typedef BOOL (WINAPI *HEAP32NEXT)(LPHEAPENTRY32); | 167 | typedef BOOL (WINAPI *HEAP32NEXT)(LPHEAPENTRY32); |
| 173 | typedef BOOL (WINAPI *HEAP32LIST)(HANDLE, LPHEAPLIST32); | 168 | typedef BOOL (WINAPI *HEAP32LIST)(HANDLE, LPHEAPLIST32); |
| 174 | typedef BOOL (WINAPI *PROCESS32)(HANDLE, LPPROCESSENTRY32); | 169 | typedef BOOL (WINAPI *PROCESS32)(HANDLE, LPPROCESSENTRY32); |
| @@ -176,7 +171,9 @@ typedef BOOL (WINAPI *THREAD32)(HANDLE, LPTHREADENTRY32); | |||
| 176 | typedef BOOL (WINAPI *MODULE32)(HANDLE, LPMODULEENTRY32); | 171 | typedef BOOL (WINAPI *MODULE32)(HANDLE, LPMODULEENTRY32); |
| 177 | 172 | ||
| 178 | #include <lmcons.h> | 173 | #include <lmcons.h> |
| 174 | #ifndef OPENSSL_SYS_WINCE | ||
| 179 | #include <lmstats.h> | 175 | #include <lmstats.h> |
| 176 | #endif | ||
| 180 | #if 1 /* The NET API is Unicode only. It requires the use of the UNICODE | 177 | #if 1 /* The NET API is Unicode only. It requires the use of the UNICODE |
| 181 | * macro. When UNICODE is defined LPTSTR becomes LPWSTR. LMSTR was | 178 | * macro. When UNICODE is defined LPTSTR becomes LPWSTR. LMSTR was |
| 182 | * was added to the Platform SDK to allow the NET API to be used in | 179 | * was added to the Platform SDK to allow the NET API to be used in |
| @@ -187,14 +184,26 @@ typedef NET_API_STATUS (NET_API_FUNCTION * NETSTATGET) | |||
| 187 | (LPWSTR, LPWSTR, DWORD, DWORD, LPBYTE*); | 184 | (LPWSTR, LPWSTR, DWORD, DWORD, LPBYTE*); |
| 188 | typedef NET_API_STATUS (NET_API_FUNCTION * NETFREE)(LPBYTE); | 185 | typedef NET_API_STATUS (NET_API_FUNCTION * NETFREE)(LPBYTE); |
| 189 | #endif /* 1 */ | 186 | #endif /* 1 */ |
| 190 | #endif /* !OPENSSL_SYS_WINCE */ | ||
| 191 | 187 | ||
| 192 | int RAND_poll(void) | 188 | int RAND_poll(void) |
| 193 | { | 189 | { |
| 194 | MEMORYSTATUS m; | 190 | MEMORYSTATUS m; |
| 195 | HCRYPTPROV hProvider = 0; | 191 | HCRYPTPROV hProvider = 0; |
| 192 | BYTE buf[64]; | ||
| 196 | DWORD w; | 193 | DWORD w; |
| 197 | int good = 0; | 194 | HWND h; |
| 195 | |||
| 196 | HMODULE advapi, kernel, user, netapi; | ||
| 197 | CRYPTACQUIRECONTEXTW acquire = 0; | ||
| 198 | CRYPTGENRANDOM gen = 0; | ||
| 199 | CRYPTRELEASECONTEXT release = 0; | ||
| 200 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this | ||
| 201 | * section is still experimental, but if all goes well, this conditional | ||
| 202 | * will be removed | ||
| 203 | */ | ||
| 204 | NETSTATGET netstatget = 0; | ||
| 205 | NETFREE netfree = 0; | ||
| 206 | #endif /* 1 */ | ||
| 198 | 207 | ||
| 199 | /* Determine the OS version we are on so we can turn off things | 208 | /* Determine the OS version we are on so we can turn off things |
| 200 | * that do not work properly. | 209 | * that do not work properly. |
| @@ -203,24 +212,21 @@ int RAND_poll(void) | |||
| 203 | osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ; | 212 | osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ; |
| 204 | GetVersionEx( &osverinfo ) ; | 213 | GetVersionEx( &osverinfo ) ; |
| 205 | 214 | ||
| 206 | #if defined(OPENSSL_SYS_WINCE) | 215 | #if defined(OPENSSL_SYS_WINCE) && WCEPLATFORM!=MS_HPC_PRO |
| 207 | # if defined(_WIN32_WCE) && _WIN32_WCE>=300 | 216 | #ifndef CryptAcquireContext |
| 208 | /* Even though MSDN says _WIN32_WCE>=210, it doesn't seem to be available | 217 | #define CryptAcquireContext CryptAcquireContextW |
| 209 | * in commonly available implementations prior 300... */ | 218 | #endif |
| 210 | { | ||
| 211 | BYTE buf[64]; | ||
| 212 | /* poll the CryptoAPI PRNG */ | 219 | /* poll the CryptoAPI PRNG */ |
| 213 | /* The CryptoAPI returns sizeof(buf) bytes of randomness */ | 220 | /* The CryptoAPI returns sizeof(buf) bytes of randomness */ |
| 214 | if (CryptAcquireContextW(&hProvider, NULL, NULL, PROV_RSA_FULL, | 221 | if (CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) |
| 215 | CRYPT_VERIFYCONTEXT)) | ||
| 216 | { | 222 | { |
| 217 | if (CryptGenRandom(hProvider, sizeof(buf), buf)) | 223 | if (CryptGenRandom(hProvider, sizeof(buf), buf)) |
| 218 | RAND_add(buf, sizeof(buf), sizeof(buf)); | 224 | RAND_add(buf, sizeof(buf), sizeof(buf)); |
| 219 | CryptReleaseContext(hProvider, 0); | 225 | CryptReleaseContext(hProvider, 0); |
| 220 | } | 226 | } |
| 221 | } | 227 | #endif |
| 222 | # endif | 228 | |
| 223 | #else /* OPENSSL_SYS_WINCE */ | 229 | #ifndef OPENSSL_SYS_WINCE |
| 224 | /* | 230 | /* |
| 225 | * None of below libraries are present on Windows CE, which is | 231 | * None of below libraries are present on Windows CE, which is |
| 226 | * why we #ifndef the whole section. This also excuses us from | 232 | * why we #ifndef the whole section. This also excuses us from |
| @@ -234,19 +240,17 @@ int RAND_poll(void) | |||
| 234 | * implement own shim routine, which would accept ANSI argument | 240 | * implement own shim routine, which would accept ANSI argument |
| 235 | * and expand it to Unicode. | 241 | * and expand it to Unicode. |
| 236 | */ | 242 | */ |
| 237 | { | ||
| 238 | /* load functions dynamically - not available on all systems */ | ||
| 239 | HMODULE advapi = LoadLibrary(TEXT("ADVAPI32.DLL")); | ||
| 240 | HMODULE kernel = LoadLibrary(TEXT("KERNEL32.DLL")); | ||
| 241 | HMODULE user = NULL; | ||
| 242 | HMODULE netapi = LoadLibrary(TEXT("NETAPI32.DLL")); | ||
| 243 | CRYPTACQUIRECONTEXTW acquire = NULL; | ||
| 244 | CRYPTGENRANDOM gen = NULL; | ||
| 245 | CRYPTRELEASECONTEXT release = NULL; | ||
| 246 | NETSTATGET netstatget = NULL; | ||
| 247 | NETFREE netfree = NULL; | ||
| 248 | BYTE buf[64]; | ||
| 249 | 243 | ||
| 244 | /* load functions dynamically - not available on all systems */ | ||
| 245 | advapi = LoadLibrary(TEXT("ADVAPI32.DLL")); | ||
| 246 | kernel = LoadLibrary(TEXT("KERNEL32.DLL")); | ||
| 247 | user = LoadLibrary(TEXT("USER32.DLL")); | ||
| 248 | netapi = LoadLibrary(TEXT("NETAPI32.DLL")); | ||
| 249 | |||
| 250 | #if 1 /* There was previously a problem with NETSTATGET. Currently, this | ||
| 251 | * section is still experimental, but if all goes well, this conditional | ||
| 252 | * will be removed | ||
| 253 | */ | ||
| 250 | if (netapi) | 254 | if (netapi) |
| 251 | { | 255 | { |
| 252 | netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet"); | 256 | netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet"); |
| @@ -276,6 +280,7 @@ int RAND_poll(void) | |||
| 276 | 280 | ||
| 277 | if (netapi) | 281 | if (netapi) |
| 278 | FreeLibrary(netapi); | 282 | FreeLibrary(netapi); |
| 283 | #endif /* 1 */ | ||
| 279 | 284 | ||
| 280 | /* 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 |
| 281 | * at random times on Windows 2000. Reported by Jeffrey Altman. | 286 | * at random times on Windows 2000. Reported by Jeffrey Altman. |
| @@ -351,13 +356,12 @@ int RAND_poll(void) | |||
| 351 | { | 356 | { |
| 352 | /* poll the CryptoAPI PRNG */ | 357 | /* poll the CryptoAPI PRNG */ |
| 353 | /* The CryptoAPI returns sizeof(buf) bytes of randomness */ | 358 | /* The CryptoAPI returns sizeof(buf) bytes of randomness */ |
| 354 | if (acquire(&hProvider, NULL, NULL, PROV_RSA_FULL, | 359 | if (acquire(&hProvider, 0, 0, PROV_RSA_FULL, |
| 355 | CRYPT_VERIFYCONTEXT)) | 360 | CRYPT_VERIFYCONTEXT)) |
| 356 | { | 361 | { |
| 357 | if (gen(hProvider, sizeof(buf), buf) != 0) | 362 | if (gen(hProvider, sizeof(buf), buf) != 0) |
| 358 | { | 363 | { |
| 359 | RAND_add(buf, sizeof(buf), 0); | 364 | RAND_add(buf, sizeof(buf), 0); |
| 360 | good = 1; | ||
| 361 | #if 0 | 365 | #if 0 |
| 362 | printf("randomness from PROV_RSA_FULL\n"); | 366 | printf("randomness from PROV_RSA_FULL\n"); |
| 363 | #endif | 367 | #endif |
| @@ -371,7 +375,6 @@ int RAND_poll(void) | |||
| 371 | if (gen(hProvider, sizeof(buf), buf) != 0) | 375 | if (gen(hProvider, sizeof(buf), buf) != 0) |
| 372 | { | 376 | { |
| 373 | RAND_add(buf, sizeof(buf), sizeof(buf)); | 377 | RAND_add(buf, sizeof(buf), sizeof(buf)); |
| 374 | good = 1; | ||
| 375 | #if 0 | 378 | #if 0 |
| 376 | printf("randomness from PROV_INTEL_SEC\n"); | 379 | printf("randomness from PROV_INTEL_SEC\n"); |
| 377 | #endif | 380 | #endif |
| @@ -383,9 +386,7 @@ int RAND_poll(void) | |||
| 383 | if (advapi) | 386 | if (advapi) |
| 384 | FreeLibrary(advapi); | 387 | FreeLibrary(advapi); |
| 385 | 388 | ||
| 386 | if ((osverinfo.dwPlatformId != VER_PLATFORM_WIN32_NT || | 389 | if (user) |
| 387 | !OPENSSL_isservice()) && | ||
| 388 | (user = LoadLibrary(TEXT("USER32.DLL")))) | ||
| 389 | { | 390 | { |
| 390 | GETCURSORINFO cursor; | 391 | GETCURSORINFO cursor; |
| 391 | GETFOREGROUNDWINDOW win; | 392 | GETFOREGROUNDWINDOW win; |
| @@ -398,7 +399,7 @@ int RAND_poll(void) | |||
| 398 | if (win) | 399 | if (win) |
| 399 | { | 400 | { |
| 400 | /* window handle */ | 401 | /* window handle */ |
| 401 | HWND h = win(); | 402 | h = win(); |
| 402 | RAND_add(&h, sizeof(h), 0); | 403 | RAND_add(&h, sizeof(h), 0); |
| 403 | } | 404 | } |
| 404 | if (cursor) | 405 | if (cursor) |
| @@ -463,7 +464,6 @@ int RAND_poll(void) | |||
| 463 | PROCESSENTRY32 p; | 464 | PROCESSENTRY32 p; |
| 464 | THREADENTRY32 t; | 465 | THREADENTRY32 t; |
| 465 | MODULEENTRY32 m; | 466 | MODULEENTRY32 m; |
| 466 | DWORD stoptime = 0; | ||
| 467 | 467 | ||
| 468 | snap = (CREATETOOLHELP32SNAPSHOT) | 468 | snap = (CREATETOOLHELP32SNAPSHOT) |
| 469 | GetProcAddress(kernel, "CreateToolhelp32Snapshot"); | 469 | GetProcAddress(kernel, "CreateToolhelp32Snapshot"); |
| @@ -495,7 +495,6 @@ int RAND_poll(void) | |||
| 495 | * of entropy. | 495 | * of entropy. |
| 496 | */ | 496 | */ |
| 497 | hlist.dwSize = sizeof(HEAPLIST32); | 497 | hlist.dwSize = sizeof(HEAPLIST32); |
| 498 | if (good) stoptime = GetTickCount() + MAXDELAY; | ||
| 499 | if (heaplist_first(handle, &hlist)) | 498 | if (heaplist_first(handle, &hlist)) |
| 500 | do | 499 | do |
| 501 | { | 500 | { |
| @@ -513,20 +512,18 @@ int RAND_poll(void) | |||
| 513 | && --entrycnt > 0); | 512 | && --entrycnt > 0); |
| 514 | } | 513 | } |
| 515 | } while (heaplist_next(handle, | 514 | } while (heaplist_next(handle, |
| 516 | &hlist) && GetTickCount() < stoptime); | 515 | &hlist)); |
| 517 | 516 | ||
| 518 | /* process walking */ | 517 | /* process walking */ |
| 519 | /* PROCESSENTRY32 contains 9 fields that will change | 518 | /* PROCESSENTRY32 contains 9 fields that will change |
| 520 | * with each entry. Consider each field a source of | 519 | * with each entry. Consider each field a source of |
| 521 | * 1 byte of entropy. | 520 | * 1 byte of entropy. |
| 522 | */ | 521 | */ |
| 523 | p.dwSize = sizeof(PROCESSENTRY32); | 522 | p.dwSize = sizeof(PROCESSENTRY32); |
| 524 | |||
| 525 | if (good) stoptime = GetTickCount() + MAXDELAY; | ||
| 526 | if (process_first(handle, &p)) | 523 | if (process_first(handle, &p)) |
| 527 | do | 524 | do |
| 528 | RAND_add(&p, p.dwSize, 9); | 525 | RAND_add(&p, p.dwSize, 9); |
| 529 | while (process_next(handle, &p) && GetTickCount() < stoptime); | 526 | while (process_next(handle, &p)); |
| 530 | 527 | ||
| 531 | /* thread walking */ | 528 | /* thread walking */ |
| 532 | /* THREADENTRY32 contains 6 fields that will change | 529 | /* THREADENTRY32 contains 6 fields that will change |
| @@ -534,11 +531,10 @@ int RAND_poll(void) | |||
| 534 | * 1 byte of entropy. | 531 | * 1 byte of entropy. |
| 535 | */ | 532 | */ |
| 536 | t.dwSize = sizeof(THREADENTRY32); | 533 | t.dwSize = sizeof(THREADENTRY32); |
| 537 | if (good) stoptime = GetTickCount() + MAXDELAY; | ||
| 538 | if (thread_first(handle, &t)) | 534 | if (thread_first(handle, &t)) |
| 539 | do | 535 | do |
| 540 | RAND_add(&t, t.dwSize, 6); | 536 | RAND_add(&t, t.dwSize, 6); |
| 541 | while (thread_next(handle, &t) && GetTickCount() < stoptime); | 537 | while (thread_next(handle, &t)); |
| 542 | 538 | ||
| 543 | /* module walking */ | 539 | /* module walking */ |
| 544 | /* MODULEENTRY32 contains 9 fields that will change | 540 | /* MODULEENTRY32 contains 9 fields that will change |
| @@ -546,22 +542,18 @@ int RAND_poll(void) | |||
| 546 | * 1 byte of entropy. | 542 | * 1 byte of entropy. |
| 547 | */ | 543 | */ |
| 548 | m.dwSize = sizeof(MODULEENTRY32); | 544 | m.dwSize = sizeof(MODULEENTRY32); |
| 549 | if (good) stoptime = GetTickCount() + MAXDELAY; | ||
| 550 | if (module_first(handle, &m)) | 545 | if (module_first(handle, &m)) |
| 551 | do | 546 | do |
| 552 | RAND_add(&m, m.dwSize, 9); | 547 | RAND_add(&m, m.dwSize, 9); |
| 553 | while (module_next(handle, &m) | 548 | while (module_next(handle, &m)); |
| 554 | && (GetTickCount() < stoptime)); | ||
| 555 | if (close_snap) | 549 | if (close_snap) |
| 556 | close_snap(handle); | 550 | close_snap(handle); |
| 557 | else | 551 | else |
| 558 | CloseHandle(handle); | 552 | CloseHandle(handle); |
| 559 | |||
| 560 | } | 553 | } |
| 561 | 554 | ||
| 562 | FreeLibrary(kernel); | 555 | FreeLibrary(kernel); |
| 563 | } | 556 | } |
| 564 | } | ||
| 565 | #endif /* !OPENSSL_SYS_WINCE */ | 557 | #endif /* !OPENSSL_SYS_WINCE */ |
| 566 | 558 | ||
| 567 | /* timer data */ | 559 | /* timer data */ |
| @@ -701,9 +693,6 @@ static void readscreen(void) | |||
| 701 | int y; /* y-coordinate of screen lines to grab */ | 693 | int y; /* y-coordinate of screen lines to grab */ |
| 702 | int n = 16; /* number of screen lines to grab at a time */ | 694 | int n = 16; /* number of screen lines to grab at a time */ |
| 703 | 695 | ||
| 704 | if (GetVersion() >= 0x80000000 || !OPENSSL_isservice()) | ||
| 705 | return; | ||
| 706 | |||
| 707 | /* Create a screen DC and a memory DC compatible to screen DC */ | 696 | /* Create a screen DC and a memory DC compatible to screen DC */ |
| 708 | hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); | 697 | hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); |
| 709 | hMemDC = CreateCompatibleDC(hScrDC); | 698 | hMemDC = CreateCompatibleDC(hScrDC); |
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c new file mode 100644 index 0000000000..d847d8ebdf --- /dev/null +++ b/src/lib/libcrypto/rand/randfile.c | |||
| @@ -0,0 +1,285 @@ | |||
| 1 | /* crypto/rand/randfile.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 | /* We need to define this to get macros like S_IFBLK and S_IFCHR */ | ||
| 60 | #define _XOPEN_SOURCE 500 | ||
| 61 | |||
| 62 | #include <errno.h> | ||
| 63 | #include <stdio.h> | ||
| 64 | #include <stdlib.h> | ||
| 65 | #include <string.h> | ||
| 66 | |||
| 67 | #include "e_os.h" | ||
| 68 | #include <openssl/crypto.h> | ||
| 69 | #include <openssl/rand.h> | ||
| 70 | #include <openssl/buffer.h> | ||
| 71 | |||
| 72 | #ifdef OPENSSL_SYS_VMS | ||
| 73 | #include <unixio.h> | ||
| 74 | #endif | ||
| 75 | #ifndef NO_SYS_TYPES_H | ||
| 76 | # include <sys/types.h> | ||
| 77 | #endif | ||
| 78 | #ifdef MAC_OS_pre_X | ||
| 79 | # include <stat.h> | ||
| 80 | #else | ||
| 81 | # include <sys/stat.h> | ||
| 82 | #endif | ||
| 83 | |||
| 84 | #undef BUFSIZE | ||
| 85 | #define BUFSIZE 1024 | ||
| 86 | #define RAND_DATA 1024 | ||
| 87 | |||
| 88 | /* #define RFILE ".rnd" - defined in ../../e_os.h */ | ||
| 89 | |||
| 90 | /* Note that these functions are intended for seed files only. | ||
| 91 | * Entropy devices and EGD sockets are handled in rand_unix.c */ | ||
| 92 | |||
| 93 | int RAND_load_file(const char *file, long bytes) | ||
| 94 | { | ||
| 95 | /* If bytes >= 0, read up to 'bytes' bytes. | ||
| 96 | * if bytes == -1, read complete file. */ | ||
| 97 | |||
| 98 | MS_STATIC unsigned char buf[BUFSIZE]; | ||
| 99 | struct stat sb; | ||
| 100 | int i,ret=0,n; | ||
| 101 | FILE *in; | ||
| 102 | |||
| 103 | if (file == NULL) return(0); | ||
| 104 | |||
| 105 | i=stat(file,&sb); | ||
| 106 | /* If the state fails, put some crap in anyway */ | ||
| 107 | RAND_add(&sb,sizeof(sb),0); | ||
| 108 | if (i < 0) return(0); | ||
| 109 | if (bytes == 0) return(ret); | ||
| 110 | |||
| 111 | in=fopen(file,"rb"); | ||
| 112 | if (in == NULL) goto err; | ||
| 113 | #if defined(S_IFBLK) && defined(S_IFCHR) | ||
| 114 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { | ||
| 115 | /* this file is a device. we don't want read an infinite number | ||
| 116 | * of bytes from a random device, nor do we want to use buffered | ||
| 117 | * I/O because we will waste system entropy. | ||
| 118 | */ | ||
| 119 | bytes = (bytes == -1) ? 2048 : bytes; /* ok, is 2048 enough? */ | ||
| 120 | setvbuf(in, NULL, _IONBF, 0); /* don't do buffered reads */ | ||
| 121 | } | ||
| 122 | #endif | ||
| 123 | for (;;) | ||
| 124 | { | ||
| 125 | if (bytes > 0) | ||
| 126 | n = (bytes < BUFSIZE)?(int)bytes:BUFSIZE; | ||
| 127 | else | ||
| 128 | n = BUFSIZE; | ||
| 129 | i=fread(buf,1,n,in); | ||
| 130 | if (i <= 0) break; | ||
| 131 | /* even if n != i, use the full array */ | ||
| 132 | RAND_add(buf,n,i); | ||
| 133 | ret+=i; | ||
| 134 | if (bytes > 0) | ||
| 135 | { | ||
| 136 | bytes-=n; | ||
| 137 | if (bytes <= 0) break; | ||
| 138 | } | ||
| 139 | } | ||
| 140 | fclose(in); | ||
| 141 | OPENSSL_cleanse(buf,BUFSIZE); | ||
| 142 | err: | ||
| 143 | return(ret); | ||
| 144 | } | ||
| 145 | |||
| 146 | int RAND_write_file(const char *file) | ||
| 147 | { | ||
| 148 | unsigned char buf[BUFSIZE]; | ||
| 149 | int i,ret=0,rand_err=0; | ||
| 150 | FILE *out = NULL; | ||
| 151 | int n; | ||
| 152 | struct stat sb; | ||
| 153 | |||
| 154 | i=stat(file,&sb); | ||
| 155 | if (i != -1) { | ||
| 156 | #if defined(S_IFBLK) && defined(S_IFCHR) | ||
| 157 | if (sb.st_mode & (S_IFBLK | S_IFCHR)) { | ||
| 158 | /* this file is a device. we don't write back to it. | ||
| 159 | * we "succeed" on the assumption this is some sort | ||
| 160 | * of random device. Otherwise attempting to write to | ||
| 161 | * and chmod the device causes problems. | ||
| 162 | */ | ||
| 163 | return(1); | ||
| 164 | } | ||
| 165 | #endif | ||
| 166 | } | ||
| 167 | |||
| 168 | #if defined(O_CREAT) && !defined(OPENSSL_SYS_WIN32) | ||
| 169 | { | ||
| 170 | /* For some reason Win32 can't write to files created this way */ | ||
| 171 | |||
| 172 | /* chmod(..., 0600) is too late to protect the file, | ||
| 173 | * permissions should be restrictive from the start */ | ||
| 174 | int fd = open(file, O_CREAT, 0600); | ||
| 175 | if (fd != -1) | ||
| 176 | out = fdopen(fd, "wb"); | ||
| 177 | } | ||
| 178 | #endif | ||
| 179 | if (out == NULL) | ||
| 180 | out = fopen(file,"wb"); | ||
| 181 | if (out == NULL) goto err; | ||
| 182 | |||
| 183 | #ifndef NO_CHMOD | ||
| 184 | chmod(file,0600); | ||
| 185 | #endif | ||
| 186 | n=RAND_DATA; | ||
| 187 | for (;;) | ||
| 188 | { | ||
| 189 | i=(n > BUFSIZE)?BUFSIZE:n; | ||
| 190 | n-=BUFSIZE; | ||
| 191 | if (RAND_bytes(buf,i) <= 0) | ||
| 192 | rand_err=1; | ||
| 193 | i=fwrite(buf,1,i,out); | ||
| 194 | if (i <= 0) | ||
| 195 | { | ||
| 196 | ret=0; | ||
| 197 | break; | ||
| 198 | } | ||
| 199 | ret+=i; | ||
| 200 | if (n <= 0) break; | ||
| 201 | } | ||
| 202 | #ifdef OPENSSL_SYS_VMS | ||
| 203 | /* Try to delete older versions of the file, until there aren't | ||
| 204 | any */ | ||
| 205 | { | ||
| 206 | char *tmpf; | ||
| 207 | |||
| 208 | tmpf = OPENSSL_malloc(strlen(file) + 4); /* to add ";-1" and a nul */ | ||
| 209 | if (tmpf) | ||
| 210 | { | ||
| 211 | strcpy(tmpf, file); | ||
| 212 | strcat(tmpf, ";-1"); | ||
| 213 | while(delete(tmpf) == 0) | ||
| 214 | ; | ||
| 215 | rename(file,";1"); /* Make sure it's version 1, or we | ||
| 216 | will reach the limit (32767) at | ||
| 217 | some point... */ | ||
| 218 | } | ||
| 219 | } | ||
| 220 | #endif /* OPENSSL_SYS_VMS */ | ||
| 221 | |||
| 222 | fclose(out); | ||
| 223 | OPENSSL_cleanse(buf,BUFSIZE); | ||
| 224 | err: | ||
| 225 | return (rand_err ? -1 : ret); | ||
| 226 | } | ||
| 227 | |||
| 228 | const char *RAND_file_name(char *buf, size_t size) | ||
| 229 | { | ||
| 230 | char *s=NULL; | ||
| 231 | int ok = 0; | ||
| 232 | #ifdef __OpenBSD__ | ||
| 233 | struct stat sb; | ||
| 234 | #endif | ||
| 235 | |||
| 236 | if (issetugid() == 0) | ||
| 237 | s=getenv("RANDFILE"); | ||
| 238 | if (s != NULL && *s && strlen(s) + 1 < size) | ||
| 239 | { | ||
| 240 | if (BUF_strlcpy(buf,s,size) >= size) | ||
| 241 | return NULL; | ||
| 242 | } | ||
| 243 | else | ||
| 244 | { | ||
| 245 | if (issetugid() == 0) | ||
| 246 | s=getenv("HOME"); | ||
| 247 | #ifdef DEFAULT_HOME | ||
| 248 | if (s == NULL) | ||
| 249 | { | ||
| 250 | s = DEFAULT_HOME; | ||
| 251 | } | ||
| 252 | #endif | ||
| 253 | if (s && *s && strlen(s)+strlen(RFILE)+2 < size) | ||
| 254 | { | ||
| 255 | BUF_strlcpy(buf,s,size); | ||
| 256 | #ifndef OPENSSL_SYS_VMS | ||
| 257 | BUF_strlcat(buf,"/",size); | ||
| 258 | #endif | ||
| 259 | BUF_strlcat(buf,RFILE,size); | ||
| 260 | ok = 1; | ||
| 261 | } | ||
| 262 | else | ||
| 263 | buf[0] = '\0'; /* no file name */ | ||
| 264 | } | ||
| 265 | |||
| 266 | #ifdef __OpenBSD__ | ||
| 267 | /* given that all random loads just fail if the file can't be | ||
| 268 | * seen on a stat, we stat the file we're returning, if it | ||
| 269 | * fails, use /dev/arandom instead. this allows the user to | ||
| 270 | * use their own source for good random data, but defaults | ||
| 271 | * to something hopefully decent if that isn't available. | ||
| 272 | */ | ||
| 273 | |||
| 274 | if (!ok) | ||
| 275 | if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) { | ||
| 276 | return(NULL); | ||
| 277 | } | ||
| 278 | if (stat(buf,&sb) == -1) | ||
| 279 | if (BUF_strlcpy(buf,"/dev/arandom",size) >= size) { | ||
| 280 | return(NULL); | ||
| 281 | } | ||
| 282 | |||
| 283 | #endif | ||
| 284 | return(buf); | ||
| 285 | } | ||
diff --git a/src/lib/libcrypto/rand/randtest.c b/src/lib/libcrypto/rand/randtest.c index 9e92a70b03..701932e6ee 100644 --- a/src/lib/libcrypto/rand/randtest.c +++ b/src/lib/libcrypto/rand/randtest.c | |||
| @@ -65,7 +65,7 @@ | |||
| 65 | /* some FIPS 140-1 random number test */ | 65 | /* some FIPS 140-1 random number test */ |
| 66 | /* some simple tests */ | 66 | /* some simple tests */ |
| 67 | 67 | ||
| 68 | int main(int argc,char **argv) | 68 | int main() |
| 69 | { | 69 | { |
| 70 | unsigned char buf[2500]; | 70 | unsigned char buf[2500]; |
| 71 | int i,j,k,s,sign,nsign,err=0; | 71 | int i,j,k,s,sign,nsign,err=0; |
| @@ -211,9 +211,6 @@ int main(int argc,char **argv) | |||
| 211 | printf("test 4 done\n"); | 211 | printf("test 4 done\n"); |
| 212 | err: | 212 | err: |
| 213 | err=((err)?1:0); | 213 | err=((err)?1:0); |
| 214 | #ifdef OPENSSL_SYS_NETWARE | ||
| 215 | if (err) printf("ERROR: %d\n", err); | ||
| 216 | #endif | ||
| 217 | EXIT(err); | 214 | EXIT(err); |
| 218 | return(err); | 215 | return(err); |
| 219 | } | 216 | } |
