diff options
Diffstat (limited to 'src/lib/libcrypto/rand')
-rw-r--r-- | src/lib/libcrypto/rand/Makefile.ssl | 41 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/md_rand.c | 102 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand.h | 31 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/rand_lib.c | 98 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/randfile.c | 39 | ||||
-rw-r--r-- | src/lib/libcrypto/rand/randtest.c | 20 |
6 files changed, 235 insertions, 96 deletions
diff --git a/src/lib/libcrypto/rand/Makefile.ssl b/src/lib/libcrypto/rand/Makefile.ssl index d04f0a9b43..76bfdfeae5 100644 --- a/src/lib/libcrypto/rand/Makefile.ssl +++ b/src/lib/libcrypto/rand/Makefile.ssl | |||
@@ -7,9 +7,11 @@ TOP= ../.. | |||
7 | CC= cc | 7 | CC= cc |
8 | INCLUDES= | 8 | INCLUDES= |
9 | CFLAG=-g | 9 | CFLAG=-g |
10 | INSTALL_PREFIX= | ||
11 | OPENSSLDIR= /usr/local/ssl | ||
10 | INSTALLTOP=/usr/local/ssl | 12 | INSTALLTOP=/usr/local/ssl |
11 | MAKE= make -f Makefile.ssl | 13 | MAKE= make -f Makefile.ssl |
12 | MAKEDEPEND= makedepend -f Makefile.ssl | 14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) |
13 | MAKEFILE= Makefile.ssl | 15 | MAKEFILE= Makefile.ssl |
14 | AR= ar r | 16 | AR= ar r |
15 | 17 | ||
@@ -20,8 +22,8 @@ TEST= randtest.c | |||
20 | APPS= | 22 | APPS= |
21 | 23 | ||
22 | LIB=$(TOP)/libcrypto.a | 24 | LIB=$(TOP)/libcrypto.a |
23 | LIBSRC=md_rand.c randfile.c | 25 | LIBSRC=md_rand.c randfile.c rand_lib.c |
24 | LIBOBJ=md_rand.o randfile.o | 26 | LIBOBJ=md_rand.o randfile.o rand_lib.o |
25 | 27 | ||
26 | SRC= $(LIBSRC) | 28 | SRC= $(LIBSRC) |
27 | 29 | ||
@@ -37,24 +39,23 @@ all: lib | |||
37 | 39 | ||
38 | lib: $(LIBOBJ) | 40 | lib: $(LIBOBJ) |
39 | $(AR) $(LIB) $(LIBOBJ) | 41 | $(AR) $(LIB) $(LIBOBJ) |
40 | sh $(TOP)/util/ranlib.sh $(LIB) | 42 | $(RANLIB) $(LIB) |
41 | @touch lib | 43 | @touch lib |
42 | 44 | ||
43 | files: | 45 | files: |
44 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | 46 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO |
45 | 47 | ||
46 | links: | 48 | links: |
47 | /bin/rm -f Makefile | 49 | @$(TOP)/util/point.sh Makefile.ssl Makefile |
48 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | 50 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) |
49 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | 51 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) |
50 | $(TOP)/util/mklink.sh ../../test $(TEST) | 52 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) |
51 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
52 | 53 | ||
53 | install: | 54 | install: |
54 | @for i in $(EXHEADER) ; \ | 55 | @for i in $(EXHEADER) ; \ |
55 | do \ | 56 | do \ |
56 | (cp $$i $(INSTALLTOP)/include/$$i; \ | 57 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ |
57 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | 58 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ |
58 | done; | 59 | done; |
59 | 60 | ||
60 | tags: | 61 | tags: |
@@ -66,15 +67,21 @@ lint: | |||
66 | lint -DLINT $(INCLUDES) $(SRC)>fluff | 67 | lint -DLINT $(INCLUDES) $(SRC)>fluff |
67 | 68 | ||
68 | depend: | 69 | depend: |
69 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | 70 | $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) |
70 | 71 | ||
71 | dclean: | 72 | dclean: |
72 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | 73 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new |
73 | mv -f Makefile.new $(MAKEFILE) | 74 | mv -f Makefile.new $(MAKEFILE) |
74 | 75 | ||
75 | clean: | 76 | clean: |
76 | /bin/rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | 77 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff |
77 | |||
78 | errors: | ||
79 | 78 | ||
80 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 79 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
80 | |||
81 | md_rand.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h | ||
82 | md_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | ||
83 | md_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/rand.h | ||
84 | md_rand.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
85 | rand_lib.o: ../../include/openssl/rand.h | ||
86 | randfile.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h | ||
87 | randfile.o: ../../include/openssl/opensslconf.h ../../include/openssl/rand.h | ||
diff --git a/src/lib/libcrypto/rand/md_rand.c b/src/lib/libcrypto/rand/md_rand.c index f44b36a8b9..6bd1960e1d 100644 --- a/src/lib/libcrypto/rand/md_rand.c +++ b/src/lib/libcrypto/rand/md_rand.c | |||
@@ -57,21 +57,25 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | ||
61 | #include <sys/types.h> | 60 | #include <sys/types.h> |
62 | #include <time.h> | 61 | #include <time.h> |
62 | #include <string.h> | ||
63 | |||
64 | #include "openssl/e_os.h" | ||
65 | |||
66 | #include <openssl/crypto.h> | ||
63 | 67 | ||
64 | #if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND) | 68 | #if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND) |
65 | #ifndef NO_MD5 | 69 | #if !defined(NO_SHA) && !defined(NO_SHA1) |
66 | #define USE_MD5_RAND | ||
67 | #elif !defined(NO_SHA1) | ||
68 | #define USE_SHA1_RAND | 70 | #define USE_SHA1_RAND |
69 | #elif !defined(NO_MDC2) | 71 | #elif !defined(NO_MD5) |
72 | #define USE_MD5_RAND | ||
73 | #elif !defined(NO_MDC2) && !defined(NO_DES) | ||
70 | #define USE_MDC2_RAND | 74 | #define USE_MDC2_RAND |
71 | #elif !defined(NO_MD2) | 75 | #elif !defined(NO_MD2) |
72 | #define USE_MD2_RAND | 76 | #define USE_MD2_RAND |
73 | #else | 77 | #else |
74 | We need a message digest of some type | 78 | #error No message digest algorithm available |
75 | #endif | 79 | #endif |
76 | #endif | 80 | #endif |
77 | 81 | ||
@@ -82,60 +86,78 @@ We need a message digest of some type | |||
82 | */ | 86 | */ |
83 | 87 | ||
84 | #if defined(USE_MD5_RAND) | 88 | #if defined(USE_MD5_RAND) |
85 | #include "md5.h" | 89 | #include <openssl/md5.h> |
86 | #define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH | 90 | #define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH |
87 | #define MD_CTX MD5_CTX | 91 | #define MD_CTX MD5_CTX |
88 | #define MD_Init(a) MD5_Init(a) | 92 | #define MD_Init(a) MD5_Init(a) |
89 | #define MD_Update(a,b,c) MD5_Update(a,b,c) | 93 | #define MD_Update(a,b,c) MD5_Update(a,b,c) |
90 | #define MD_Final(a,b) MD5_Final(a,b) | 94 | #define MD_Final(a,b) MD5_Final(a,b) |
95 | #define MD(a,b,c) MD5(a,b,c) | ||
91 | #elif defined(USE_SHA1_RAND) | 96 | #elif defined(USE_SHA1_RAND) |
92 | #include "sha.h" | 97 | #include <openssl/sha.h> |
93 | #define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH | 98 | #define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH |
94 | #define MD_CTX SHA_CTX | 99 | #define MD_CTX SHA_CTX |
95 | #define MD_Init(a) SHA1_Init(a) | 100 | #define MD_Init(a) SHA1_Init(a) |
96 | #define MD_Update(a,b,c) SHA1_Update(a,b,c) | 101 | #define MD_Update(a,b,c) SHA1_Update(a,b,c) |
97 | #define MD_Final(a,b) SHA1_Final(a,b) | 102 | #define MD_Final(a,b) SHA1_Final(a,b) |
103 | #define MD(a,b,c) SHA1(a,b,c) | ||
98 | #elif defined(USE_MDC2_RAND) | 104 | #elif defined(USE_MDC2_RAND) |
99 | #include "mdc2.h" | 105 | #include <openssl/mdc2.h> |
100 | #define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH | 106 | #define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH |
101 | #define MD_CTX MDC2_CTX | 107 | #define MD_CTX MDC2_CTX |
102 | #define MD_Init(a) MDC2_Init(a) | 108 | #define MD_Init(a) MDC2_Init(a) |
103 | #define MD_Update(a,b,c) MDC2_Update(a,b,c) | 109 | #define MD_Update(a,b,c) MDC2_Update(a,b,c) |
104 | #define MD_Final(a,b) MDC2_Final(a,b) | 110 | #define MD_Final(a,b) MDC2_Final(a,b) |
111 | #define MD(a,b,c) MDC2(a,b,c) | ||
105 | #elif defined(USE_MD2_RAND) | 112 | #elif defined(USE_MD2_RAND) |
106 | #include "md2.h" | 113 | #include <openssl/md2.h> |
107 | #define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH | 114 | #define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH |
108 | #define MD_CTX MD2_CTX | 115 | #define MD_CTX MD2_CTX |
109 | #define MD_Init(a) MD2_Init(a) | 116 | #define MD_Init(a) MD2_Init(a) |
110 | #define MD_Update(a,b,c) MD2_Update(a,b,c) | 117 | #define MD_Update(a,b,c) MD2_Update(a,b,c) |
111 | #define MD_Final(a,b) MD2_Final(a,b) | 118 | #define MD_Final(a,b) MD2_Final(a,b) |
119 | #define MD(a,b,c) MD2(a,b,c) | ||
112 | #endif | 120 | #endif |
113 | 121 | ||
114 | #include "rand.h" | 122 | #include <openssl/rand.h> |
115 | 123 | ||
116 | /*#define NORAND 1 */ | 124 | /* #define NORAND 1 */ |
117 | /*#define PREDICT 1 */ | 125 | /* #define PREDICT 1 */ |
118 | 126 | ||
119 | #define STATE_SIZE 1023 | 127 | #define STATE_SIZE 1023 |
120 | static int state_num=0,state_index=0; | 128 | static int state_num=0,state_index=0; |
121 | static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH]; | 129 | static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH]; |
122 | static unsigned char md[MD_DIGEST_LENGTH]; | 130 | static unsigned char md[MD_DIGEST_LENGTH]; |
123 | static int md_count=0; | 131 | static long md_count[2]={0,0}; |
132 | |||
133 | const char *RAND_version="RAND" OPENSSL_VERSION_PTEXT; | ||
134 | |||
135 | static void ssleay_rand_cleanup(void); | ||
136 | static void ssleay_rand_seed(const void *buf, int num); | ||
137 | static void ssleay_rand_bytes(unsigned char *buf, int num); | ||
124 | 138 | ||
125 | char *RAND_version="RAND part of SSLeay 0.9.0b 29-Jun-1998"; | 139 | RAND_METHOD rand_ssleay_meth={ |
140 | ssleay_rand_seed, | ||
141 | ssleay_rand_bytes, | ||
142 | ssleay_rand_cleanup, | ||
143 | }; | ||
126 | 144 | ||
127 | void RAND_cleanup() | 145 | RAND_METHOD *RAND_SSLeay(void) |
146 | { | ||
147 | return(&rand_ssleay_meth); | ||
148 | } | ||
149 | |||
150 | static void ssleay_rand_cleanup(void) | ||
128 | { | 151 | { |
129 | memset(state,0,sizeof(state)); | 152 | memset(state,0,sizeof(state)); |
130 | state_num=0; | 153 | state_num=0; |
131 | state_index=0; | 154 | state_index=0; |
132 | memset(md,0,MD_DIGEST_LENGTH); | 155 | memset(md,0,MD_DIGEST_LENGTH); |
133 | md_count=0; | 156 | md_count[0]=0; |
157 | md_count[1]=0; | ||
134 | } | 158 | } |
135 | 159 | ||
136 | void RAND_seed(buf,num) | 160 | static void ssleay_rand_seed(const void *buf, int num) |
137 | unsigned char *buf; | ||
138 | int num; | ||
139 | { | 161 | { |
140 | int i,j,k,st_idx,st_num; | 162 | int i,j,k,st_idx,st_num; |
141 | MD_CTX m; | 163 | MD_CTX m; |
@@ -178,9 +200,11 @@ int num; | |||
178 | MD_Update(&m,&(state[st_idx]),j); | 200 | MD_Update(&m,&(state[st_idx]),j); |
179 | 201 | ||
180 | MD_Update(&m,buf,j); | 202 | MD_Update(&m,buf,j); |
203 | MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count)); | ||
181 | MD_Final(md,&m); | 204 | MD_Final(md,&m); |
205 | md_count[1]++; | ||
182 | 206 | ||
183 | buf+=j; | 207 | buf=(const char *)buf + j; |
184 | 208 | ||
185 | for (k=0; k<j; k++) | 209 | for (k=0; k<j; k++) |
186 | { | 210 | { |
@@ -195,9 +219,7 @@ int num; | |||
195 | memset((char *)&m,0,sizeof(m)); | 219 | memset((char *)&m,0,sizeof(m)); |
196 | } | 220 | } |
197 | 221 | ||
198 | void RAND_bytes(buf,num) | 222 | static void ssleay_rand_bytes(unsigned char *buf, int num) |
199 | unsigned char *buf; | ||
200 | int num; | ||
201 | { | 223 | { |
202 | int i,j,k,st_num,st_idx; | 224 | int i,j,k,st_num,st_idx; |
203 | MD_CTX m; | 225 | MD_CTX m; |
@@ -221,19 +243,18 @@ int num; | |||
221 | 243 | ||
222 | if (init) | 244 | if (init) |
223 | { | 245 | { |
224 | init=0; | ||
225 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); | 246 | CRYPTO_w_unlock(CRYPTO_LOCK_RAND); |
226 | /* put in some default random data, we need more than | 247 | /* put in some default random data, we need more than |
227 | * just this */ | 248 | * just this */ |
228 | RAND_seed((unsigned char *)&m,sizeof(m)); | 249 | RAND_seed(&m,sizeof(m)); |
229 | #ifndef MSDOS | 250 | #ifndef MSDOS |
230 | l=getpid(); | 251 | l=getpid(); |
231 | RAND_seed((unsigned char *)&l,sizeof(l)); | 252 | RAND_seed(&l,sizeof(l)); |
232 | l=getuid(); | 253 | l=getuid(); |
233 | RAND_seed((unsigned char *)&l,sizeof(l)); | 254 | RAND_seed(&l,sizeof(l)); |
234 | #endif | 255 | #endif |
235 | l=time(NULL); | 256 | l=time(NULL); |
236 | RAND_seed((unsigned char *)&l,sizeof(l)); | 257 | RAND_seed(&l,sizeof(l)); |
237 | 258 | ||
238 | /* #ifdef DEVRANDOM */ | 259 | /* #ifdef DEVRANDOM */ |
239 | /* | 260 | /* |
@@ -261,6 +282,7 @@ int num; | |||
261 | memset(md,0,MD_DIGEST_LENGTH); | 282 | memset(md,0,MD_DIGEST_LENGTH); |
262 | #endif | 283 | #endif |
263 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); | 284 | CRYPTO_w_lock(CRYPTO_LOCK_RAND); |
285 | init=0; | ||
264 | } | 286 | } |
265 | 287 | ||
266 | st_idx=state_index; | 288 | st_idx=state_index; |
@@ -277,6 +299,7 @@ int num; | |||
277 | num-=j; | 299 | num-=j; |
278 | MD_Init(&m); | 300 | MD_Init(&m); |
279 | MD_Update(&m,&(md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2); | 301 | MD_Update(&m,&(md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2); |
302 | MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count)); | ||
280 | #ifndef PURIFY | 303 | #ifndef PURIFY |
281 | MD_Update(&m,buf,j); /* purify complains */ | 304 | MD_Update(&m,buf,j); /* purify complains */ |
282 | #endif | 305 | #endif |
@@ -300,7 +323,8 @@ int num; | |||
300 | } | 323 | } |
301 | 324 | ||
302 | MD_Init(&m); | 325 | MD_Init(&m); |
303 | MD_Update(&m,(unsigned char *)&md_count,sizeof(md_count)); md_count++; | 326 | MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count)); |
327 | md_count[0]++; | ||
304 | MD_Update(&m,md,MD_DIGEST_LENGTH); | 328 | MD_Update(&m,md,MD_DIGEST_LENGTH); |
305 | MD_Final(md,&m); | 329 | MD_Final(md,&m); |
306 | memset(&m,0,sizeof(m)); | 330 | memset(&m,0,sizeof(m)); |
@@ -308,7 +332,7 @@ int num; | |||
308 | 332 | ||
309 | #ifdef WINDOWS | 333 | #ifdef WINDOWS |
310 | #include <windows.h> | 334 | #include <windows.h> |
311 | #include <rand.h> | 335 | #include <openssl/rand.h> |
312 | 336 | ||
313 | /***************************************************************************** | 337 | /***************************************************************************** |
314 | * Initialisation function for the SSL random generator. Takes the contents | 338 | * Initialisation function for the SSL random generator. Takes the contents |
@@ -320,13 +344,13 @@ int num; | |||
320 | * <URL:http://www.microsoft.com/kb/developr/win_dk/q97193.htm>; | 344 | * <URL:http://www.microsoft.com/kb/developr/win_dk/q97193.htm>; |
321 | * the original copyright message is: | 345 | * the original copyright message is: |
322 | * | 346 | * |
323 | // (C) Copyright Microsoft Corp. 1993. All rights reserved. | 347 | * (C) Copyright Microsoft Corp. 1993. All rights reserved. |
324 | // | 348 | * |
325 | // You have a royalty-free right to use, modify, reproduce and | 349 | * You have a royalty-free right to use, modify, reproduce and |
326 | // distribute the Sample Files (and/or any modified version) in | 350 | * distribute the Sample Files (and/or any modified version) in |
327 | // any way you find useful, provided that you agree that | 351 | * any way you find useful, provided that you agree that |
328 | // Microsoft has no warranty obligations or liability for any | 352 | * Microsoft has no warranty obligations or liability for any |
329 | // Sample Application Files which are modified. | 353 | * Sample Application Files which are modified. |
330 | */ | 354 | */ |
331 | /* | 355 | /* |
332 | * I have modified the loading of bytes via RAND_seed() mechanism since | 356 | * I have modified the loading of bytes via RAND_seed() mechanism since |
@@ -385,7 +409,7 @@ void RAND_screen(void) | |||
385 | GetBitmapBits(hBitmap, size, bmbits); | 409 | GetBitmapBits(hBitmap, size, bmbits); |
386 | 410 | ||
387 | /* Get the MD5 of the bitmap */ | 411 | /* Get the MD5 of the bitmap */ |
388 | MD5(bmbits,size,md); | 412 | MD(bmbits,size,md); |
389 | 413 | ||
390 | /* Seed the random generator with the MD5 digest */ | 414 | /* Seed the random generator with the MD5 digest */ |
391 | RAND_seed(md, MD_DIGEST_LENGTH); | 415 | RAND_seed(md, MD_DIGEST_LENGTH); |
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h index 477d7a150a..fd8ee38366 100644 --- a/src/lib/libcrypto/rand/rand.h +++ b/src/lib/libcrypto/rand/rand.h | |||
@@ -63,28 +63,25 @@ | |||
63 | extern "C" { | 63 | extern "C" { |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #ifndef NOPROTO | 66 | typedef struct rand_meth_st |
67 | { | ||
68 | void (*seed)(const void *buf, int num); | ||
69 | void (*bytes)(unsigned char *buf, int num); | ||
70 | void (*cleanup)(void); | ||
71 | } RAND_METHOD; | ||
72 | |||
73 | void RAND_set_rand_method(RAND_METHOD *meth); | ||
74 | RAND_METHOD *RAND_get_rand_method(void ); | ||
75 | RAND_METHOD *RAND_SSLeay(void); | ||
67 | void RAND_cleanup(void ); | 76 | void RAND_cleanup(void ); |
68 | void RAND_bytes( unsigned char *buf,int num); | 77 | void RAND_bytes(unsigned char *buf,int num); |
69 | void RAND_seed( unsigned char *buf,int num); | 78 | void RAND_seed(const void *buf,int num); |
70 | int RAND_load_file(char *file,long max_bytes); | 79 | int RAND_load_file(const char *file,long max_bytes); |
71 | int RAND_write_file(char *file); | 80 | int RAND_write_file(const char *file); |
72 | char *RAND_file_name(char *file,int num); | 81 | char *RAND_file_name(char *file,int num); |
73 | #ifdef WINDOWS | 82 | #ifdef WINDOWS |
74 | void RAND_screen(void); | 83 | void RAND_screen(void); |
75 | #endif | 84 | #endif |
76 | #else | ||
77 | void RAND_cleanup(); | ||
78 | void RAND_bytes(); | ||
79 | void RAND_seed(); | ||
80 | int RAND_load_file(); | ||
81 | int RAND_write_file(); | ||
82 | char *RAND_file_name(); | ||
83 | #ifdef WINDOWS | ||
84 | void RAND_screen(); | ||
85 | #endif | ||
86 | #endif | ||
87 | |||
88 | #ifdef __cplusplus | 85 | #ifdef __cplusplus |
89 | } | 86 | } |
90 | #endif | 87 | #endif |
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c new file mode 100644 index 0000000000..34c6d5b968 --- /dev/null +++ b/src/lib/libcrypto/rand/rand_lib.c | |||
@@ -0,0 +1,98 @@ | |||
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 <sys/types.h> | ||
61 | #include <time.h> | ||
62 | #include <openssl/rand.h> | ||
63 | |||
64 | #ifdef NO_RAND | ||
65 | static RAND_METHOD *rand_meth=NULL; | ||
66 | #else | ||
67 | extern RAND_METHOD rand_ssleay_meth; | ||
68 | static RAND_METHOD *rand_meth= &rand_ssleay_meth; | ||
69 | #endif | ||
70 | |||
71 | void RAND_set_rand_method(RAND_METHOD *meth) | ||
72 | { | ||
73 | rand_meth=meth; | ||
74 | } | ||
75 | |||
76 | RAND_METHOD *RAND_get_rand_method(void) | ||
77 | { | ||
78 | return(rand_meth); | ||
79 | } | ||
80 | |||
81 | void RAND_cleanup(void) | ||
82 | { | ||
83 | if (rand_meth != NULL) | ||
84 | rand_meth->cleanup(); | ||
85 | } | ||
86 | |||
87 | void RAND_seed(const void *buf, int num) | ||
88 | { | ||
89 | if (rand_meth != NULL) | ||
90 | rand_meth->seed(buf,num); | ||
91 | } | ||
92 | |||
93 | void RAND_bytes(unsigned char *buf, int num) | ||
94 | { | ||
95 | if (rand_meth != NULL) | ||
96 | rand_meth->bytes(buf,num); | ||
97 | } | ||
98 | |||
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index f2b3746363..6829d4ec37 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c | |||
@@ -56,11 +56,17 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <errno.h> | ||
59 | #include <stdio.h> | 60 | #include <stdio.h> |
60 | #include "cryptlib.h" | 61 | #include <stdlib.h> |
62 | #include <string.h> | ||
63 | #include <sys/types.h> | ||
61 | #include <sys/stat.h> | 64 | #include <sys/stat.h> |
62 | #include <sys/types.h> | 65 | #include <sys/types.h> |
63 | #include "rand.h" | 66 | |
67 | #include "openssl/e_os.h" | ||
68 | |||
69 | #include <openssl/rand.h> | ||
64 | 70 | ||
65 | #undef BUFSIZE | 71 | #undef BUFSIZE |
66 | #define BUFSIZE 1024 | 72 | #define BUFSIZE 1024 |
@@ -68,9 +74,7 @@ | |||
68 | 74 | ||
69 | /* #define RFILE ".rand" - defined in ../../e_os.h */ | 75 | /* #define RFILE ".rand" - defined in ../../e_os.h */ |
70 | 76 | ||
71 | int RAND_load_file(file,bytes) | 77 | int RAND_load_file(const char *file, long bytes) |
72 | char *file; | ||
73 | long bytes; | ||
74 | { | 78 | { |
75 | MS_STATIC unsigned char buf[BUFSIZE]; | 79 | MS_STATIC unsigned char buf[BUFSIZE]; |
76 | struct stat sb; | 80 | struct stat sb; |
@@ -81,12 +85,12 @@ long bytes; | |||
81 | 85 | ||
82 | i=stat(file,&sb); | 86 | i=stat(file,&sb); |
83 | /* If the state fails, put some crap in anyway */ | 87 | /* If the state fails, put some crap in anyway */ |
84 | RAND_seed((unsigned char *)&sb,sizeof(sb)); | 88 | RAND_seed(&sb,sizeof(sb)); |
85 | ret+=sizeof(sb); | 89 | ret+=sizeof(sb); |
86 | if (i < 0) return(0); | 90 | if (i < 0) return(0); |
87 | if (bytes <= 0) return(ret); | 91 | if (bytes <= 0) return(ret); |
88 | 92 | ||
89 | in=fopen(file,"r"); | 93 | in=fopen(file,"rb"); |
90 | if (in == NULL) goto err; | 94 | if (in == NULL) goto err; |
91 | for (;;) | 95 | for (;;) |
92 | { | 96 | { |
@@ -105,15 +109,24 @@ err: | |||
105 | return(ret); | 109 | return(ret); |
106 | } | 110 | } |
107 | 111 | ||
108 | int RAND_write_file(file) | 112 | int RAND_write_file(const char *file) |
109 | char *file; | ||
110 | { | 113 | { |
111 | unsigned char buf[BUFSIZE]; | 114 | unsigned char buf[BUFSIZE]; |
112 | int i,ret=0; | 115 | int i,ret=0; |
113 | FILE *out; | 116 | FILE *out; |
114 | int n; | 117 | int n; |
115 | 118 | ||
116 | out=fopen(file,"w"); | 119 | /* Under VMS, fopen(file, "wb") will craete a new version of the |
120 | same file. This is not good, so let's try updating an existing | ||
121 | one, and create file only if it doesn't already exist. This | ||
122 | should be completely harmless on system that have no file | ||
123 | versions. -- Richard Levitte */ | ||
124 | out=fopen(file,"rb+"); | ||
125 | if (out == NULL && errno == ENOENT) | ||
126 | { | ||
127 | errno = 0; | ||
128 | out=fopen(file,"wb"); | ||
129 | } | ||
117 | if (out == NULL) goto err; | 130 | if (out == NULL) goto err; |
118 | chmod(file,0600); | 131 | chmod(file,0600); |
119 | n=RAND_DATA; | 132 | n=RAND_DATA; |
@@ -137,9 +150,7 @@ err: | |||
137 | return(ret); | 150 | return(ret); |
138 | } | 151 | } |
139 | 152 | ||
140 | char *RAND_file_name(buf,size) | 153 | char *RAND_file_name(char *buf, int size) |
141 | char *buf; | ||
142 | int size; | ||
143 | { | 154 | { |
144 | char *s; | 155 | char *s; |
145 | char *ret=NULL; | 156 | char *ret=NULL; |
@@ -158,7 +169,9 @@ int size; | |||
158 | if (((int)(strlen(s)+strlen(RFILE)+2)) > size) | 169 | if (((int)(strlen(s)+strlen(RFILE)+2)) > size) |
159 | return(RFILE); | 170 | return(RFILE); |
160 | strcpy(buf,s); | 171 | strcpy(buf,s); |
172 | #ifndef VMS | ||
161 | strcat(buf,"/"); | 173 | strcat(buf,"/"); |
174 | #endif | ||
162 | strcat(buf,RFILE); | 175 | strcat(buf,RFILE); |
163 | ret=buf; | 176 | ret=buf; |
164 | } | 177 | } |
diff --git a/src/lib/libcrypto/rand/randtest.c b/src/lib/libcrypto/rand/randtest.c index e0ba61e123..f0706d779a 100644 --- a/src/lib/libcrypto/rand/randtest.c +++ b/src/lib/libcrypto/rand/randtest.c | |||
@@ -58,7 +58,7 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
61 | #include "rand.h" | 61 | #include <openssl/rand.h> |
62 | 62 | ||
63 | /* some FIPS 140-1 random number test */ | 63 | /* some FIPS 140-1 random number test */ |
64 | /* some simple tests */ | 64 | /* some simple tests */ |
@@ -117,7 +117,7 @@ int main() | |||
117 | /* test 1 */ | 117 | /* test 1 */ |
118 | if (!((9654 < n1) && (n1 < 10346))) | 118 | if (!((9654 < n1) && (n1 < 10346))) |
119 | { | 119 | { |
120 | printf("test 1 failed, X=%ld\n",n1); | 120 | printf("test 1 failed, X=%lu\n",n1); |
121 | err++; | 121 | err++; |
122 | } | 122 | } |
123 | printf("test 1 done\n"); | 123 | printf("test 1 done\n"); |
@@ -150,37 +150,37 @@ int main() | |||
150 | { | 150 | { |
151 | if (!((2267 < runs[i][0]) && (runs[i][0] < 2733))) | 151 | if (!((2267 < runs[i][0]) && (runs[i][0] < 2733))) |
152 | { | 152 | { |
153 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | 153 | printf("test 3 failed, bit=%d run=%d num=%lu\n", |
154 | i,1,runs[i][0]); | 154 | i,1,runs[i][0]); |
155 | err++; | 155 | err++; |
156 | } | 156 | } |
157 | if (!((1079 < runs[i][1]) && (runs[i][1] < 1421))) | 157 | if (!((1079 < runs[i][1]) && (runs[i][1] < 1421))) |
158 | { | 158 | { |
159 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | 159 | printf("test 3 failed, bit=%d run=%d num=%lu\n", |
160 | i,2,runs[i][1]); | 160 | i,2,runs[i][1]); |
161 | err++; | 161 | err++; |
162 | } | 162 | } |
163 | if (!(( 502 < runs[i][2]) && (runs[i][2] < 748))) | 163 | if (!(( 502 < runs[i][2]) && (runs[i][2] < 748))) |
164 | { | 164 | { |
165 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | 165 | printf("test 3 failed, bit=%d run=%d num=%lu\n", |
166 | i,3,runs[i][2]); | 166 | i,3,runs[i][2]); |
167 | err++; | 167 | err++; |
168 | } | 168 | } |
169 | if (!(( 223 < runs[i][3]) && (runs[i][3] < 402))) | 169 | if (!(( 223 < runs[i][3]) && (runs[i][3] < 402))) |
170 | { | 170 | { |
171 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | 171 | printf("test 3 failed, bit=%d run=%d num=%lu\n", |
172 | i,4,runs[i][3]); | 172 | i,4,runs[i][3]); |
173 | err++; | 173 | err++; |
174 | } | 174 | } |
175 | if (!(( 90 < runs[i][4]) && (runs[i][4] < 223))) | 175 | if (!(( 90 < runs[i][4]) && (runs[i][4] < 223))) |
176 | { | 176 | { |
177 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | 177 | printf("test 3 failed, bit=%d run=%d num=%lu\n", |
178 | i,5,runs[i][4]); | 178 | i,5,runs[i][4]); |
179 | err++; | 179 | err++; |
180 | } | 180 | } |
181 | if (!(( 90 < runs[i][5]) && (runs[i][5] < 223))) | 181 | if (!(( 90 < runs[i][5]) && (runs[i][5] < 223))) |
182 | { | 182 | { |
183 | printf("test 3 failed, bit=%d run=%d num=%ld\n", | 183 | printf("test 3 failed, bit=%d run=%d num=%lu\n", |
184 | i,6,runs[i][5]); | 184 | i,6,runs[i][5]); |
185 | err++; | 185 | err++; |
186 | } | 186 | } |
@@ -190,13 +190,13 @@ int main() | |||
190 | /* test 4 */ | 190 | /* test 4 */ |
191 | if (runs[0][33] != 0) | 191 | if (runs[0][33] != 0) |
192 | { | 192 | { |
193 | printf("test 4 failed, bit=%d run=%d num=%ld\n", | 193 | printf("test 4 failed, bit=%d run=%d num=%lu\n", |
194 | 0,34,runs[0][33]); | 194 | 0,34,runs[0][33]); |
195 | err++; | 195 | err++; |
196 | } | 196 | } |
197 | if (runs[1][33] != 0) | 197 | if (runs[1][33] != 0) |
198 | { | 198 | { |
199 | printf("test 4 failed, bit=%d run=%d num=%ld\n", | 199 | printf("test 4 failed, bit=%d run=%d num=%lu\n", |
200 | 1,34,runs[1][33]); | 200 | 1,34,runs[1][33]); |
201 | err++; | 201 | err++; |
202 | } | 202 | } |