aboutsummaryrefslogtreecommitdiff
path: root/lib/random/sysrandom.h
blob: ea29296bce317f91b9a8e2618ef1d197a23a34fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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