Skip to content

Commit 71aa611

Browse files
jallisonciqPlaidCat
authored andcommitted
crypto: jitter - add oversampling of noise source
The output n bits can receive more than n bits of min entropy, of course, but the fixed output of the conditioning function can only asymptotically approach the output size bits of min entropy, not attain that bound. Random maps will tend to have output collisions, which reduces the creditable output entropy (that is what SP 800-90B Section 3.1.5.1.2 attempts to bound). The value "64" is justified in Appendix A.4 of the current 90C draft, and aligns with NIST's in "epsilon" definition in this document, which is that a string can be considered "full entropy" if you can bound the min entropy in each bit of output to at least 1-epsilon, where epsilon is required to be <= 2^(-32). Note, this patch causes the Jitter RNG to cut its performance in half in FIPS mode because the conditioning function of the LFSR produces 64 bits of entropy in one block. The oversampling requires that additionally 64 bits of entropy are sampled from the noise source. If the conditioner is changed, such as using SHA-256, the impact of the oversampling is only one fourth, because for the 256 bit block of the conditioner, only 64 additional bits from the noise source must be sampled. This patch is derived from the user space jitterentropy-library. Signed-off-by: Stephan Mueller <smueller@chronox.de> Reviewed-by: Simo Sorce <simo@redhat.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Back-port of upstream commit 908dffa. Signed-off-by: Jeremy Allison <jallison@ciq.com> Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 3efaf28 commit 71aa611

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

crypto/jitterentropy.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ struct rand_data {
119119
#define JENT_ESTUCK 8 /* Too many stuck results during init. */
120120
#define JENT_EHEALTH 9 /* Health test failed during initialization */
121121

122+
/*
123+
* The output n bits can receive more than n bits of min entropy, of course,
124+
* but the fixed output of the conditioning function can only asymptotically
125+
* approach the output size bits of min entropy, not attain that bound. Random
126+
* maps will tend to have output collisions, which reduces the creditable
127+
* output entropy (that is what SP 800-90B Section 3.1.5.1.2 attempts to bound).
128+
*
129+
* The value "64" is justified in Appendix A.4 of the current 90C draft,
130+
* and aligns with NIST's in "epsilon" definition in this document, which is
131+
* that a string can be considered "full entropy" if you can bound the min
132+
* entropy in each bit of output to at least 1-epsilon, where epsilon is
133+
* required to be <= 2^(-32).
134+
*/
135+
#define JENT_ENTROPY_SAFETY_FACTOR 64
136+
137+
#include <linux/fips.h>
122138
#include "jitterentropy.h"
123139

124140
/***************************************************************************
@@ -463,7 +479,10 @@ static int jent_measure_jitter(struct rand_data *ec)
463479
*/
464480
static void jent_gen_entropy(struct rand_data *ec)
465481
{
466-
unsigned int k = 0;
482+
unsigned int k = 0, safety_factor = 0;
483+
484+
if (fips_enabled)
485+
safety_factor = JENT_ENTROPY_SAFETY_FACTOR;
467486

468487
/* priming of the ->prev_time value */
469488
jent_measure_jitter(ec);
@@ -477,7 +496,7 @@ static void jent_gen_entropy(struct rand_data *ec)
477496
* We multiply the loop value with ->osr to obtain the
478497
* oversampling rate requested by the caller
479498
*/
480-
if (++k >= (DATA_SIZE_BITS * ec->osr))
499+
if (++k >= ((DATA_SIZE_BITS + safety_factor) * ec->osr))
481500
break;
482501
}
483502
}

0 commit comments

Comments
 (0)