diff --git a/Recipe b/Recipe index 18f5637a..216ef967 100644 --- a/Recipe +++ b/Recipe @@ -239,7 +239,8 @@ pageant : [G] winpgnt sshrsa sshpubk sshdes sshbn sshmd5 version tree234 puttygen : [G] winpgen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version + sshrand winnoise sshsha winstore misc winctrls sshrsa sshdss winmisc - + sshpubk sshaes sshsh512 import winutils puttygen.res tree234 LIBS + + sshpubk sshaes sshsh512 import winutils puttygen.res tree234 + + notiming LIBS pterm : [X] UXTERM uxmisc misc ldisc settings pty uxsel BE_NONE uxstore + signal CHARSET cmdline ptermm version @@ -252,7 +253,7 @@ plink : [U] uxplink uxcons NONSSH UXSSH BE_ALL logging UXMISC signal ux_x11 puttygen : [U] cmdgen sshrsag sshdssg sshprime sshdes sshbn sshmd5 version + sshrand uxnoise sshsha misc sshrsa sshdss uxcons uxstore uxmisc - + sshpubk sshaes sshsh512 import puttygen.res tree234 uxgen + + sshpubk sshaes sshsh512 import puttygen.res tree234 uxgen notiming pscp : [U] scp uxsftp uxcons UXSSH BE_SSH SFTP wildcard UXMISC psftp : [U] psftp uxsftp uxcons UXSSH BE_SSH SFTP UXMISC diff --git a/be_nossh.c b/be_nossh.c index 90ab9987..18ba32a7 100644 --- a/be_nossh.c +++ b/be_nossh.c @@ -31,7 +31,3 @@ void random_destroy_seed(void) void noise_ultralight(unsigned long data) { } - -void noise_regular(void) -{ -} diff --git a/cmdgen.c b/cmdgen.c index 467bab62..42772aa3 100644 --- a/cmdgen.c +++ b/cmdgen.c @@ -616,7 +616,7 @@ int main(int argc, char **argv) else strftime(default_comment, 30, "rsa-key-%Y%m%d", tm); - random_init(); + random_ref(); entropy = get_random_data(bits / 8); random_add_heavynoise(entropy, bits / 8); memset(entropy, 0, bits/8); diff --git a/putty.h b/putty.h index 4ad3124a..d880dbe2 100644 --- a/putty.h +++ b/putty.h @@ -742,10 +742,14 @@ void luni_send(void *, wchar_t * widebuf, int len, int interactive); */ void random_add_noise(void *noise, int length); -void random_init(void); int random_byte(void); void random_get_savedata(void **data, int *len); extern int random_active; +/* The random number subsystem is activated if at least one other entity + * within the program expresses an interest in it. So each SSH session + * calls random_ref on startup and random_unref on shutdown. */ +void random_ref(void); +void random_unref(void); /* * Exports from pinger.c. diff --git a/ssh.c b/ssh.c index 422897f2..07d06f1f 100644 --- a/ssh.c +++ b/ssh.c @@ -2576,8 +2576,6 @@ static int do_ssh1_login(Ssh ssh, unsigned char *in, int inlen, crBegin(ssh->do_ssh1_login_crstate); - random_init(); - if (!pktin) crWaitUntil(pktin); @@ -4299,7 +4297,6 @@ static int do_ssh2_transport(Ssh ssh, unsigned char *in, int inlen, s->csmac_tobe = s->scmac_tobe = NULL; s->cscomp_tobe = s->sccomp_tobe = NULL; - random_init(); s->first_kex = 1; { @@ -7145,6 +7142,8 @@ static const char *ssh_init(void *frontend_handle, void **backend_handle, if (p != NULL) return p; + random_ref(); + return NULL; } @@ -7223,6 +7222,8 @@ static void ssh_free(void *handle) sfree(ssh); if (ssh->pinger) pinger_free(ssh->pinger); + + random_unref(); } /* 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) diff --git a/windows/winpgen.c b/windows/winpgen.c index 3f2be92e..e80dbfec 100644 --- a/windows/winpgen.c +++ b/windows/winpgen.c @@ -1445,7 +1445,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) help_path = NULL; } - random_init(); + random_ref(); return DialogBox(hinst, MAKEINTRESOURCE(201), NULL, MainDlgProc) != IDOK; }