+#include "../crypto.h"
+
+#ifndef HAVE_MINGW
+
+static int random_fd = -1;
+
+static void random_init(void) {
+ random_fd = open("/dev/urandom", O_RDONLY);
+
+ if(random_fd < 0) {
+ random_fd = open("/dev/random", O_RDONLY);
+ }
+
+ if(random_fd < 0) {
+ fprintf(stderr, "Could not open source of random numbers: %s\n", strerror(errno));
+ abort();
+ }
+}
+
+static void random_exit(void) {
+ close(random_fd);
+}
+
+void randomize(void *vout, size_t outlen) {
+ uint8_t *out = vout;
+
+ while(outlen) {
+ ssize_t len = read(random_fd, out, outlen);