mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
Add getentropy, getrandom, <sys/random.h> [BZ #17252]
This commit is contained in:
@ -2090,6 +2090,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -2001,6 +2001,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -91,6 +91,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
73
sysdeps/unix/sysv/linux/getentropy.c
Normal file
73
sysdeps/unix/sysv/linux/getentropy.c
Normal file
@ -0,0 +1,73 @@
|
||||
/* Implementation of getentropy based on the getrandom system call.
|
||||
Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <sys/random.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __NR_getrandom
|
||||
/* Write LENGTH bytes of randomness starting at BUFFER. Return 0 on
|
||||
success and -1 on failure. */
|
||||
int
|
||||
getentropy (void *buffer, size_t length)
|
||||
{
|
||||
/* The interface is documented to return EIO for buffer lengths
|
||||
longer than 256 bytes. */
|
||||
if (length > 256)
|
||||
{
|
||||
__set_errno (EIO);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Try to fill the buffer completely. Even with the 256 byte limit
|
||||
above, we might still receive an EINTR error (when blocking
|
||||
during boot). */
|
||||
void *end = buffer + length;
|
||||
while (buffer < end)
|
||||
{
|
||||
/* NB: No cancellation point. */
|
||||
ssize_t bytes = INLINE_SYSCALL_CALL (getrandom, buffer, end - buffer, 0);
|
||||
if (bytes < 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
/* Try again if interrupted by a signal. */
|
||||
continue;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
if (bytes == 0)
|
||||
{
|
||||
/* No more bytes available. This should not happen under
|
||||
normal circumstances. */
|
||||
__set_errno (EIO);
|
||||
return -1;
|
||||
}
|
||||
/* Try again in case of a short read. */
|
||||
buffer += bytes;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int
|
||||
getentropy (void *buffer, size_t length)
|
||||
{
|
||||
__set_errno (ENOSYS);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
43
sysdeps/unix/sysv/linux/getrandom.c
Normal file
43
sysdeps/unix/sysv/linux/getrandom.c
Normal file
@ -0,0 +1,43 @@
|
||||
/* Implementation of the getrandom system call.
|
||||
Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <sys/random.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sysdep-cancel.h>
|
||||
|
||||
#ifdef __NR_getrandom
|
||||
/* Write LENGTH bytes of randomness starting at BUFFER. Return 0 on
|
||||
success and -1 on failure. */
|
||||
ssize_t
|
||||
getrandom (void *buffer, size_t length, unsigned int flags)
|
||||
{
|
||||
return SYSCALL_CANCEL (getrandom, buffer, length, flags);
|
||||
}
|
||||
#else
|
||||
/* Always provide a definition, even if the kernel headers lack the
|
||||
system call number. */
|
||||
ssize_t
|
||||
getrandom (void *buffer, size_t length, unsigned int flags)
|
||||
{
|
||||
/* Ideally, we would add a cancellation point here, but we currently
|
||||
cannot do so inside libc. */
|
||||
__set_errno (ENOSYS);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
@ -1855,6 +1855,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -2013,6 +2013,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1877,6 +1877,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -92,6 +92,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1969,6 +1969,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -2090,6 +2090,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1944,6 +1944,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1942,6 +1942,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1940,6 +1940,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1935,6 +1935,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -2131,6 +2131,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1973,6 +1973,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1978,6 +1978,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -2178,6 +2178,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -92,6 +92,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1973,6 +1973,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1874,6 +1874,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1859,6 +1859,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1965,6 +1965,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1903,6 +1903,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -2097,6 +2097,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -2097,6 +2097,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -2097,6 +2097,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -1854,6 +1854,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
@ -2097,6 +2097,8 @@ GLIBC_2.23 fts64_set F
|
||||
GLIBC_2.24 GLIBC_2.24 A
|
||||
GLIBC_2.24 quick_exit F
|
||||
GLIBC_2.25 GLIBC_2.25 A
|
||||
GLIBC_2.25 getentropy F
|
||||
GLIBC_2.25 getrandom F
|
||||
GLIBC_2.25 strfromd F
|
||||
GLIBC_2.25 strfromf F
|
||||
GLIBC_2.25 strfroml F
|
||||
|
Reference in New Issue
Block a user