Rather useless entropy-collection functions for Mac OS. These need work.
authorben <ben@cda61777-01e9-0310-a592-d414129be87e>
Wed, 8 Jan 2003 23:56:48 +0000 (23:56 +0000)
committerben <ben@cda61777-01e9-0310-a592-d414129be87e>
Wed, 8 Jan 2003 23:56:48 +0000 (23:56 +0000)
git-svn-id: svn://svn.tartarus.org/sgt/putty@2502 cda61777-01e9-0310-a592-d414129be87e

mac/macnoise.c [new file with mode: 0644]

diff --git a/mac/macnoise.c b/mac/macnoise.c
new file mode 100644 (file)
index 0000000..8fe70ad
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Noise generation for PuTTY's cryptographic random number
+ * generator.
+ */
+
+#include <Types.h>
+#include <Timer.h>
+
+#include "putty.h"
+#include "ssh.h"
+#include "storage.h"
+
+/*
+ * This function is called once, at PuTTY startup, and will do some
+ * seriously silly things like listing directories and getting disk
+ * free space and a process snapshot.
+ */
+
+void noise_get_heavy(void (*func) (void *, int))
+{
+
+    read_random_seed(func);
+    /* Update the seed immediately, in case another instance uses it. */
+    random_save_seed();
+}
+
+void random_save_seed(void)
+{
+    int len;
+    void *data;
+
+    if (random_active) {
+       random_get_savedata(&data, &len);
+       write_random_seed(data, len);
+       sfree(data);
+    }
+}
+
+/*
+ * This function is called every time the random pool needs
+ * stirring, and will acquire the system time.
+ */
+void noise_get_light(void (*func) (void *, int))
+{
+    UnsignedWide utc;
+
+    Microseconds(&utc);
+    func(&utc, sizeof(utc));
+}
+
+/*
+ * This function is called on every keypress or mouse move, and
+ * will add the current time to the noise pool. It gets the scan
+ * code or mouse position passed in, and adds that too.
+ */
+void noise_ultralight(unsigned long data)
+{
+    UnsignedWide utc;
+
+    Microseconds(&utc);
+    random_add_noise(&utc, sizeof(utc));
+    random_add_noise(&data, sizeof(data));
+}
+
+/*
+ * Local Variables:
+ * c-file-style: "simon"
+ * End:
+ */