Unlike getrandom(), this function is supported by most BSDs
(with the exception of NetBSD), and by various Illumos distributions.
'linux/if_tun.h',
'netpacket/packet.h',
'sys/epoll.h',
- 'sys/random.h',
]
-check_functions += [
- 'recvmmsg',
- 'getrandom',
-]
+check_functions += 'recvmmsg'
src_tincd += files('device.c')
'sys/ioctl.h',
'sys/mman.h',
'sys/param.h',
+ 'sys/random.h',
'sys/resource.h',
'sys/socket.h',
'sys/stat.h',
'explicit_bzero',
'explicit_memset',
'fchmod',
+ 'getentropy',
'gettimeofday',
'memset_s',
'mlockall',
#include "random.h"
-#ifndef HAVE_GETRANDOM
+#ifndef HAVE_GETENTROPY
static int random_fd = -1;
#endif
void random_init(void) {
-#ifndef HAVE_GETRANDOM
+#ifndef HAVE_GETENTROPY
random_fd = open("/dev/urandom", O_RDONLY);
if(random_fd < 0) {
}
void random_exit(void) {
-#ifndef HAVE_GETRANDOM
+#ifndef HAVE_GETENTROPY
close(random_fd);
#endif
}
uint8_t *out = vout;
while(outlen) {
-#ifdef HAVE_GETRANDOM
- ssize_t len = getrandom(out, outlen, 0);
+#ifdef HAVE_GETENTROPY
+ int reqlen = (int) MIN(256, outlen);
+ int len = !getentropy(out, reqlen) ? reqlen : -1;
#else
ssize_t len = read(random_fd, out, outlen);
#endif
#include "unittest.h"
-#ifdef HAVE_GETRANDOM
+#ifdef HAVE_GETENTROPY
int main(void) {
return 1;
}
randomize(buf, sizeof(buf));
return 0;
}
-#endif // HAVE_GETRANDOM
+#endif // HAVE_GETENTROPY