summaryrefslogtreecommitdiff
path: root/entropy.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2001-03-19 09:38:15 +1100
committerDamien Miller <djm@mindrot.org>2001-03-19 09:38:15 +1100
commit60bc51735643baa1b7fb237ea56303fed454dadb (patch)
tree8ece761df99755046be27984f4ea8dcbca1d99d5 /entropy.c
parentb399be4436914e23dd066482a371e068f2724f5c (diff)
- (djm) Seed PRNG at startup, rather than waiting for arc4random calls to
do it implicitly.
Diffstat (limited to 'entropy.c')
-rw-r--r--entropy.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/entropy.c b/entropy.c
index 665f77324..8bd540dc5 100644
--- a/entropy.c
+++ b/entropy.c
@@ -40,7 +40,7 @@
40#include "pathnames.h" 40#include "pathnames.h"
41#include "log.h" 41#include "log.h"
42 42
43RCSID("$Id: entropy.c,v 1.35 2001/03/03 13:29:21 djm Exp $"); 43RCSID("$Id: entropy.c,v 1.36 2001/03/18 22:38:16 djm Exp $");
44 44
45#ifndef offsetof 45#ifndef offsetof
46# define offsetof(type, member) ((size_t) &((type *)0)->member) 46# define offsetof(type, member) ((size_t) &((type *)0)->member)
@@ -68,7 +68,8 @@ RCSID("$Id: entropy.c,v 1.35 2001/03/03 13:29:21 djm Exp $");
68# define SAVED_IDS_WORK_WITH_SETEUID 68# define SAVED_IDS_WORK_WITH_SETEUID
69#endif 69#endif
70 70
71void check_openssl_version(void) 71void
72check_openssl_version(void)
72{ 73{
73 if (SSLeay() != OPENSSL_VERSION_NUMBER) 74 if (SSLeay() != OPENSSL_VERSION_NUMBER)
74 fatal("OpenSSL version mismatch. Built against %lx, you " 75 fatal("OpenSSL version mismatch. Built against %lx, you "
@@ -83,7 +84,8 @@ void check_openssl_version(void)
83 84
84#ifdef USE_PRNGD 85#ifdef USE_PRNGD
85/* Collect entropy from PRNGD/EGD */ 86/* Collect entropy from PRNGD/EGD */
86int get_random_bytes(unsigned char *buf, int len) 87int
88get_random_bytes(unsigned char *buf, int len)
87{ 89{
88 int fd; 90 int fd;
89 char msg[2]; 91 char msg[2];
@@ -180,7 +182,8 @@ done:
180#else /* !USE_PRNGD */ 182#else /* !USE_PRNGD */
181#ifdef RANDOM_POOL 183#ifdef RANDOM_POOL
182/* Collect entropy from /dev/urandom or pipe */ 184/* Collect entropy from /dev/urandom or pipe */
183int get_random_bytes(unsigned char *buf, int len) 185int
186get_random_bytes(unsigned char *buf, int len)
184{ 187{
185 int random_pool; 188 int random_pool;
186 189
@@ -226,7 +229,8 @@ seed_rng(void)
226 memset(buf, '\0', sizeof(buf)); 229 memset(buf, '\0', sizeof(buf));
227} 230}
228 231
229void init_rng(void) 232void
233init_rng(void)
230{ 234{
231 check_openssl_version(); 235 check_openssl_version();
232} 236}
@@ -403,8 +407,7 @@ stir_rusage(int who, double entropy_estimate)
403} 407}
404 408
405 409
406static 410static int
407int
408_get_timeval_msec_difference(struct timeval *t1, struct timeval *t2) { 411_get_timeval_msec_difference(struct timeval *t1, struct timeval *t2) {
409 int secdiff, usecdiff; 412 int secdiff, usecdiff;
410 413
@@ -842,8 +845,10 @@ seed_rng(void)
842 /* commands */ 845 /* commands */
843 old_sigchld_handler = mysignal(SIGCHLD, SIG_DFL); 846 old_sigchld_handler = mysignal(SIGCHLD, SIG_DFL);
844 847
845 debug("Seeded RNG with %i bytes from programs", (int)stir_from_programs()); 848 debug("Seeded RNG with %i bytes from programs",
846 debug("Seeded RNG with %i bytes from system calls", (int)stir_from_system()); 849 (int)stir_from_programs());
850 debug("Seeded RNG with %i bytes from system calls",
851 (int)stir_from_system());
847 852
848 if (!RAND_status()) 853 if (!RAND_status())
849 fatal("Not enough entropy in RNG"); 854 fatal("Not enough entropy in RNG");
@@ -854,7 +859,8 @@ seed_rng(void)
854 fatal("Couldn't initialise builtin random number generator -- exiting."); 859 fatal("Couldn't initialise builtin random number generator -- exiting.");
855} 860}
856 861
857void init_rng(void) 862void
863init_rng(void)
858{ 864{
859 int original_euid; 865 int original_euid;
860 866