crypto: Jitter RNG SP800-90B compliance
v2 cover crypto: Jitter RNG SP800-90B compliance
Hi,
This patch set adds SP800-90B compliance to the Jitter RNG. The SP800-90B patch is tested for more than half a year in user space with the Jitter RNG version 2.2.0.
The full SP800-90B assessment of the Jitter RNG is provided at [1].
In addition, the DRBG implementation is updated to always be reseeded from the Jitter RNG. To ensure the DRBG is reseeded within an appropriate amount of time, the reseed threshold is lowered.
Changes v2:
* Instead of free/alloc of the Jitter RNG instance in case of a health test error, re-initialize the RNG instance by performing the power-up test and after a success, clear the health test status and error.
[1] http://www.chronox.de/jent/doc/CPU-Jitter-NPTRNG.pdf
Stephan Mueller (2):
crypto: Jitter RNG SP800-90B compliance
crypto: DRBG always seeded with SP800-90B compliant noise source
crypto/drbg.c | 26 ++- crypto/jitterentropy-kcapi.c | 27 +++ crypto/jitterentropy.c | 417 ++++++++++++++++++++++++++--------- include/crypto/drbg.h | 6 +- 4 files changed, 363 insertions(+), 113 deletions(-)
Signature · 1 line
2.25.2
PATCH v2 1/2 crypto: Jitter RNG SP800-90B compliance
SP800-90B specifies various requirements for the noise source(s) that may seed any DRNG including SP800-90A DRBGs. In November 2020, SP800-90B will be mandated for all noise sources that provide entropy to DRBGs as part of a FIPS 140-[2|3] validation or other evaluation types. Without SP800-90B compliance, a noise source is defined to always deliver zero bits of entropy.
This patch ports the SP800-90B compliance from the user space Jitter RNG version 2.2.0.
The following changes are applied:
- addition of (an enhanced version of) the repetitive count test (RCT) from SP800-90B section 4.4.1 - the enhancement is due to the fact of using the stuck test as input to the RCT.
- addition of the adaptive proportion test (APT) from SP800-90B section 4.4.2
- update of the power-on self test to perform a test measurement of 1024 noise samples compliant to SP800-90B section 4.3
- remove of the continuous random number generator test which is replaced by APT and RCT
Health test failures due to the SP800-90B operation are only enforced in FIPS mode. If a runtime health test failure is detected, the Jitter RNG is reset. If more than 1024 resets in a row are performed, a permanent error is returned to the caller.
--- crypto/jitterentropy-kcapi.c | 27 +++ crypto/jitterentropy.c | 417 ++++++++++++++++++++++++++--------- 2 files changed, 343 insertions(+), 101 deletions(-)
crypto/jitterentropy-kcapi.c +27 -0
@@ -108,6 +108,7 @@ void jent_get_nstime(__u64 *out)struct jitterentropy {spinlock_t jent_lock;struct rand_data *entropy_collector; +unsigned int reset_cnt; };static int jent_kcapi_init (struct crypto_tfm *tfm)
@@ -142,7 +143,33 @@ static int jent_kcapi_random(struct crypto_rng *tfm,int ret =0 ;spin_lock (&rng->jent_lock); + +/* Return a permanent error in case we had too many resets in a row. */ +if (rng->reset_cnt > (1 <<10 )) { + ret = -EFAULT ; + goto out; + } + ret =jent_read_entropy (rng->entropy_collector, rdata, dlen); + +/* Reset RNG in case of health failures */ +if (ret <-1 ) { +pr_warn_ratelimited ("Reset Jitter RNG due to health test failure: %s failure\n" , + (ret ==-2 ) ?"Repetition Count Test" : +"Adaptive Proportion Test" ); + + rng->reset_cnt++; + + ret = -EAGAIN ; + }else { + rng->reset_cnt =0 ; + +/* Convert the Jitter RNG error into a usable error code */ +if (ret ==-1 ) + ret = -EINVAL ; + } + +out:spin_unlock (&rng->jent_lock);return ret;
crypto/jitterentropy.c +316 -101
580 lines not on this page · raw message
Signature · 1 line
2.25.2
PATCH v2 2/2 crypto: DRBG always seeded with SP800-90B compliant noise source
In reply to Stephan MüllerAs the Jitter RNG provides an SP800-90B compliant noise source, use this noise source always for the (re)seeding of the DRBG.
To make sure the DRBG is always properly seeded, the reseed threshold is reduced to 1<<20 generate operations.
The Jitter RNG may report health test failures. Such health test failures are treated as transient as follows. The DRBG will not reseed from the Jitter RNG (but from get_random_bytes) in case of a health test failure. Though, it produces the requested random number.
The Jitter RNG has a failure counter where at most 1024 consecutive resets due to a health test failure are considered as a transient error. If more consecutive resets are required, the Jitter RNG will return a permanent error which is returned to the caller by the DRBG. With this approach, the worst case reseed threshold is significantly lower than mandated by SP800-90A in order to seed with an SP800-90B noise source:
the DRBG has a reseed threshold of 2^20 * 1024 = 2^30 generate requests.
Yet, in case of a transient Jitter RNG health test failure, the DRBG is seeded with the data obtained from get_random_bytes.
However, if the Jitter RNG fails during the initial seeding operation even due to a health test error, the DRBG will send an error to the caller because at that time, the DRBG has received no seed that is SP800-90B compliant.
--- crypto/drbg.c | 26 +++++++++++++++++++------- include/crypto/drbg.h | 6 +----- 2 files changed, 20 insertions(+), 12 deletions(-)
crypto/drbg.c +19 -7
@@ -1087,10 +1087,6 @@ static void drbg_async_seed(struct work_struct *work)if (ret) goto unlock; -/* If nonblocking pool is initialized, deactivate Jitter RNG */ -crypto_free_rng (drbg->jent); - drbg->jent =NULL ; -/* Set seeded to false so that if __drbg_seed fails the * next generate call will trigger a reseed. */
@@ -1168,7 +1164,23 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, entropylen);if (ret) {pr_devel ("DRBG: jent failed with %d\n" , ret); - goto out; + +/* +* Do not treat the transient failure of the +* Jitter RNG as an error that needs to be +* reported. The combined number of the +* maximum reseed threshold times the maximum +* number of Jitter RNG transient errors is +* less than the reseed threshold required by +* SP800-90A allowing us to treat the +* transient errors as such. +* +* However, we mandate that at least the first +* seeding operation must succeed with the +* Jitter RNG. +*/ +if (!reseed || ret != -EAGAIN ) + goto out; }drbg_string_fill (&data1, entropy, entropylen *2 );
@@ -1492,6 +1504,8 @@ static int drbg_prepare_hrng(struct drbg_state *drbg)if (list_empty (&drbg->test_data.list))return 0 ; + drbg->jent =crypto_alloc_rng ("jitterentropy_rng" ,0 ,0 ); +INIT_WORK (&drbg->seed_work, drbg_async_seed); drbg->random_ready.owner =THIS_MODULE ;
@@ -1512,8 +1526,6 @@ static int drbg_prepare_hrng(struct drbg_state *drbg)return err; } - drbg->jent =crypto_alloc_rng ("jitterentropy_rng" ,0 ,0 ); -/* * Require frequent reseeds until the seed source is fully * initialized.
include/crypto/drbg.h +1 -5
@@ -184,11 +184,7 @@ static inline size_t drbg_max_addtl(struct drbg_state *drbg)static inline size_t drbg_max_requests (struct drbg_state *drbg) {/* SP800-90A requires 2**48 maximum requests before reseeding */ -#if (__BITS_PER_LONG ==32 ) -return SIZE_MAX ; -#else -return (1UL <<48 ); -#endif +return (1 <<20 ); }/*
Signature · 1 line
2.25.2
Herbert Xu
maintainerQuoted 24 lines · Stephan Müller
Hi,
This patch set adds SP800-90B compliance to the Jitter RNG. The SP800-90B patch is tested for more than half a year in user space with the Jitter RNG version 2.2.0.
The full SP800-90B assessment of the Jitter RNG is provided at [1].
In addition, the DRBG implementation is updated to always be reseeded from the Jitter RNG. To ensure the DRBG is reseeded within an appropriate amount of time, the reseed threshold is lowered.
Changes v2:
* Instead of free/alloc of the Jitter RNG instance in case of a health test error, re-initialize the RNG instance by performing the power-up test and after a success, clear the health test status and error.[1] http://www.chronox.de/jent/doc/CPU-Jitter-NPTRNG.pdf
Stephan Mueller (2):
crypto: Jitter RNG SP800-90B compliance
crypto: DRBG always seeded with SP800-90B compliant noise source
Quoted 5 lines
crypto/drbg.c | 26 ++- crypto/jitterentropy-kcapi.c | 27 +++ crypto/jitterentropy.c | 417 ++++++++++++++++++++++++++--------- include/crypto/drbg.h | 6 +- 4 files changed, 363 insertions(+), 113 deletions(-)
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt