6 static int random_fd = -1;
9 void random_init(void) {
10 #ifndef HAVE_GETRANDOM
11 random_fd = open("/dev/urandom", O_RDONLY);
14 random_fd = open("/dev/random", O_RDONLY);
18 fprintf(stderr, "Could not open source of random numbers: %s\n", strerror(errno));
25 void random_exit(void) {
26 #ifndef HAVE_GETRANDOM
31 void randomize(void *vout, size_t outlen) {
36 ssize_t len = getrandom(out, outlen, 0);
38 ssize_t len = read(random_fd, out, outlen);
42 if(len == -1 && (errno == EAGAIN || errno == EINTR)) {
46 fprintf(stderr, "Could not read random numbers: %s\n", strerror(errno));