From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 2B2C91F55B for ; Mon, 25 May 2020 19:38:17 +0000 (UTC) Received: from localhost ([::1]:46590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdIvP-0000yO-Vk for normalperson@yhbt.net; Mon, 25 May 2020 15:38:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdIvI-0000yF-Qa for bug-gnulib@gnu.org; Mon, 25 May 2020 15:38:08 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:41418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdIvF-00078L-Pd for bug-gnulib@gnu.org; Mon, 25 May 2020 15:38:08 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 0A9241600E7 for ; Mon, 25 May 2020 12:38:01 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id x_KtS-ULuCPo; Mon, 25 May 2020 12:37:58 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id DBFEC1600E0; Mon, 25 May 2020 12:37:58 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id YrY551KpL73E; Mon, 25 May 2020 12:37:58 -0700 (PDT) Received: from day.example.com (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id AA8391600D3; Mon, 25 May 2020 12:37:58 -0700 (PDT) From: Paul Eggert To: bug-gnulib@gnu.org Subject: [PATCH] getentropy, getrandom: new modules Date: Mon, 25 May 2020 12:37:53 -0700 Message-Id: <20200525193753.12395-1-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.17.1 Received-SPF: pass client-ip=131.179.128.68; envelope-from=eggert@cs.ucla.edu; helo=zimbra.cs.ucla.edu X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/25 15:38:01 X-ACL-Warn: Detected OS = Linux 3.1-3.10 X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" * MODULES.html.sh (func_all_modules): * lib/unistd.in.h (getentropy, getrandom): * m4/unistd_h.m4 (gl_UNISTD_H, gl_UNISTD_H_DEFAULTS): * modules/unistd (unistd.h): Add support for getentropy, getrandom. * doc/glibc-functions/getentropy.texi (getentropy): * doc/glibc-functions/getrandom.texi (getrandom): These are now fixed on some platforms. * lib/getentropy.c, lib/getrandom.c, lib/sys_random.in.h: * m4/getentropy.m4, m4/getrandom.m4: * modules/getentropy, modules/getentropy-tests: * modules/getrandom, modules/getrandom-tests: * tests/test-getentropy.c, tests/test-getrandom.c: New files. --- ChangeLog | 18 ++++++++++ MODULES.html.sh | 2 ++ doc/glibc-functions/getentropy.texi | 10 ++++-- doc/glibc-functions/getrandom.texi | 8 +++-- lib/getentropy.c | 51 ++++++++++++++++++++++++++++ lib/getrandom.c | 52 +++++++++++++++++++++++++++++ lib/sys_random.in.h | 9 +++++ lib/unistd.in.h | 34 +++++++++++++++++++ m4/getentropy.m4 | 16 +++++++++ m4/getrandom.m4 | 15 +++++++++ m4/unistd_h.m4 | 8 +++-- modules/getentropy | 29 ++++++++++++++++ modules/getentropy-tests | 12 +++++++ modules/getrandom | 44 ++++++++++++++++++++++++ modules/unistd | 4 +++ tests/test-getentropy.c | 43 ++++++++++++++++++++++++ 16 files changed, 348 insertions(+), 7 deletions(-) create mode 100644 lib/getentropy.c create mode 100644 lib/getrandom.c create mode 100644 lib/sys_random.in.h create mode 100644 m4/getentropy.m4 create mode 100644 m4/getrandom.m4 create mode 100644 modules/getentropy create mode 100644 modules/getentropy-tests create mode 100644 modules/getrandom create mode 100644 tests/test-getentropy.c diff --git a/ChangeLog b/ChangeLog index 6b2faf17e..b1acb99ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2020-05-25 Paul Eggert + + getentropy, getrandom: new modules + * MODULES.html.sh (func_all_modules): + * lib/unistd.in.h (getentropy, getrandom): + * m4/unistd_h.m4 (gl_UNISTD_H, gl_UNISTD_H_DEFAULTS): + * modules/unistd (unistd.h): + Add support for getentropy, getrandom. + * doc/glibc-functions/getentropy.texi (getentropy): + * doc/glibc-functions/getrandom.texi (getrandom): + These are now fixed on some platforms. + * lib/getentropy.c, lib/getrandom.c, lib/sys_random.in.h: + * m4/getentropy.m4, m4/getrandom.m4: + * modules/getentropy, modules/getentropy-tests: + * modules/getrandom, modules/getrandom-tests: + * tests/test-getentropy.c, tests/test-getrandom.c: + New files. + 2020-05-25 Bruno Haible Add missing C99 dependencies. diff --git a/MODULES.html.sh b/MODULES.html.sh index 318a15a1d..4db2a77ec 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -3484,9 +3484,11 @@ func_all_modules () func_module forkpty func_module getdomainname func_module xgetdomainname + func_module getentropy func_module getloadavg func_module getpagesize func_module getprogname + func_module getrandom func_module getusershell func_module lib-symbol-visibility func_module login_tty diff --git a/doc/glibc-functions/getentropy.texi b/doc/glibc-functions/getentropy.texi index 5ad873a71..5281dcd4e 100644 --- a/doc/glibc-functions/getentropy.texi +++ b/doc/glibc-functions/getentropy.texi @@ -15,15 +15,19 @@ Documentation: @uref{https://www.kernel.org/doc/man-pages/online/pages/man3/getentropy.3.html,,man getentropy}. @end itemize -Gnulib module: --- +Gnulib module: getentropy Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +glibc 2.24, Mac OS X 10.5, FreeBSD 11.0, NetBSD 5.0, OpenBSD 3.8, +Solaris 11.0, Android 9.0. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on many non-glibc platforms: -glibc 2.24, Mac OS X 10.5, FreeBSD 11.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.0, Cygwin, mingw, MSVC 14, Android 9.0. +This function is missing on some platforms: +Minix 3.1.8, IRIX 6.5, mingw, MSVC 14. @end itemize diff --git a/doc/glibc-functions/getrandom.texi b/doc/glibc-functions/getrandom.texi index 25e899d63..2f4debcfe 100644 --- a/doc/glibc-functions/getrandom.texi +++ b/doc/glibc-functions/getrandom.texi @@ -19,11 +19,15 @@ Gnulib module: --- Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +glibc 2.24, Mac OS X 10.5, FreeBSD 11.0, NetBSD 5.0, OpenBSD 3.8, +Solaris 11.0, Android 9.0. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on many non-glibc platforms: -glibc 2.24, Mac OS X 10.5, FreeBSD 11.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.0, Cygwin, mingw, MSVC 14, Android 9.0. +This function is missing on some platforms: +Minix 3.1.8, IRIX 6.5, mingw, MSVC 14. @end itemize diff --git a/lib/getentropy.c b/lib/getentropy.c new file mode 100644 index 000000000..2b6c3f55f --- /dev/null +++ b/lib/getentropy.c @@ -0,0 +1,51 @@ +/* Fill a buffer with random bytes. + Copyright 2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert. */ + +#include + +#include + +#include +#include + +/* Overwrite BUFFER with random data. BUFFER contains LENGTH bytes. + LENGTH must be at most 256. Return 0 on success, -1 (setting + errno) on failure. */ +int +getentropy (void *buffer, size_t length) +{ + char *buf = buffer; + + if (length <= 256) + for (;;) + { + ssize_t bytes; + if (length == 0) + return 0; + while ((bytes = getrandom (buf, length, 0)) < 0) + if (errno != EINTR) + return -1; + if (bytes == 0) + break; + buf += bytes; + length -= bytes; + } + + errno = EIO; + return -1; +} diff --git a/lib/getrandom.c b/lib/getrandom.c new file mode 100644 index 000000000..9b6ecb43b --- /dev/null +++ b/lib/getrandom.c @@ -0,0 +1,52 @@ +/* Obtain a series of random bytes. + + Copyright 2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert. */ + +#include + +#include + +#include "minmax.h" +#include +#include +#include + +/* Set BUFFER (of size LENGTH) to random bytes under the control of FLAGS. + Return the number of bytes written, or -1 on error. */ +ssize_t +getrandom (void *buffer, size_t length, unsigned int flags) +{ + static int randfd[2] = { -1, -1 }; + bool devrandom = (flags & GRND_RANDOM) != 0; + int fd = randfd[devrandom]; + + if (fd < 0) + { + static char const randdevice[][MAX (sizeof NAME_OF_NONCE_DEVICE, + sizeof NAME_OF_RANDOM_DEVICE)] + = { NAME_OF_NONCE_DEVICE, NAME_OF_RANDOM_DEVICE }; + int oflags = (O_RDONLY + O_CLOEXEC + + (flags & GRND_NONBLOCK ? O_NONBLOCK : 0)); + fd = open (randdevice[devrandom], oflags); + if (fd < 0) + return fd; + randfd[devrandom] = fd; + } + + return read (fd, buffer, length); +} diff --git a/lib/sys_random.in.h b/lib/sys_random.in.h new file mode 100644 index 000000000..e3f308ce4 --- /dev/null +++ b/lib/sys_random.in.h @@ -0,0 +1,9 @@ +#ifndef _SYS_RANDOM_H +#define _SYS_RANDOM_H 1 + +#include +#define GRND_NONBLOCK 1 +#define GRND_RANDOM 2 +ssize_t getrandom (void *, size_t, unsigned int); + +#endif diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 1454d7e85..4a0d6655a 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -763,6 +763,22 @@ _GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - " #endif +#if @GNULIB_GETENTROPY@ +/* Fill a buffer with random bytes. */ +# if !@HAVE_GETENTROPY@ +_GL_FUNCDECL_SYS (getentropy, int, (void *buffer, size_t length)); +# endif +_GL_CXXALIAS_SYS (getentropy, int, (void *buffer, size_t length)); +_GL_CXXALIASWARN (getentropy); +#elif defined GNULIB_POSIXCHECK +# undef getentropy +# if HAVE_RAW_DECL_GETENTROPY +_GL_WARN_ON_USE (getentropy, "getentropy is unportable - " + "use gnulib module getentropy for portability"); +# endif +#endif + + #if @GNULIB_GETGROUPS@ /* Return the supplemental groups that the current process belongs to. It is unspecified whether the effective group id is in the list. @@ -1014,6 +1030,24 @@ _GL_WARN_ON_USE (getpass, "getpass is unportable - " #endif +#if @GNULIB_GETRANDOM@ +/* Fill a buffer with random bytes. */ +# if !@HAVE_GETRANDOM@ +_GL_FUNCDECL_SYS (getrandom, int, (void *buffer, size_t length, + unsigned int flags)); +# endif +_GL_CXXALIAS_SYS (getrandom, int, (void *buffer, size_t length, + unsigned int flags)); +_GL_CXXALIASWARN (getrandom); +#elif defined GNULIB_POSIXCHECK +# undef getrandom +# if HAVE_RAW_DECL_GETRANDOM +_GL_WARN_ON_USE (getrandom, "getrandom is unportable - " + "use gnulib module getrandom for portability"); +# endif +#endif + + #if @GNULIB_GETUSERSHELL@ /* Return the next valid login shell on the system, or NULL when the end of the list has been reached. */ diff --git a/m4/getentropy.m4 b/m4/getentropy.m4 new file mode 100644 index 000000000..596544b2e --- /dev/null +++ b/m4/getentropy.m4 @@ -0,0 +1,16 @@ +# getentropy.m4 +dnl Copyright 2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Paul Eggert. + +AC_DEFUN([gl_FUNC_GETENTROPY], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + AC_CHECK_FUNCS_ONCE([getentropy]) + if test $ac_cv_func_getentropy = no; then + HAVE_GETENTROPY=0 + fi +]) diff --git a/m4/getrandom.m4 b/m4/getrandom.m4 new file mode 100644 index 000000000..ecb44aebf --- /dev/null +++ b/m4/getrandom.m4 @@ -0,0 +1,15 @@ +# getrandom.m4 +dnl Copyright 2020 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Paul Eggert. + +AC_DEFUN([gl_FUNC_GETRANDOM], +[ + AC_CHECK_FUNCS_ONCE([getrandom]) + if test "$ac_cv_func_getrandom" != yes; then + HAVE_GETRANDOM=0 + fi +]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index e776f3bd4..1f39d53e1 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -43,8 +43,8 @@ AC_DEFUN([gl_UNISTD_H], #endif ]], [access chdir chown dup dup2 dup3 environ euidaccess faccessat fchdir fchownat fdatasync fsync ftruncate getcwd getdomainname getdtablesize - getgroups gethostname getlogin getlogin_r getpagesize getpass - getusershell setusershell endusershell + getentropy getgroups gethostname getlogin getlogin_r getpagesize getpass + getrandom getusershell setusershell endusershell group_member isatty lchown link linkat lseek pipe pipe2 pread pwrite readlink readlinkat rmdir sethostname sleep symlink symlinkat truncate ttyname_r unlink unlinkat usleep]) @@ -82,6 +82,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD]) GNULIB_GETDOMAINNAME=0; AC_SUBST([GNULIB_GETDOMAINNAME]) GNULIB_GETDTABLESIZE=0; AC_SUBST([GNULIB_GETDTABLESIZE]) + GNULIB_GETENTROPY=0; AC_SUBST([GNULIB_GETENTROPY]) GNULIB_GETGROUPS=0; AC_SUBST([GNULIB_GETGROUPS]) GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME]) GNULIB_GETLOGIN=0; AC_SUBST([GNULIB_GETLOGIN]) @@ -89,6 +90,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], GNULIB_GETOPT_POSIX=0; AC_SUBST([GNULIB_GETOPT_POSIX]) GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE]) GNULIB_GETPASS=0; AC_SUBST([GNULIB_GETPASS]) + GNULIB_GETRANDOM=0; AC_SUBST([GNULIB_GETRANDOM]) GNULIB_GETUSERSHELL=0; AC_SUBST([GNULIB_GETUSERSHELL]) GNULIB_GROUP_MEMBER=0; AC_SUBST([GNULIB_GROUP_MEMBER]) GNULIB_ISATTY=0; AC_SUBST([GNULIB_ISATTY]) @@ -129,11 +131,13 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], HAVE_FSYNC=1; AC_SUBST([HAVE_FSYNC]) HAVE_FTRUNCATE=1; AC_SUBST([HAVE_FTRUNCATE]) HAVE_GETDTABLESIZE=1; AC_SUBST([HAVE_GETDTABLESIZE]) + HAVE_GETENTROPY=1; AC_SUBST([HAVE_GETENTROPY]) HAVE_GETGROUPS=1; AC_SUBST([HAVE_GETGROUPS]) HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME]) HAVE_GETLOGIN=1; AC_SUBST([HAVE_GETLOGIN]) HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE]) HAVE_GETPASS=1; AC_SUBST([HAVE_GETPASS]) + HAVE_GETRANDOM=1; AC_SUBST([HAVE_GETRANDOM]) HAVE_GROUP_MEMBER=1; AC_SUBST([HAVE_GROUP_MEMBER]) HAVE_LCHOWN=1; AC_SUBST([HAVE_LCHOWN]) HAVE_LINK=1; AC_SUBST([HAVE_LINK]) diff --git a/modules/getentropy b/modules/getentropy new file mode 100644 index 000000000..9696c1e1d --- /dev/null +++ b/modules/getentropy @@ -0,0 +1,29 @@ +Description: +Fill buffer with random bytes. + +Files: +lib/getentropy.c +m4/getentropy.m4 + +Depends-on: +getrandom [test $HAVE_GETENTROPY = 0] +extensions +unistd + +configure.ac: +gl_FUNC_GETENTROPY +if test $HAVE_GETENTROPY = 0; then + AC_LIBOBJ([getentropy]) +fi +gl_UNISTD_MODULE_INDICATOR([getentropy]) + +Makefile.am: + +Include: + + +License: +LGPL + +Maintainer: +all diff --git a/modules/getentropy-tests b/modules/getentropy-tests new file mode 100644 index 000000000..b5c4b1144 --- /dev/null +++ b/modules/getentropy-tests @@ -0,0 +1,12 @@ +Files: +tests/test-getentropy.c +tests/signature.h +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-getentropy +check_PROGRAMS += test-getentropy diff --git a/modules/getrandom b/modules/getrandom new file mode 100644 index 000000000..2ae374f61 --- /dev/null +++ b/modules/getrandom @@ -0,0 +1,44 @@ +Description: +Fill buffer with random bytes. + +Files: +lib/getrandom.c +lib/sys_random.in.h +m4/getrandom.m4 + +Depends-on: +crypto/gc-random [test $HAVE_GETRANDOM = 0] +fcntl-h [test $HAVE_GETRANDOM = 0] +minmax [test $HAVE_GETRANDOM = 0] +open [test $HAVE_GETRANDOM = 0] + +configure.ac: +gl_FUNC_GETRANDOM +if test $HAVE_GETRANDOM = 0; then + AC_LIBOBJ([getrandom]) +fi +gl_UNISTD_MODULE_INDICATOR([getrandom]) + +Makefile.am: +BUILT_SOURCES += sys/random.h + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +sys/random.h: sys_random.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H) + $(AM_V_at)$(MKDIR_P) sys + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + cat $(srcdir)/sys_random.in.h; \ + } > $@-t && \ + mv -f $@-t $@ +MOSTLYCLEANFILES += sys/random.h sys/random.h-t +MOSTLYCLEANDIRS += sys + +Include: + + +License: +LGPL + +Maintainer: +all diff --git a/modules/unistd b/modules/unistd index 3c28f36ca..dc32ce056 100644 --- a/modules/unistd +++ b/modules/unistd @@ -55,6 +55,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's/@''GNULIB_GETCWD''@/$(GNULIB_GETCWD)/g' \ -e 's/@''GNULIB_GETDOMAINNAME''@/$(GNULIB_GETDOMAINNAME)/g' \ -e 's/@''GNULIB_GETDTABLESIZE''@/$(GNULIB_GETDTABLESIZE)/g' \ + -e 's/@''GNULIB_GETENTROPY''@/$(GNULIB_GETENTROPY)/g' \ -e 's/@''GNULIB_GETGROUPS''@/$(GNULIB_GETGROUPS)/g' \ -e 's/@''GNULIB_GETHOSTNAME''@/$(GNULIB_GETHOSTNAME)/g' \ -e 's/@''GNULIB_GETLOGIN''@/$(GNULIB_GETLOGIN)/g' \ @@ -62,6 +63,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's/@''GNULIB_GETOPT_POSIX''@/$(GNULIB_GETOPT_POSIX)/g' \ -e 's/@''GNULIB_GETPAGESIZE''@/$(GNULIB_GETPAGESIZE)/g' \ -e 's/@''GNULIB_GETPASS''@/$(GNULIB_GETPASS)/g' \ + -e 's/@''GNULIB_GETRANDOM''@/$(GNULIB_GETRANDOM)/g' \ -e 's/@''GNULIB_GETUSERSHELL''@/$(GNULIB_GETUSERSHELL)/g' \ -e 's/@''GNULIB_GROUP_MEMBER''@/$(GNULIB_GROUP_MEMBER)/g' \ -e 's/@''GNULIB_ISATTY''@/$(GNULIB_ISATTY)/g' \ @@ -103,10 +105,12 @@ unistd.h: unistd.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \ -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \ -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \ + -e 's|@''HAVE_GETENTROPY''@|$(HAVE_GETENTROPY)|g' \ -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \ -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \ -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ -e 's|@''HAVE_GETPASS''@|$(HAVE_GETPASS)|g' \ + -e 's|@''HAVE_GETRANDOM''@|$(HAVE_GETRANDOM)|g' \ -e 's|@''HAVE_GROUP_MEMBER''@|$(HAVE_GROUP_MEMBER)|g' \ -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \ -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \ diff --git a/tests/test-getentropy.c b/tests/test-getentropy.c new file mode 100644 index 000000000..845c5dcaf --- /dev/null +++ b/tests/test-getentropy.c @@ -0,0 +1,43 @@ +/* Test the getentropy function. + Copyright 2020 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Paul Eggert. */ + +#include + +#include + +#include + +#include "signature.h" +SIGNATURE_CHECK (getentropy, int, (void *, size_t)); + +#include "macros.h" + +char empty_buf[256]; +char buf[256]; + +int +main (int argc, char *argv[]) +{ + /* If this test fails, there's something wrong with the setup anyway. */ + ASSERT (getentropy (buf, sizeof buf) == 0); + + /* This test fails with probability 2**-2048. (Run it again if so. :-) */ + ASSERT (memcmp (buf, empty_buf, sizeof buf) != 0); + + return 0; +} -- 2.17.1