aboutsummaryrefslogtreecommitdiff
path: root/lib/random/sysrandom.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/random/sysrandom.h')
-rw-r--r--lib/random/sysrandom.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/random/sysrandom.h b/lib/random/sysrandom.h
new file mode 100644
index 00000000..ea29296b
--- /dev/null
+++ b/lib/random/sysrandom.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
+static ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
+ (void)flags;
+ arc4random_buf(buf, buflen);
+ return buflen;
+}
+#elif defined(__linux__)
+// Use getrandom()
+# include <sys/random.h>
+#else
+ #error "Unsupported platform for secure random number generation"
+#endif