5a5bf04851
libgcrypt 1.8.4 OBS-URL: https://build.opensuse.org/request/show/645112 OBS-URL: https://build.opensuse.org/package/show/devel:libraries:c_c++/libgcrypt?expand=0&rev=117
86 lines
2.6 KiB
Diff
86 lines
2.6 KiB
Diff
Index: libgcrypt-1.8.4/random/rndlinux.c
|
|
===================================================================
|
|
--- libgcrypt-1.8.4.orig/random/rndlinux.c
|
|
+++ libgcrypt-1.8.4/random/rndlinux.c
|
|
@@ -40,7 +40,9 @@
|
|
#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
|
|
@@ -63,7 +65,7 @@ set_cloexec_flag (int fd)
|
|
* 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;
|
|
|
|
@@ -71,6 +73,8 @@ open_device (const char *name, int retry
|
|
_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;
|
|
@@ -116,6 +120,7 @@ _gcry_rndlinux_gather_random (void (*add
|
|
{
|
|
static int fd_urandom = -1;
|
|
static int fd_random = -1;
|
|
+ static int fd_configured = -1;
|
|
static int only_urandom = -1;
|
|
static unsigned char ever_opened;
|
|
static volatile pid_t my_pid; /* The volatile is there to make sure
|
|
@@ -156,6 +161,11 @@ _gcry_rndlinux_gather_random (void (*add
|
|
close (fd_urandom);
|
|
fd_urandom = -1;
|
|
}
|
|
+ if (fd_configured != -1)
|
|
+ {
|
|
+ close (fd_configured);
|
|
+ fd_configured = -1;
|
|
+ }
|
|
return 0;
|
|
}
|
|
|
|
@@ -215,11 +225,21 @@ _gcry_rndlinux_gather_random (void (*add
|
|
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;
|
|
+ }
|
|
+
|
|
if (level >= GCRY_VERY_STRONG_RANDOM && !only_urandom)
|
|
{
|
|
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;
|
|
@@ -228,7 +248,7 @@ _gcry_rndlinux_gather_random (void (*add
|
|
{
|
|
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;
|