From 6de2d68a700a137bbe55668e036c62280ece8bb5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 1 Apr 2025 16:55:24 -0400 Subject: Moved RNG out of the compiler and into a standalone library --- examples/random/sysrandom.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 examples/random/sysrandom.h (limited to 'examples/random/sysrandom.h') diff --git a/examples/random/sysrandom.h b/examples/random/sysrandom.h new file mode 100644 index 00000000..ea29296b --- /dev/null +++ b/examples/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 +#else + #error "Unsupported platform for secure random number generation" +#endif -- cgit v1.2.3