|
|
241384 |
diff -up libgcrypt-1.5.3/random/drbg.c.cfgrandom libgcrypt-1.5.3/random/drbg.c
|
|
|
241384 |
--- libgcrypt-1.5.3/random/drbg.c.cfgrandom 2014-10-30 16:42:49.000000000 +0100
|
|
|
241384 |
+++ libgcrypt-1.5.3/random/drbg.c 2014-10-30 16:46:57.291800433 +0100
|
|
|
241384 |
@@ -485,8 +485,11 @@ gcry_drbg_get_entropy (struct gcry_drbg_
|
|
|
241384 |
read_cb_size = len;
|
|
|
241384 |
read_cb_len = 0;
|
|
|
241384 |
#if USE_RNDLINUX
|
|
|
241384 |
+ _gcry_rndlinux_gather_random (gcry_drbg_read_cb, 0, len,
|
|
|
241384 |
+ -1);
|
|
|
241384 |
+ read_cb_len = 0;
|
|
|
241384 |
rc = _gcry_rndlinux_gather_random (gcry_drbg_read_cb, 0, len,
|
|
|
241384 |
- GCRY_VERY_STRONG_RANDOM);
|
|
|
241384 |
+ GCRY_STRONG_RANDOM);
|
|
|
241384 |
#elif USE_RNDUNIX
|
|
|
241384 |
rc = _gcry_rndunix_gather_random (read_cb, 0, length,
|
|
|
241384 |
GCRY_VERY_STRONG_RANDOM);
|
|
|
241384 |
diff -up libgcrypt-1.5.3/random/random-fips.c.cfgrandom libgcrypt-1.5.3/random/random-fips.c
|
|
|
241384 |
--- libgcrypt-1.5.3/random/random-fips.c.cfgrandom 2014-10-30 16:42:49.942216405 +0100
|
|
|
241384 |
+++ libgcrypt-1.5.3/random/random-fips.c 2014-10-30 16:42:49.970217037 +0100
|
|
|
241384 |
@@ -27,10 +27,10 @@
|
|
|
241384 |
There are 3 random context which map to the different levels of
|
|
|
241384 |
random quality:
|
|
|
241384 |
|
|
|
241384 |
- Generator Seed and Key Kernel entropy (init/reseed)
|
|
|
241384 |
- ------------------------------------------------------------
|
|
|
241384 |
- GCRY_VERY_STRONG_RANDOM /dev/random 256/128 bits
|
|
|
241384 |
- GCRY_STRONG_RANDOM /dev/random 256/128 bits
|
|
|
241384 |
+ Generator Seed and Key Kernel entropy (init/reseed)
|
|
|
241384 |
+ ---------------------------------------------------------------------------------------
|
|
|
241384 |
+ GCRY_VERY_STRONG_RANDOM /etc/gcrypt/rngseed+/dev/urandom 256/128 bits
|
|
|
241384 |
+ GCRY_STRONG_RANDOM /etc/gcrypt/rngseed+/dev/urandom 256/128 bits
|
|
|
241384 |
gcry_create_nonce GCRY_STRONG_RANDOM n/a
|
|
|
241384 |
|
|
|
241384 |
All random generators return their data in 128 bit blocks. If the
|
|
|
241384 |
@@ -40,8 +40,10 @@
|
|
|
241384 |
(SEED_TTL) output blocks; the re-seeding is disabled in test mode.
|
|
|
241384 |
|
|
|
241384 |
The GCRY_VERY_STRONG_RANDOM and GCRY_STRONG_RANDOM generators are
|
|
|
241384 |
- keyed and seeded from the /dev/random device. Thus these
|
|
|
241384 |
- generators may block until the kernel has collected enough entropy.
|
|
|
241384 |
+ keyed and seeded with data that is loaded from the /etc/gcrypt/rngseed
|
|
|
241384 |
+ if the device or symlink to device exists xored with the data
|
|
|
241384 |
+ from the /dev/urandom device. This allows the system administrator
|
|
|
241384 |
+ to always seed the RNGs from /dev/random if it is required.
|
|
|
241384 |
|
|
|
241384 |
The gcry_create_nonce generator is keyed and seeded from the
|
|
|
241384 |
GCRY_STRONG_RANDOM generator. It may also block if the
|
|
|
241384 |
@@ -560,9 +562,13 @@ get_entropy (size_t nbytes)
|
|
|
241384 |
entropy_collect_buffer_len = 0;
|
|
|
241384 |
|
|
|
241384 |
#if USE_RNDLINUX
|
|
|
241384 |
+ _gcry_rndlinux_gather_random (entropy_collect_cb, 0,
|
|
|
241384 |
+ X931_AES_KEYLEN,
|
|
|
241384 |
+ -1);
|
|
|
241384 |
+ entropy_collect_buffer_len = 0;
|
|
|
241384 |
rc = _gcry_rndlinux_gather_random (entropy_collect_cb, 0,
|
|
|
241384 |
X931_AES_KEYLEN,
|
|
|
241384 |
- GCRY_VERY_STRONG_RANDOM);
|
|
|
241384 |
+ GCRY_STRONG_RANDOM);
|
|
|
241384 |
#elif USE_RNDW32
|
|
|
241384 |
do
|
|
|
241384 |
{
|
|
|
241384 |
diff -up libgcrypt-1.5.3/random/rndlinux.c.cfgrandom libgcrypt-1.5.3/random/rndlinux.c
|
|
|
241384 |
--- libgcrypt-1.5.3/random/rndlinux.c.cfgrandom 2014-10-30 16:42:49.949216563 +0100
|
|
|
241384 |
+++ libgcrypt-1.5.3/random/rndlinux.c 2014-10-30 16:42:49.971217059 +0100
|
|
|
241384 |
@@ -37,7 +37,9 @@
|
|
|
241384 |
#include "g10lib.h"
|
|
|
241384 |
#include "rand-internal.h"
|
|
|
241384 |
|
|
|
241384 |
-static int open_device ( const char *name );
|
|
|
241384 |
+#define NAME_OF_CFG_RNGSEED "/etc/gcrypt/rngseed"
|
|
|
241384 |
+
|
|
|
241384 |
+static int open_device ( const char *name, int fatal );
|
|
|
241384 |
|
|
|
241384 |
|
|
|
241384 |
static int
|
|
|
241384 |
@@ -58,13 +60,17 @@ set_cloexec_flag (int fd)
|
|
|
241384 |
* Used to open the /dev/random devices (Linux, xBSD, Solaris (if it exists)).
|
|
|
241384 |
*/
|
|
|
241384 |
static int
|
|
|
241384 |
-open_device ( const char *name )
|
|
|
241384 |
+open_device ( const char *name, int fatal )
|
|
|
241384 |
{
|
|
|
241384 |
int fd;
|
|
|
241384 |
|
|
|
241384 |
fd = open ( name, O_RDONLY );
|
|
|
241384 |
if ( fd == -1 )
|
|
|
241384 |
- log_fatal ("can't open %s: %s\n", name, strerror(errno) );
|
|
|
241384 |
+ {
|
|
|
241384 |
+ if (! fatal)
|
|
|
241384 |
+ return fd;
|
|
|
241384 |
+ log_fatal ("can't open %s: %s\n", name, strerror(errno) );
|
|
|
241384 |
+ }
|
|
|
241384 |
|
|
|
241384 |
if (set_cloexec_flag (fd))
|
|
|
241384 |
log_error ("error setting FD_CLOEXEC on fd %d: %s\n",
|
|
|
241384 |
@@ -93,6 +99,7 @@ _gcry_rndlinux_gather_random (void (*add
|
|
|
241384 |
{
|
|
|
241384 |
static int fd_urandom = -1;
|
|
|
241384 |
static int fd_random = -1;
|
|
|
241384 |
+ static int fd_configured = -1;
|
|
|
241384 |
int fd;
|
|
|
241384 |
int n;
|
|
|
241384 |
byte buffer[768];
|
|
|
241384 |
@@ -101,6 +108,7 @@ _gcry_rndlinux_gather_random (void (*add
|
|
|
241384 |
size_t last_so_far = 0;
|
|
|
241384 |
int any_need_entropy = 0;
|
|
|
241384 |
int delay;
|
|
|
241384 |
+ size_t orig_length = length;
|
|
|
241384 |
|
|
|
241384 |
/* First read from a hardware source. However let it account only
|
|
|
241384 |
for up to 50% of the requested bytes. */
|
|
|
241384 |
@@ -111,16 +119,26 @@ _gcry_rndlinux_gather_random (void (*add
|
|
|
241384 |
length -= n_hw;
|
|
|
241384 |
|
|
|
241384 |
/* Open the requested device. */
|
|
|
241384 |
+
|
|
|
241384 |
+ if (level == -1)
|
|
|
241384 |
+ {
|
|
|
241384 |
+ if (fd_configured == -1)
|
|
|
241384 |
+ fd_configured = open_device ( NAME_OF_CFG_RNGSEED, 0 );
|
|
|
241384 |
+ fd = fd_configured;
|
|
|
241384 |
+ if (fd == -1)
|
|
|
241384 |
+ return -1;
|
|
|
241384 |
+ }
|
|
|
241384 |
+
|
|
|
241384 |
if (level >= 2)
|
|
|
241384 |
{
|
|
|
241384 |
if( fd_random == -1 )
|
|
|
241384 |
- fd_random = open_device ( NAME_OF_DEV_RANDOM );
|
|
|
241384 |
+ fd_random = open_device ( NAME_OF_DEV_RANDOM, 1 );
|
|
|
241384 |
fd = fd_random;
|
|
|
241384 |
}
|
|
|
241384 |
- else
|
|
|
241384 |
+ else if (level != -1)
|
|
|
241384 |
{
|
|
|
241384 |
if( fd_urandom == -1 )
|
|
|
241384 |
- fd_urandom = open_device ( NAME_OF_DEV_URANDOM );
|
|
|
241384 |
+ fd_urandom = open_device ( NAME_OF_DEV_URANDOM, 1 );
|
|
|
241384 |
fd = fd_urandom;
|
|
|
241384 |
}
|
|
|
241384 |
|