X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshrand.c;h=a7b3dc4eced186a9a033ab744887c39426b4a644;hb=fc9dd5cbaaa5466d09a2a53c33c175280069db59;hp=7c401af4a06de6b340b34feaada3bae8a4d426cc;hpb=dac0d4569960236264898b112707c2b574eb285b;p=PuTTY.git diff --git a/sshrand.c b/sshrand.c index 7c401af4..a7b3dc4e 100644 --- a/sshrand.c +++ b/sshrand.c @@ -2,6 +2,7 @@ * cryptographic random number generator for PuTTY's ssh client */ +#include "putty.h" #include "ssh.h" void noise_get_heavy(void (*func) (void *, int)); @@ -41,7 +42,7 @@ struct RandPool { static struct RandPool pool; int random_active = 0; -void random_stir(void) +static void random_stir(void) { word32 block[HASHINPUT / sizeof(word32)]; word32 digest[HASHSIZE / sizeof(word32)]; @@ -183,12 +184,14 @@ static void random_add_heavynoise_bitbybit(void *noise, int length) void random_init(void) { - memset(&pool, 0, sizeof(pool)); /* just to start with */ + if (!random_active) { + memset(&pool, 0, sizeof(pool)); /* just to start with */ - random_active = 1; + random_active = 1; - noise_get_heavy(random_add_heavynoise_bitbybit); - random_stir(); + noise_get_heavy(random_add_heavynoise_bitbybit); + random_stir(); + } } int random_byte(void) @@ -201,7 +204,10 @@ int random_byte(void) void random_get_savedata(void **data, int *len) { + void *buf = snewn(POOLSIZE / 2, char); random_stir(); - *data = pool.pool + pool.poolpos; + memcpy(buf, pool.pool + pool.poolpos, POOLSIZE / 2); *len = POOLSIZE / 2; + *data = buf; + random_stir(); }