2 * Noise generation for PuTTY's cryptographic random number
14 * This function is called once, at PuTTY startup, and will do some
15 * seriously silly things like listing directories and getting disk
16 * free space and a process snapshot.
19 void noise_get_heavy(void (*func) (void *, int)) {
21 WIN32_FIND_DATA finddata;
22 char winpath[MAX_PATH+3];
24 GetWindowsDirectory(winpath, sizeof(winpath));
25 strcat(winpath, "\\*");
26 srch = FindFirstFile(winpath, &finddata);
27 if (srch != INVALID_HANDLE_VALUE) {
29 func(&finddata, sizeof(finddata));
30 } while (FindNextFile(srch, &finddata));
34 read_random_seed(func);
37 void random_save_seed(void) {
41 random_get_savedata(&data, &len);
42 write_random_seed(data, len);
46 * This function is called every time the random pool needs
47 * stirring, and will acquire the system time in all available
48 * forms and the battery status.
50 void noise_get_light(void (*func) (void *, int)) {
54 SYSTEM_POWER_STATUS pwrstat;
56 GetSystemTime(&systime);
57 func(&systime, sizeof(systime));
59 GetSystemTimeAdjustment(&adjust[0], &adjust[1], &rubbish);
60 func(&adjust, sizeof(adjust));
63 if (GetSystemPowerStatus(&pwrstat))
64 func(&pwrstat, sizeof(pwrstat));
69 * This function is called on every keypress or mouse move, and
70 * will add the current Windows time and performance monitor
71 * counter to the noise pool. It gets the scan code or mouse
74 void noise_ultralight(DWORD data) {
76 LARGE_INTEGER perftime;
78 random_add_noise(&data, sizeof(DWORD));
80 wintime = GetTickCount();
81 random_add_noise(&wintime, sizeof(DWORD));
83 if (QueryPerformanceCounter(&perftime))
84 random_add_noise(&perftime, sizeof(perftime));