2018-10-28 22:21:59 +01:00
|
|
|
Index: libgcrypt-1.8.4/random/rndlinux.c
|
2014-03-31 09:35:35 +02:00
|
|
|
===================================================================
|
2018-10-28 22:21:59 +01:00
|
|
|
--- libgcrypt-1.8.4.orig/random/rndlinux.c
|
|
|
|
+++ libgcrypt-1.8.4/random/rndlinux.c
|
2016-08-22 11:21:16 +02:00
|
|
|
@@ -40,7 +40,9 @@
|
2014-03-31 09:35:35 +02:00
|
|
|
#include "g10lib.h"
|
|
|
|
#include "rand-internal.h"
|
|
|
|
|
|
|
|
-static int open_device (const char *name, int retry);
|
|
|
|
+#define NAME_OF_CFG_RNGSEED "/etc/gcrypt/rngseed"
|
|
|
|
+
|
|
|
|
+static int open_device (const char *name, int retry, int fatal);
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2016-08-22 11:21:16 +02:00
|
|
|
@@ -63,7 +65,7 @@ set_cloexec_flag (int fd)
|
2014-03-31 09:35:35 +02:00
|
|
|
* a fatal error but retries until it is able to reopen the device.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
-open_device (const char *name, int retry)
|
|
|
|
+open_device (const char *name, int retry, int fatal)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2016-08-22 11:21:16 +02:00
|
|
|
@@ -71,6 +73,8 @@ open_device (const char *name, int retry
|
2014-03-31 09:35:35 +02:00
|
|
|
_gcry_random_progress ("open_dev_random", 'X', 1, 0);
|
|
|
|
again:
|
|
|
|
fd = open (name, O_RDONLY);
|
|
|
|
+ if (fd == -1 && !fatal)
|
|
|
|
+ return fd;
|
|
|
|
if (fd == -1 && retry)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
2018-10-28 22:21:59 +01:00
|
|
|
@@ -116,6 +120,7 @@ _gcry_rndlinux_gather_random (void (*add
|
2014-03-31 09:35:35 +02:00
|
|
|
{
|
|
|
|
static int fd_urandom = -1;
|
|
|
|
static int fd_random = -1;
|
|
|
|
+ static int fd_configured = -1;
|
2017-07-24 10:15:56 +02:00
|
|
|
static int only_urandom = -1;
|
2014-03-31 09:35:35 +02:00
|
|
|
static unsigned char ever_opened;
|
2018-10-28 22:21:59 +01:00
|
|
|
static volatile pid_t my_pid; /* The volatile is there to make sure
|
|
|
|
@@ -156,6 +161,11 @@ _gcry_rndlinux_gather_random (void (*add
|
2014-03-31 09:35:35 +02:00
|
|
|
close (fd_urandom);
|
|
|
|
fd_urandom = -1;
|
|
|
|
}
|
|
|
|
+ if (fd_configured != -1)
|
|
|
|
+ {
|
|
|
|
+ close (fd_configured);
|
|
|
|
+ fd_configured = -1;
|
|
|
|
+ }
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-28 22:21:59 +01:00
|
|
|
@@ -215,11 +225,21 @@ _gcry_rndlinux_gather_random (void (*add
|
2014-03-31 09:35:35 +02:00
|
|
|
that we always require the device to be existent but want a more
|
|
|
|
graceful behaviour if the rarely needed close operation has been
|
|
|
|
used and the device needs to be re-opened later. */
|
|
|
|
+
|
|
|
|
+ if (level == -1)
|
|
|
|
+ {
|
|
|
|
+ if (fd_configured == -1)
|
|
|
|
+ fd_configured = open_device ( NAME_OF_CFG_RNGSEED, 0, 0 );
|
|
|
|
+ fd = fd_configured;
|
|
|
|
+ if (fd == -1)
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
2017-07-24 10:15:56 +02:00
|
|
|
if (level >= GCRY_VERY_STRONG_RANDOM && !only_urandom)
|
2014-03-31 09:35:35 +02:00
|
|
|
{
|
|
|
|
if (fd_random == -1)
|
|
|
|
{
|
|
|
|
- fd_random = open_device (NAME_OF_DEV_RANDOM, (ever_opened & 1));
|
|
|
|
+ fd_random = open_device (NAME_OF_DEV_RANDOM, (ever_opened & 1), 1);
|
|
|
|
ever_opened |= 1;
|
|
|
|
}
|
|
|
|
fd = fd_random;
|
2018-10-28 22:21:59 +01:00
|
|
|
@@ -228,7 +248,7 @@ _gcry_rndlinux_gather_random (void (*add
|
2014-03-31 09:35:35 +02:00
|
|
|
{
|
|
|
|
if (fd_urandom == -1)
|
|
|
|
{
|
|
|
|
- fd_urandom = open_device (NAME_OF_DEV_URANDOM, (ever_opened & 2));
|
|
|
|
+ fd_urandom = open_device (NAME_OF_DEV_URANDOM, (ever_opened & 2), 1);
|
|
|
|
ever_opened |= 2;
|
|
|
|
}
|
|
|
|
fd = fd_urandom;
|