diff options
author | Damien Miller <djm@mindrot.org> | 2000-09-29 12:12:36 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2000-09-29 12:12:36 +1100 |
commit | cb5e44a440c1b310a9dc5b8b5abe32fe11ed479b (patch) | |
tree | e71546529e0058787f555ebf3c2fc03ad826bb89 /entropy.c | |
parent | 280e71bcb631d205fec33b1dd695263e2696a3f1 (diff) |
- (djm) Clean up. Strip some unnecessary differences with OpenBSD's code,
tidy necessary differences. Use Markus' new debugN() in entropy.c
Diffstat (limited to 'entropy.c')
-rw-r--r-- | entropy.c | 27 |
1 files changed, 10 insertions, 17 deletions
@@ -35,15 +35,12 @@ | |||
35 | # include <floatingpoint.h> | 35 | # include <floatingpoint.h> |
36 | #endif /* HAVE_FLOATINGPOINT_H */ | 36 | #endif /* HAVE_FLOATINGPOINT_H */ |
37 | 37 | ||
38 | RCSID("$Id: entropy.c,v 1.19 2000/09/16 05:09:28 djm Exp $"); | 38 | RCSID("$Id: entropy.c,v 1.20 2000/09/29 01:12:36 djm Exp $"); |
39 | 39 | ||
40 | #ifndef offsetof | 40 | #ifndef offsetof |
41 | # define offsetof(type, member) ((size_t) &((type *)0)->member) | 41 | # define offsetof(type, member) ((size_t) &((type *)0)->member) |
42 | #endif | 42 | #endif |
43 | 43 | ||
44 | /* Print lots of detail */ | ||
45 | /* #define DEBUG_ENTROPY */ | ||
46 | |||
47 | /* Number of times to pass through command list gathering entropy */ | 44 | /* Number of times to pass through command list gathering entropy */ |
48 | #define NUM_ENTROPY_RUNS 1 | 45 | #define NUM_ENTROPY_RUNS 1 |
49 | 46 | ||
@@ -272,10 +269,8 @@ stir_from_programs(void) | |||
272 | /* Stir it in */ | 269 | /* Stir it in */ |
273 | RAND_add(hash, sizeof(hash), entropy_estimate); | 270 | RAND_add(hash, sizeof(hash), entropy_estimate); |
274 | 271 | ||
275 | #ifdef DEBUG_ENTROPY | 272 | debug3("Got %0.2f bytes of entropy from '%s'", entropy_estimate, |
276 | debug("Got %0.2f bytes of entropy from '%s'", entropy_estimate, | ||
277 | entropy_sources[c].cmdstring); | 273 | entropy_sources[c].cmdstring); |
278 | #endif | ||
279 | 274 | ||
280 | total_entropy_estimate += entropy_estimate; | 275 | total_entropy_estimate += entropy_estimate; |
281 | 276 | ||
@@ -285,10 +280,8 @@ stir_from_programs(void) | |||
285 | total_entropy_estimate += stir_rusage(RUSAGE_SELF, 0.1); | 280 | total_entropy_estimate += stir_rusage(RUSAGE_SELF, 0.1); |
286 | total_entropy_estimate += stir_rusage(RUSAGE_CHILDREN, 0.1); | 281 | total_entropy_estimate += stir_rusage(RUSAGE_CHILDREN, 0.1); |
287 | } else { | 282 | } else { |
288 | #ifdef DEBUG_ENTROPY | 283 | debug2("Command '%s' disabled (badness %d)", |
289 | debug("Command '%s' disabled (badness %d)", | ||
290 | entropy_sources[c].cmdstring, entropy_sources[c].badness); | 284 | entropy_sources[c].cmdstring, entropy_sources[c].badness); |
291 | #endif | ||
292 | 285 | ||
293 | if (entropy_sources[c].badness > 0) | 286 | if (entropy_sources[c].badness > 0) |
294 | entropy_sources[c].badness--; | 287 | entropy_sources[c].badness--; |
@@ -373,6 +366,8 @@ hash_output_from_command(entropy_source_t *src, char *hash) | |||
373 | int total_bytes_read; | 366 | int total_bytes_read; |
374 | SHA_CTX sha; | 367 | SHA_CTX sha; |
375 | 368 | ||
369 | debug3("Reading output from \'%s\'", src->cmdstring); | ||
370 | |||
376 | if (devnull == -1) { | 371 | if (devnull == -1) { |
377 | devnull = open("/dev/null", O_RDWR); | 372 | devnull = open("/dev/null", O_RDWR); |
378 | if (devnull == -1) | 373 | if (devnull == -1) |
@@ -470,12 +465,10 @@ hash_output_from_command(entropy_source_t *src, char *hash) | |||
470 | 465 | ||
471 | close(p[0]); | 466 | close(p[0]); |
472 | 467 | ||
473 | #ifdef DEBUG_ENTROPY | 468 | debug3("Time elapsed: %d msec", msec_elapsed); |
474 | debug("Time elapsed: %d msec", msec_elapsed); | ||
475 | #endif | ||
476 | 469 | ||
477 | if (waitpid(pid, &status, 0) == -1) { | 470 | if (waitpid(pid, &status, 0) == -1) { |
478 | debug("Couldn't wait for child '%s' completion: %s", src->cmdstring, | 471 | error("Couldn't wait for child '%s' completion: %s", src->cmdstring, |
479 | strerror(errno)); | 472 | strerror(errno)); |
480 | return(0.0); | 473 | return(0.0); |
481 | } | 474 | } |
@@ -486,7 +479,7 @@ hash_output_from_command(entropy_source_t *src, char *hash) | |||
486 | /* closing p[0] on timeout causes the entropy command to | 479 | /* closing p[0] on timeout causes the entropy command to |
487 | * SIGPIPE. Take whatever output we got, and mark this command | 480 | * SIGPIPE. Take whatever output we got, and mark this command |
488 | * as slow */ | 481 | * as slow */ |
489 | debug("Command '%s' timed out", src->cmdstring); | 482 | debug2("Command '%s' timed out", src->cmdstring); |
490 | src->sticky_badness *= 2; | 483 | src->sticky_badness *= 2; |
491 | src->badness = src->sticky_badness; | 484 | src->badness = src->sticky_badness; |
492 | return(total_bytes_read); | 485 | return(total_bytes_read); |
@@ -496,13 +489,13 @@ hash_output_from_command(entropy_source_t *src, char *hash) | |||
496 | if (WEXITSTATUS(status)==0) { | 489 | if (WEXITSTATUS(status)==0) { |
497 | return(total_bytes_read); | 490 | return(total_bytes_read); |
498 | } else { | 491 | } else { |
499 | debug("Command '%s' exit status was %d", src->cmdstring, | 492 | debug2("Command '%s' exit status was %d", src->cmdstring, |
500 | WEXITSTATUS(status)); | 493 | WEXITSTATUS(status)); |
501 | src->badness = src->sticky_badness = 128; | 494 | src->badness = src->sticky_badness = 128; |
502 | return (0.0); | 495 | return (0.0); |
503 | } | 496 | } |
504 | } else if (WIFSIGNALED(status)) { | 497 | } else if (WIFSIGNALED(status)) { |
505 | debug("Command '%s' returned on uncaught signal %d !", src->cmdstring, | 498 | debug2("Command '%s' returned on uncaught signal %d !", src->cmdstring, |
506 | status); | 499 | status); |
507 | src->badness = src->sticky_badness = 128; | 500 | src->badness = src->sticky_badness = 128; |
508 | return(0.0); | 501 | return(0.0); |