+/* --- @noise_freewheel@ --- *
+ *
+ * Arguments: @rand_pool *r@ = pointer to a randomness pool
+ *
+ * Returns: Nonzero if some randomness was contributed.
+ *
+ * Use: Runs a free counter for a short while as a desparate attempt
+ * to get randomness from somewhere. This is actually quite
+ * effective.
+ */
+
+#ifdef USE_FREEWHEEL
+
+static jmp_buf fwjmp;
+
+static void fwalarm(int sig)
+{
+ siglongjmp(fwjmp, 1);
+}
+
+int noise_freewheel(rand_pool *r)
+{
+ void (*sigal)(int) = 0;
+ struct itimerval oitv, itv = { { 0, 0 }, { 0, 5000 } };
+ int rc = 0;
+ volatile uint32 fwcount = 0;
+
+ if (!sigsetjmp(fwjmp, 1)) {
+ if ((sigal = signal(SIGALRM, fwalarm)) == SIG_ERR)
+ return (0);
+ if (setitimer(ITIMER_REAL, &itv, &oitv))
+ goto done;
+ for (;;)
+ fwcount++;
+ } else {
+ octet buf[4];
+ STORE32(buf, fwcount);
+ rand_add(r, buf, sizeof(buf), 16);
+ rc = 1;
+ }
+
+done:
+ signal(SIGALRM, sigal);
+ if (oitv.it_value.tv_sec || oitv.it_value.tv_usec)
+ TV_SUB(&oitv.it_value, &oitv.it_value, &itv.it_value);
+ setitimer(ITIMER_REAL, &oitv, 0);
+ return (rc);
+}
+
+#else
+
+int noise_freewheel(rand_pool *r)
+{
+ return (0);
+}
+
+#endif
+
+/* --- @noise_enquire@ --- *
+ *
+ * Arguments: @rand_pool *r@ = pointer to a randomness pool
+ *
+ * Returns: Nonzero if some randomness was contributed.
+ *
+ * Use: Runs some shell commands to enquire about the prevailing
+ * environment. This can gather quite a lot of low-quality
+ * entropy.
+ */
+
+int noise_enquire(rand_pool *r)
+{
+ struct tab {
+ const char *cmd;
+ unsigned rate;
+ } tab[] = {
+ { "ps alxww || ps -elf", 16 },
+ { "netstat -n", 6 },
+ { "ifconfig -a", 8 },
+ { "df", 20 },
+ { "w", 6 },
+ { "ls -align /tmp/.", 10 },
+ { 0, 0 }
+ };
+ int i;
+
+ for (i = 0; tab[i].cmd; i++)
+ noise_filter(r, tab[i].rate, tab[i].cmd);
+ return (1);
+}
+