X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshrand.c;h=43b81234240f8d9e7ca37d51c5e89276a1bbf7ca;hb=f237e23affe0460e529ec200a9490de5e68ae0bf;hp=a7b3dc4eced186a9a033ab744887c39426b4a644;hpb=06e9857f891a84dec25f930d7670cae5a593adb5;p=PuTTY.git diff --git a/sshrand.c b/sshrand.c index a7b3dc4e..43b81234 100644 --- a/sshrand.c +++ b/sshrand.c @@ -5,6 +5,9 @@ #include "putty.h" #include "ssh.h" +/* Collect environmental noise every 5 minutes */ +#define NOISE_REGULAR_INTERVAL (5*60*TICKSPERSEC) + void noise_get_heavy(void (*func) (void *, int)); void noise_get_light(void (*func) (void *, int)); @@ -41,6 +44,7 @@ struct RandPool { static struct RandPool pool; int random_active = 0; +long next_noise_collection; static void random_stir(void) { @@ -182,16 +186,33 @@ static void random_add_heavynoise_bitbybit(void *noise, int length) pool.poolpos = i; } -void random_init(void) +static void random_timer(void *ctx, long now) +{ + if (random_active > 0 && now - next_noise_collection >= 0) { + noise_regular(); + next_noise_collection = + schedule_timer(NOISE_REGULAR_INTERVAL, random_timer, &pool); + } +} + +void random_ref(void) { if (!random_active) { memset(&pool, 0, sizeof(pool)); /* just to start with */ - random_active = 1; - noise_get_heavy(random_add_heavynoise_bitbybit); random_stir(); + + next_noise_collection = + schedule_timer(NOISE_REGULAR_INTERVAL, random_timer, &pool); } + + random_active++; +} + +void random_unref(void) +{ + random_active--; } int random_byte(void)