Loose end from timing shakeup: sshrand.c is now a client of

timing.c, and hence takes its own responsibility for calling
noise_regular() at regular intervals. Again, this means it will be
called consistently in _all_ the SSH-speaking tools, not just those
in which I remembered to call it!

[originally from svn r4913]
This commit is contained in:
Simon Tatham 2004-11-27 19:56:38 +00:00
Родитель 9fc67313fb
Коммит 8c69ba0672
7 изменённых файлов: 38 добавлений и 15 удалений

5
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

Просмотреть файл

@ -31,7 +31,3 @@ void random_destroy_seed(void)
void noise_ultralight(unsigned long data)
{
}
void noise_regular(void)
{
}

Просмотреть файл

@ -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);

Просмотреть файл

@ -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.

7
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();
}
/*

Просмотреть файл

@ -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)

Просмотреть файл

@ -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;
}