diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/stdlib/stdlib.c | 14 | ||||
| -rw-r--r-- | src/stdlib/threads.c | 14 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c index 4a1f7dd8..97c7b219 100644 --- a/src/stdlib/stdlib.c +++ b/src/stdlib/stdlib.c @@ -10,7 +10,6 @@ #include <stdint.h> #include <stdlib.h> #include <sys/param.h> -#include <sys/random.h> #include <time.h> #include "print.h" @@ -30,6 +29,19 @@ #include "text.h" #include "util.h" +#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 + public bool USE_COLOR; static void signal_handler(int sig, siginfo_t *, void *) diff --git a/src/stdlib/threads.c b/src/stdlib/threads.c index 9ad68c81..05f5a941 100644 --- a/src/stdlib/threads.c +++ b/src/stdlib/threads.c @@ -10,7 +10,6 @@ #include <stdlib.h> #include <pthread.h> #include <sys/param.h> -#include <sys/random.h> #include "arrays.h" #include "datatypes.h" @@ -21,6 +20,19 @@ #include "types.h" #include "util.h" +#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 + static void *run_thread(Closure_t *closure) { uint8_t *random_bytes = GC_MALLOC_ATOMIC(40); |
