chg: [client] getentropy is not available on old Linux distributions

pull/23/head
Gerard Wagener 2019-04-05 15:02:55 +02:00
parent 4e8b287606
commit 88e22b3e62
1 changed files with 10 additions and 1 deletions

View File

@ -98,6 +98,15 @@ int random_get_fd(void)
return fd;
}
int my_getentropy(void *buf, size_t buflen)
{
if (buflen > 256) {
errno = EIO;
return -1;
}
return syscall(SYS_getrandom, buf, buflen, 0);
}
/*
* Generate a stream of random nbytes into buf.
* Use /dev/urandom if possible, and if not,
@ -117,7 +126,7 @@ void random_get_bytes(void *buf, size_t nbytes)
int x;
errno = 0;
x = getentropy(cp, n);
x = my_getentropy(cp, n);
if (x > 0) { /* success */
n -= x;
cp += x;