Steffen Nurpmeso wrote in
<20200529202134.6lzbj%stef...@sdaoden.eu>:
 |Steffen Nurpmeso wrote in
 |<20200529155411.tgyu1%stef...@sdaoden.eu>:
 ||Werner Koch wrote in
 ||<87sgfjrqf1....@wheatstone.g10code.de>:
 |||On Thu, 28 May 2020 14:43, Steffen Nurpmeso said:
 ...
 |So with the attached patch libgcrypt solely relies upon getentropy
 |if available, no FD handling is done no more if at all possible.
 |The test suite passes, a short review makes me think it is alright.

Maybe, but it was not.
Please find attached a second one to be applied on top, it fixes
some preprocessor problems.

Please just feel free to take those, and commit under your name or
any way you like it.  Joining them into one would be nice...

Thank you, and Ciao,

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
commit 5761c3fb (HEAD -> refs/heads/me)
Author:     Steffen Nurpmeso <stef...@sdaoden.eu>
AuthorDate: 2020-05-30 16:33:34 +0200
Commit:     Steffen Nurpmeso <stef...@sdaoden.eu>
CommitDate: 2020-05-30 16:44:53 +0200

    Tweak previous..
    
    - Fix preprocessor statement in #include block, it missed a && in
      between two conditions.
    
    - Drop usage of direct syscall in _gcry_rndlinux_setup(): it used
      GRND_NONBLOCK, but that in turn needs sys/random.h which is not
      tested by the configuration.
    
      And GRND_NONBLOCK was defined in include/uapi/linux/random.h
      once the syscall had been introduced.  And whereas the value
      always has been 0x1, it seems better to simplify the code
      regardless of the possible bad side effect of blocking the
      program.
    
      (As stated on the gnupg-users ML OpenBSD i think never blocks,
      and newer Linux, i think 5.6, block in-kernel on boot until
      entropy is set free, and for older kernels it is likely that
      people use haveged or another kind of entropy booster, and/or
      ensure to restore entropy via the RNDADDENTROP ioctl(2).
      This because boot hangs became a problem several years ago.)

    - Please let me use my #ifdef instead of #if.
---
 random/rndlinux.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/random/rndlinux.c b/random/rndlinux.c
index c710d368..eff5a505 100644
--- a/random/rndlinux.c
+++ b/random/rndlinux.c
@@ -32,13 +32,11 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-#undef HAVE_GETRANDOM_SYSCALL
-#if !defined(HAVE_GETENTROPY)
-# if defined(__linux__) defined(HAVE_SYSCALL)
+#ifndef HAVE_GETENTROPY
+# if defined(__linux__) && defined(HAVE_SYSCALL)
 #  include <sys/syscall.h>
 #  ifdef __NR_getrandom
 #   define HAVE_GETENTROPY
-#   define HAVE_GETRANDOM_SYSCALL
 #   define getentropy(buf,buflen) syscall (__NR_getrandom, buf, buflen, 0)
 #  endif
 # endif
@@ -115,7 +113,7 @@ _gcry_rndlinux_setup (void)
 {
   int rv = 0;
 
-#if HAVE_GETENTROPY
+#ifdef HAVE_GETENTROPY
   if (!a_rndlinux_have_getentropy)
     {
       char buf[8];
@@ -124,13 +122,7 @@ _gcry_rndlinux_setup (void)
       do
         {
           _gcry_pre_syscall ();
-          ret =
-# ifdef HAVE_GETRANDOM_SYSCALL
-                syscall (__NR_getrandom, buf, 1, GRND_NONBLOCK
-# else
-                getentropy (buf, 1
-# endif
-                );
+          ret = getentropy (buf, 1);
           _gcry_post_syscall ();
         }
       while (ret == -1 && errno == EINTR);
@@ -139,7 +131,7 @@ _gcry_rndlinux_setup (void)
     }
   else
     rv = (a_rndlinux_have_getentropy != -1);
-#endif /* HAVE_GETENTROPY */
+#endif
 
   if (!rv && !access (NAME_OF_DEV_RANDOM, R_OK)
       && !access (NAME_OF_DEV_URANDOM, R_OK))
@@ -257,7 +249,7 @@ _gcry_rndlinux_gather_random (void (*add)(const void*, size_t,
   /* If we have a modern kernel, try to use the new getentropy function.
    * It guarantees that the kernel's RNG has been properly seeded before
    * returning any data. */
-#if HAVE_GETENTROPY
+#ifdef HAVE_GETENTROPY
   if (a_rndlinux_have_getentropy != -1)
     {
       long ret;
@@ -388,7 +380,7 @@ _gcry_rndlinux_gather_random (void (*add)(const void*, size_t,
       length -= n;
     }
 
-#if HAVE_GETENTROPY
+#ifdef HAVE_GETENTROPY
 jhave_data:
 #endif
 
_______________________________________________
Gnupg-users mailing list
Gnupg-users@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gnupg-users

Reply via email to