forked from pool/libgcrypt
b75d794f38
libgcrypt 1.7.3 OBS-URL: https://build.opensuse.org/request/show/420659 OBS-URL: https://build.opensuse.org/package/show/devel:libraries:c_c++/libgcrypt?expand=0&rev=87
88 lines
2.5 KiB
Diff
88 lines
2.5 KiB
Diff
Index: libgcrypt-1.7.2/random/rndlinux.c
|
|
===================================================================
|
|
--- libgcrypt-1.7.2.orig/random/rndlinux.c
|
|
+++ libgcrypt-1.7.2/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;
|
|
@@ -115,6 +119,7 @@ _gcry_rndlinux_gather_random (void (*add
|
|
{
|
|
static int fd_urandom = -1;
|
|
static int fd_random = -1;
|
|
+ static int fd_configured = -1;
|
|
static unsigned char ever_opened;
|
|
int fd;
|
|
int n;
|
|
@@ -138,6 +143,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;
|
|
}
|
|
|
|
@@ -165,20 +175,30 @@ _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 >= 2)
|
|
{
|
|
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;
|
|
}
|
|
- else
|
|
+ else if (level != -1)
|
|
{
|
|
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;
|