Throw away "./" in findfile so that the Mac makefile has valid paths.
[sgt/putty] / mac / macnoise.c
CommitLineData
d4af3006 1/*
2 * Noise generation for PuTTY's cryptographic random number
3 * generator.
4 */
5
62cd4f18 6#include <Processes.h>
d4af3006 7#include <Types.h>
8#include <Timer.h>
9
10#include "putty.h"
11#include "ssh.h"
12#include "storage.h"
13
14/*
15 * This function is called once, at PuTTY startup, and will do some
16 * seriously silly things like listing directories and getting disk
17 * free space and a process snapshot.
18 */
19
62cd4f18 20static void noise_get_processes(void (*func) (void *, int))
21{
22 ProcessSerialNumber psn = {0, kNoProcess};
23 ProcessInfoRec info;
24
25 for (;;) {
26 GetNextProcess(&psn);
27 if (psn.highLongOfPSN == 0 && psn.lowLongOfPSN == kNoProcess) return;
28 info.processInfoLength = sizeof(info);
29 info.processName = NULL;
30 info.processAppSpec = NULL;
31 GetProcessInformation(&psn, &info);
32 func(&info, sizeof(info));
33 }
34}
35
d4af3006 36void noise_get_heavy(void (*func) (void *, int))
37{
38
62cd4f18 39 noise_get_light(func);
40 noise_get_processes(func);
d4af3006 41 read_random_seed(func);
42 /* Update the seed immediately, in case another instance uses it. */
43 random_save_seed();
44}
45
46void random_save_seed(void)
47{
48 int len;
49 void *data;
50
51 if (random_active) {
52 random_get_savedata(&data, &len);
53 write_random_seed(data, len);
54 sfree(data);
55 }
56}
57
58/*
59 * This function is called every time the random pool needs
60 * stirring, and will acquire the system time.
61 */
62void noise_get_light(void (*func) (void *, int))
63{
64 UnsignedWide utc;
65
66 Microseconds(&utc);
67 func(&utc, sizeof(utc));
68}
69
70/*
71 * This function is called on every keypress or mouse move, and
72 * will add the current time to the noise pool. It gets the scan
73 * code or mouse position passed in, and adds that too.
74 */
75void noise_ultralight(unsigned long data)
76{
77 UnsignedWide utc;
78
79 Microseconds(&utc);
80 random_add_noise(&utc, sizeof(utc));
81 random_add_noise(&data, sizeof(data));
82}
83
84/*
85 * Local Variables:
86 * c-file-style: "simon"
87 * End:
88 */