112 #define OPENSSL_FIPSEVP
138 #define STATE_SIZE 1023
139 static int state_num=0,state_index=0;
142 static long md_count[2]={0,0};
143 static double entropy=0;
144 static int initialized=0;
146 static unsigned int crypto_lock_rand = 0;
154 int rand_predictable=0;
159 static void ssleay_rand_cleanup(
void);
160 static void ssleay_rand_seed(
const void *buf,
int num);
161 static void ssleay_rand_add(
const void *buf,
int num,
double add_entropy);
162 static int ssleay_rand_bytes(
unsigned char *buf,
int num,
int pseudo);
163 static int ssleay_rand_nopseudo_bytes(
unsigned char *buf,
int num);
164 static int ssleay_rand_pseudo_bytes(
unsigned char *buf,
int num);
165 static int ssleay_rand_status(
void);
169 ssleay_rand_nopseudo_bytes,
172 ssleay_rand_pseudo_bytes,
178 return(&rand_ssleay_meth);
181 static void ssleay_rand_cleanup(
void)
193 static void ssleay_rand_add(
const void *buf,
int num,
double add)
217 if (crypto_lock_rand)
235 md_c[0] = md_count[0];
236 md_c[1] = md_count[1];
238 memcpy(local_md, md,
sizeof md);
249 if (state_index > state_num)
250 state_num=state_index;
288 MD_Update(&m,(
unsigned char *)&(md_c[0]),
sizeof(md_c));
292 buf=(
const char *)buf + j;
304 state[st_idx++]^=local_md[k];
316 for (k = 0; k < (int)
sizeof(md); k++)
318 md[k] ^= local_md[k];
324 #if !defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32)
325 assert(md_c[1] == md_count[1]);
329 static void ssleay_rand_seed(
const void *buf,
int num)
331 ssleay_rand_add(buf, num, (
double)num);
334 static int ssleay_rand_bytes(
unsigned char *buf,
int num,
int pseudo)
336 static volatile int stirred_pool = 0;
337 int i,j,k,st_num,st_idx;
343 #ifndef GETPID_IS_MEANINGLESS
344 pid_t curr_pid = getpid();
346 int do_stir_pool = 0;
349 if (rand_predictable)
351 static unsigned char val=0;
353 for (i=0; i<
num; i++)
390 crypto_lock_rand = 1;
433 #if MD_DIGEST_LENGTH > 20
434 # error "Please adjust DUMMY_SEED."
436 #define DUMMY_SEED "...................."
448 md_c[0] = md_count[0];
449 md_c[1] = md_count[1];
450 memcpy(local_md, md,
sizeof md);
452 state_index+=num_ceil;
453 if (state_index > state_num)
454 state_index %= state_num;
462 crypto_lock_rand = 0;
471 #ifndef GETPID_IS_MEANINGLESS
474 MD_Update(&m,(
unsigned char*)&curr_pid,
sizeof curr_pid);
479 MD_Update(&m,(
unsigned char *)&(md_c[0]),
sizeof(md_c));
504 state[st_idx++]^=local_md[i];
505 if (st_idx >= st_num)
513 MD_Update(&m,(
unsigned char *)&(md_c[0]),
sizeof(md_c));
529 "http://www.openssl.org/support/faq.html");
534 static int ssleay_rand_nopseudo_bytes(
unsigned char *buf,
int num)
536 return ssleay_rand_bytes(buf, num, 0);
541 static int ssleay_rand_pseudo_bytes(
unsigned char *buf,
int num)
543 return ssleay_rand_bytes(buf, num, 1);
546 static int ssleay_rand_status(
void)
555 if (crypto_lock_rand)
572 crypto_lock_rand = 1;
586 crypto_lock_rand = 0;