mirror of https://github.com/D4-project/d4-core
chg: [client] getentropy is not available on old Linux distributions
parent
4e8b287606
commit
88e22b3e62
|
@ -98,6 +98,15 @@ int random_get_fd(void)
|
||||||
return fd;
|
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.
|
* Generate a stream of random nbytes into buf.
|
||||||
* Use /dev/urandom if possible, and if not,
|
* Use /dev/urandom if possible, and if not,
|
||||||
|
@ -117,7 +126,7 @@ void random_get_bytes(void *buf, size_t nbytes)
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
x = getentropy(cp, n);
|
x = my_getentropy(cp, n);
|
||||||
if (x > 0) { /* success */
|
if (x > 0) { /* success */
|
||||||
n -= x;
|
n -= x;
|
||||||
cp += x;
|
cp += x;
|
||||||
|
|
Loading…
Reference in New Issue