X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=sshrand.c;h=31b1739e46c9a2b16f57114632d4ef9696307d54;hb=d33d8d72ad936ae05ca1b5ecb55b129bf3d4b9f1;hp=c26fc75706541c775d1c44864a2ca0e8c057cac7;hpb=8966f7c1eac34b6d732aa54b32d67819eb6bdce2;p=PuTTY.git diff --git a/sshrand.c b/sshrand.c index c26fc757..31b1739e 100644 --- a/sshrand.c +++ b/sshrand.c @@ -45,8 +45,23 @@ struct RandPool { int stir_pending; }; -static struct RandPool pool; int random_active = 0; + +#ifdef FUZZING +/* + * Special dummy version of the RNG for use when fuzzing. + */ +void random_add_noise(void *noise, int length) { } +void random_add_heavynoise(void *noise, int length) { } +void random_ref(void) { } +void random_unref(void) { } +int random_byte(void) +{ + return 0x45; /* Chosen by eight fair coin tosses */ +} +void random_get_savedata(void **data, int *len) { } +#else /* !FUZZING */ +static struct RandPool pool; long next_noise_collection; #ifdef RANDOM_DIAGNOSTICS @@ -225,7 +240,7 @@ void random_add_noise(void *noise, int length) length -= HASHINPUT - pool.incomingpos; SHATransform((word32 *) pool.incoming, (word32 *) pool.incomingb); for (i = 0; i < HASHSIZE; i++) { - pool.pool[pool.poolpos++] ^= pool.incomingb[i]; + pool.pool[pool.poolpos++] ^= pool.incoming[i]; if (pool.poolpos >= POOLSIZE) pool.poolpos = 0; } @@ -288,14 +303,13 @@ 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) @@ -327,3 +341,4 @@ void random_get_savedata(void **data, int *len) *data = buf; random_stir(); } +#endif