2 * Noise generation for PuTTY's cryptographic random number
16 * FIXME. This module currently depends critically on /dev/urandom,
17 * because it has no fallback mechanism for doing anything else.
20 static void read_dev_urandom(char *buf, int len)
25 fd = open("/dev/urandom", O_RDONLY);
27 perror("/dev/urandom: open");
33 ret = read(fd, buf+ngot, len-ngot);
35 perror("/dev/urandom: read");
43 * This function is called once, at PuTTY startup. Currently it
44 * will read 32 bytes out of /dev/urandom and seed the internal
45 * generator with them.
48 void noise_get_heavy(void (*func) (void *, int))
51 read_dev_urandom(buf, sizeof(buf));
52 func(buf, sizeof(buf));
55 void random_save_seed(void)
57 /* Currently we do nothing here. FIXME? */
61 * This function is called every time the urandom pool needs
62 * stirring, and will acquire the system time.
64 void noise_get_light(void (*func) (void *, int))
67 gettimeofday(&tv, NULL);
68 func(&tv, sizeof(tv));
72 * This function is called on a timer, and it will just pull some
73 * stuff out of /dev/urandom. FIXME: really I suspect we ought not
74 * to deplete /dev/urandom like this. Better to grab something more
77 void noise_regular(void)
80 read_dev_urandom(buf, sizeof(buf));
81 random_add_noise(buf, sizeof(buf));
85 * This function is called on every keypress or mouse move, and
86 * will add the current time to the noise pool. It gets the scan
87 * code or mouse position passed in, and adds that too.
89 void noise_ultralight(unsigned long data)
92 gettimeofday(&tv, NULL);
93 random_add_noise(&tv, sizeof(tv));
94 random_add_noise(&data, sizeof(data));