X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/ab076e024dead93707ab637800ddcdad0a289e0a..6702cd9b0acb17017ae68581582cc6d9f158aef8:/sshrand.c diff --git a/sshrand.c b/sshrand.c index 26fcfe52..797fce73 100644 --- a/sshrand.c +++ b/sshrand.c @@ -4,6 +4,7 @@ #include "putty.h" #include "ssh.h" +#include /* Collect environmental noise every 5 minutes */ #define NOISE_REGULAR_INTERVAL (5*60*TICKSPERSEC) @@ -198,9 +199,9 @@ static void random_add_heavynoise_bitbybit(void *noise, int length) pool.poolpos = i; } -static void random_timer(void *ctx, long now) +static void random_timer(void *ctx, unsigned long now) { - if (random_active > 0 && now - next_noise_collection >= 0) { + if (random_active > 0 && now == next_noise_collection) { noise_regular(); next_noise_collection = schedule_timer(NOISE_REGULAR_INTERVAL, random_timer, &pool); @@ -212,23 +213,30 @@ void random_ref(void) if (!random_active) { memset(&pool, 0, sizeof(pool)); /* just to start with */ + random_active++; + 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) { + assert(random_active > 0); + if (random_active == 1) { + random_save_seed(); + expire_timer_context(&pool); + } random_active--; } int random_byte(void) { + assert(random_active); + if (pool.poolpos >= POOLSIZE) random_stir();