+#define SEED_SIZE 512
+
+void read_random_seed(noise_consumer_t consumer)
+{
+ short puttyVRefNum;
+ long puttyDirID;
+ OSErr error;
+ char buf[SEED_SIZE];
+ short refnum;
+ long count = SEED_SIZE;
+
+ if (get_putty_dir(kDontCreateFolder, &puttyVRefNum, &puttyDirID) != noErr)
+ return;
+ if (HOpenDF(puttyVRefNum, puttyDirID, "\pPuTTY Random Seed", fsRdPerm,
+ &refnum) != noErr)
+ return;
+ error = FSRead(refnum, &count, buf);
+ if (error != noErr && error != eofErr)
+ return;
+ (*consumer)(buf, count);
+ FSClose(refnum);
+}
+
+/*
+ * We don't bother with the usual FSpExchangeFiles dance here because
+ * it doesn't really matter if the old random seed gets lost.
+ */
+void write_random_seed(void *data, int len)
+{
+ short puttyVRefNum;
+ long puttyDirID;
+ OSErr error;
+ FSSpec dstfile;
+ short refnum;
+ long count = len;
+
+ if (get_putty_dir(kCreateFolder, &puttyVRefNum, &puttyDirID) != noErr)
+ return;
+
+ error = FSMakeFSSpec(puttyVRefNum, puttyDirID, "\pPuTTY Random Seed",
+ &dstfile);
+ if (error == fnfErr) {
+ /* Set up standard resources */
+ FSpCreateResFile(&dstfile, INTERNAL_CREATOR, SEED_TYPE, smRoman);
+ refnum = FSpOpenResFile(&dstfile, fsWrPerm);
+ if (ResError() == noErr) {
+ copy_resource('STR ', -16397);
+ CloseResFile(refnum);
+ }
+ } else if (error != noErr) return;
+
+ if (FSpOpenDF(&dstfile, fsWrPerm, &refnum) != noErr) return;
+ FSWrite(refnum, &count, data);
+ FSClose(refnum);
+
+ return;
+}