glib-aux: add getrandom() syscall wrapper as fallback

We make an effort to get a better fallback case with
_bad_random_bytes().

Also make an effort to get good randomness in the first place. Even if
we compile against libc headers that don't provide getrandom(). Also,
this isn't really ugly, because for a long time glibc was reluctant to
add getrandom() wrapper and using syscall() was the way to go.

(cherry picked from commit 05a6936bef)
This commit is contained in:
Thomas Haller 2021-07-09 08:18:57 +02:00
parent f84ebc4611
commit e427f53b8f
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -9,6 +9,7 @@
#include <fcntl.h>
#include <sys/auxv.h>
#include <sys/syscall.h>
#if USE_SYS_RANDOM_H
#include <sys/random.h>
@ -21,6 +22,26 @@
/*****************************************************************************/
#if !defined(SYS_getrandom) && defined(__NR_getrandom)
#define SYS_getrandom __NR_getrandom
#endif
#ifndef GRND_NONBLOCK
#define GRND_NONBLOCK 0x01
#endif
#if !HAVE_GETRANDOM && defined(SYS_getrandom)
static int
getrandom(void *buf, size_t buflen, unsigned flags)
{
return syscall(SYS_getrandom, buf, buflen, flags);
}
#undef HAVE_GETRANDOM
#define HAVE_GETRANDOM 1
#endif
/*****************************************************************************/
#define STATIC_SALT "l6z5vMBldDlCD6na"
typedef struct _nm_packed {