* cryptographic random number generator for PuTTY's ssh client
*/
+#include "putty.h"
#include "ssh.h"
void noise_get_heavy(void (*func) (void *, int));
};
static struct RandPool pool;
-static int random_active = 0;
+int random_active = 0;
-void random_stir(void)
+static void random_stir(void)
{
word32 block[HASHINPUT / sizeof(word32)];
word32 digest[HASHSIZE / sizeof(word32)];
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)
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();
}