-/* slow command timeouts (all in milliseconds) */
-/* static int entropy_timeout_default = ENTROPY_TIMEOUT_MSEC; */
-static int entropy_timeout_current = ENTROPY_TIMEOUT_MSEC;
-
-static int prng_seed_loaded = 0;
-static int prng_seed_saved = 0;
-
-typedef struct
-{
- /* Proportion of data that is entropy */
- double rate;
- /* Counter goes positive if this command times out */
- unsigned int badness;
- /* Increases by factor of two each timeout */
- unsigned int sticky_badness;
- /* Path to executable */
- const char *path;
- /* argv to pass to executable */
- const char *args[5];
-} entropy_source_t;
-
-double stir_from_system(void);
-double stir_from_programs(void);
-double stir_gettimeofday(double entropy_estimate);
-double stir_clock(double entropy_estimate);
-double stir_rusage(int who, double entropy_estimate);
-double hash_output_from_command(entropy_source_t *src, char *hash);
-
-entropy_source_t entropy_sources[] = {
-#ifdef PROG_LS
- { 0.002, 0, 1, PROG_LS, { "ls", "-alni", "/var/log", NULL } },
- { 0.002, 0, 1, PROG_LS, { "ls", "-alni", "/var/adm", NULL } },
- { 0.002, 0, 1, PROG_LS, { "ls", "-alni", "/var/mail", NULL } },
- { 0.002, 0, 1, PROG_LS, { "ls", "-alni", "/var/spool/mail", NULL } },
- { 0.002, 0, 1, PROG_LS, { "ls", "-alni", "/proc", NULL } },
- { 0.002, 0, 1, PROG_LS, { "ls", "-alni", "/tmp", NULL } },
-#endif
-#ifdef PROG_NETSTAT
- { 0.005, 0, 1, PROG_NETSTAT, { "netstat","-an", NULL, NULL } },
- { 0.010, 0, 1, PROG_NETSTAT, { "netstat","-in", NULL, NULL } },
- { 0.002, 0, 1, PROG_NETSTAT, { "netstat","-rn", NULL, NULL } },
- { 0.002, 0, 1, PROG_NETSTAT, { "netstat","-s", NULL, NULL } },
-#endif
-#ifdef PROG_ARP
- { 0.002, 0, 1, PROG_ARP, { "arp","-a","-n", NULL } },
-#endif
-#ifdef PROG_IFCONFIG
- { 0.002, 0, 1, PROG_IFCONFIG, { "ifconfig", "-a", NULL, NULL } },
-#endif
-#ifdef PROG_PS
- { 0.003, 0, 1, PROG_PS, { "ps", "laxww", NULL, NULL } },
- { 0.003, 0, 1, PROG_PS, { "ps", "-al", NULL, NULL } },
- { 0.003, 0, 1, PROG_PS, { "ps", "-efl", NULL, NULL } },
-#endif
-#ifdef PROG_W
- { 0.005, 0, 1, PROG_W, { "w", NULL, NULL, NULL } },
-#endif
-#ifdef PROG_WHO
- { 0.001, 0, 1, PROG_WHO, { "who","-i", NULL, NULL } },
-#endif
-#ifdef PROG_LAST
- { 0.001, 0, 1, PROG_LAST, { "last", NULL, NULL, NULL } },
-#endif
-#ifdef PROG_LASTLOG
- { 0.001, 0, 1, PROG_LASTLOG, { "lastlog", NULL, NULL, NULL } },
-#endif
-#ifdef PROG_DF
- { 0.010, 0, 1, PROG_DF, { "df", NULL, NULL, NULL } },
- { 0.010, 0, 1, PROG_DF, { "df", "-i", NULL, NULL } },
-#endif
-#ifdef PROG_VMSTAT
- { 0.010, 0, 1, PROG_VMSTAT, { "vmstat", NULL, NULL, NULL } },
-#endif
-#ifdef PROG_UPTIME
- { 0.001, 0, 1, PROG_UPTIME, { "uptime", NULL, NULL, NULL } },
-#endif
-#ifdef PROG_IPCS
- { 0.001, 0, 1, PROG_IPCS, { "-a", NULL, NULL, NULL } },
-#endif
-#ifdef PROG_TAIL
- { 0.001, 0, 1, PROG_TAIL, { "tail", "-200", "/var/log/messages", NULL, NULL } },
- { 0.001, 0, 1, PROG_TAIL, { "tail", "-200", "/var/log/syslog", NULL, NULL } },
- { 0.001, 0, 1, PROG_TAIL, { "tail", "-200", "/var/adm/messages", NULL, NULL } },
- { 0.001, 0, 1, PROG_TAIL, { "tail", "-200", "/var/adm/syslog", NULL, NULL } },
- { 0.001, 0, 1, PROG_TAIL, { "tail", "-200", "/var/log/maillog", NULL, NULL } },
- { 0.001, 0, 1, PROG_TAIL, { "tail", "-200", "/var/adm/maillog", NULL, NULL } },
-#endif
- { 0.000, 0, 0, NULL, { NULL, NULL, NULL, NULL, NULL } },
-};
-
-double
-stir_from_system(void)
-{
- double total_entropy_estimate;
- long int i;
-
- total_entropy_estimate = 0;
-
- i = getpid();
- RAND_add(&i, sizeof(i), 0.1);
- total_entropy_estimate += 0.1;
-
- i = getppid();
- RAND_add(&i, sizeof(i), 0.1);
- total_entropy_estimate += 0.1;
-
- i = getuid();
- RAND_add(&i, sizeof(i), 0.0);
- i = getgid();
- RAND_add(&i, sizeof(i), 0.0);
-
- total_entropy_estimate += stir_gettimeofday(1.0);
- total_entropy_estimate += stir_clock(0.2);
- total_entropy_estimate += stir_rusage(RUSAGE_SELF, 2.0);
-
- return(total_entropy_estimate);
-}
-
-double
-stir_from_programs(void)
-{
- int i;
- int c;
- double entropy_estimate;
- double total_entropy_estimate;
- char hash[SHA_DIGEST_LENGTH];
-
- /*
- * Run through list of programs twice to catch differences
- */
- total_entropy_estimate = 0;
- for(i = 0; i < 2; i++) {
- c = 0;
- while (entropy_sources[c].path != NULL) {
-
- if (!entropy_sources[c].badness) {
- /* Hash output from command */
- entropy_estimate = hash_output_from_command(&entropy_sources[c], hash);
-
- /* Scale back entropy estimate according to command's rate */
- entropy_estimate *= entropy_sources[c].rate;
-
- /* Upper bound of entropy estimate is SHA_DIGEST_LENGTH */
- if (entropy_estimate > SHA_DIGEST_LENGTH)
- entropy_estimate = SHA_DIGEST_LENGTH;
-
- /* * Scale back estimates for subsequent passes through list */
- entropy_estimate /= 10.0 * (i + 1.0);
-
- /* Stir it in */
- RAND_add(hash, sizeof(hash), entropy_estimate);
-
-/* FIXME: turn this off later */
-#if 1
- debug("Got %0.2f bytes of entropy from %s", entropy_estimate,
- entropy_sources[c].path);
-#endif
-
- total_entropy_estimate += entropy_estimate;