/dev/random - a new approach with full SP800-90B compliance
Subsystems (3)
PATCH v27 5/12 crypto: DRBG - externalize DRBG functions for LRNG
In reply to Stephan MüllerThis patch allows several DRBG functions to be called by the LRNG kernel code paths outside the drbg.c file.
--- crypto/drbg.c | 16 ++++++++++------ include/crypto/drbg.h | 7 +++++++ 2 files changed, 17 insertions(+), 6 deletions(-)
crypto/drbg.c +10 -6
@@ -113,7 +113,7 @@* the SHA256 / AES 256 over other ciphers. Thus, the favored * DRBGs are the latest entries in this array. */ -static const struct drbg_core drbg_cores[] = { +const struct drbg_core drbg_cores[] = { #ifdef CONFIG_CRYPTO_DRBG_CTR { .flags = DRBG_CTR | DRBG_STRENGTH128,
@@ -190,6 +190,7 @@ static const struct drbg_core drbg_cores[] = { },#endif /* CONFIG_CRYPTO_DRBG_HMAC */ }; +EXPORT_SYMBOL (drbg_cores);static int drbg_uninstantiate (struct drbg_state *drbg);
@@ -205,7 +206,7 @@ static int drbg_uninstantiate(struct drbg_state *drbg);* Return: normalized strength in *bytes* value or 32 as default * to counter programming errors */ -static inline unsigned short drbg_sec_strength (drbg_flag_t flags) +unsigned short drbg_sec_strength (drbg_flag_t flags) {switch (flags &DRBG_STRENGTH_MASK ) {case DRBG_STRENGTH128 :
@@ -218,6 +219,7 @@ static inline unsigned short drbg_sec_strength(drbg_flag_t flags)return 32 ; } } +EXPORT_SYMBOL (drbg_sec_strength);/* * FIPS 140-2 continuous self test for the noise source
@@ -1202,7 +1204,7 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, }/* Free all substructures in a DRBG state without the DRBG state structure */ -static inline void drbg_dealloc_state (struct drbg_state *drbg) +void drbg_dealloc_state (struct drbg_state *drbg) {if (!drbg)return ;
@@ -1223,12 +1225,13 @@ static inline void drbg_dealloc_state(struct drbg_state *drbg) drbg->fips_primed = false; } } +EXPORT_SYMBOL (drbg_dealloc_state);/* * Allocate all sub-structures for a DRBG state. * The DRBG state structure must already be allocated. */ -static inline int drbg_alloc_state (struct drbg_state *drbg) +int drbg_alloc_state (struct drbg_state *drbg) {int ret = -ENOMEM ;unsigned int sb_size =0 ;
@@ -1307,6 +1310,7 @@ static inline int drbg_alloc_state(struct drbg_state *drbg)drbg_dealloc_state (drbg);return ret; } +EXPORT_SYMBOL (drbg_alloc_state);/************************************************************************* * DRBG interface functions
@@ -1874,8 +1878,7 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg,* * return: flags */ -static inline void drbg_convert_tfm_core (const char *cra_driver_name, -int *coreref,bool *pr) +void drbg_convert_tfm_core (const char *cra_driver_name,int *coreref,bool *pr) {int i =0 ;size_t start =0 ;
@@ -1902,6 +1905,7 @@ static inline void drbg_convert_tfm_core(const char *cra_driver_name, } } } +EXPORT_SYMBOL (drbg_convert_tfm_core);static int drbg_kcapi_init (struct crypto_tfm *tfm) {
include/crypto/drbg.h +7 -0
@@ -282,4 +282,11 @@ enum drbg_prefixes {DRBG_PREFIX3 }; +extern int drbg_alloc_state (struct drbg_state *drbg); +extern void drbg_dealloc_state (struct drbg_state *drbg); +extern void drbg_convert_tfm_core (const char *cra_driver_name,int *coreref, +bool *pr); +extern const struct drbg_core drbg_cores[]; +extern unsigned short drbg_sec_strength (drbg_flag_t flags); +#endif /* _DRBG_H */
Signature · 1 line
2.24.1
PATCH v27 6/12 LRNG - add SP800-90A DRBG extension
In reply to Stephan MüllerUsing the LRNG switchable DRNG support, the SP800-90A DRBG extension is implemented.
The DRBG uses the kernel crypto API DRBG implementation. In addition, it uses the kernel crypto API SHASH support to provide the hashing operation.
The DRBG supports the choice of either a CTR DRBG using AES-256, HMAC DRBG with SHA-512 core or Hash DRBG with SHA-512 core. The used core can be selected with the module parameter lrng_drbg_type. The default is the CTR DRBG.
When compiling the DRBG extension statically, the DRBG is loaded at late_initcall stage which implies that with the start of user space, the user space interfaces of getrandom(2), /dev/random and /dev/urandom provide random data produced by an SP800-90A DRBG.
--- drivers/char/lrng/Kconfig | 11 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_drbg.c | 261 ++++++++++++++++++++++++++++++++++ 3 files changed, 273 insertions(+) create mode 100644 drivers/char/lrng/lrng_drbg.c
drivers/char/lrng/Kconfig +11 -0
@@ -71,4 +71,15 @@ menuconfig LRNG_DRNG_SWITCH accessible via the external interfaces. With this configuration option other DRNGs can be selected and loaded at runtime. +if LRNG_DRNG_SWITCH +config LRNG_DRBG + tristate "SP800-90A support for the LRNG" + select CRYPTO_DRBG_MENU + select CRYPTO_CMAC if CRYPTO_DRBG_CTR + help + Enable the SP800-90A DRBG support for the LRNG. Once the + module is loaded, output from /dev/random, /dev/urandom, + getrandom(2), or get_random_bytes is provided by a DRBG. +endif # LRNG_DRNG_SWITCH + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-y += lrng_pool.o lrng_aux.o \ obj-$(CONFIG_NUMA) += lrng_numa.o obj-$(CONFIG_SYSCTL) += lrng_proc.o obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o +obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o
drivers/char/lrng/lrng_drbg.c new file +261 -0
261 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v27 7/12 LRNG - add kernel crypto API PRNG extension
In reply to Stephan MüllerAdd runtime-pluggable support for all PRNGs that are accessible via the kernel crypto API, including hardware PRNGs. The PRNG is selected with the module parameter drng_name where the name must be one that the kernel crypto API can resolve into an RNG.
This allows using of the kernel crypto API PRNG implementations that provide an interface to hardware PRNGs. Using this extension, the LRNG uses the hardware PRNGs to generate random numbers. An example is the S390 CPACF support providing such a PRNG.
The hash is provided by a kernel crypto API SHASH whose digest size complies with the seedsize of the PRNG.
--- drivers/char/lrng/Kconfig | 10 + drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_kcapi.c | 328 +++++++++++++++++++++++++++++++++ 3 files changed, 339 insertions(+) create mode 100644 drivers/char/lrng/lrng_kcapi.c
drivers/char/lrng/Kconfig +10 -0
@@ -80,6 +80,16 @@ config LRNG_DRBG Enable the SP800-90A DRBG support for the LRNG. Once the module is loaded, output from /dev/random, /dev/urandom, getrandom(2), or get_random_bytes is provided by a DRBG. + +config LRNG_KCAPI + tristate "Kernel Crypto API support for the LRNG" + select CRYPTO_RNG + help + Enable the support for generic pseudo-random number + generators offered by the kernel crypto API with the + LRNG. Once the module is loaded, output from /dev/random, + /dev/urandom, getrandom(2), or get_random_bytes is + provided by the selected kernel crypto API RNG. endif # LRNG_DRNG_SWITCH endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_NUMA) += lrng_numa.o obj-$(CONFIG_SYSCTL) += lrng_proc.o obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o +obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o
drivers/char/lrng/lrng_kcapi.c new file +328 -0
328 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v27 8/12 crypto: provide access to a static Jitter RNG state
In reply to Stephan MüllerTo support the LRNG operation which uses the Jitter RNG separately from the kernel crypto API, at a time where potentially the regular memory management is not yet initialized, the Jitter RNG needs to provide a state whose memory is defined at compile time. As only once instance will ever be needed by the LRNG, define once static memory block which is solely to be used by the LRNG.
---
crypto/jitterentropy-kcapi.c | 3 +--
crypto/jitterentropy.c | 25 ++++++++++++++++++-
.../crypto/internal}/jitterentropy.h | 3 +++
3 files changed, 28 insertions(+), 3 deletions(-)
rename {crypto => include/crypto/internal}/jitterentropy.h (84%)crypto/jitterentropy-kcapi.c +1 -2
@@ -43,8 +43,7 @@#include <linux/time.h> #include <linux/crypto.h> #include <crypto/internal/rng.h> - -#include "jitterentropy.h" +#include <crypto/internal/jitterentropy.h> /*************************************************************************** * Helper function
crypto/jitterentropy.c +24 -1
@@ -103,7 +103,7 @@ struct rand_data {* Helper functions ***************************************************************************/ -#include "jitterentropy.h" +#include <crypto/internal/jitterentropy.h> /** * Update of the loop count used for the next round of
@@ -639,3 +639,26 @@ int jent_entropy_init(void)return 0 ; } + +struct rand_data *jent_lrng_entropy_collector (void ) +{ +static unsigned char lrng_jent_mem[JENT_MEMORY_SIZE ]; +static struct rand_data lrng_jent_state = { + .data =0 , + .old_data =0 , + .prev_time =0 , + .last_delta =0 , + .last_delta2 =0 , + .osr =1 , + .mem = lrng_jent_mem, + .memlocation =0 , + .memblocks =JENT_MEMORY_BLOCKSIZE , + .memblocksize =JENT_MEMORY_BLOCKS , + .memaccessloops =JENT_MEMORY_ACCESSLOOPS , + }; + +if (jent_entropy_init ()) +return NULL ; + +return &lrng_jent_state; +}
include/crypto/internal/jitterentropy.h renamed from crypto/jitterentropy.h +3 -0
@@ -15,3 +15,6 @@ extern int jent_read_entropy(struct rand_data *ec, unsigned char *data,extern struct rand_data *jent_entropy_collector_alloc (unsigned int osr,unsigned int flags);extern void jent_entropy_collector_free (struct rand_data *entropy_collector); + +/* Access to statically allocated Jitter RNG instance */ +extern struct rand_data *jent_lrng_entropy_collector (void );
Signature · 1 line
2.24.1
PATCH v27 9/12 LRNG - add Jitter RNG fast noise source
In reply to Stephan MüllerThe Jitter RNG fast noise source implemented as part of the kernel crypto API is queried for 256 bits of entropy at the time the seed buffer managed by the LRNG is about to be filled.
--- drivers/char/lrng/Kconfig | 11 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_jent.c | 87 +++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/char/lrng/lrng_jent.c
drivers/char/lrng/Kconfig +11 -0
@@ -92,4 +92,15 @@ config LRNG_KCAPI provided by the selected kernel crypto API RNG. endif # LRNG_DRNG_SWITCH +config LRNG_JENT + bool "Enable Jitter RNG as LRNG Seed Source" + select CRYPTO_JITTERENTROPY + help + The Linux RNG may use the Jitter RNG as noise source. Enabling + this option enables the use of the Jitter RNG. Its default + entropy level is 16 bits of entropy per 256 data bits delivered + by the Jitter RNG. This entropy level can be changed at boot + time or at runtime with the lrng_base.jitterrng configuration + variable. + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-$(CONFIG_SYSCTL) += lrng_proc.o obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o +obj-$(CONFIG_LRNG_JENT) += lrng_jent.o
drivers/char/lrng/lrng_jent.c new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH v27 09/12] LRNG - add Jitter RNG fast noise source
Hi,
Quoted 38 lines · Stephan Müller
--- drivers/char/lrng/Kconfig | 11 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_jent.c | 87 +++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/char/lrng/lrng_jent.cdrivers/char/lrng/lrng_jent.c new file +24
-0@@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* LRNG Fast Noise Source: Jitter RNG +* +* Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/types.h> +#include <crypto/internal/jitterentropy.h> + +#include "lrng_internal.h" + +/* +* Estimated entropy of data is a 16th of LRNG_DRNG_SECURITY_STRENGTH_BITS. +* Albeit a full entropy assessment is provided for the noise source indicating +* that it provides high entropy rates and considering that it deactivates +* when it detects insufficient hardware, the chosen under estimation of +* entropy is considered to be acceptable to all reviewers. +*/ +static u32 jitterrng =LRNG_DRNG_SECURITY_STRENGTH_BITS >>4 ; +module_param (jitterrng, uint,0644 ); +MODULE_PARM_DESC(jitterrng, "Entropy in bits of 256 data bits from Jitter "
drivers/char/lrng/lrng_jent.c line 34
Quoted 10 lines
drivers/char/lrng/lrng_jent.c new file +10
-0+ "RNG noise source"); + +/** +* Get Jitter RNG entropy +* +* @outbuf buffer to store entropy +* @outbuflen length of buffer +* @return > 0 on success where value provides the added entropy in bits +* 0 if no fast source was available +*/
Don't begin the comment block with /**
or convert it to Linux kernel-doc notation format.
Quoted 44 lines
drivers/char/lrng/lrng_jent.c new file +43
-0+static struct rand_data *lrng_jent_state; + +u32 lrng_get_jent (u8 *outbuf,unsigned int outbuflen) +{ +int ret; +u32 ent_bits = jitterrng; +unsigned long flags; +static DEFINE_SPINLOCK (lrng_jent_lock); +static int lrng_jent_initialized =0 ; + +spin_lock_irqsave (&lrng_jent_lock, flags); + +if (!ent_bits || (lrng_jent_initialized ==-1 )) { +spin_unlock_irqrestore (&lrng_jent_lock, flags); +return 0 ; + } + +if (!lrng_jent_initialized) { + lrng_jent_state =jent_lrng_entropy_collector (); +if (!lrng_jent_state) { + jitterrng =0 ; + lrng_jent_initialized =-1 ; +spin_unlock_irqrestore (&lrng_jent_lock, flags); +pr_info ("Jitter RNG unusable on current system\n" ); +return 0 ; + } + lrng_jent_initialized =1 ; +pr_debug ("Jitter RNG working on current system\n" ); + } + ret =jent_read_entropy (lrng_jent_state, outbuf, outbuflen); +spin_unlock_irqrestore (&lrng_jent_lock, flags); + +if (ret) { +pr_debug ("Jitter RNG failed with %d\n" , ret); +return 0 ; + } + +/* Obtain entropy statement */ +if (outbuflen !=LRNG_DRNG_SECURITY_STRENGTH_BYTES ) + ent_bits = (ent_bits * outbuflen<<3 ) / +LRNG_DRNG_SECURITY_STRENGTH_BITS ; +/* Cap entropy to buffer size in bits */ + ent_bits =min_t (u32, ent_bits, outbuflen<<3 );
drivers/char/lrng/lrng_jent.c line 87
Quoted 10 lines
drivers/char/lrng/lrng_jent.c new file +10
-0+pr_debug ("obtained %u bits of entropy from Jitter RNG noise source\n" , + ent_bits); + +return ent_bits; +} + +u32 lrng_jent_entropylevel (void ) +{ +return min_t (u32, jitterrng,LRNG_DRNG_SECURITY_STRENGTH_BITS ); +}
thanks.
Signature · 1 line
~Randy
Re: [PATCH v27 09/12] LRNG - add Jitter RNG fast noise source
Am Freitag, 10. Januar 2020, 01:24:47 CET schrieb Randy Dunlap:
Hi Randy,
Quoted 47 lines
Hi,
Quoted 44 lines · Stephan Müller
---
drivers/char/lrng/Kconfig | 11 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_jent.c | 87 +++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/char/lrng/lrng_jent.cdrivers/char/lrng/lrng_jent.c new file +16
-0@@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* LRNG Fast Noise Source: Jitter RNG +* +* Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/types.h> +#include <crypto/internal/jitterentropy.h> + +#include "lrng_internal.h" + +/* +* Estimated entropy of data is a 16th of
LRNG_DRNG_SECURITY_STRENGTH_BITS. + * Albeit a full entropy assessment is provided for the noise source indicating + * that it provides high entropy rates and considering that it deactivates + * when it detects insufficient hardware, the chosen under estimation of + * entropy is considered to be acceptable to all reviewers.
+ */drivers/char/lrng/lrng_jent.c new file +3
-0+static u32 jitterrng =LRNG_DRNG_SECURITY_STRENGTH_BITS >>4 ; +module_param (jitterrng, uint,0644 ); +MODULE_PARM_DESC(jitterrng, "Entropy in bits of 256 data bits from Jitter" + "RNG noise source");
drivers/char/lrng/lrng_jent.c new file +4
-0+ +/** +* Get Jitter RNG entropy +*
Quoted 8 lines
Quoted 5 lines
+ * @outbuf buffer to store entropy
+ * @outbuflen length of buffer
+ * @return > 0 on success where value provides the added entropy in bits
+ * 0 if no fast source was available
+ */Don't begin the comment block with /**
or convert it to Linux kernel-doc notation format.
Yes, the colons are missing and there is no @return. It will be fixed with the next patch set.
Thank you.
Quoted 48 lines
Quoted 48 lines
drivers/char/lrng/lrng_jent.c new file +47
-0+static struct rand_data *lrng_jent_state; + +u32 lrng_get_jent (u8 *outbuf,unsigned int outbuflen) +{ +int ret; +u32 ent_bits = jitterrng; +unsigned long flags; +static DEFINE_SPINLOCK (lrng_jent_lock); +static int lrng_jent_initialized =0 ; + +spin_lock_irqsave (&lrng_jent_lock, flags); + +if (!ent_bits || (lrng_jent_initialized ==-1 )) { +spin_unlock_irqrestore (&lrng_jent_lock, flags); +return 0 ; + } + +if (!lrng_jent_initialized) { + lrng_jent_state =jent_lrng_entropy_collector (); +if (!lrng_jent_state) { + jitterrng =0 ; + lrng_jent_initialized =-1 ; +spin_unlock_irqrestore (&lrng_jent_lock, flags); +pr_info ("Jitter RNG unusable on current system\n" ); +return 0 ; + } + lrng_jent_initialized =1 ; +pr_debug ("Jitter RNG working on current system\n" ); + } + ret =jent_read_entropy (lrng_jent_state, outbuf, outbuflen); +spin_unlock_irqrestore (&lrng_jent_lock, flags); + +if (ret) { +pr_debug ("Jitter RNG failed with %d\n" , ret); +return 0 ; + } + +/* Obtain entropy statement */ +if (outbuflen !=LRNG_DRNG_SECURITY_STRENGTH_BYTES ) + ent_bits = (ent_bits * outbuflen<<3 ) / +LRNG_DRNG_SECURITY_STRENGTH_BITS ; +/* Cap entropy to buffer size in bits */ + ent_bits =min_t (u32, ent_bits, outbuflen<<3 ); +pr_debug ("obtained %u bits of entropy from Jitter RNG noise source\n" , + ent_bits); + +return ent_bits;
Quoted 8 lines
drivers/char/lrng/lrng_jent.c line 87
Quoted 6 lines
drivers/char/lrng/lrng_jent.c new file +6
-0+} + +u32 lrng_jent_entropylevel (void ) +{ +return min_t (u32, jitterrng,LRNG_DRNG_SECURITY_STRENGTH_BITS ); +}thanks.
Ciao
Stephan
PATCH v27 10/12 LRNG - add SP800-90B compliant health tests
In reply to Stephan MüllerImplement health tests for LRNG's slow noise sources as mandated by SP-800-90B The file contains the following health tests:
- stuck test: The stuck test calculates the first, second and third discrete derivative of the time stamp to be processed by the LFSR. Only if all three values are non-zero, the received time delta is considered to be non-stuck.
- SP800-90B Repetition Count Test (RCT): The LRNG uses an enhanced version of the RCT specified in SP800-90B section 4.4.1. Instead of counting identical back-to-back values, the input to the RCT is the counting of the stuck values during the processing of received interrupt events. The RCT is applied with alpha=2^-30 compliant to the recommendation of FIPS 140-2 IG 9.8. During the counting operation, the LRNG always calculates the RCT cut-off value of C. If that value exceeds the allowed cut-off value, the LRNG will trigger the health test failure discussed below. An error is logged to the kernel log that such RCT failure occurred. This test is only applied and enforced in FIPS mode, i.e. when the kernel compiled with CONFIG_CONFIG_FIPS is started with fips=1.
- SP800-90B Adaptive Proportion Test (APT): The LRNG implements the APT as defined in SP800-90B section 4.4.2. The applied significance level again is alpha=2^-30 compliant to the recommendation of FIPS 140-2 IG 9.8.
The aforementioned health tests are applied to the first 1,024 time stamps obtained from interrupt events. In case one error is identified for either the RCT, or the APT, the collected entropy is invalidated and the SP800-90B startup health test is restarted.
As long as the SP800-90B startup health test is not completed, all LRNG random number output interfaces that may block will block and not generate any data. This implies that only those potentially blocking interfaces are defined to provide random numbers that are seeded with the interrupt noise source being SP800-90B compliant. All other output interfaces will not be affected by the SP800-90B startup test and thus are not considered SP800-90B compliant.
At runtime, the SP800-90B APT and RCT are applied to each time stamp generated for a received interrupt. When either the APT and RCT indicates a noise source failure, the LRNG is reset to a state it has immediately after boot:
- all entropy counters are set to zero
- the SP800-90B startup tests are re-performed which implies that getrandom(2) would block again until new entropy was collected
To summarize, the following rules apply:
• SP800-90B compliant output interfaces
- /dev/random
- getrandom(2) system call
- get_random_bytes kernel-internal interface when being triggered by the callback registered with add_random_ready_callback
• SP800-90B non-compliant output interfaces
- /dev/urandom
- get_random_bytes kernel-internal interface called directly
- randomize_page kernel-internal interface
- get_random_u32 and get_random_u64 kernel-internal interfaces
- get_random_u32_wait, get_random_u64_wait, get_random_int_wait, and get_random_long_wait kernel-internal interfaces
If either the RCT, or the APT health test fails irrespective whether during initialization or runtime, the following actions occur:
1. The entropy of the entire entropy pool is invalidated.
2. All DRNGs are reset which imply that they are treated as being not seeded and require a reseed during next invocation.
3. The SP800-90B startup health test are initiated with all implications of the startup tests. That implies that from that point on, new events must be observed and its entropy must be inserted into the entropy pool before random numbers are calculated from the entropy pool.
Further details on the SP800-90B compliance and the availability of all test tools required to perform all tests mandated by SP800-90B are provided at [1].
The entire health testing code is compile-time configurable.
The patch provides a CONFIG_BROKEN configuration of the APT / RCT cutoff values which have a high likelihood to trigger the health test failure. The BROKEN APT cutoff is set to the exact mean of the expected value if the time stamps are equally distributed (512 time stamps divided by 16 possible values due to using the 4 LSB of the time stamp). The BROKEN RCT cutoff value is set to 1 which is likely to be triggered during regular operation.
--- drivers/char/lrng/Kconfig | 56 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_health.c | 409 ++++++++++++++++++++++++++++++++ 3 files changed, 466 insertions(+) create mode 100644 drivers/char/lrng/lrng_health.c
drivers/char/lrng/Kconfig +56 -0
@@ -103,4 +103,60 @@ config LRNG_JENT time or at runtime with the lrng_base.jitterrng configuration variable. +config LRNG_HEALTH_TESTS + bool "Enable noise source online health tests" + help + The online health tests validate the noise source at + runtime for fatal errors. These tests include SP800-90B + compliant tests which are invoked if the system is booted + with fips=1. In case of fatal errors during active + SP800-90B tests, the issue is logged and the noise + data is discarded. These tests are required for full + compliance with SP800-90B. + + If unsure, say Y. + +config LRNG_RCT_BROKEN + bool "SP800-90B RCT with dangerous low cutoff value" + depends on LRNG_HEALTH_TESTS + depends on BROKEN + default n + help + This option enables a dangerously low SP800-90B repetitive + count test (RCT) cutoff value which makes it very likely + that the RCT is triggered to raise a self test failure. + + This option is ONLY intended for developers wanting to + test the effectiveness of the SP800-90B RCT health test. + + If unsure, say N. + +config LRNG_APT_BROKEN + bool "SP800-90B APT with dangerous low cutoff value" + depends on LRNG_HEALTH_TESTS + depends on BROKEN + default n + help + This option enables a dangerously low SP800-90B adaptive + proportion test (APT) cutoff value which makes it very + likely that the RCT is triggered to raise a self test + failure. + + This option is ONLY intended for developers wanting to + test the effectiveness of the SP800-90B APT health test. + + If unsure, say N. + +# Default taken from SP800-90B sec 4.4.1 - significance level 2^-30 +config LRNG_RCT_CUTOFF + int + default 30 if !LRNG_RCT_BROKEN + default 1 if LRNG_RCT_BROKEN + +# Default taken from SP800-90B sec 4.4.2 - significance level 2^-30 +config LRNG_APT_CUTOFF + int + default 325 if !LRNG_APT_BROKEN + default 32 if LRNG_APT_BROKEN + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -14,3 +14,4 @@ obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o obj-$(CONFIG_LRNG_JENT) += lrng_jent.o +obj-$(CONFIG_LRNG_HEALTH_TESTS) += lrng_health.o
drivers/char/lrng/lrng_health.c new file +409 -0
409 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH v27 10/12] LRNG - add SP800-90B compliant health tests
Hi,
Quoted 27 lines · Stephan Müller
--- drivers/char/lrng/Kconfig | 56 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_health.c | 409 ++++++++++++++++++++++++++++++++ 3 files changed, 466 insertions(+) create mode 100644 drivers/char/lrng/lrng_health.cdrivers/char/lrng/Kconfig +12
-0@@ -103,4 +103,60 @@ config LRNG_JENT time or at runtime with the lrng_base.jitterrng configuration variable. +config LRNG_HEALTH_TESTS + bool "Enable noise source online health tests" + help + The online health tests validate the noise source at + runtime for fatal errors. These tests include SP800-90B + compliant tests which are invoked if the system is booted + with fips=1. In case of fatal errors during active + SP800-90B tests, the issue is logged and the noise + data is discarded. These tests are required for full + compliance with SP800-90B. + + If unsure, say Y.
drivers/char/lrng/Kconfig config LRNG_JENT · line 127
Quoted 10 lines
drivers/char/lrng/Kconfig +10
-0+ +config LRNG_RCT_BROKEN + bool "SP800-90B RCT with dangerous low cutoff value" + depends on LRNG_HEALTH_TESTS + depends on BROKEN + default n + help + This option enables a dangerously low SP800-90B repetitive + count test (RCT) cutoff value which makes it very likely + that the RCT is triggered to raise a self test failure.
self-test
Quoted 5 lines
drivers/char/lrng/Kconfig +5
-0+ + This option is ONLY intended for developers wanting to + test the effectiveness of the SP800-90B RCT health test. + + If unsure, say N.
drivers/char/lrng/Kconfig config LRNG_JENT · line 142
Quoted 10 lines
drivers/char/lrng/Kconfig +10
-0+ +config LRNG_APT_BROKEN + bool "SP800-90B APT with dangerous low cutoff value" + depends on LRNG_HEALTH_TESTS + depends on BROKEN + default n + help + This option enables a dangerously low SP800-90B adaptive + proportion test (APT) cutoff value which makes it very + likely that the RCT is triggered to raise a self test
self-test
Quoted 33 lines
drivers/char/lrng/Kconfig +19
-0+ failure. + + This option is ONLY intended for developers wanting to + test the effectiveness of the SP800-90B APT health test. + + If unsure, say N. + +# Default taken from SP800-90B sec 4.4.1 - significance level 2^-30 +config LRNG_RCT_CUTOFF + int + default 30 if !LRNG_RCT_BROKEN + default 1 if LRNG_RCT_BROKEN + +# Default taken from SP800-90B sec 4.4.2 - significance level 2^-30 +config LRNG_APT_CUTOFF + int + default 325 if !LRNG_APT_BROKEN + default 32 if LRNG_APT_BROKEN + endif # LRNGdrivers/char/lrng/lrng_health.c new file +6
-0@@ -0,0 +1,409 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* Linux Random Number Generator (LRNG) Health Testing +* +* Copyright (C) 2019 - 2020, Stephan Mueller <[email protected]> +*/
[snip]
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+ +/*************************************************************************** +* SP800-90B Compliance +* +* If the Linux-RNG is booted into FIPS mode, the following interfaces +* provide an SP800-90B compliant noise source: +* +* * /dev/random +* * getrandom(2) +* * get_random_bytes when using it in conjunction with
drivers/char/lrng/lrng_health.c line 104
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+* add_random_ready_callback +* +* All other interfaces, including /dev/urandom or get_random_bytes without +* the add_random_ready_callback cannot claim to use an SP800-90B compliant +* noise source. +***************************************************************************/ + +/** +* Perform SP800-90B startup testing +*/
/** in the kernel sources means "this is the beginning of a kernel-doc comment block", but this is not a kernel-doc comment block, so just use /* to begin the comment.
Quoted 11 lines
drivers/char/lrng/lrng_health.c new file +11
-0+static inline void lrng_sp80090b_startup (struct lrng_health *health) +{ +if (!health->sp80090b_startup_done && +atomic_dec_and_test (&health->sp80090b_startup_blocks)) { + health->sp80090b_startup_done = true; +pr_info ("SP800-90B startup health tests completed\n" ); +lrng_init_ops (0 ); + +/* +* Force a reseed of DRNGs to ensure they are seeded with +* entropy that passed the SP800-90B health tests.
drivers/char/lrng/lrng_health.c line 125
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+* As the DRNG always will reseed before generating +* random numbers, it does not need a reseed trigger. +*/ +lrng_drng_force_reseed (); + } +} + +/** +* Handle failure of SP800-90B startup testing +*/
ditto
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+static inline void lrng_sp80090b_startup_failure (struct lrng_health *health) +{ +/* Reset of LRNG and its entropy - NOTE: we are in atomic context */ +lrng_reset (); + +/* +* Reset the SP800-90B startup test. +* +* NOTE SP800-90B section 4.3 bullet 4 does not specify what +* exactly is to be done in case of failure! Thus, we do what
drivers/char/lrng/lrng_health.c line 145
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+* makes sense, i.e. restarting the health test and thus gating +* the output function of /dev/random and getrandom(2). +*/ +atomic_set (&health->sp80090b_startup_blocks, +LRNG_SP80090B_STARTUP_BLOCKS ); +} + +/** +* Handle failure of SP800-90B runtime testing +*/
ditto
Quoted 15 lines
drivers/char/lrng/lrng_health.c new file +15
-0+static inline void lrng_sp80090b_runtime_failure (struct lrng_health *health) +{ +lrng_sp80090b_startup_failure (health); + health->sp80090b_startup_done = false; +} + +static inline void lrng_sp80090b_failure (struct lrng_health *health) +{ +if (health->sp80090b_startup_done) { +pr_err ("SP800-90B runtime health test failure - invalidating " +"all existing entropy and initiate SP800-90B startup\n" ); +lrng_sp80090b_runtime_failure (health); + }else { +pr_err ("SP800-90B startup test failure - resetting\n" ); +lrng_sp80090b_startup_failure (health);
drivers/char/lrng/lrng_health.c line 170
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+ } +} + +/** +* Is the SP800-90B startup testing complete? +* +* This function is called by the LRNG to determine whether to unblock +* a certain user interface. Therefore, only the potentially blocking +* user interfaces are considered SP800-90B compliant. +*/
ditto.
Quoted 16 lines
drivers/char/lrng/lrng_health.c new file +16
-0+bool lrng_sp80090b_startup_complete (void ) +{ +struct lrng_health *health = &lrng_health; + +return (lrng_sp80090b_health_enabled ()) ? health->sp80090b_startup_done: + true; +} + +bool lrng_sp80090b_compliant (void ) +{ +struct lrng_health *health = &lrng_health; + +return lrng_sp80090b_health_enabled () && health->sp80090b_startup_done; +} + +/***************************************************************************
drivers/char/lrng/lrng_health.c line 196
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+* Adaptive Proportion Test +* +* This test complies with SP800-90B section 4.4.2. +***************************************************************************/ + +/** +* Reset the APT counter +* +* @health [in] Reference to health state +*/
ditto
Quoted 21 lines
drivers/char/lrng/lrng_health.c new file +21
-0+static inline void lrng_apt_reset (struct lrng_health *health, +unsigned int time_masked) +{ +struct lrng_apt *apt = &health->apt; + +pr_debug ("APT value %d for base %d\n" , +atomic_read (&apt->apt_count),atomic_read (&apt->apt_base)); + +/* Reset APT */ +atomic_set (&apt->apt_count,0 ); +atomic_set (&apt->apt_base, time_masked); +} + +static inline void lrng_apt_restart (struct lrng_health *health) +{ +struct lrng_apt *apt = &health->apt; + +atomic_set (&apt->apt_trigger,LRNG_APT_WINDOW_SIZE ); +} + +/**
drivers/char/lrng/lrng_health.c line 227
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+* Insert a new entropy event into APT +* +* This function does is void as it does not decide about the fate of a time +* stamp. An APT failure can only happen at the same time of a stuck test +* failure. Thus, the stuck failure will already decide how the time stamp +* is handled. +* +* @health [in] Reference to health state +* @now_time [in] Time stamp to process +*/
ditto
or use complete kernel-doc notation.
Quoted 44 lines
drivers/char/lrng/lrng_health.c new file +44
-0+static inline void lrng_apt_insert (struct lrng_health *health, +unsigned int now_time) +{ +struct lrng_apt *apt = &health->apt; + +if (!lrng_sp80090b_health_requested ()) +return ; + + now_time &=LRNG_APT_WORD_MASK ; + +/* Initialization of APT */ +if (!apt->apt_base_set) { +atomic_set (&apt->apt_base, now_time); + apt->apt_base_set = true; +return ; + } + +if (now_time == (unsigned int )atomic_read (&apt->apt_base)) { +u32 apt_val = (u32 )atomic_inc_return_relaxed (&apt->apt_count); + +if (apt_val >=CONFIG_LRNG_APT_CUTOFF ) +lrng_sp80090b_failure (health); + } + +if (atomic_dec_and_test (&apt->apt_trigger)) { +lrng_apt_restart (health); +lrng_apt_reset (health, now_time); +lrng_sp80090b_startup (health); + } +} + +/*************************************************************************** +* Repetition Count Test +* +* The LRNG uses an enhanced version of the Repetition Count Test +* (RCT) specified in SP800-90B section 4.4.1. Instead of counting identical +* back-to-back values, the input to the RCT is the counting of the stuck +* values while filling the entropy pool. +* +* The RCT is applied with an alpha of 2^-30 compliant to FIPS 140-2 IG 9.8. +* +* During the counting operation, the LRNG always calculates the RCT +* cut-off value of C. If that value exceeds the allowed cut-off value, +* the LRNG will invalidate all entropy for the entropy pool which implies
drivers/char/lrng/lrng_health.c line 281
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+* that no data can be extracted from the entropy pool unless new entropy +* is received. +***************************************************************************/ + +/** +* Hot code path - Insert data for Repetition Count Test +* +* @health: Reference to health information +* @stuck: Decision of stuck test +*/
ditto
Quoted 58 lines
drivers/char/lrng/lrng_health.c new file +58
-0+static inline void lrng_rct (struct lrng_health *health,int stuck) +{ +struct lrng_rct *rct = &health->rct; + +if (!lrng_sp80090b_health_requested ()) +return ; + +if (stuck) { +u32 rct_count =atomic_add_return_relaxed (1 , &rct->rct_count); + +pr_debug ("RCT count: %u\n" , rct_count); + +/* +* The cutoff value is based on the following consideration: +* alpha = 2^-30 as recommended in FIPS 140-2 IG 9.8. +* In addition, we imply an entropy value H of 1 bit as this +* is the minimum entropy required to provide full entropy. +* +* Note, rct_count (which equals to value B in the +* pseudo code of SP800-90B section 4.4.1) starts with zero. +* Hence we need to subtract one from the cutoff value as +* calculated following SP800-90B. +*/ +if (rct_count >=CONFIG_LRNG_RCT_CUTOFF ) { +atomic_set (&rct->rct_count,0 ); + +/* +* APT must start anew as we consider all previously +* recorded data to contain no entropy. +*/ +lrng_apt_restart (health); + +lrng_sp80090b_failure (health); + } + }else { +atomic_set (&rct->rct_count,0 ); + } +} + +/*************************************************************************** +* Stuck Test +* +* Checking the: +* 1st derivative of the event occurrence (time delta) +* 2nd derivative of the event occurrence (delta of time deltas) +* 3rd derivative of the event occurrence (delta of delta of time deltas) +* +* All values must always be non-zero. The stuck test is only valid disabled if +* high-resolution time stamps are identified after initialization. +***************************************************************************/ + +static inline u32 lrng_delta (u32 prev,u32 next) +{ +/* +* Note that this (unsigned) subtraction does yield the correct value +* in the wraparound-case, i.e. when next < prev. +*/ +return (next - prev);
drivers/char/lrng/lrng_health.c line 349
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+} + +/** +* Hot code path +* +* @health: Reference to health information +* @now: Event time +* @return: 0 event occurrence not stuck (good time stamp) +* != 0 event occurrence stuck (reject time stamp) +*/
ditto
Quoted 13 lines
drivers/char/lrng/lrng_health.c new file +13
-0+static inline int lrng_irq_stuck (struct lrng_stuck_test *stuck,u32 now_time) +{ +u32 delta =lrng_delta (stuck->last_time, now_time); +u32 delta2 =lrng_delta (stuck->last_delta, delta); +u32 delta3 =lrng_delta (stuck->last_delta2, delta2); + + stuck->last_time = now_time; + stuck->last_delta = delta; + stuck->last_delta2 = delta2; + +if (!delta || !delta2 || !delta3) +return 1 ; +
drivers/char/lrng/lrng_health.c line 372
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+return 0 ; +} + +/*************************************************************************** +* Health test interfaces +***************************************************************************/ + +/** +* Disable all health tests +*/
ditto
Quoted 6 lines
drivers/char/lrng/lrng_health.c new file +6
-0+void lrng_health_disable (void ) +{ +struct lrng_health *health = &lrng_health; + + health->health_test_enabled = false; +
drivers/char/lrng/lrng_health.c line 388
Quoted 10 lines
drivers/char/lrng/lrng_health.c new file +10
-0+if (lrng_sp80090b_health_requested ()) +pr_warn ("SP800-90B compliance requested but the Linux RNG is " +"NOT SP800-90B compliant\n" ); +} + +/** +* Hot code path - Perform health test on time stamp received from an event +* +* @now_time Time stap +*/
ditto
drivers/char/lrng/lrng_health.c line 390
Quoted 2 lines
drivers/char/lrng/lrng_health.c new file +2
-0+enum lrng_health_res lrng_health_test (u32 now_time) +{
Thanks.
Signature · 1 line
~Randy
Re: [PATCH v27 10/12] LRNG - add SP800-90B compliant health tests
Am Freitag, 10. Januar 2020, 01:20:44 CET schrieb Randy Dunlap:
Hi Randy,
I have removed the two stars in front of each comment.
I have also fixed the respective comments in lrng_interfaces.c, lrng_archrandom.c, lrng_chacha20.c, lrng_drng.c, lrng_pool.c, lrng_switch.c, lrng_sw_noise.c. In all other files there were no changes needed.
Thank you.
Ciao
Stephan
PATCH v27 11/12 LRNG - add interface for gathering of raw entropy
In reply to Stephan MüllerThe test interface allows a privileged process to capture the raw unconditioned noise that is collected by the LRNG for statistical analysis. Such testing allows the analysis how much entropy the interrupt noise source provides on a given platform. Extracted noise data is not used to seed the LRNG. This is a test interface and not appropriate for production systems. Yet, the interface is considered to be sufficiently secured for production systems.
Access to the data is given through the lrng_raw debugfs file. The data buffer should be multiples of sizeof(u32) to fill the entire buffer. Using the option lrng_testing.boot_test=1 the raw noise of the first 1000 entropy events since boot can be sampled.
This test interface allows generating the data required for analysis whether the LRNG is in compliance with SP800-90B sections 3.1.3 and 3.1.4.
--- drivers/char/lrng/Kconfig | 16 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_testing.c | 271 +++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+) create mode 100644 drivers/char/lrng/lrng_testing.c
drivers/char/lrng/Kconfig +16 -0
@@ -159,4 +159,20 @@ config LRNG_APT_CUTOFF default 325 if !LRNG_APT_BROKEN default 32 if LRNG_APT_BROKEN +config LRNG_TESTING + bool "Enable entropy test interface to LRNG noise source" + depends on DEBUG_FS + help + The test interface allows a privileged process to capture + the raw unconditioned noise that is collected by the LRNG + for statistical analysis. Extracted noise data is not used + to seed the LRNG. + + The raw noise data can be obtained using the lrng_raw + debugfs file. Using the option lrng_testing.boot_test=1 + the raw noise of the first 1000 entropy events since boot + can be sampled. + + If unsure, say N. + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o obj-$(CONFIG_LRNG_JENT) += lrng_jent.o obj-$(CONFIG_LRNG_HEALTH_TESTS) += lrng_health.o +obj-$(CONFIG_LRNG_TESTING) += lrng_testing.o
drivers/char/lrng/lrng_testing.c new file +271 -0
271 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v27 12/12 LRNG - add power-on and runtime self-tests
In reply to Stephan MüllerParts of the LFSR are already covered by self-tests, including:
* Self-test of SP800-90A DRBG provided by the Linux kernel crypto API.
* Self-test of the PRNG provided by the Linux kernel crypto API.
* Raw noise source data testing including SP800-90B compliant tests when enabling CONFIG_LRNG_HEALTH_TESTS
This patch adds the self tests for the remaining critical functions of the LRNG that are essential to maintain entropy and provide cryptographic strong random numbers. The following self tests are implemented:
* Self-test of the time array maintenance. This test verifies whether the time stamp array management to store multiple values in one integer implements a concatenation of the data.
* Self-test of the LFSR operation. This test injects a monotonic increasing counter into the LFSR. After completion of the injection of the counter, 3 pool words are compared with known good values. The known good values are calculated with the newly-developed tool lfsr_testvector_generation provided as part of the LRNG test tool set at [1].
* Self-test of the Hash_DF operation ensures that this function operates compliant to the specification. The self-test performs a Hash_DF operation of a zeroized entropy pool state. The test vectors are generated using the newly-developed tool hash_df_testvector_generation provided as part of the LRNG test tool set at [1].
* Self-test of the ChaCha20 DRNG is based on the self tests that are already present and implemented with the stand-alone user space ChaCha20 DRNG implementation available at [2]. The self-tests cover different use cases of the DRNG seeded with known seed data.
The status of the LRNG self-tests is provided with the selftest_status SysFS file. If the file contains a zero, the self-tests passed. The value 0xffffffff means that the self-tests were not executed. Any other value indicates a self test failure.
The self-test may be compiled to panic the system if the self-test fails.
All self tests operate on private state data structures. This implies that none of the self-tests have any impact on the regular LRNG operations. This allows the self-tests to be repeated at runtime by writing anything into the selftest_status SysFS file.
[1] https://www.chronox.de/lrng.html
[2] https://www.chronox.de/chacha20.html
--- drivers/char/lrng/Kconfig | 25 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_selftest.c | 418 ++++++++++++++++++++++++++++++ 3 files changed, 444 insertions(+) create mode 100644 drivers/char/lrng/lrng_selftest.c
drivers/char/lrng/Kconfig +25 -0
@@ -175,4 +175,29 @@ config LRNG_TESTING If unsure, say N. +config LRNG_SELFTEST + bool "Enable power-on and on-demand self-tests" + help + The power-on self tests are executed during boot time + covering the ChaCha20 DRNG, the LFSR processing and the + time stamp management of the LRNG. + + The on-demand self-tests are triggered by writing any + value into the SysFS file selftest_status. At the same + time, when reading this file, the test status is + returned. A zero indicates that all tests were executed + successfully. + + If unsure, say Y. + +if LRNG_SELFTEST + +config LRNG_SELFTEST_PANIC + bool "Panic the kernel upon self-test failure" + help + If the option is enabled, the kernel is terminated if an + LRNG power-on self-test failure is detected. + +endif # LRNG_SELFTEST + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -16,3 +16,4 @@ obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o obj-$(CONFIG_LRNG_JENT) += lrng_jent.o obj-$(CONFIG_LRNG_HEALTH_TESTS) += lrng_health.o obj-$(CONFIG_LRNG_TESTING) += lrng_testing.o +obj-$(CONFIG_LRNG_SELFTEST) += lrng_selftest.o
drivers/char/lrng/lrng_selftest.c new file +418 -0
418 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH v27 12/12] LRNG - add power-on and runtime self-tests
Hi,
Quoted 12 lines · Stephan Müller
--- drivers/char/lrng/Kconfig | 25 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_selftest.c | 418 ++++++++++++++++++++++++++++++ 3 files changed, 444 insertions(+) create mode 100644 drivers/char/lrng/lrng_selftest.cdrivers/char/lrng/Kconfig +0
-0
drivers/char/lrng/Kconfig config LRNG_TESTING · line 181
Quoted 7 lines
drivers/char/lrng/Kconfig +4
-0@@ -175,4 +175,29 @@ config LRNG_TESTING If unsure, say N. +config LRNG_SELFTEST + bool "Enable power-on and on-demand self-tests" + help + The power-on self tests are executed during boot time
self-tests
Quoted 22 lines
drivers/char/lrng/Kconfig +21
-0+ covering the ChaCha20 DRNG, the LFSR processing and the + time stamp management of the LRNG. + + The on-demand self-tests are triggered by writing any + value into the SysFS file selftest_status. At the same + time, when reading this file, the test status is + returned. A zero indicates that all tests were executed + successfully. + + If unsure, say Y. + +if LRNG_SELFTEST + +config LRNG_SELFTEST_PANIC + bool "Panic the kernel upon self-test failure" + help + If the option is enabled, the kernel is terminated if an + LRNG power-on self-test failure is detected. + +endif # LRNG_SELFTEST + endif # LRNG
Signature · 1 line
~Randy
Re: [PATCH v27 12/12] LRNG - add power-on and runtime self-tests
Am Freitag, 10. Januar 2020, 01:22:51 CET schrieb Randy Dunlap:
Hi Randy,
Quoted 17 lines
Hi,
Quoted 14 lines · Stephan Müller
---
drivers/char/lrng/Kconfig | 25 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_selftest.c | 418 ++++++++++++++++++++++++++++++ 3 files changed, 444 insertions(+) create mode 100644 drivers/char/lrng/lrng_selftest.cdrivers/char/lrng/Kconfig +0
-0@@ -175,4 +175,29 @@ config LRNG_TESTING
Quoted 8 lines
drivers/char/lrng/Kconfig config LRNG_TESTING · line 181
Quoted 6 lines
drivers/char/lrng/Kconfig +4
-0If unsure, say N. +config LRNG_SELFTEST + bool "Enable power-on and on-demand self-tests" + help + The power-on self tests are executed during boot timeself-tests
Fixed in all occurrences. Thank you.
Quoted 23 lines
Quoted 23 lines
drivers/char/lrng/Kconfig +21
-0+ covering the ChaCha20 DRNG, the LFSR processing and the + time stamp management of the LRNG. + + The on-demand self-tests are triggered by writing any + value into the SysFS file selftest_status. At the same + time, when reading this file, the test status is + returned. A zero indicates that all tests were executed + successfully. + + If unsure, say Y. + +if LRNG_SELFTEST + +config LRNG_SELFTEST_PANIC + bool "Panic the kernel upon self-test failure" + help + If the option is enabled, the kernel is terminated if an + LRNG power-on self-test failure is detected. + +endif # LRNG_SELFTEST +
Quoted 1 line
Quoted 1 line
endif # LRNG
Ciao
Stephan
Re: [PATCH v27 12/12] LRNG - add power-on and runtime self-tests
In reply to Stephan MüllerHi "Stephan,
url: https://github.com/0day-ci/linux/commits/Stephan-M-ller/dev-random-a-new-approach-with-full-SP800-90B/20200110-084934 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git 68faa679b8be1a74e6663c21c3a9d25d32f1c079
If you fix the issue, kindly add following tag
smatch warnings:drivers/char/lrng/lrng_selftest.c:117 lrng_pool_lfsr_selftest() warn: sizeof(NUMBER)? drivers/char/lrng/lrng_selftest.c:229 lrng_hash_df_selftest() warn: sizeof(NUMBER)?
# https://github.com/0day-ci/linux/commit/5b6f2811172c968d8eb78167825c58557ea91995
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 5b6f2811172c968d8eb78167825c58557ea91995
vim +117 drivers/char/lrng/lrng_selftest.c
5b6f2811172c96 Stephan Müller 2020-01-09 89 static unsigned int lrng_pool_lfsr_selftest(void)
5b6f2811172c96 Stephan Müller 2020-01-09 90 {
5b6f2811172c96 Stephan Müller 2020-01-09 91 /*
5b6f2811172c96 Stephan Müller 2020-01-09 92 * First, 67th and last entry of entropy pool.
5b6f2811172c96 Stephan Müller 2020-01-09 93 *
5b6f2811172c96 Stephan Müller 2020-01-09 94 * The 67th entry is picked because this one is the first to receive
5b6f2811172c96 Stephan Müller 2020-01-09 95 * an entry. As we start with 1 to inject into the LFSR, the
5b6f2811172c96 Stephan Müller 2020-01-09 96 * 67th entry should be equal to rol(1, 7) >> 3 considering that
5b6f2811172c96 Stephan Müller 2020-01-09 97 * all other values of the LFSR are zero and the the twist value of 0
5b6f2811172c96 Stephan Müller 2020-01-09 98 * is applied.
5b6f2811172c96 Stephan Müller 2020-01-09 99 */
5b6f2811172c96 Stephan Müller 2020-01-09 100 static u32 const lrng_lfsr_selftest_result[][3] = {
5b6f2811172c96 Stephan Müller 2020-01-09 101 { 0xf56df24a, 0x00000010, 0x0e014939 },
5b6f2811172c96 Stephan Müller 2020-01-09 102 { 0x4b130726, 0x00000010, 0x2802f509 },
5b6f2811172c96 Stephan Müller 2020-01-09 103 { 0x87279152, 0x00000010, 0x00150000 },
5b6f2811172c96 Stephan Müller 2020-01-09 104 { 0x0b67f997, 0x00000010, 0x00150000 },
5b6f2811172c96 Stephan Müller 2020-01-09 105 { 0x4fea174f, 0x00000010, 0xcbf4a6ae },
5b6f2811172c96 Stephan Müller 2020-01-09 106 { 0x77149108, 0x00000010, 0x77bfadf2 },
5b6f2811172c96 Stephan Müller 2020-01-09 107 { 0x1e96037e, 0x00000010, 0x18017e79 },
5b6f2811172c96 Stephan Müller 2020-01-09 108 { 0xc84acef2, 0x00000010, 0x6345f7a8 },
5b6f2811172c96 Stephan Müller 2020-01-09 109 { 0x6a2eb6df, 0x00000010, 0x03950000 },
5b6f2811172c96 Stephan Müller 2020-01-09 110 };
5b6f2811172c96 Stephan Müller 2020-01-09 111 struct lrng_pool *lrng_pool, *lrng_pool_aligned;
5b6f2811172c96 Stephan Müller 2020-01-09 112 u32 i, ret = LRNG_SELFTEST_PASSED;
5b6f2811172c96 Stephan Müller 2020-01-09 113
5b6f2811172c96 Stephan Müller 2020-01-09 114 BUILD_BUG_ON(ARRAY_SIZE(lrng_lfsr_selftest_result) <
5b6f2811172c96 Stephan Müller 2020-01-09 115 CONFIG_LRNG_POOL_SIZE);
5b6f2811172c96 Stephan Müller 2020-01-09 116
5b6f2811172c96 Stephan Müller 2020-01-09 @117 lrng_pool = kzalloc(sizeof(struct lrng_pool) + sizeof(LRNG_KCAPI_ALIGN),
^^^^^^^^^^^^^^^^^^^^^^^^Probably just LRNG_KCAPI_ALIGN is intended with no sizeof().
5b6f2811172c96 Stephan Müller 2020-01-09 118 GFP_KERNEL);
5b6f2811172c96 Stephan Müller 2020-01-09 119 if (!lrng_pool)
5b6f2811172c96 Stephan Müller 2020-01-09 120 return LRNG_SEFLTEST_ERROR_LFSR;
5b6f2811172c96 Stephan Müller 2020-01-09 121 lrng_pool_aligned = PTR_ALIGN(lrng_pool, sizeof(u32));
5b6f2811172c96 Stephan Müller 2020-01-09 122
5b6f2811172c96 Stephan Müller 2020-01-09 123 for (i = 1; i <= LRNG_POOL_SIZE; i++)
5b6f2811172c96 Stephan Müller 2020-01-09 124 _lrng_pool_lfsr_u32(lrng_pool_aligned, i);
5b6f2811172c96 Stephan Müller 2020-01-09 125
5b6f2811172c96 Stephan Müller 2020-01-09 126 if ((atomic_read_u32(&lrng_pool_aligned->pool[0]) !=
5b6f2811172c96 Stephan Müller 2020-01-09 127 lrng_lfsr_selftest_result[CONFIG_LRNG_POOL_SIZE][0]) ||
5b6f2811172c96 Stephan Müller 2020-01-09 128 (atomic_read_u32(&lrng_pool_aligned->pool[67 &
5b6f2811172c96 Stephan Müller 2020-01-09 129 (LRNG_POOL_SIZE - 1)]) !=
5b6f2811172c96 Stephan Müller 2020-01-09 130 lrng_lfsr_selftest_result[CONFIG_LRNG_POOL_SIZE][1]) ||
5b6f2811172c96 Stephan Müller 2020-01-09 131 (atomic_read_u32(&lrng_pool_aligned->pool[LRNG_POOL_SIZE - 1]) !=
5b6f2811172c96 Stephan Müller 2020-01-09 132 lrng_lfsr_selftest_result[CONFIG_LRNG_POOL_SIZE][2])) {
5b6f2811172c96 Stephan Müller 2020-01-09 133 pr_err("LRNG LFSR self-test FAILED\n");
5b6f2811172c96 Stephan Müller 2020-01-09 134 ret = LRNG_SEFLTEST_ERROR_LFSR;
5b6f2811172c96 Stephan Müller 2020-01-09 135 }
5b6f2811172c96 Stephan Müller 2020-01-09 136
5b6f2811172c96 Stephan Müller 2020-01-09 137 kfree(lrng_pool);
5b6f2811172c96 Stephan Müller 2020-01-09 138 return ret;
5b6f2811172c96 Stephan Müller 2020-01-09 139 }
5b6f2811172c96 Stephan Müller 2020-01-09 140
5b6f2811172c96 Stephan Müller 2020-01-09 141 /*
5b6f2811172c96 Stephan Müller 2020-01-09 142 * The test vectors are generated with the hash_df_testvector_generation tool
5b6f2811172c96 Stephan Müller 2020-01-09 143 * provided as part of the test tool set of the LRNG.
5b6f2811172c96 Stephan Müller 2020-01-09 144 */
5b6f2811172c96 Stephan Müller 2020-01-09 145 static unsigned int lrng_hash_df_selftest(void)
5b6f2811172c96 Stephan Müller 2020-01-09 146 {
5b6f2811172c96 Stephan Müller 2020-01-09 147 const struct lrng_crypto_cb *crypto_cb = &lrng_cc20_crypto_cb;
5b6f2811172c96 Stephan Müller 2020-01-09 148
5b6f2811172c96 Stephan Müller 2020-01-09 149 /*
5b6f2811172c96 Stephan Müller 2020-01-09 150 * The size of 45 bytes is chosen arbitrarily. Yet, this size should
5b6f2811172c96 Stephan Müller 2020-01-09 151 * ensure that we have at least two hash blocks plus some fraction
5b6f2811172c96 Stephan Müller 2020-01-09 152 * of a hash block generated.
5b6f2811172c96 Stephan Müller 2020-01-09 153 */
5b6f2811172c96 Stephan Müller 2020-01-09 154 static u8 const lrng_hash_df_selftest_result[][45] = {
5b6f2811172c96 Stephan Müller 2020-01-09 155 {
5b6f2811172c96 Stephan Müller 2020-01-09 156 0x3b, 0xbe, 0x7a, 0xbd, 0x2b, 0x16, 0x02, 0x4c,
5b6f2811172c96 Stephan Müller 2020-01-09 157 0xfc, 0xd3, 0x02, 0x15, 0xf0, 0x86, 0xd4, 0xdb,
5b6f2811172c96 Stephan Müller 2020-01-09 158 0x49, 0xec, 0x26, 0x53, 0xd6, 0xc9, 0x6d, 0xad,
5b6f2811172c96 Stephan Müller 2020-01-09 159 0x24, 0xca, 0x72, 0x89, 0x2c, 0xfa, 0x48, 0x18,
5b6f2811172c96 Stephan Müller 2020-01-09 160 0xf7, 0x47, 0xb5, 0x2f, 0x92, 0xa2, 0x1b, 0xd9,
5b6f2811172c96 Stephan Müller 2020-01-09 161 0x24, 0xa7, 0x2f, 0xa2, 0x0b,
5b6f2811172c96 Stephan Müller 2020-01-09 162 }, {
5b6f2811172c96 Stephan Müller 2020-01-09 163 0xd2, 0xaa, 0xf9, 0x76, 0x26, 0xc6, 0x13, 0xea,
5b6f2811172c96 Stephan Müller 2020-01-09 164 0xb8, 0xde, 0xe6, 0x88, 0x8f, 0xc4, 0x7a, 0x7d,
5b6f2811172c96 Stephan Müller 2020-01-09 165 0x9c, 0xb4, 0x1b, 0xd1, 0xd1, 0x8a, 0x40, 0xc9,
5b6f2811172c96 Stephan Müller 2020-01-09 166 0xaa, 0x45, 0xa6, 0xb6, 0xb5, 0x6f, 0xf6, 0xbc,
5b6f2811172c96 Stephan Müller 2020-01-09 167 0xbb, 0x77, 0x37, 0xbc, 0x5a, 0x2d, 0xcc, 0x84,
5b6f2811172c96 Stephan Müller 2020-01-09 168 0x25, 0x68, 0x5e, 0xba, 0x16,
5b6f2811172c96 Stephan Müller 2020-01-09 169 }, {
5b6f2811172c96 Stephan Müller 2020-01-09 170 0x58, 0x66, 0x82, 0x88, 0x29, 0x19, 0xa4, 0xbb,
5b6f2811172c96 Stephan Müller 2020-01-09 171 0x33, 0x42, 0xc9, 0x72, 0x0d, 0x68, 0x6e, 0xb9,
5b6f2811172c96 Stephan Müller 2020-01-09 172 0xc6, 0xe0, 0x7a, 0xf9, 0x20, 0xca, 0x6d, 0x18,
5b6f2811172c96 Stephan Müller 2020-01-09 173 0x35, 0xec, 0xfa, 0x9e, 0xf6, 0x3a, 0xa7, 0xb6,
5b6f2811172c96 Stephan Müller 2020-01-09 174 0x92, 0x7a, 0xe5, 0xcd, 0xc5, 0x13, 0x9f, 0x65,
5b6f2811172c96 Stephan Müller 2020-01-09 175 0x6a, 0xe1, 0xe4, 0x3f, 0xb9,
5b6f2811172c96 Stephan Müller 2020-01-09 176 }, {
5b6f2811172c96 Stephan Müller 2020-01-09 177 0xdd, 0xf1, 0x34, 0xca, 0x08, 0xe3, 0xce, 0x8a,
5b6f2811172c96 Stephan Müller 2020-01-09 178 0x26, 0x6b, 0xce, 0x99, 0x8a, 0x84, 0xd2, 0x21,
5b6f2811172c96 Stephan Müller 2020-01-09 179 0x98, 0x10, 0x95, 0x5f, 0x9f, 0xc3, 0xf2, 0xe4,
5b6f2811172c96 Stephan Müller 2020-01-09 180 0x79, 0x75, 0xb5, 0x15, 0xa7, 0xa2, 0xf1, 0xc4,
5b6f2811172c96 Stephan Müller 2020-01-09 181 0xdc, 0x67, 0xcb, 0x67, 0x8c, 0xb2, 0x1b, 0xd5,
5b6f2811172c96 Stephan Müller 2020-01-09 182 0xd6, 0x8b, 0xc2, 0x34, 0xd6,
5b6f2811172c96 Stephan Müller 2020-01-09 183 }, {
5b6f2811172c96 Stephan Müller 2020-01-09 184 0xc3, 0x16, 0x9d, 0xf0, 0x78, 0x15, 0xab, 0xf2,
5b6f2811172c96 Stephan Müller 2020-01-09 185 0x2f, 0xc9, 0x2e, 0xe1, 0xc6, 0x5e, 0xfa, 0x03,
5b6f2811172c96 Stephan Müller 2020-01-09 186 0xaf, 0xd4, 0xd5, 0x47, 0x2a, 0xe8, 0x06, 0xe8,
5b6f2811172c96 Stephan Müller 2020-01-09 187 0x7e, 0x0a, 0x71, 0xc7, 0x0d, 0x39, 0xb1, 0xa9,
5b6f2811172c96 Stephan Müller 2020-01-09 188 0x5a, 0x49, 0xee, 0x8b, 0x2f, 0xcd, 0xea, 0x96,
5b6f2811172c96 Stephan Müller 2020-01-09 189 0xcc, 0x08, 0x71, 0xef, 0x9c,
5b6f2811172c96 Stephan Müller 2020-01-09 190 }, {
5b6f2811172c96 Stephan Müller 2020-01-09 191 0x1a, 0x3d, 0x70, 0x39, 0xc2, 0x02, 0x4d, 0x3a,
5b6f2811172c96 Stephan Müller 2020-01-09 192 0xaa, 0x14, 0x20, 0x88, 0x96, 0x4c, 0x7c, 0xe4,
5b6f2811172c96 Stephan Müller 2020-01-09 193 0xaa, 0x49, 0x89, 0x30, 0x50, 0x96, 0xb6, 0xa7,
5b6f2811172c96 Stephan Müller 2020-01-09 194 0x55, 0x0a, 0xf8, 0xd2, 0x4e, 0x83, 0x9d, 0x1f,
5b6f2811172c96 Stephan Müller 2020-01-09 195 0x56, 0x49, 0x13, 0xc6, 0x46, 0x55, 0x73, 0x0d,
5b6f2811172c96 Stephan Müller 2020-01-09 196 0x74, 0xcd, 0x81, 0xe0, 0x65,
5b6f2811172c96 Stephan Müller 2020-01-09 197 }, {
5b6f2811172c96 Stephan Müller 2020-01-09 198 0x4b, 0xf6, 0x49, 0x89, 0x2a, 0x9f, 0x67, 0xd7,
5b6f2811172c96 Stephan Müller 2020-01-09 199 0xb8, 0x1d, 0xbb, 0x5d, 0xf0, 0x1b, 0x60, 0xb6,
5b6f2811172c96 Stephan Müller 2020-01-09 200 0xb7, 0xf3, 0x86, 0x6d, 0xe0, 0x04, 0xa1, 0xbc,
5b6f2811172c96 Stephan Müller 2020-01-09 201 0x3b, 0xb0, 0x10, 0x91, 0xe8, 0x22, 0x67, 0x5b,
5b6f2811172c96 Stephan Müller 2020-01-09 202 0xe8, 0xf0, 0x4f, 0x82, 0x70, 0xc7, 0xe1, 0xc8,
5b6f2811172c96 Stephan Müller 2020-01-09 203 0xd8, 0xad, 0x70, 0xcf, 0xf6,
5b6f2811172c96 Stephan Müller 2020-01-09 204 }, {
5b6f2811172c96 Stephan Müller 2020-01-09 205 0x60, 0x1f, 0x71, 0x07, 0x92, 0xae, 0xa0, 0x24,
5b6f2811172c96 Stephan Müller 2020-01-09 206 0xb6, 0xa4, 0x10, 0x70, 0x1f, 0x94, 0x51, 0x9a,
5b6f2811172c96 Stephan Müller 2020-01-09 207 0x5a, 0x81, 0xc4, 0x46, 0x78, 0x56, 0x71, 0xdd,
5b6f2811172c96 Stephan Müller 2020-01-09 208 0x45, 0x63, 0x01, 0x34, 0x87, 0x79, 0xb4, 0xd5,
5b6f2811172c96 Stephan Müller 2020-01-09 209 0x91, 0x79, 0xb9, 0x93, 0x11, 0x44, 0x50, 0xad,
5b6f2811172c96 Stephan Müller 2020-01-09 210 0x64, 0x7e, 0x5c, 0xec, 0x16,
5b6f2811172c96 Stephan Müller 2020-01-09 211 }, {
5b6f2811172c96 Stephan Müller 2020-01-09 212 0x49, 0x2f, 0xa0, 0x45, 0xf8, 0xb0, 0x80, 0x88,
5b6f2811172c96 Stephan Müller 2020-01-09 213 0x79, 0xeb, 0xb6, 0x82, 0x1c, 0xf3, 0x67, 0xc4,
5b6f2811172c96 Stephan Müller 2020-01-09 214 0x88, 0x88, 0xe9, 0x75, 0x20, 0x54, 0x78, 0xc6,
5b6f2811172c96 Stephan Müller 2020-01-09 215 0x5c, 0x59, 0xcf, 0xd9, 0x73, 0x12, 0x17, 0xf4,
5b6f2811172c96 Stephan Müller 2020-01-09 216 0x30, 0x9c, 0xb7, 0x21, 0x45, 0xe2, 0xb6, 0x0c,
5b6f2811172c96 Stephan Müller 2020-01-09 217 0x0c, 0xeb, 0x1b, 0xdc, 0xdc,
5b6f2811172c96 Stephan Müller 2020-01-09 218 }
5b6f2811172c96 Stephan Müller 2020-01-09 219 };
5b6f2811172c96 Stephan Müller 2020-01-09 220 struct lrng_pool *lrng_pool, *lrng_pool_aligned;
5b6f2811172c96 Stephan Müller 2020-01-09 221 u8 hash_df[sizeof(lrng_hash_df_selftest_result[0])]
5b6f2811172c96 Stephan Müller 2020-01-09 222 __aligned(sizeof(u32));
5b6f2811172c96 Stephan Müller 2020-01-09 223 u32 generated;
5b6f2811172c96 Stephan Müller 2020-01-09 224 int ret = 0;
5b6f2811172c96 Stephan Müller 2020-01-09 225
5b6f2811172c96 Stephan Müller 2020-01-09 226 BUILD_BUG_ON(ARRAY_SIZE(lrng_hash_df_selftest_result) <
5b6f2811172c96 Stephan Müller 2020-01-09 227 CONFIG_LRNG_POOL_SIZE);
5b6f2811172c96 Stephan Müller 2020-01-09 228
5b6f2811172c96 Stephan Müller 2020-01-09 @229 lrng_pool = kzalloc(sizeof(struct lrng_pool) + sizeof(LRNG_KCAPI_ALIGN),
^^^^^^^^^^^^^^^^^^^^^^^^Here too.
5b6f2811172c96 Stephan Müller 2020-01-09 230 GFP_KERNEL);
5b6f2811172c96 Stephan Müller 2020-01-09 231 if (!lrng_pool)
5b6f2811172c96 Stephan Müller 2020-01-09 232 return LRNG_SEFLTEST_ERROR_HASHDF;
5b6f2811172c96 Stephan Müller 2020-01-09 233 lrng_pool_aligned = PTR_ALIGN(lrng_pool, sizeof(u32));
5b6f2811172c96 Stephan Müller 2020-01-09 234
5b6f2811172c96 Stephan Müller 2020-01-09 235 generated = __lrng_pool_hash_df(crypto_cb, NULL, lrng_pool_aligned,
5b6f2811172c96 Stephan Müller 2020-01-09 236 hash_df, sizeof(hash_df) << 3);
5b6f2811172c96 Stephan Müller 2020-01-09 237
5b6f2811172c96 Stephan Müller 2020-01-09 238 if ((generated >> 3) != sizeof(hash_df) ||
5b6f2811172c96 Stephan Müller 2020-01-09 239 memcmp(hash_df, lrng_hash_df_selftest_result[CONFIG_LRNG_POOL_SIZE],
5b6f2811172c96 Stephan Müller 2020-01-09 240 sizeof(hash_df))) {
5b6f2811172c96 Stephan Müller 2020-01-09 241 pr_err("LRNG Hash DF self-test FAILED\n");
5b6f2811172c96 Stephan Müller 2020-01-09 242 ret = LRNG_SEFLTEST_ERROR_HASHDF;
5b6f2811172c96 Stephan Müller 2020-01-09 243 }
5b6f2811172c96 Stephan Müller 2020-01-09 244
5b6f2811172c96 Stephan Müller 2020-01-09 245 kfree(lrng_pool);
5b6f2811172c96 Stephan Müller 2020-01-09 246 return ret;
5b6f2811172c96 Stephan Müller 2020-01-09 247 }---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/[email protected] Intel Corporation
Re: [PATCH v27 12/12] LRNG - add power-on and runtime self-tests
Am Montag, 13. Januar 2020, 11:39:41 CET schrieb Dan Carpenter:
Hi Dan,
Quoted 27 lines
Hi "Stephan,
url:
https://github.com/0day-ci/linux/commits/Stephan-M-ller/dev-random-a-new-ap
proach-with-full-SP800-90B/20200110-084934 base:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git68faa679b8be1a74e6663c21c3a9d25d32f1c079If you fix the issue, kindly add following tag
Reported-by kbuild test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>smatch warnings:
drivers/char/lrng/lrng_selftest.c:117lrng_pool_lfsr_selftest()warn:
sizeof(NUMBER)?drivers/char/lrng/lrng_selftest.c:229lrng_hash_df_selftest()warn: sizeof(NUMBER)?#
https://github.com/0day-ci/linux/commit/5b6f2811172c968d8eb78167825c58557ea
91995 git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout5b6f2811172c968d8eb78167825c58557ea91995vim +117drivers/char/lrng/lrng_selftest.c
5b6f2811172c96Stephan Müller 2020-01-09 89 static unsigned intlrng_pool_lfsr_selftest(void)5b6f2811172c96Stephan Müller 2020-01-09 90
{
Quoted 6 lines
5b6f2811172c96 Stephan Müller 2020-01-09 91 /* 5b6f2811172c96 Stephan Müller 2020-01-09 92 * First, 67th and lastentry of entropy pool.
5b6f2811172c96Stephan Müller 2020-01-09 93 *5b6f2811172c96Stephan Müller 2020-01-09 94 * The 67th entry is picked
because this one is the first to receive5b6f2811172c96Stephan Müller
2020-01-09 95 * an entry. As we start with 1 to inject into the
LFSR,
Quoted 1 line
the
5b6f2811172c96Stephan Müller 2020-01-09 96 * 67th entry should
be
Quoted 9 lines
equal to
rol(1, 7)>> 3 considering that5b6f2811172c96Stephan Müller
2020-01-09 97 * all other values of the LFSR are zero and the the
twist value of 05b6f2811172c96Stephan Müller 2020-01-09 98 * is
applied.5b6f2811172c96Stephan Müller 2020-01-09 99 */5b6f2811172c96Stephan Müller 2020-01-09 100 static u32 const
lrng_lfsr_selftest_result[][3] = {5b6f2811172c96Stephan Müller 2020-01-09
101 {0xf56df24a,0x00000010,0x0e014939},5b6f2811172c96Stephan
Müller 2020-01-09 102 {0x4b130726,0x00000010,0x2802f509
},
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 103 {0x87279152,
0x00000010,
Quoted 3 lines
0x00150000},5b6f2811172c96Stephan Müller 2020-01-09 104 {0x0b67f997,0x00000010,0x00150000},5b6f2811172c96Stephan Müller
2020-01-09 105 {0x4fea174f,0x00000010,0xcbf4a6ae},
5b6f2811172c96
Quoted 1 line
Stephan Müller 2020-01-09 106 {
0x77149108,0x00000010,
0x77bfadf2 },
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 107 {0x1e96037e,
0x00000010,
Quoted 3 lines
0x18017e79},5b6f2811172c96Stephan Müller 2020-01-09 108 {0xc84acef2,0x00000010,0x6345f7a8},5b6f2811172c96Stephan Müller
2020-01-09 109 {0x6a2eb6df,0x00000010,0x03950000},
5b6f2811172c96
Quoted 3 lines
Stephan Müller 2020-01-09 110 };
5b6f2811172c96Stephan Müller 2020-01-09 111 structlrng_pool*lrng_pool,*lrng_pool_aligned;5b6f2811172c96Stephan Müller 2020-01-09 112 u32
i,
Quoted 4 lines
ret =
LRNG_SELFTEST_PASSED;5b6f2811172c96Stephan Müller 2020-01-09 1135b6f2811172c96Stephan Müller 2020-01-09 114BUILD_BUG_ON(ARRAY_SIZE(lrng_lfsr_selftest_result) < 5b6f2811172c96Stephan Müller 2020-01-09 115
CONFIG_LRNG_POOL_SIZE);
Quoted 5 lines
5b6f2811172c96Stephan Müller 2020-01-09 1165b6f2811172c96Stephan Müller 2020-01-09 @117lrng_pool=
kzalloc(sizeof(structlrng_pool) +sizeof(LRNG_KCAPI_ALIGN), ^^^^^^^^^^^^^^^^^^^^^^^^ Probably justLRNG_KCAPI_ALIGNis intended with nosizeof().
Yes, absolutely. Fixed in both cases.
Thank you!
Quoted 2 lines
5b6f2811172c96Stephan Müller 2020-01-09 118
GFP_KERNEL);
Quoted 8 lines
5b6f2811172c96 Stephan Müller 2020-01-09 119 if (!lrng_pool) 5b6f2811172c96 Stephan Müller 2020-01-09 120 return LRNG_SEFLTEST_ERROR_LFSR; 5b6f2811172c96 Stephan Müller 2020-01-09 121 lrng_pool_aligned = PTR_ALIGN(lrng_pool, sizeof(u32)); 5b6f2811172c96 Stephan Müller 2020-01-09 122 5b6f2811172c96 Stephan Müller 2020-01-09 123 for (i = 1; i <= LRNG_POOL_SIZE; i++) 5b6f2811172c96 Stephan Müller 2020-01-09 124 _lrng_pool_lfsr_u32(lrng_pool_aligned, i); 5b6f2811172c96
Stephan Müller
Quoted 8 lines
2020-01-09 125
5b6f2811172c96Stephan Müller 2020-01-09 126 if
((atomic_read_u32(&lrng_pool_aligned->pool[0])!=5b6f2811172c96Stephan Müller 2020-01-09 127 lrng_lfsr_selftest_result[CONFIG_LRNG_POOL_SIZE][0]) ||5b6f2811172c96Stephan Müller 2020-01-09 128 (atomic_read_u32(&lrng_pool_aligned->pool[67 &5b6f2811172c96Stephan Müller 2020-01-09 129
(LRNG_POOL_SIZE - 1)]) !=
Quoted 7 lines
5b6f2811172c96Stephan Müller 2020-01-09 130 lrng_lfsr_selftest_result[CONFIG_LRNG_POOL_SIZE][1]) ||5b6f2811172c96Stephan Müller 2020-01-09 131 (atomic_read_u32(&lrng_pool_aligned->pool[LRNG_POOL_SIZE - 1])!=5b6f2811172c96Stephan Müller 2020-01-09 132 lrng_lfsr_selftest_result[CONFIG_LRNG_POOL_SIZE][2])) {5b6f2811172c96
Stephan Müller 2020-01-09 133 pr_err("LRNG LFSR self-test
FAILED\n");
Quoted 2 lines
5b6f2811172c96Stephan Müller 2020-01-09 134 ret =LRNG_SEFLTEST_ERROR_LFSR;5b6f2811172c96Stephan Müller 2020-01-09 135
}
Quoted 16 lines
5b6f2811172c96 Stephan Müller 2020-01-09 136 5b6f2811172c96 Stephan Müller 2020-01-09 137 kfree(lrng_pool); 5b6f2811172c96 Stephan Müller 2020-01-09 138 return ret; 5b6f2811172c96 Stephan Müller 2020-01-09 139 } 5b6f2811172c96 Stephan Müller 2020-01-09 140 5b6f2811172c96 Stephan Müller 2020-01-09 141 /* 5b6f2811172c96 Stephan Müller 2020-01-09 142 * The test vectors aregenerated with the
hash_df_testvector_generationtool5b6f2811172c96
Stephan Müller 2020-01-09 143 * provided as part of the test tool set of
the LRNG.5b6f2811172c96Stephan Müller 2020-01-09 144 */5b6f2811172c96Stephan Müller 2020-01-09 145 static unsigned intlrng_hash_df_selftest(void)5b6f2811172c96Stephan Müller 2020-01-09 146 {5b6f2811172c96Stephan Müller 2020-01-09 147 const structlrng_crypto_cb*crypto_cb=&lrng_cc20_crypto_cb;5b6f2811172c96Stephan Müller 2020-01-09
148
Quoted 4 lines
5b6f2811172c96 Stephan Müller 2020-01-09 149 /* 5b6f2811172c96 Stephan Müller 2020-01-09 150 * The size of 45 bytes ischosen arbitrarily. Yet, this size should
5b6f2811172c96Stephan Müller
2020-01-09 151 * ensure that we have at least two hash blocks plus
some
Quoted 6 lines
fraction
5b6f2811172c96Stephan Müller 2020-01-09 152 * of a hash block
generated.5b6f2811172c96Stephan Müller 2020-01-09 153 */5b6f2811172c96Stephan Müller 2020-01-09 154 static u8 const
lrng_hash_df_selftest_result[][45] = {5b6f2811172c96Stephan Müller
2020-01-09 155 {5b6f2811172c96Stephan Müller 2020-01-09 1560x3b,0xbe,
0x7a, 0xbd,
Quoted 2 lines
0x2b,0x16,0x02,0x4c,5b6f2811172c96Stephan Müller 2020-01-09 1570xfc, 0xd3, 0x02, 0x15, 0xf0, 0x86, 0xd4, 0xdb,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 158
0x49,0xec,0x26,0x53,0xd6,
0xc9, 0x6d, 0xad,
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 1590x24,0xca,
0x72, 0x89,
Quoted 2 lines
0x2c,0xfa,0x48,0x18,5b6f2811172c96Stephan Müller 2020-01-09 1600xf7, 0x47, 0xb5, 0x2f, 0x92, 0xa2, 0x1b, 0xd9,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 161
0x24,0xa7,0x2f,0xa2,0x0b,
5b6f2811172c96
Quoted 2 lines
Stephan Müller 2020-01-09 162 }, {
5b6f2811172c96Stephan Müller 2020-01-09 1630xd2,0xaa,
0xf9, 0x76,
Quoted 2 lines
0x26,0xc6,0x13,0xea,5b6f2811172c96Stephan Müller 2020-01-09 1640xb8, 0xde, 0xe6, 0x88, 0x8f, 0xc4, 0x7a, 0x7d,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 165
0x9c,0xb4,0x1b,0xd1,0xd1,
0x8a, 0x40, 0xc9,
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 1660xaa,0x45,
0xa6, 0xb6,
Quoted 2 lines
0xb5,0x6f,0xf6,0xbc,5b6f2811172c96Stephan Müller 2020-01-09 1670xbb, 0x77, 0x37, 0xbc, 0x5a, 0x2d, 0xcc, 0x84,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 168
0x25,0x68,0x5e,0xba,0x16,
5b6f2811172c96
Quoted 2 lines
Stephan Müller 2020-01-09 169 }, {
5b6f2811172c96Stephan Müller 2020-01-09 1700x58,0x66,
0x82, 0x88,
Quoted 2 lines
0x29,0x19,0xa4,0xbb,5b6f2811172c96Stephan Müller 2020-01-09 1710x33, 0x42, 0xc9, 0x72, 0x0d, 0x68, 0x6e, 0xb9,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 172
0xc6,0xe0,0x7a,0xf9,0x20,
0xca, 0x6d, 0x18,
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 1730x35,0xec,
0xfa, 0x9e,
Quoted 2 lines
0xf6,0x3a,0xa7,0xb6,5b6f2811172c96Stephan Müller 2020-01-09 1740x92, 0x7a, 0xe5, 0xcd, 0xc5, 0x13, 0x9f, 0x65,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 175
0x6a,0xe1,0xe4,0x3f,0xb9,
5b6f2811172c96
Quoted 2 lines
Stephan Müller 2020-01-09 176 }, {
5b6f2811172c96Stephan Müller 2020-01-09 1770xdd,0xf1,
0x34, 0xca,
Quoted 2 lines
0x08,0xe3,0xce,0x8a,5b6f2811172c96Stephan Müller 2020-01-09 1780x26, 0x6b, 0xce, 0x99, 0x8a, 0x84, 0xd2, 0x21,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 179
0x98,0x10,0x95,0x5f,0x9f,
0xc3, 0xf2, 0xe4,
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 1800x79,0x75,
0xb5, 0x15,
Quoted 2 lines
0xa7,0xa2,0xf1,0xc4,5b6f2811172c96Stephan Müller 2020-01-09 1810xdc, 0x67, 0xcb, 0x67, 0x8c, 0xb2, 0x1b, 0xd5,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 182
0xd6,0x8b,0xc2,0x34,0xd6,
5b6f2811172c96
Quoted 2 lines
Stephan Müller 2020-01-09 183 }, {
5b6f2811172c96Stephan Müller 2020-01-09 1840xc3,0x16,
0x9d, 0xf0,
Quoted 2 lines
0x78,0x15,0xab,0xf2,5b6f2811172c96Stephan Müller 2020-01-09 1850x2f, 0xc9, 0x2e, 0xe1, 0xc6, 0x5e, 0xfa, 0x03,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 186
0xaf,0xd4,0xd5,0x47,0x2a,
0xe8, 0x06, 0xe8,
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 1870x7e,0x0a,
0x71, 0xc7,
Quoted 2 lines
0x0d,0x39,0xb1,0xa9,5b6f2811172c96Stephan Müller 2020-01-09 1880x5a, 0x49, 0xee, 0x8b, 0x2f, 0xcd, 0xea, 0x96,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 189
0xcc,0x08,0x71,0xef,0x9c,
5b6f2811172c96
Quoted 2 lines
Stephan Müller 2020-01-09 190 }, {
5b6f2811172c96Stephan Müller 2020-01-09 1910x1a,0x3d,
0x70, 0x39,
Quoted 2 lines
0xc2,0x02,0x4d,0x3a,5b6f2811172c96Stephan Müller 2020-01-09 1920xaa, 0x14, 0x20, 0x88, 0x96, 0x4c, 0x7c, 0xe4,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 193
0xaa,0x49,0x89,0x30,0x50,
0x96, 0xb6, 0xa7,
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 1940x55,0x0a,
0xf8, 0xd2,
Quoted 2 lines
0x4e,0x83,0x9d,0x1f,5b6f2811172c96Stephan Müller 2020-01-09 1950x56, 0x49, 0x13, 0xc6, 0x46, 0x55, 0x73, 0x0d,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 196
0x74,0xcd,0x81,0xe0,0x65,
5b6f2811172c96
Quoted 2 lines
Stephan Müller 2020-01-09 197 }, {
5b6f2811172c96Stephan Müller 2020-01-09 1980x4b,0xf6,
0x49, 0x89,
Quoted 2 lines
0x2a,0x9f,0x67,0xd7,5b6f2811172c96Stephan Müller 2020-01-09 1990xb8, 0x1d, 0xbb, 0x5d, 0xf0, 0x1b, 0x60, 0xb6,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 200
0xb7,0xf3,0x86,0x6d,0xe0,
0x04, 0xa1, 0xbc,
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 2010x3b,0xb0,
0x10, 0x91,
Quoted 2 lines
0xe8,0x22,0x67,0x5b,5b6f2811172c96Stephan Müller 2020-01-09 2020xe8, 0xf0, 0x4f, 0x82, 0x70, 0xc7, 0xe1, 0xc8,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 203
0xd8,0xad,0x70,0xcf,0xf6,
5b6f2811172c96
Quoted 2 lines
Stephan Müller 2020-01-09 204 }, {
5b6f2811172c96Stephan Müller 2020-01-09 2050x60,0x1f,
0x71, 0x07,
Quoted 2 lines
0x92,0xae,0xa0,0x24,5b6f2811172c96Stephan Müller 2020-01-09 2060xb6, 0xa4, 0x10, 0x70, 0x1f, 0x94, 0x51, 0x9a,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 207
0x5a,0x81,0xc4,0x46,0x78,
0x56, 0x71, 0xdd,
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 2080x45,0x63,
0x01, 0x34,
Quoted 2 lines
0x87,0x79,0xb4,0xd5,5b6f2811172c96Stephan Müller 2020-01-09 2090x91, 0x79, 0xb9, 0x93, 0x11, 0x44, 0x50, 0xad,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 210
0x64,0x7e,0x5c,0xec,0x16,
5b6f2811172c96
Quoted 2 lines
Stephan Müller 2020-01-09 211 }, {
5b6f2811172c96Stephan Müller 2020-01-09 2120x49,0x2f,
0xa0, 0x45,
Quoted 2 lines
0xf8,0xb0,0x80,0x88,5b6f2811172c96Stephan Müller 2020-01-09 2130x79, 0xeb, 0xb6, 0x82, 0x1c, 0xf3, 0x67, 0xc4,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 214
0x88,0x88,0xe9,0x75,0x20,
0x54, 0x78, 0xc6,
Quoted 1 line
5b6f2811172c96Stephan Müller 2020-01-09 2150x5c,0x59,
0xcf, 0xd9,
Quoted 2 lines
0x73,0x12,0x17,0xf4,5b6f2811172c96Stephan Müller 2020-01-09 2160x30, 0x9c, 0xb7, 0x21, 0x45, 0xe2, 0xb6, 0x0c,
5b6f2811172c96 Stephan
Quoted 1 line
Müller 2020-01-09 217
0x0c,0xeb,0x1b,0xdc,0xdc,
5b6f2811172c96
Quoted 6 lines
Stephan Müller 2020-01-09 218 }
5b6f2811172c96 Stephan Müller 2020-01-09 219 }; 5b6f2811172c96 Stephan Müller 2020-01-09 220 struct lrng_pool *lrng_pool,
*lrng_pool_aligned;5b6f2811172c96Stephan Müller 2020-01-09 221 u8
hash_df[sizeof(lrng_hash_df_selftest_result[0])]5b6f2811172c96Stephan Müller 2020-01-09 222
__aligned(sizeof(u32)); 5b6f2811172c96
Quoted 6 lines
Stephan Müller 2020-01-09 223 u32 generated;
5b6f2811172c96 Stephan Müller 2020-01-09 224 int ret = 0; 5b6f2811172c96 Stephan Müller 2020-01-09 225 5b6f2811172c96 Stephan Müller 2020-01-09 226 BUILD_BUG_ON(ARRAY_SIZE(lrng_hash_df_selftest_result) < 5b6f2811172c96Stephan Müller 2020-01-09 227
CONFIG_LRNG_POOL_SIZE);
Quoted 7 lines
5b6f2811172c96Stephan Müller 2020-01-09 2285b6f2811172c96Stephan Müller 2020-01-09 @229lrng_pool=
kzalloc(sizeof(structlrng_pool) +sizeof(LRNG_KCAPI_ALIGN), ^^^^^^^^^^^^^^^^^^^^^^^^ Here too.
5b6f2811172c96Stephan Müller 2020-01-09 230
GFP_KERNEL);
Quoted 8 lines
5b6f2811172c96 Stephan Müller 2020-01-09 231 if (!lrng_pool) 5b6f2811172c96 Stephan Müller 2020-01-09 232 return LRNG_SEFLTEST_ERROR_HASHDF; 5b6f2811172c96 Stephan Müller 2020-01-09 233 lrng_pool_aligned = PTR_ALIGN(lrng_pool, sizeof(u32)); 5b6f2811172c96Stephan Müller 2020-01-09 234
5b6f2811172c96Stephan Müller 2020-01-09 235 generated =
__lrng_pool_hash_df(crypto_cb, NULL,lrng_pool_aligned,5b6f2811172c96Stephan Müller 2020-01-09 236
hash_df, sizeof(hash_df) << 3);
Quoted 5 lines
5b6f2811172c96Stephan Müller 2020-01-09 2375b6f2811172c96Stephan Müller 2020-01-09 238 if ((generated >> 3) !=sizeof(hash_df)||5b6f2811172c96Stephan Müller 2020-01-09 239 memcmp(hash_df, lrng_hash_df_selftest_result[CONFIG_LRNG_POOL_SIZE],5b6f2811172c96Stephan Müller 2020-01-09 240sizeof(hash_df)))
{
Quoted 2 lines
5b6f2811172c96Stephan Müller 2020-01-09 241 pr_err("LRNG Hash DF
self-test FAILED\n");5b6f2811172c96Stephan Müller 2020-01-09 242
ret
Quoted 11 lines
=
LRNG_SEFLTEST_ERROR_HASHDF;5b6f2811172c96Stephan Müller 2020-01-09 243
}5b6f2811172c96 Stephan Müller 2020-01-09 244 5b6f2811172c96 Stephan Müller 2020-01-09 245 kfree(lrng_pool); 5b6f2811172c96 Stephan Müller 2020-01-09 246 return ret; 5b6f2811172c96 Stephan Müller 2020-01-09 247 }---
0-DAY kernel test infrastructure Open Source Technology
Center https://lists.01.org/hyperkitty/list/[email protected] Intel Corporation
Ciao
Stephan
v28 cover /dev/random - a new approach with full SP800-90B
In reply to Stephan MüllerHi,
The following patch set provides a different approach to /dev/random which is called Linux Random Number Generator (LRNG) to collect entropy within the Linux kernel. The main improvements compared to the existing /dev/random is to provide sufficient entropy during boot time as well as in virtual environments and when using SSDs. A secondary design goal is to limit the impact of the entropy collection on massive parallel systems and also allow the use accelerated cryptographic primitives. Also, all steps of the entropic data processing are testable.
The LRNG patch set allows a user to select use of the existing /dev/random or the LRNG during compile time. As the LRNG provides API and ABI compatible interfaces to the existing /dev/random implementation, the user can freely chose the RNG implementation without affecting kernel or user space operations.
This patch set provides early boot-time entropy which implies that no additional flags to the getrandom(2) system call discussed recently on the LKML is considered to be necessary. Yet, if additional flags are introduced to cover special hardware, the LRNG implementation will also provide them to be fully ABI and API compliant as already discussed on LKML.
The LRNG is fully compliant to SP800-90B requirements and is shipped with a full SP800-90B assessment and all required test tools. The existing /dev/random implementation on the other hand has architectural limitations which does not easily allow to bring the implementation in compliance with SP800-90B. The key statement that causes concern is SP800-90B section 3.1.6. This section denies crediting entropy to multiple similar noise sources. This section explicitly references different noise sources resting on the timing of events and their derivatives (i.e. it is a direct complaint to the existing existing /dev/random implementation). Therefore, SP800-90B now denies the very issue mentioned in [1] with the existing /dev/random implementation for a long time: crediting entropy to interrupts as well as crediting entropy to derivatives of interrupts (HID and disk events). This is not permissible with SP800-90B.
SP800-90B specifies various requirements for the noise source(s) that seed any DRNG including SP800-90A DRBGs. In about a year from now, 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. That means, if we there are no solutions to comply with the requirements of SP800-90B found till one year from now, any random number generation and ciphers based on random numbers on Linux will be considered and treated as not applicable and delivering no entropy! As /dev/urandom, getrandom(2) and /dev/random are the most common and prevalent noise sources for DRNGs, all these DRNGs are affected. This applies across the board for all validations of cryptography executing on Linux (kernel and user space modules).
For users that are not interested in SP800-90B, the entire code for the compliance as well as test interfaces can be deselected at compile time.
The design and implementation is driven by a set of goals described in [1] that the LRNG completely implements. Furthermore, [1] includes the full assessment of the SP800-90B compliance as well as a comparison with RNG design suggestions of SP800-90C, and AIS20/31.
The LRNG provides a complete separation of the noise source maintenance and the collection of entropy into an entropy pool from the post-processing using a pseudo-random number generator. Different DRNGs are supported, including:
* The LRNG can be compile-time enabled to replace the existing /dev/random implementation. When not selecting the LRNG at compile time (default), the existing /dev/random implementation is built.
* Built-in ChaCha20 DRNG which has no dependency to other kernel frameworks.
* SP800-90A DRBG using the kernel crypto API including its accelerated raw cipher implementations. This implies that the output of /dev/random, getrandom(2), /dev/urandom or get_random_bytes is fully compliant to SP800-90A.
* Arbitrary DRNGs registered with the kernel crypto API
* Full compliance with SP800-90B which covers the startup and runtime health tests mandated by SP800-90B as well as providing the test tools and test interfaces to obtain raw noise data securely. The test tools are provided at [1].
Booting the patch with the kernel command line option "dyndbg=file drivers/char/lrng/* +p" generates logs indicating the operation of the LRNG. Each log is pre-pended with "lrng".
The LRNG has a flexible design by allowing an easy replacement of the deterministic random number generator component.
Compared to the existing /dev/random implementation, the compiled binary is smaller when the LRNG is compiled with all options equal to the existing /dev/random (i.e. only CONFIG_LRNG is set): random.o is 52.5 kBytes whereas all LRNG object files are in 49 kBytes in size. The fully SP800-90A/SP800-90B compliant binary code (CONFIG_LRNG, CONFIG_LRNG_DRNG_SWITCH, CONFIG_LRNG_DRBG, CONFIG_LRNG_HEALTH_TESTS) uses some 61 kBytes. In addition, the LRNG is about 50% faster in the performance critical interrupt handler code path compared to the existing /dev/random implementation.
[1] http://www.chronox.de/lrng.html - If the patch is accepted, I would be volunteering to convert the documentation into RST format and contribute it to the Linux kernel documentation directory.
Changes (compared to the previous patch set):
* make comments compliant to kernel-doc style
* update LRNG_RCT_CUTOFF from 30 to 31 (a cutoff of 30 implies an alpha of 2^-29 and a cutoff of 31 is an alpha of 2^-30 - both values are in line with SP800-90B, but to be consistent with documentation update the cutoff value) - reported by Marcos Portnoi
* remove lrng_drng_generate_helper_full that was only needed by removed TRNG support
* Remove "unlikely" from lrng_drng_lock which seems to cause additional grief with sparse. Note, sparse will still report a lock context imbalance as it used to since we indeed have two lock contexts as documented in lrng_drng_switch. Reported-by: kbuild test robot <[email protected]>
* Fix allocation size calculation in self-test code as reported by Dan Carpenter <[email protected]>
This patch requires the presence of patch 75551dbf112c992bc6c99a972990b3f272247e23 from Ted Tso's kernel tree (specifically the addition of GRND_INSECURE to random.h)
As a side node: With the switchable DRNG support offered in this patch set, the following areas could be removed. As the existing /dev/random has no support for switchable DRNGs, however, this is not yet feasible though.
* remove lrng_ready_list and all code around it in lrng_interfaces.c
* remove the kernel crypto API RNG API to avoid having two random number providing APIs - this would imply that all RNGs developed for this API would be converted to the LRNG interface
Stephan Mueller (12):
Linux Random Number Generator
LRNG - allocate one DRNG instance per NUMA node LRNG - sysctls and /proc interface
LRNG - add switchable DRNG support
crypto: DRBG - externalize DRBG functions for LRNG LRNG - add SP800-90A DRBG extension
LRNG - add kernel crypto API PRNG extension
crypto: provide access to a static Jitter RNG state LRNG - add Jitter RNG fast noise source LRNG - add SP800-90B compliant health tests LRNG - add interface for gathering of raw entropy LRNG - add power-on and runtime self-tests
MAINTAINERS | 7 +
crypto/drbg.c | 16 +-
crypto/jitterentropy-kcapi.c | 3 +-
crypto/jitterentropy.c | 25 +-
drivers/char/Kconfig | 2 +
drivers/char/Makefile | 9 +-
drivers/char/lrng/Kconfig | 203 ++++++
drivers/char/lrng/Makefile | 19 +
drivers/char/lrng/lrng_archrandom.c | 94 +++
drivers/char/lrng/lrng_aux.c | 148 ++++
drivers/char/lrng/lrng_chacha20.c | 265 ++++++++
drivers/char/lrng/lrng_chacha20.h | 25 +
drivers/char/lrng/lrng_drbg.c | 260 +++++++
drivers/char/lrng/lrng_drng.c | 400 +++++++++++
drivers/char/lrng/lrng_health.c | 409 +++++++++++
drivers/char/lrng/lrng_interfaces.c | 637 ++++++++++++++++++
drivers/char/lrng/lrng_internal.h | 305 +++++++++
drivers/char/lrng/lrng_jent.c | 89 +++
drivers/char/lrng/lrng_kcapi.c | 327 +++++++++
drivers/char/lrng/lrng_lfsr.h | 152 +++++
drivers/char/lrng/lrng_numa.c | 101 +++
drivers/char/lrng/lrng_pool.c | 588 ++++++++++++++++
drivers/char/lrng/lrng_proc.c | 163 +++++
drivers/char/lrng/lrng_selftest.c | 418 ++++++++++++
drivers/char/lrng/lrng_sw_noise.c | 102 +++
drivers/char/lrng/lrng_sw_noise.h | 57 ++
drivers/char/lrng/lrng_switch.c | 183 +++++
drivers/char/lrng/lrng_testing.c | 271 ++++++++
include/crypto/drbg.h | 7 +
.../crypto/internal}/jitterentropy.h | 3 +
include/linux/lrng.h | 63 ++
31 files changed, 5341 insertions(+), 10 deletions(-)
create mode 100644 drivers/char/lrng/Kconfig
create mode 100644 drivers/char/lrng/Makefile
create mode 100644 drivers/char/lrng/lrng_archrandom.c
create mode 100644 drivers/char/lrng/lrng_aux.c
create mode 100644 drivers/char/lrng/lrng_chacha20.c
create mode 100644 drivers/char/lrng/lrng_chacha20.h
create mode 100644 drivers/char/lrng/lrng_drbg.c
create mode 100644 drivers/char/lrng/lrng_drng.c
create mode 100644 drivers/char/lrng/lrng_health.c
create mode 100644 drivers/char/lrng/lrng_interfaces.c
create mode 100644 drivers/char/lrng/lrng_internal.h
create mode 100644 drivers/char/lrng/lrng_jent.c
create mode 100644 drivers/char/lrng/lrng_kcapi.c
create mode 100644 drivers/char/lrng/lrng_lfsr.h
create mode 100644 drivers/char/lrng/lrng_numa.c
create mode 100644 drivers/char/lrng/lrng_pool.c
create mode 100644 drivers/char/lrng/lrng_proc.c
create mode 100644 drivers/char/lrng/lrng_selftest.c
create mode 100644 drivers/char/lrng/lrng_sw_noise.c
create mode 100644 drivers/char/lrng/lrng_sw_noise.h
create mode 100644 drivers/char/lrng/lrng_switch.c
create mode 100644 drivers/char/lrng/lrng_testing.c
rename {crypto => include/crypto/internal}/jitterentropy.h (84%)
create mode 100644 include/linux/lrng.hSignature · 1 line
2.24.1
PATCH v28 1/12 Linux Random Number Generator
In an effort to provide a flexible implementation for a random number generator that also delivers entropy during early boot time, allows replacement of the deterministic random number generation mechanism, implement the various components in separate code for easier maintenance, and provide compliance to SP800-90[A|B|C], introduce the Linux Random Number Generator (LRNG) framework.
The general design is as follows. Additional implementation details are given in [1]. The LRNG consists of the following components:
1. The LRNG implements a DRNG. The DRNG always generates the requested amount of output. When using the SP800-90A terminology it operates without prediction resistance. The secondary DRNG maintains a counter of how many bytes were generated since last re-seed and a timer of the elapsed time since last re-seed. If either the counter or the timer reaches a threshold, the secondary DRNG is seeded from the entropy pool.
In case the Linux kernel detects a NUMA system, one secondary DRNG instance per NUMA node is maintained.
2. The DRNG is seeded by concatenating the data from the following sources:
(a) the output of the entropy pool,
(b) the Jitter RNG if available and enabled, and
(c) the CPU-based noise source such as Intel RDRAND if available and enabled.
The entropy estimate of the data of all noise sources are added to form the entropy estimate of the data used to seed the DRNG with. The LRNG ensures, however, that the DRNG after seeding is at maximum the security strength of the DRNG.
The LRNG is designed such that none of these noise sources can dominate the other noise sources to provide seed data to the DRNG during due to the following:
(a) During boot time, the amount of received interrupts are the trigger points to (re)seed the DRNG.
(b) At runtime, the available entropy from the slow noise source is concatenated with a pre-defined amount of data from the fast noise sources. In addition, each DRNG reseed operation triggers external noise source providers to deliver one block of data.
3. The entropy pool accumulates entropy obtained from certain events, which will henceforth be collectively called "slow noise sources". The entropy pool collects noise data from slow noise sources. Any data received by the LRNG from the slow noise sources is inserted into the entropy pool using an LFSR with a primitive and irreducible polynomial. The following sources of entropy are used:
(a) When an interrupt occurs, the high-resolution time stamp is mixed
into the LFSR. This time stamp is credited with heuristically implied entropy.
(b) HID event data like the key stroke or the mouse coordinates are
mixed into the LFSR. This data is not credited with entropy by the LRNG.
(c) Device drivers may provide data that is mixed into the LFSR. This
data is not credited with entropy by the LRNG.
(d) After the entropy pool is ``read'' by the DRNG, the data
used to seed the DRNG is mixed back into the entropy pool to stir the pool. This data is not credited with entropy by the LRNG.
Any data provided from user space by either writing to /dev/random, /dev/urandom or the IOCTL of RNDADDENTROPY on both device files are always injected into the entropy pool.
In addition, when a hardware random number generator covered by the Linux kernel HW generator framework wants to deliver random numbers, it is injected into the entropy pool as well. HW generator noise source is handled separately from the other noise source due to the fact that the HW generator framework may decide by itself when to deliver data whereas the other noise sources always requested for data driven by the LRNG operation. Similarly any user space provided data is inserted into the entropy pool.
When the DRNG requires data from the entropy pool, the entire entropy pool is processed with an SP800-90A section 10.3.1 compliant hash_df function to generate random numbers.
To speed up the interrupt handling code of the LRNG, the time stamp collected for an interrupt event is truncated to the 8 least significant bits. 64 truncated time stamps are concatenated and then jointly inserted into the LFSR. During boot time, until the fully seeded stage is reached, each time stamp with its 32 least significant bits is inserted into the LFSR at the time of arrival.
The LRNG allows the DRNG mechanism to be changed at runtime. Per default, a ChaCha20-based DRNG is used. The ChaCha20-DRNG implemented for the LRNG is also provided as a stand-alone user space deterministic random number generator. The LRNG also offers an SP800-90A DRBG based on the Linux kernel crypto API DRBG implementation.
The processing of entropic data from the noise source before injecting them into the DRNG is performed with the following mathematical operations:
1. LFSR: The 8 least significant bits of the time stamp data received from the interrupts are processed with an LFSR. That LFSR is implemented identically to the LSFR used in the existing /dev/random implementation except that it is capable of processing an entire word and that a different polynomial is used. The reason for the different polynomial is performance in a performance sensitive code section, the interrupt handler. The chosen polynomials have 4 taps. Also, this LFSR-approach is used in the OpenBSD /dev/random equivalent.
2. Concatenation: The temporary seed buffer used to seed the DRNG is a concatenation of parts of the entropy pool data, and the CPU noise source output.
The DRNG always tries to seed itself with 256 bits of entropy, except during boot. In any case, if the noise sources cannot deliver that amount, the available entropy is used and the DRNG keeps track on how much entropy it was seeded with. The entropy implied by the LRNG available in the entropy pool may be too conservative. To ensure that during boot time all available entropy from the entropy pool is transferred to the DRNG, the hash_df function always generates 256 data bits during boot to seed the DRNG. During boot, the DRNG is seeded as follows:
1. The DRNG is reseeded from the entropy pool and potentially the fast noise sources if the entropy pool has collected at least 32 bits of entropy from the interrupt noise source. The goal of this step is to ensure that the DRNG receives some initial entropy as early as possible. In addition it receives the entropy available from the fast noise sources.
2. The DRNG is reseeded from the entropy pool and potentially the fast noise sources if all noise sources collectively can provide at least 128 bits of entropy.
3. The DRNG is reseeded from the entropy pool and potentially the fast noise sources if all noise sources collectivel can provide at least 256 bits.
At the time of the reseeding steps, the DRNG requests as much entropy as is available in order to skip certain steps and reach the seeding level of 256 bits. This may imply that one or more of the aforementioned steps are skipped.
In all listed steps, the DRNG is (re)seeded with a number of random bytes from the entropy pool that is at most the amount of entropy present in the entropy pool. This means that when the entropy pool contains 128 or 256 bits of entropy, the DRNG is seeded with that amount of entropy as well.
Before the DRNG is seeded with 256 bits of entropy in step 3, requests of random data from /dev/random are not processed.
The hash_df operation providing random data from the entropy pool will always require that all entropy sources collectively can deliver at least 129 entropy bits as configured with (128 bits of entropy for seeding plus one bit of entropy that is lost with the post processing as defined in SP800-90B).
The DRNG operates as deterministic random number generator with the following properties:
* The maximum number of random bytes that can be generated with one DRNG generate operation is limited to 4096 bytes. When longer random numbers are requested, multiple DRNG generate operations are performed. The ChaCha20 DRNG as well as the SP800-90A DRBGs implement an update of their state after completing a generate request for backtracking resistance.
* The secondary DRNG is reseeded with whatever entropy is available – in the worst case where no additional entropy can be provided by the noise sources, the DRNG is not re-seeded and continues its operation to try to reseed again after again the expiry of one of these thresholds:
- If the last reseeding of the secondary DRNG is more than 600 seconds ago, or
- 2^20 DRNG generate operations are performed, whatever comes first, or
- the secondary DRNG is forced to reseed before the next generation of random numbers if data has been injected into the LRNG by writing data into /dev/random or /dev/urandom.
The chosen values prevent high-volume requests from user space to cause frequent reseeding operations which drag down the performance of the DRNG.
With the automatic reseeding after 600 seconds, the LRNG is triggered to reseed itself before the first request after a suspend that put the hardware to sleep for longer than 600 seconds.
The LRNG uses the following runtime memory using the currently smallest configuration:
* 576 bytes (512 bytes for the entropy pool and 64 for the entropy pool meta data) for the entropy pool management
* 64 bytes per CPU for the time stamp array
To support smaller devices including IoT environments, this patch allows reducing the runtime memory footprint of the LRNG at compile time by selecting smaller entropy pool sizes.
The entropy pool has support for sizes of 256, 128 and 64 bytes supported by primitive and irreducible polynomials.
The time stamp array is reduced to one atomic_t variable per CPU, i.e. 4 bytes when CONFIG_BASE_SMALL is selected during kernel configuration. This implies that after the receipt of 4 interrupts on one CPU, the data is injected into the LFSR. Depending on the behavior of the CPU caches, this may imply that the average interrupt handler execution time increases a bit, since instead of injecting 8 atomic_t values at one given time into the LFSR, only one is processed which may incur cache misses.
When selecting the compilation of a kernel for a small environment, prevent the allocation of a buffer up to 4096 bytes to serve user space requests. In this case, the stack variable of 64 bytes is used to serve all user space requests.
The LRNG has the following properties:
* internal noise source: interrupts timing with fast boot time seeding
* high performance of interrupt handling code: The LRNG impact on the interrupt handling has been reduced to a minimum. On one example system, the LRNG interrupt handling code executes within an average of 65 cycles whereas the existing /dev/random on the same device takes about 97 cycles when measuring the execution time of add_interrupt_randomness().
* lockless LFSR to collect raw entropy supporing concurrency-free use of massive parallel systems
* use of standalone ChaCha20 based RNG with the option to use a different DRNG selectable at compile time
* "atomic" seeding of secondary DRBG to ensure full entropy transport
* instantiate one DRNG per NUMA node
* support for runtime switchable output DRNGs
* use of only well-defined entropy-preserving operations to collect, compress and forward entropy: concatenation, LFSR, SP800-90A hash_df function
* compile-time selectable entropy pool size: the choice also uses the applicable LFSR polynomial to maintain the entropy pool size
* support of small systems by allowing the reduction of the runtime memory needs
Further details including the rationale for the design choices and properties of the LRNG together with testing is provided at [1]. In addition, the documentation explains the conducted regression tests to verify that the LRNG is API and ABI compatible with the existing /dev/random implementation.
[1] https://www.chronox.de/lrng.html
CC: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected]>
CC: "Alexander E. Patrakov" <[email protected]>
CC: "Ahmed S. Darwish" <[email protected]>
CC: "Theodore Y. Ts'o" <[email protected]>
CC: Willy Tarreau <[email protected]>
CC: Matthew Garrett <[email protected]>
CC: Vito Caputo <[email protected]>
CC: Andreas Dilger <[email protected]>
CC: Jan Kara <[email protected]>
CC: Ray Strode <[email protected]>
CC: William Jon McCann <[email protected]>
CC: zhangjs <zachary-+jQ8zvd9CV5SzTKKI/[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Florian Weimer <[email protected]>
CC: Lennart Poettering <[email protected]>
CC: Nicolai Stange <[email protected]>
Mathematical aspects Reviewed-by: "Peter, Matthias" <[email protected]>
--- MAINTAINERS | 7 + drivers/char/Kconfig | 2 + drivers/char/Makefile | 9 +- drivers/char/lrng/Kconfig | 67 +++ drivers/char/lrng/Makefile | 9 + drivers/char/lrng/lrng_archrandom.c | 94 ++++ drivers/char/lrng/lrng_aux.c | 148 +++++++ drivers/char/lrng/lrng_chacha20.c | 265 ++++++++++++ drivers/char/lrng/lrng_chacha20.h | 25 ++ drivers/char/lrng/lrng_drng.c | 400 +++++++++++++++++ drivers/char/lrng/lrng_interfaces.c | 638 ++++++++++++++++++++++++++++ drivers/char/lrng/lrng_internal.h | 296 +++++++++++++ drivers/char/lrng/lrng_lfsr.h | 152 +++++++ drivers/char/lrng/lrng_pool.c | 588 +++++++++++++++++++++++++ drivers/char/lrng/lrng_sw_noise.c | 102 +++++ drivers/char/lrng/lrng_sw_noise.h | 57 +++ include/linux/lrng.h | 63 +++ 17 files changed, 2921 insertions(+), 1 deletion(-) create mode 100644 drivers/char/lrng/Kconfig create mode 100644 drivers/char/lrng/Makefile create mode 100644 drivers/char/lrng/lrng_archrandom.c create mode 100644 drivers/char/lrng/lrng_aux.c create mode 100644 drivers/char/lrng/lrng_chacha20.c create mode 100644 drivers/char/lrng/lrng_chacha20.h create mode 100644 drivers/char/lrng/lrng_drng.c create mode 100644 drivers/char/lrng/lrng_interfaces.c create mode 100644 drivers/char/lrng/lrng_internal.h create mode 100644 drivers/char/lrng/lrng_lfsr.h create mode 100644 drivers/char/lrng/lrng_pool.c create mode 100644 drivers/char/lrng/lrng_sw_noise.c create mode 100644 drivers/char/lrng/lrng_sw_noise.h create mode 100644 include/linux/lrng.h
MAINTAINERS +7 -0
@@ -9606,6 +9606,13 @@ F: Documentation/core-api/atomic_ops.rst F: Documentation/core-api/refcount-vs-atomic.rst F: Documentation/memory-barriers.txt +LINUX RANDOM NUMBER GENERATOR (LRNG) DRIVER +M: Stephan Mueller <[email protected]> +S: Maintained +W: https://www.chronox.de/lrng.html +F: drivers/char/lrng/* +F: include/linux/lrng.h + LIS3LV02D ACCELEROMETER DRIVER M: Eric Piel <[email protected]> S: Maintained
drivers/char/Kconfig +2 -0
@@ -535,6 +535,8 @@ config ADI and SSM (Silicon Secured Memory). Intended consumers of this driver include crash and makedumpfile. +source "drivers/char/lrng/Kconfig" + endmenu config RANDOM_TRUST_CPU
drivers/char/Makefile +8 -1
@@ -3,7 +3,14 @@ # Makefile for the kernel character device drivers. # -obj-y += mem.o random.o +obj-y += mem.o + +ifeq ($(CONFIG_LRNG),y) + obj-y += lrng/ +else + obj-y += random.o +endif + obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o obj-y += misc.o obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
drivers/char/lrng/Kconfig new file +67 -0
67 lines not on this page · raw message
drivers/char/lrng/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the Linux Random Number Generator. +# + +obj-y += lrng_pool.o lrng_aux.o \ + lrng_sw_noise.o lrng_archrandom.o \ + lrng_drng.o lrng_chacha20.o \ + lrng_interfaces.o \
drivers/char/lrng/lrng_archrandom.c new file +94 -0
94 lines not on this page · raw message
drivers/char/lrng/lrng_aux.c new file +148 -0
148 lines not on this page · raw message
drivers/char/lrng/lrng_chacha20.c new file +265 -0
265 lines not on this page · raw message
drivers/char/lrng/lrng_chacha20.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* +* LRNG ChaCha20 definitions +* +* Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]> +*/ + +#include <crypto/chacha.h> + +/* State according to RFC 7539 section 2.3 */ +struct chacha20_block { +u32 constants[4 ]; +union { +#define CHACHA_KEY_SIZE_WORDS (CHACHA_KEY_SIZE / sizeof(u32)) +u32 u[CHACHA_KEY_SIZE_WORDS ]; +u8 b[CHACHA_KEY_SIZE ]; + } key; +u32 counter; +u32 nonce[3 ]; +}; + +static inline void lrng_cc20_init_rfc7539 (struct chacha20_block *chacha20) +{ +memcpy (&chacha20->constants[0 ],"expand 32-byte k" ,16 ); +}
drivers/char/lrng/lrng_drng.c new file +400 -0
400 lines not on this page · raw message
drivers/char/lrng/lrng_interfaces.c new file +638 -0
638 lines not on this page · raw message
drivers/char/lrng/lrng_internal.h new file +296 -0
296 lines not on this page · raw message
drivers/char/lrng/lrng_lfsr.h new file +152 -0
152 lines not on this page · raw message
drivers/char/lrng/lrng_pool.c new file +588 -0
588 lines not on this page · raw message
drivers/char/lrng/lrng_sw_noise.c new file +102 -0
102 lines not on this page · raw message
drivers/char/lrng/lrng_sw_noise.h new file +57 -0
57 lines not on this page · raw message
include/linux/lrng.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH v28 01/12] Linux Random Number Generator
Hi,
Quoted 64 lines · Stephan Müller
CC: "Eric W. Biederman" <[email protected]>
CC: "Alexander E. Patrakov" <[email protected]>
CC: "Ahmed S. Darwish" <[email protected]>
CC: "Theodore Y. Ts'o" <[email protected]>
CC: Willy Tarreau <[email protected]>
CC: Matthew Garrett <[email protected]>
CC: Vito Caputo <[email protected]>
CC: Andreas Dilger <[email protected]>
CC: Jan Kara <[email protected]>
CC: Ray Strode <[email protected]>
CC: William Jon McCann <[email protected]>
CC: zhangjs <[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Florian Weimer <[email protected]>
CC: Lennart Poettering <[email protected]>
CC: Nicolai Stange <[email protected]>
Mathematical aspects Reviewed-by: "Peter, Matthias" <[email protected]>Reviewed-by Marcelo Henrique Cerri <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>--- MAINTAINERS | 7 + drivers/char/Kconfig | 2 + drivers/char/Makefile | 9 +- drivers/char/lrng/Kconfig | 67 +++ drivers/char/lrng/Makefile | 9 + drivers/char/lrng/lrng_archrandom.c | 94 ++++ drivers/char/lrng/lrng_aux.c | 148 +++++++ drivers/char/lrng/lrng_chacha20.c | 265 ++++++++++++ drivers/char/lrng/lrng_chacha20.h | 25 ++ drivers/char/lrng/lrng_drng.c | 400 +++++++++++++++++ drivers/char/lrng/lrng_interfaces.c | 638 ++++++++++++++++++++++++++++ drivers/char/lrng/lrng_internal.h | 296 +++++++++++++ drivers/char/lrng/lrng_lfsr.h | 152 +++++++ drivers/char/lrng/lrng_pool.c | 588 +++++++++++++++++++++++++ drivers/char/lrng/lrng_sw_noise.c | 102 +++++ drivers/char/lrng/lrng_sw_noise.h | 57 +++ include/linux/lrng.h | 63 +++ 17 files changed, 2921 insertions(+), 1 deletion(-) create mode 100644 drivers/char/lrng/Kconfig create mode 100644 drivers/char/lrng/Makefile create mode 100644 drivers/char/lrng/lrng_archrandom.c create mode 100644 drivers/char/lrng/lrng_aux.c create mode 100644 drivers/char/lrng/lrng_chacha20.c create mode 100644 drivers/char/lrng/lrng_chacha20.h create mode 100644 drivers/char/lrng/lrng_drng.c create mode 100644 drivers/char/lrng/lrng_interfaces.c create mode 100644 drivers/char/lrng/lrng_internal.h create mode 100644 drivers/char/lrng/lrng_lfsr.h create mode 100644 drivers/char/lrng/lrng_pool.c create mode 100644 drivers/char/lrng/lrng_sw_noise.c create mode 100644 drivers/char/lrng/lrng_sw_noise.h create mode 100644 include/linux/lrng.hdrivers/char/lrng/Kconfig new file +0
-0
drivers/char/lrng/Kconfig line 7
Quoted 7 lines
drivers/char/lrng/Kconfig new file +7
-0@@ -0,0 +1,67 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Linux Random Number Generator configuration +# + +menuconfig LRNG + bool "Linux Random Number Generator"
This should probably depend on CRYPTO and/or some other CRYPTO_xxx symbols. Or (worst case) select them. :(
This message (when CONFIG_CRYPTO is disabled and no crypto facilities are enabled) should be avoidable when the correct Kconfig entries are used:
../drivers/char/lrng/lrng_drbg.c:38:2: error: #error "Unknown DRBG in use"
#error "Unknown DRBG in use"
Quoted 85 lines
drivers/char/lrng/Kconfig new file +60
-0+ help + The Linux Random Number Generator (LRNG) is the replacement + of the existing /dev/random provided with drivers/char/random.c. + It generates entropy from different noise sources and + delivers significant entropy during boot. + +if LRNG + +choice + prompt "LRNG Entropy Pool Size" + default LRNG_POOL_SIZE_4096 + help + Select the size of the LRNG entropy pool. The size of the + entropy pool is relevant for the amount of entropy that + the LRNG can maintain as a maximum. The larger the size + of the entropy pool is the more entropy can be maintained + but the less often older entropic values are overwritten + with new entropy. + + config LRNG_POOL_SIZE_512 + bool "512 bits" + + config LRNG_POOL_SIZE_1024 + bool "1024 bits" + + config LRNG_POOL_SIZE_2048 + bool "2048 bits" + + config LRNG_POOL_SIZE_4096 + bool "4096 bits (default)" + + config LRNG_POOL_SIZE_8192 + bool "8192 bits" + + config LRNG_POOL_SIZE_16384 + bool "16384 bits" + + config LRNG_POOL_SIZE_32768 + bool "32768 bits" + + config LRNG_POOL_SIZE_65536 + bool "65536 bits" + + config LRNG_POOL_SIZE_131072 + bool "131072 bits" +endchoice + +config LRNG_POOL_SIZE + int + default 0 if LRNG_POOL_SIZE_512 + default 1 if LRNG_POOL_SIZE_1024 + default 2 if LRNG_POOL_SIZE_2048 + default 3 if LRNG_POOL_SIZE_4096 + default 4 if LRNG_POOL_SIZE_8192 + default 5 if LRNG_POOL_SIZE_16384 + default 6 if LRNG_POOL_SIZE_32768 + default 7 if LRNG_POOL_SIZE_65536 + default 8 if LRNG_POOL_SIZE_131072 + +endif # LRNGdrivers/char/lrng/lrng_archrandom.c new file +18
-0@@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* LRNG Fast Noise Source: CPU-based noise source +* +* Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/random.h> + +#include "lrng_internal.h" + +/* +* Estimated entropy of data is a 32th of LRNG_DRNG_SECURITY_STRENGTH_BITS. +* As we have no ability to review the implementation of those noise sources, +* it is prudent to have a conservative estimate here. +*/
drivers/char/lrng/lrng_archrandom.c line 28
Quoted 10 lines
drivers/char/lrng/lrng_archrandom.c new file +10
-0+#define LRNG_ARCHRANDOM_DEFAULT_STRENGTH (LRNG_DRNG_SECURITY_STRENGTH_BITS>>5) +#define LRNG_ARCHRANDOM_TRUST_CPU_STRENGTH LRNG_DRNG_SECURITY_STRENGTH_BITS +#ifdef CONFIG_RANDOM_TRUST_CPU +static u32 archrandom =LRNG_ARCHRANDOM_TRUST_CPU_STRENGTH ; +#else +static u32 archrandom =LRNG_ARCHRANDOM_DEFAULT_STRENGTH ; +#endif +module_param (archrandom, uint,0644 ); +MODULE_PARM_DESC (archrandom,"Entropy in bits of 256 data bits from CPU noise " +"source (e.g. RDRAND)" );
Please put the string on one line like several other MODULE_PARM_DESC() are done:
+MODULE_PARM_DESC(archrandom,
+ "Entropy in bits of 256 data bits from CPU noise source (e.g. RDRAND)");
With CONFIG_CRYPTO disabled, these warnings happen:
WARNING: unmet direct dependencies detected for CRYPTO_DRBG_MENU
Depends on [n]: CRYPTO [=n]
Selected by [m]:
- LRNG_DRBG [=m] && LRNG [=y] && LRNG_DRNG_SWITCH [=y]
WARNING: unmet direct dependencies detected for CRYPTO_RNG
Depends on [n]: CRYPTO [=n]
Selected by [m]:
- LRNG_KCAPI [=m] && LRNG [=y] && LRNG_DRNG_SWITCH [=y]
../drivers/char/lrng/lrng_drbg.c: In function ‘lrng_hash_name’:../drivers/char/lrng/lrng_drbg.c:225:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^../drivers/char/lrng/lrng_drbg.c: In function ‘lrng_drbg_name’:../drivers/char/lrng/lrng_drbg.c:220:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
and build errors happen also, which can be prevented with Kconfig fixes.
Signature · 2 lines
~Randy Reported-by: Randy Dunlap <[email protected]>
Re: [PATCH v28 01/12] Linux Random Number Generator
Am Donnerstag, 16. Januar 2020, 01:11:40 CET schrieb Randy Dunlap:
Hi Randy,
Quoted 62 lines
Hi,
Quoted 59 lines · Stephan Müller
CC: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/[email protected]>
CC: "Alexander E. Patrakov" <[email protected]>
CC: "Ahmed S. Darwish" <[email protected]>
CC: "Theodore Y. Ts'o" <[email protected]>
CC: Willy Tarreau <[email protected]>
CC: Matthew Garrett <[email protected]>
CC: Vito Caputo <[email protected]>
CC: Andreas Dilger <[email protected]>
CC: Jan Kara <[email protected]>
CC: Ray Strode <[email protected]>
CC: William Jon McCann <[email protected]>
CC: zhangjs <zachary-+jQ8zvd9CV5SzTKKI/[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Florian Weimer <[email protected]>
CC: Lennart Poettering <[email protected]>
CC: Nicolai Stange <[email protected]>
Mathematical aspects Reviewed-by: "Peter, Matthias" <[email protected]> Reviewed-by: Marcelo Henrique Cerri <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>---
MAINTAINERS | 7 + drivers/char/Kconfig | 2 + drivers/char/Makefile | 9 +- drivers/char/lrng/Kconfig | 67 +++ drivers/char/lrng/Makefile | 9 + drivers/char/lrng/lrng_archrandom.c | 94 ++++ drivers/char/lrng/lrng_aux.c | 148 +++++++ drivers/char/lrng/lrng_chacha20.c | 265 ++++++++++++ drivers/char/lrng/lrng_chacha20.h | 25 ++ drivers/char/lrng/lrng_drng.c | 400 +++++++++++++++++ drivers/char/lrng/lrng_interfaces.c | 638 ++++++++++++++++++++++++++++ drivers/char/lrng/lrng_internal.h | 296 +++++++++++++ drivers/char/lrng/lrng_lfsr.h | 152 +++++++ drivers/char/lrng/lrng_pool.c | 588 +++++++++++++++++++++++++ drivers/char/lrng/lrng_sw_noise.c | 102 +++++ drivers/char/lrng/lrng_sw_noise.h | 57 +++ include/linux/lrng.h | 63 +++ 17 files changed, 2921 insertions(+), 1 deletion(-) create mode 100644 drivers/char/lrng/Kconfig create mode 100644 drivers/char/lrng/Makefile create mode 100644 drivers/char/lrng/lrng_archrandom.c create mode 100644 drivers/char/lrng/lrng_aux.c create mode 100644 drivers/char/lrng/lrng_chacha20.c create mode 100644 drivers/char/lrng/lrng_chacha20.h create mode 100644 drivers/char/lrng/lrng_drng.c create mode 100644 drivers/char/lrng/lrng_interfaces.c create mode 100644 drivers/char/lrng/lrng_internal.h create mode 100644 drivers/char/lrng/lrng_lfsr.h create mode 100644 drivers/char/lrng/lrng_pool.c create mode 100644 drivers/char/lrng/lrng_sw_noise.c create mode 100644 drivers/char/lrng/lrng_sw_noise.h create mode 100644 include/linux/lrng.h
Quoted 16 lines
drivers/char/lrng/Kconfig line 7
Quoted 13 lines
drivers/char/lrng/Kconfig new file +7
-0@@ -0,0 +1,67 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Linux Random Number Generator configuration +# + +menuconfig LRNG + bool "Linux Random Number Generator"This should probably depend on CRYPTO and/or some other
CRYPTO_xxxsymbols. Or (worst case) select them. :(
It does not - all CRYPTO related code is limited into the lrng_drbg.c, lrng_kcapi.c and lrng_jent.c which are all guarded by a Kconfig option.
Quoted 6 lines
This message (when
CONFIG_CRYPTOis disabled and no crypto facilities are enabled) should be avoidable when the correctKconfigentries are used:
../drivers/char/lrng/lrng_drbg.c:38:2: error: #error "Unknown DRBG in use"
#error "Unknown DRBG in use"
Right - this should now be fixed with a depends on CRYPTO for the aforementioned 3 C files which have an equal entry in Kconfig.
Quoted 102 lines
Quoted 97 lines
drivers/char/lrng/Kconfig new file +60
-0+ help + The Linux Random Number Generator (LRNG) is the replacement + of the existing /dev/random provided with drivers/char/random.c. + It generates entropy from different noise sources and + delivers significant entropy during boot. + +if LRNG + +choice + prompt "LRNG Entropy Pool Size" + default LRNG_POOL_SIZE_4096 + help + Select the size of the LRNG entropy pool. The size of the + entropy pool is relevant for the amount of entropy that + the LRNG can maintain as a maximum. The larger the size + of the entropy pool is the more entropy can be maintained + but the less often older entropic values are overwritten + with new entropy. + + config LRNG_POOL_SIZE_512 + bool "512 bits" + + config LRNG_POOL_SIZE_1024 + bool "1024 bits" + + config LRNG_POOL_SIZE_2048 + bool "2048 bits" + + config LRNG_POOL_SIZE_4096 + bool "4096 bits (default)" + + config LRNG_POOL_SIZE_8192 + bool "8192 bits" + + config LRNG_POOL_SIZE_16384 + bool "16384 bits" + + config LRNG_POOL_SIZE_32768 + bool "32768 bits" + + config LRNG_POOL_SIZE_65536 + bool "65536 bits" + + config LRNG_POOL_SIZE_131072 + bool "131072 bits" +endchoice + +config LRNG_POOL_SIZE + int + default 0 if LRNG_POOL_SIZE_512 + default 1 if LRNG_POOL_SIZE_1024 + default 2 if LRNG_POOL_SIZE_2048 + default 3 if LRNG_POOL_SIZE_4096 + default 4 if LRNG_POOL_SIZE_8192 + default 5 if LRNG_POOL_SIZE_16384 + default 6 if LRNG_POOL_SIZE_32768 + default 7 if LRNG_POOL_SIZE_65536 + default 8 if LRNG_POOL_SIZE_131072 + +endif # LRNG(quoted diff) +0
-0
b/drivers/char/lrng/lrng_archrandom.cnew file mode 100644 index 000000000000..eeba708d025fdrivers/char/lrng/lrng_archrandom.c new file +15
-0@@ -0,0 +1,94 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* LRNG Fast Noise Source: CPU-based noise source +* +* Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/random.h> + +#include "lrng_internal.h" + +/* +* Estimated entropy of data is a 32th of
LRNG_DRNG_SECURITY_STRENGTH_BITS. + * As we have no ability to review the implementation of those noise sources, + * it is prudent to have a conservative estimate here.
+ */
+#defineLRNG_ARCHRANDOM_DEFAULT_STRENGTH(LRNG_DRNG_SECURITY_STRENGTH_BITS>>5) +#defineLRNG_ARCHRANDOM_TRUST_CPU_STRENGTHLRNG_DRNG_SECURITY_STRENGTH_BITSdrivers/char/lrng/lrng_archrandom.c new file +7
-0+#ifdef CONFIG_RANDOM_TRUST_CPU +static u32 archrandom =LRNG_ARCHRANDOM_TRUST_CPU_STRENGTH ; +#else +static u32 archrandom =LRNG_ARCHRANDOM_DEFAULT_STRENGTH ; +#endif +module_param (archrandom, uint,0644 ); +MODULE_PARM_DESC(archrandom, "Entropy in bits of 256 data bits from CPUQuoted 1 line
noise " + "source (e.g. RDRAND)");
Please put the string on one line like several other
MODULE_PARM_DESC()are done:
Review
Quoted 2 lines
(quoted diff) +2
-0+MODULE_PARM_DESC(archrandom, + "Entropy in bits of 256 data bits from CPU noise source (e.g.
RDRAND)");
Done.
Quoted 23 lines
With
CONFIG_CRYPTOdisabled, these warnings happen:WARNING: unmet direct dependencies detected for
CRYPTO_DRBG_MENU
Depends on [n]: CRYPTO [=n]
Selected by [m]:
-LRNG_DRBG[=m] && LRNG [=y] &&LRNG_DRNG_SWITCH[=y]WARNING: unmet direct dependencies detected for
CRYPTO_RNG
Depends on [n]: CRYPTO [=n]
Selected by [m]:
-LRNG_KCAPI[=m] && LRNG [=y] &&LRNG_DRNG_SWITCH[=y]
../drivers/char/lrng/lrng_drbg.c: In function ‘lrng_hash_name’:../drivers/char/lrng/lrng_drbg.c:225:1: warning: control reaches end of non-void function [-Wreturn-type] }
^../drivers/char/lrng/lrng_drbg.c: In function ‘lrng_drbg_name’:../drivers/char/lrng/lrng_drbg.c:220:1: warning: control reaches end of non-void function [-Wreturn-type] }
^
Quoted 1 line
and build errors happen also, which can be prevented with
Kconfigfixes.
With the changes to the Kconfig file as explained in the other emails, I can successfully compile the LRNG without the crypto API being enabled.
Thank you for pointing that one out.
Ciao
Stephan
PATCH v28 2/12 LRNG - allocate one DRNG instance per NUMA node
In reply to Stephan MüllerIn order to improve NUMA-locality when serving getrandom(2) requests, allocate one DRNG instance per node.
The DRNG instance that is present right from the start of the kernel is reused as the first per-NUMA-node DRNG. For all remaining online NUMA nodes a new DRNG instance is allocated.
During boot time, the multiple DRNG instances are seeded sequentially. With this, the first DRNG instance (referenced as the initial DRNG in the code) is completely seeded with 256 bits of entropy before the next DRNG instance is completely seeded.
When random numbers are requested, the NUMA-node-local DRNG is checked whether it has been already fully seeded. If this is not the case, the initial DRNG is used to serve the request.
--- drivers/char/lrng/Makefile | 2 + drivers/char/lrng/lrng_internal.h | 5 ++ drivers/char/lrng/lrng_numa.c | 101 ++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 drivers/char/lrng/lrng_numa.c
drivers/char/lrng/Makefile +2 -0
@@ -7,3 +7,5 @@ obj-y += lrng_pool.o lrng_aux.o \ lrng_sw_noise.o lrng_archrandom.o \ lrng_drng.o lrng_chacha20.o \ lrng_interfaces.o \ + +obj-$(CONFIG_NUMA) += lrng_numa.o
drivers/char/lrng/lrng_internal.h +5 -0
@@ -246,8 +246,13 @@ int lrng_drng_get_sleep(u8 *outbuf, u32 outbuflen);void lrng_drng_force_reseed (void );void lrng_drng_seed_work (struct work_struct *dummy); +#ifdef CONFIG_NUMA +struct lrng_drng **lrng_drng_instances (void ); +void lrng_drngs_numa_alloc (void ); +#else /* CONFIG_NUMA */ static inline struct lrng_drng **lrng_drng_instances (void ) {return NULL ; }static inline void lrng_drngs_numa_alloc (void ) {return ; } +#endif /* CONFIG_NUMA */ /************************** Health Test linking code **************************/
drivers/char/lrng/lrng_numa.c new file +101 -0
101 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v28 3/12 LRNG - sysctls and /proc interface
In reply to Stephan MüllerThe LRNG sysctl interface provides the same controls as the existing /dev/random implementation. These sysctls behave identically and are implemented identically. The goal is to allow a possible merge of the existing /dev/random implementation with this implementation which implies that this patch tries have a very close similarity. Yet, all sysctls are documented at [1].
In addition, it provides the file lrng_type which provides details about the LRNG:
- the name of the DRNG that produces the random numbers for /dev/random, /dev/urandom, getrandom(2)
- the hash used to produce random numbers from the entropy pool
- the number of secondary DRNG instances
- indicator whether the LRNG operates SP800-90B compliant
- indicator whether a high-resolution timer is identified - only with a high-resolution timer the interrupt noise source will deliver sufficient entropy
- indicator whether the LRNG has been minimally seeded (i.e. is the secondary DRNG seeded with at least 128 bits of of entropy)
- indicator whether the LRNG has been fully seeded (i.e. is the secondary DRNG seeded with at least 256 bits of entropy)
[1] https://www.chronox.de/lrng.html
--- drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_interfaces.c | 1 - drivers/char/lrng/lrng_internal.h | 4 + drivers/char/lrng/lrng_proc.c | 163 ++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 drivers/char/lrng/lrng_proc.c
drivers/char/lrng/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-y += lrng_pool.o lrng_aux.o \ lrng_interfaces.o \ obj-$(CONFIG_NUMA) += lrng_numa.o +obj-$(CONFIG_SYSCTL) += lrng_proc.o
drivers/char/lrng/lrng_interfaces.c +0 -1
@@ -34,7 +34,6 @@ static DECLARE_WAIT_QUEUE_HEAD(lrng_write_wait);static DECLARE_WAIT_QUEUE_HEAD (lrng_init_wait);static struct fasync_struct *fasync; -struct ctl_table random_table[];/********************************** Helper ***********************************/ /* Is the DRNG seed level too low? */
drivers/char/lrng/lrng_internal.h +4 -0
@@ -116,7 +116,11 @@ void lrng_cc20_init_state(struct chacha20_state *state);/********************************** /proc *************************************/ +#ifdef CONFIG_SYSCTL +void lrng_pool_inc_numa_node (void ); +#else static inline void lrng_pool_inc_numa_node (void ) { } +#endif /****************************** LRNG interfaces *******************************/
drivers/char/lrng/lrng_proc.c new file +163 -0
163 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v28 4/12 LRNG - add switchable DRNG support
In reply to Stephan MüllerThe DRNG switch support allows replacing the DRNG mechanism of the LRNG. The switching support rests on the interface definition of include/linux/lrng.h. A new DRNG is implemented by filling in the interface defined in this header file.
In addition to the DRNG, the extension also has to provide a hash implementation that is used to hash the entropy pool for random number extraction.
Note: It is permissible to implement a DRNG whose operations may sleep. However, the hash function must not sleep.
The switchable DRNG support allows replacing the DRNG at runtime. However, only one DRNG extension is allowed to be loaded at any given time. Before replacing it with another DRNG implementation, the possibly existing DRNG extension must be unloaded.
The switchable DRNG extension activates the new DRNG during load time. It is expected, however, that such a DRNG switch would be done only once by an administrator to load the intended DRNG implementation.
It is permissible to compile DRNG extensions either as kernel modules or statically. The initialization of the DRNG extension should be performed with a late_initcall to ensure the extension is available when user space starts but after all other initialization completed. The initialization is performed by registering the function call data structure with the lrng_set_drng_cb function. In order to unload the DRNG extension, lrng_set_drng_cb must be invoked with the NULL parameter.
The DRNG extension should always provide a security strength that is at least as strong as LRNG_DRNG_SECURITY_STRENGTH_BITS.
--- drivers/char/lrng/Kconfig | 7 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_switch.c | 183 ++++++++++++++++++++++++++++++++ 3 files changed, 191 insertions(+) create mode 100644 drivers/char/lrng/lrng_switch.c
drivers/char/lrng/Kconfig +7 -0
@@ -64,4 +64,11 @@ config LRNG_POOL_SIZE default 7 if LRNG_POOL_SIZE_65536 default 8 if LRNG_POOL_SIZE_131072 +menuconfig LRNG_DRNG_SWITCH + bool "Support DRNG runtime switching" + help + The Linux RNG per default uses a ChaCha20 DRNG that is + accessible via the external interfaces. With this configuration + option other DRNGs can be selected and loaded at runtime. + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-y += lrng_pool.o lrng_aux.o \ obj-$(CONFIG_NUMA) += lrng_numa.o obj-$(CONFIG_SYSCTL) += lrng_proc.o +obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o
drivers/char/lrng/lrng_switch.c new file +183 -0
183 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v28 5/12 crypto: DRBG - externalize DRBG functions for LRNG
In reply to Stephan MüllerThis patch allows several DRBG functions to be called by the LRNG kernel code paths outside the drbg.c file.
--- crypto/drbg.c | 16 ++++++++++------ include/crypto/drbg.h | 7 +++++++ 2 files changed, 17 insertions(+), 6 deletions(-)
crypto/drbg.c +10 -6
@@ -113,7 +113,7 @@* the SHA256 / AES 256 over other ciphers. Thus, the favored * DRBGs are the latest entries in this array. */ -static const struct drbg_core drbg_cores[] = { +const struct drbg_core drbg_cores[] = { #ifdef CONFIG_CRYPTO_DRBG_CTR { .flags = DRBG_CTR | DRBG_STRENGTH128,
@@ -190,6 +190,7 @@ static const struct drbg_core drbg_cores[] = { },#endif /* CONFIG_CRYPTO_DRBG_HMAC */ }; +EXPORT_SYMBOL (drbg_cores);static int drbg_uninstantiate (struct drbg_state *drbg);
@@ -205,7 +206,7 @@ static int drbg_uninstantiate(struct drbg_state *drbg);* Return: normalized strength in *bytes* value or 32 as default * to counter programming errors */ -static inline unsigned short drbg_sec_strength (drbg_flag_t flags) +unsigned short drbg_sec_strength (drbg_flag_t flags) {switch (flags &DRBG_STRENGTH_MASK ) {case DRBG_STRENGTH128 :
@@ -218,6 +219,7 @@ static inline unsigned short drbg_sec_strength(drbg_flag_t flags)return 32 ; } } +EXPORT_SYMBOL (drbg_sec_strength);/* * FIPS 140-2 continuous self test for the noise source
@@ -1202,7 +1204,7 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, }/* Free all substructures in a DRBG state without the DRBG state structure */ -static inline void drbg_dealloc_state (struct drbg_state *drbg) +void drbg_dealloc_state (struct drbg_state *drbg) {if (!drbg)return ;
@@ -1223,12 +1225,13 @@ static inline void drbg_dealloc_state(struct drbg_state *drbg) drbg->fips_primed = false; } } +EXPORT_SYMBOL (drbg_dealloc_state);/* * Allocate all sub-structures for a DRBG state. * The DRBG state structure must already be allocated. */ -static inline int drbg_alloc_state (struct drbg_state *drbg) +int drbg_alloc_state (struct drbg_state *drbg) {int ret = -ENOMEM ;unsigned int sb_size =0 ;
@@ -1307,6 +1310,7 @@ static inline int drbg_alloc_state(struct drbg_state *drbg)drbg_dealloc_state (drbg);return ret; } +EXPORT_SYMBOL (drbg_alloc_state);/************************************************************************* * DRBG interface functions
@@ -1874,8 +1878,7 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg,* * return: flags */ -static inline void drbg_convert_tfm_core (const char *cra_driver_name, -int *coreref,bool *pr) +void drbg_convert_tfm_core (const char *cra_driver_name,int *coreref,bool *pr) {int i =0 ;size_t start =0 ;
@@ -1902,6 +1905,7 @@ static inline void drbg_convert_tfm_core(const char *cra_driver_name, } } } +EXPORT_SYMBOL (drbg_convert_tfm_core);static int drbg_kcapi_init (struct crypto_tfm *tfm) {
include/crypto/drbg.h +7 -0
@@ -282,4 +282,11 @@ enum drbg_prefixes {DRBG_PREFIX3 }; +extern int drbg_alloc_state (struct drbg_state *drbg); +extern void drbg_dealloc_state (struct drbg_state *drbg); +extern void drbg_convert_tfm_core (const char *cra_driver_name,int *coreref, +bool *pr); +extern const struct drbg_core drbg_cores[]; +extern unsigned short drbg_sec_strength (drbg_flag_t flags); +#endif /* _DRBG_H */
Signature · 1 line
2.24.1
PATCH v28 6/12 LRNG - add SP800-90A DRBG extension
In reply to Stephan MüllerUsing the LRNG switchable DRNG support, the SP800-90A DRBG extension is implemented.
The DRBG uses the kernel crypto API DRBG implementation. In addition, it uses the kernel crypto API SHASH support to provide the hashing operation.
The DRBG supports the choice of either a CTR DRBG using AES-256, HMAC DRBG with SHA-512 core or Hash DRBG with SHA-512 core. The used core can be selected with the module parameter lrng_drbg_type. The default is the CTR DRBG.
When compiling the DRBG extension statically, the DRBG is loaded at late_initcall stage which implies that with the start of user space, the user space interfaces of getrandom(2), /dev/random and /dev/urandom provide random data produced by an SP800-90A DRBG.
--- drivers/char/lrng/Kconfig | 11 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_drbg.c | 260 ++++++++++++++++++++++++++++++++++ 3 files changed, 272 insertions(+) create mode 100644 drivers/char/lrng/lrng_drbg.c
drivers/char/lrng/Kconfig +11 -0
@@ -71,4 +71,15 @@ menuconfig LRNG_DRNG_SWITCH accessible via the external interfaces. With this configuration option other DRNGs can be selected and loaded at runtime. +if LRNG_DRNG_SWITCH +config LRNG_DRBG + tristate "SP800-90A support for the LRNG" + select CRYPTO_DRBG_MENU + select CRYPTO_CMAC if CRYPTO_DRBG_CTR + help + Enable the SP800-90A DRBG support for the LRNG. Once the + module is loaded, output from /dev/random, /dev/urandom, + getrandom(2), or get_random_bytes is provided by a DRBG. +endif # LRNG_DRNG_SWITCH + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-y += lrng_pool.o lrng_aux.o \ obj-$(CONFIG_NUMA) += lrng_numa.o obj-$(CONFIG_SYSCTL) += lrng_proc.o obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o +obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o
drivers/char/lrng/lrng_drbg.c new file +260 -0
260 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH v28 06/12] LRNG - add SP800-90A DRBG extension
Quoted 34 lines · Stephan Müller
CC "Eric W. Biederman" <[email protected]>CC "Alexander E. Patrakov" <[email protected]>CC "Ahmed S. Darwish" <[email protected]>CC "Theodore Y. Ts'o" <[email protected]>CC Willy Tarreau <[email protected]>CC Matthew Garrett <[email protected]>CC Vito Caputo <[email protected]>CC Andreas Dilger <[email protected]>CC Jan Kara <[email protected]>CC Ray Strode <[email protected]>CC William Jon McCann <[email protected]>CC zhangjs <[email protected]>CC Andy Lutomirski <[email protected]>CC Florian Weimer <[email protected]>CC Lennart Poettering <[email protected]>CC Nicolai Stange <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>--- drivers/char/lrng/Kconfig | 11 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_drbg.c | 260 ++++++++++++++++++++++++++++++++++ 3 files changed, 272 insertions(+) create mode 100644 drivers/char/lrng/lrng_drbg.cdrivers/char/lrng/Kconfig +0
-0
drivers/char/lrng/Kconfig menuconfig LRNG_DRNG_SWITCH · line 78
Quoted 8 lines
drivers/char/lrng/Kconfig +5
-0@@ -71,4 +71,15 @@ menuconfig LRNG_DRNG_SWITCH accessible via the external interfaces. With this configuration option other DRNGs can be selected and loaded at runtime. +if LRNG_DRNG_SWITCH +config LRNG_DRBG + tristate "SP800-90A support for the LRNG" + select CRYPTO_DRBG_MENU + select CRYPTO_CMAC if CRYPTO_DRBG_CTR
Don't select these if CRYPTO is not already set/enabled. It causes Kconfig warnings and possible build errors.
Quoted 48 lines
drivers/char/lrng/Kconfig +6
-0+ help + Enable the SP800-90A DRBG support for the LRNG. Once the + module is loaded, output from /dev/random, /dev/urandom, + getrandom(2), or get_random_bytes is provided by a DRBG. +endif # LRNG_DRNG_SWITCH + endif # LRNGdrivers/char/lrng/lrng_drbg.c new file +34
-0@@ -0,0 +1,260 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* Backend for the LRNG providing the cryptographic primitives using the +* kernel crypto API and its DRBG. +* +* Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <crypto/drbg.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/lrng.h> + +/* +* Define a DRBG plus a hash / MAC used to extract data from the entropy pool. +* For LRNG_HASH_NAME you can use a hash or a MAC (HMAC or CMAC) of your choice +* (Note, you should use the suggested selections below -- using SHA-1 or MD5 +* is not wise). The idea is that the used cipher primitive can be selected to +* be the same as used for the DRBG. I.e. the LRNG only uses one cipher +* primitive using the same cipher implementation with the options offered in +* the following. This means, if the CTR DRBG is selected and AES-NI is present, +* both the CTR DRBG and the selected cmac(aes) use AES-NI. +* +* The security strengths of the DRBGs are all 256 bits according to +* SP800-57 section 5.6.1. +* +* This definition is allowed to be changed. +*/ +#ifdef CONFIG_CRYPTO_DRBG_CTR +static unsigned int lrng_drbg_type =0 ; +#elif definedCONFIG_CRYPTO_DRBG_HMAC +static unsigned int lrng_drbg_type =1 ;
drivers/char/lrng/lrng_drbg.c line 44
Quoted 10 lines
drivers/char/lrng/lrng_drbg.c new file +10
-0+#elif definedCONFIG_CRYPTO_DRBG_HASH +static unsigned int lrng_drbg_type =2 ; +#else +#error "Unknown DRBG in use" +#endif + +/* The parameter must be r/o in sysfs as otherwise races appear. */ +module_param (lrng_drbg_type, uint,0444 ); +MODULE_PARM_DESC (lrng_drbg_type,"DRBG type used for LRNG (0->CTR_DRBG, " +"1->HMAC_DRBG, 2->Hash_DRBG)" );
One line for the string, please, not split.
Signature · 2 lines
~Randy Reported-by: Randy Dunlap <[email protected]>
Re: [PATCH v28 06/12] LRNG - add SP800-90A DRBG extension
Am Donnerstag, 16. Januar 2020, 01:14:35 CET schrieb Randy Dunlap:
Hi Randy,
Quoted 39 lines · Stephan Müller
Quoted 38 lines
CC "Eric W. Biederman" <[email protected]>CC "Alexander E. Patrakov" <[email protected]>CC "Ahmed S. Darwish" <[email protected]>CC "Theodore Y. Ts'o" <[email protected]>CC Willy Tarreau <[email protected]>CC Matthew Garrett <[email protected]>CC Vito Caputo <[email protected]>CC Andreas Dilger <[email protected]>CC Jan Kara <[email protected]>CC Ray Strode <[email protected]>CC William Jon McCann <[email protected]>CC zhangjs <[email protected]>CC Andy Lutomirski <[email protected]>CC Florian Weimer <[email protected]>CC Lennart Poettering <[email protected]>CC Nicolai Stange <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>---
drivers/char/lrng/Kconfig | 11 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_drbg.c | 260 ++++++++++++++++++++++++++++++++++ 3 files changed, 272 insertions(+) create mode 100644 drivers/char/lrng/lrng_drbg.cdrivers/char/lrng/Kconfig +0
-0@@ -71,4 +71,15 @@ menuconfig LRNG_DRNG_SWITCH accessible via the external interfaces. With this configuration option other DRNGs can be selected and loaded at runtime.
Quoted 8 lines
drivers/char/lrng/Kconfig menuconfig LRNG_DRNG_SWITCH · line 78
Quoted 5 lines
drivers/char/lrng/Kconfig +5
-0+if LRNG_DRNG_SWITCH +config LRNG_DRBG + tristate "SP800-90A support for the LRNG" + select CRYPTO_DRBG_MENU + select CRYPTO_CMAC if CRYPTO_DRBG_CTRDon't select these if CRYPTO is not already set/enabled. It causes
Kconfigwarnings and possible build errors.
I added "depends on CRYPTO"
Quoted 55 lines
Quoted 55 lines
drivers/char/lrng/Kconfig +6
-0+ help + Enable the SP800-90A DRBG support for the LRNG. Once the + module is loaded, output from /dev/random, /dev/urandom, + getrandom(2), or get_random_bytes is provided by a DRBG. +endif # LRNG_DRNG_SWITCH +endif # LRNG
drivers/char/lrng/lrng_drbg.c new file +17
-0@@ -0,0 +1,260 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* Backend for the LRNG providing the cryptographic primitives using the +* kernel crypto API and its DRBG. +* +* Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <crypto/drbg.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/lrng.h> + +/* +* Define a DRBG plus a hash / MAC used to extract data from the entropy pool. + * For
LRNG_HASH_NAMEyou can use a hash or a MAC (HMAC or CMAC) of your choice + * (Note, you should use the suggested selections below -- using SHA-1 or MD5 + * is not wise). The idea is that the used cipher primitive can be selected to + * be the same as used for the DRBG. I.e. the LRNG only uses one cipher + * primitive using the same cipher implementation with the options offered in + * the following. This means, if the CTR DRBG is selected and AES-NI is present, + * both the CTR DRBG and the selected cmac(aes) use AES-NI.
+ *
+ * The security strengths of the DRBGs are all 256 bits according to
+ * SP800-57 section 5.6.1.
+ *
+ * This definition is allowed to be changed.
+ */drivers/char/lrng/lrng_drbg.c new file +8
-0+#ifdef CONFIG_CRYPTO_DRBG_CTR +static unsigned int lrng_drbg_type =0 ; +#elif definedCONFIG_CRYPTO_DRBG_HMAC +static unsigned int lrng_drbg_type =1 ; +#elif definedCONFIG_CRYPTO_DRBG_HASH +static unsigned int lrng_drbg_type =2 ; +#else +#error "Unknown DRBG in use"
Quoted 8 lines
drivers/char/lrng/lrng_drbg.c line 44
Quoted 6 lines
drivers/char/lrng/lrng_drbg.c new file +6
-0+#endif + +/* The parameter must be r/o in sysfs as otherwise races appear. */ +module_param (lrng_drbg_type, uint,0444 ); +MODULE_PARM_DESC (lrng_drbg_type,"DRBG type used for LRNG (0->CTR_DRBG, " +"1->HMAC_DRBG, 2->Hash_DRBG)" );One line for the string, please, not split.
Changed
Thank you.
Ciao
Stephan
PATCH v28 7/12 LRNG - add kernel crypto API PRNG extension
In reply to Stephan MüllerAdd runtime-pluggable support for all PRNGs that are accessible via the kernel crypto API, including hardware PRNGs. The PRNG is selected with the module parameter drng_name where the name must be one that the kernel crypto API can resolve into an RNG.
This allows using of the kernel crypto API PRNG implementations that provide an interface to hardware PRNGs. Using this extension, the LRNG uses the hardware PRNGs to generate random numbers. An example is the S390 CPACF support providing such a PRNG.
The hash is provided by a kernel crypto API SHASH whose digest size complies with the seedsize of the PRNG.
--- drivers/char/lrng/Kconfig | 10 + drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_kcapi.c | 327 +++++++++++++++++++++++++++++++++ 3 files changed, 338 insertions(+) create mode 100644 drivers/char/lrng/lrng_kcapi.c
drivers/char/lrng/Kconfig +10 -0
@@ -80,6 +80,16 @@ config LRNG_DRBG Enable the SP800-90A DRBG support for the LRNG. Once the module is loaded, output from /dev/random, /dev/urandom, getrandom(2), or get_random_bytes is provided by a DRBG. + +config LRNG_KCAPI + tristate "Kernel Crypto API support for the LRNG" + select CRYPTO_RNG + help + Enable the support for generic pseudo-random number + generators offered by the kernel crypto API with the + LRNG. Once the module is loaded, output from /dev/random, + /dev/urandom, getrandom(2), or get_random_bytes is + provided by the selected kernel crypto API RNG. endif # LRNG_DRNG_SWITCH endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_NUMA) += lrng_numa.o obj-$(CONFIG_SYSCTL) += lrng_proc.o obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o +obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o
drivers/char/lrng/lrng_kcapi.c new file +327 -0
327 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH v28 07/12] LRNG - add kernel crypto API PRNG extension
Quoted 35 lines · Stephan Müller
CC "Eric W. Biederman" <[email protected]>CC "Alexander E. Patrakov" <[email protected]>CC "Ahmed S. Darwish" <[email protected]>CC "Theodore Y. Ts'o" <[email protected]>CC Willy Tarreau <[email protected]>CC Matthew Garrett <[email protected]>CC Vito Caputo <[email protected]>CC Andreas Dilger <[email protected]>CC Jan Kara <[email protected]>CC Ray Strode <[email protected]>CC William Jon McCann <[email protected]>CC zhangjs <[email protected]>CC Andy Lutomirski <[email protected]>CC Florian Weimer <[email protected]>CC Lennart Poettering <[email protected]>CC Nicolai Stange <[email protected]>Reviewed-by Marcelo Henrique Cerri <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>--- drivers/char/lrng/Kconfig | 10 + drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_kcapi.c | 327 +++++++++++++++++++++++++++++++++ 3 files changed, 338 insertions(+) create mode 100644 drivers/char/lrng/lrng_kcapi.cdrivers/char/lrng/Kconfig +0
-0
drivers/char/lrng/Kconfig config LRNG_DRBG · line 86
Quoted 7 lines
drivers/char/lrng/Kconfig +4
-0@@ -80,6 +80,16 @@ config LRNG_DRBG Enable the SP800-90A DRBG support for the LRNG. Once the module is loaded, output from /dev/random, /dev/urandom, getrandom(2), or get_random_bytes is provided by a DRBG. + +config LRNG_KCAPI + tristate "Kernel Crypto API support for the LRNG" + select CRYPTO_RNG
Don't select CRYPTO_RNG unless you know that CRYPTO is set/enabled.
Quoted 9 lines
drivers/char/lrng/Kconfig +6
-0+ help + Enable the support for generic pseudo-random number + generators offered by the kernel crypto API with the + LRNG. Once the module is loaded, output from /dev/random, + /dev/urandom, getrandom(2), or get_random_bytes is + provided by the selected kernel crypto API RNG. endif # LRNG_DRNG_SWITCH endif # LRNG
Signature · 2 lines
~Randy Reported-by: Randy Dunlap <[email protected]>
Re: [PATCH v28 07/12] LRNG - add kernel crypto API PRNG extension
Am Donnerstag, 16. Januar 2020, 01:15:46 CET schrieb Randy Dunlap:
Hi Randy,
Quoted 41 lines · Stephan Müller
Quoted 40 lines
CC "Eric W. Biederman" <[email protected]>CC "Alexander E. Patrakov" <[email protected]>CC "Ahmed S. Darwish" <[email protected]>CC "Theodore Y. Ts'o" <[email protected]>CC Willy Tarreau <[email protected]>CC Matthew Garrett <[email protected]>CC Vito Caputo <[email protected]>CC Andreas Dilger <[email protected]>CC Jan Kara <[email protected]>CC Ray Strode <[email protected]>CC William Jon McCann <[email protected]>CC zhangjs <[email protected]>CC Andy Lutomirski <[email protected]>CC Florian Weimer <[email protected]>CC Lennart Poettering <[email protected]>CC Nicolai Stange <[email protected]>Reviewed-by Marcelo Henrique Cerri <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>---
drivers/char/lrng/Kconfig | 10 + drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_kcapi.c | 327 +++++++++++++++++++++++++++++++++ 3 files changed, 338 insertions(+) create mode 100644 drivers/char/lrng/lrng_kcapi.cdrivers/char/lrng/Kconfig +0
-0@@ -80,6 +80,16 @@ config LRNG_DRBG Enable the SP800-90A DRBG support for the LRNG. Once the module is loaded, output from /dev/random, /dev/urandom, getrandom(2), or get_random_bytes is provided by a DRBG.
Quoted 6 lines
drivers/char/lrng/Kconfig config LRNG_DRBG · line 86
Quoted 4 lines
drivers/char/lrng/Kconfig +4
-0+ +config LRNG_KCAPI + tristate "Kernel Crypto API support for the LRNG" + select CRYPTO_RNGDon't select
CRYPTO_RNGunless you know that CRYPTO is set/enabled.
I added "depends on CRYPTO"
Quoted 11 lines
Quoted 11 lines
drivers/char/lrng/Kconfig +6
-0+ help + Enable the support for generic pseudo-random number + generators offered by the kernel crypto API with the + LRNG. Once the module is loaded, output from /dev/random, + /dev/urandom, getrandom(2), or get_random_bytes is + provided by the selected kernel crypto API RNG.endif #
LRNG_DRNG_SWITCHendif # LRNG
Thank you.
Ciao
Stephan
PATCH v28 8/12 crypto: provide access to a static Jitter RNG state
In reply to Stephan MüllerTo support the LRNG operation which uses the Jitter RNG separately from the kernel crypto API, at a time where potentially the regular memory management is not yet initialized, the Jitter RNG needs to provide a state whose memory is defined at compile time. As only once instance will ever be needed by the LRNG, define once static memory block which is solely to be used by the LRNG.
---
crypto/jitterentropy-kcapi.c | 3 +--
crypto/jitterentropy.c | 25 ++++++++++++++++++-
.../crypto/internal}/jitterentropy.h | 3 +++
3 files changed, 28 insertions(+), 3 deletions(-)
rename {crypto => include/crypto/internal}/jitterentropy.h (84%)crypto/jitterentropy-kcapi.c +1 -2
@@ -43,8 +43,7 @@#include <linux/time.h> #include <linux/crypto.h> #include <crypto/internal/rng.h> - -#include "jitterentropy.h" +#include <crypto/internal/jitterentropy.h> /*************************************************************************** * Helper function
crypto/jitterentropy.c +24 -1
@@ -103,7 +103,7 @@ struct rand_data {* Helper functions ***************************************************************************/ -#include "jitterentropy.h" +#include <crypto/internal/jitterentropy.h> /** * Update of the loop count used for the next round of
@@ -639,3 +639,26 @@ int jent_entropy_init(void)return 0 ; } + +struct rand_data *jent_lrng_entropy_collector (void ) +{ +static unsigned char lrng_jent_mem[JENT_MEMORY_SIZE ]; +static struct rand_data lrng_jent_state = { + .data =0 , + .old_data =0 , + .prev_time =0 , + .last_delta =0 , + .last_delta2 =0 , + .osr =1 , + .mem = lrng_jent_mem, + .memlocation =0 , + .memblocks =JENT_MEMORY_BLOCKSIZE , + .memblocksize =JENT_MEMORY_BLOCKS , + .memaccessloops =JENT_MEMORY_ACCESSLOOPS , + }; + +if (jent_entropy_init ()) +return NULL ; + +return &lrng_jent_state; +}
include/crypto/internal/jitterentropy.h renamed from crypto/jitterentropy.h +3 -0
@@ -15,3 +15,6 @@ extern int jent_read_entropy(struct rand_data *ec, unsigned char *data,extern struct rand_data *jent_entropy_collector_alloc (unsigned int osr,unsigned int flags);extern void jent_entropy_collector_free (struct rand_data *entropy_collector); + +/* Access to statically allocated Jitter RNG instance */ +extern struct rand_data *jent_lrng_entropy_collector (void );
Signature · 1 line
2.24.1
PATCH v28 9/12 LRNG - add Jitter RNG fast noise source
In reply to Stephan MüllerFrom 1666398d358388d0476f79019e0a6116c30db8a4 Mon Sep 17 00:00:00 2001
From: Stephan Mueller <[email protected]>
Date: Sun, 12 Jan 2020 11:56:31 +0100
Subject: [PATCH v28 09/12] LRNG - add Jitter RNG fast noise source
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The Jitter RNG fast noise source implemented as part of the kernel crypto API is queried for 256 bits of entropy at the time the seed buffer managed by the LRNG is about to be filled.
--- drivers/char/lrng/Kconfig | 11 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_jent.c | 89 +++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 drivers/char/lrng/lrng_jent.c
drivers/char/lrng/Kconfig +11 -0
@@ -92,4 +92,15 @@ config LRNG_KCAPI provided by the selected kernel crypto API RNG. endif # LRNG_DRNG_SWITCH +config LRNG_JENT + bool "Enable Jitter RNG as LRNG Seed Source" + select CRYPTO_JITTERENTROPY + help + The Linux RNG may use the Jitter RNG as noise source. Enabling + this option enables the use of the Jitter RNG. Its default + entropy level is 16 bits of entropy per 256 data bits delivered + by the Jitter RNG. This entropy level can be changed at boot + time or at runtime with the lrng_base.jitterrng configuration + variable. + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-$(CONFIG_SYSCTL) += lrng_proc.o obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o +obj-$(CONFIG_LRNG_JENT) += lrng_jent.o
drivers/char/lrng/lrng_jent.c new file +89 -0
89 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH v28 09/12] LRNG - add Jitter RNG fast noise source
Quoted 35 lines · Stephan Müller
CC "Eric W. Biederman" <[email protected]>CC "Alexander E. Patrakov" <[email protected]>CC "Ahmed S. Darwish" <[email protected]>CC "Theodore Y. Ts'o" <[email protected]>CC Willy Tarreau <[email protected]>CC Matthew Garrett <[email protected]>CC Vito Caputo <[email protected]>CC Andreas Dilger <[email protected]>CC Jan Kara <[email protected]>CC Ray Strode <[email protected]>CC William Jon McCann <[email protected]>CC zhangjs <[email protected]>CC Andy Lutomirski <[email protected]>CC Florian Weimer <[email protected]>CC Lennart Poettering <[email protected]>CC Nicolai Stange <[email protected]>Reviewed-by Marcelo Henrique Cerri <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>--- drivers/char/lrng/Kconfig | 11 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_jent.c | 89 +++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 drivers/char/lrng/lrng_jent.cdrivers/char/lrng/Kconfig +0
-0
drivers/char/lrng/Kconfig config LRNG_KCAPI · line 97
Quoted 6 lines
drivers/char/lrng/Kconfig +3
-0@@ -92,4 +92,15 @@ config LRNG_KCAPI provided by the selected kernel crypto API RNG. endif # LRNG_DRNG_SWITCH +config LRNG_JENT + bool "Enable Jitter RNG as LRNG Seed Source" + select CRYPTO_JITTERENTROPY
Don't select unless CRYPTO is already set/enabled.
Quoted 31 lines
drivers/char/lrng/Kconfig +8
-0+ help + The Linux RNG may use the Jitter RNG as noise source. Enabling + this option enables the use of the Jitter RNG. Its default + entropy level is 16 bits of entropy per 256 data bits delivered + by the Jitter RNG. This entropy level can be changed at boot + time or at runtime with the lrng_base.jitterrng configuration + variable. + endif # LRNGdrivers/char/lrng/lrng_jent.c new file +15
-0@@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* LRNG Fast Noise Source: Jitter RNG +* +* Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/types.h> +#include <crypto/internal/jitterentropy.h> + +#include "lrng_internal.h" + +/*
drivers/char/lrng/lrng_jent.c line 25
Quoted 10 lines
drivers/char/lrng/lrng_jent.c new file +10
-0+* Estimated entropy of data is a 16th of LRNG_DRNG_SECURITY_STRENGTH_BITS. +* Albeit a full entropy assessment is provided for the noise source indicating +* that it provides high entropy rates and considering that it deactivates +* when it detects insufficient hardware, the chosen under estimation of +* entropy is considered to be acceptable to all reviewers. +*/ +static u32 jitterrng =LRNG_DRNG_SECURITY_STRENGTH_BITS >>4 ; +module_param (jitterrng, uint,0644 ); +MODULE_PARM_DESC (jitterrng,"Entropy in bits of 256 data bits from Jitter " +"RNG noise source" );
One line for the string, please, not split to 2 lines.
Signature · 2 lines
~Randy Reported-by: Randy Dunlap <[email protected]>
Re: [PATCH v28 09/12] LRNG - add Jitter RNG fast noise source
Am Donnerstag, 16. Januar 2020, 01:17:05 CET schrieb Randy Dunlap:
Hi Randy,
Quoted 39 lines · Stephan Müller
Quoted 38 lines
CC "Eric W. Biederman" <[email protected]>CC "Alexander E. Patrakov" <[email protected]>CC "Ahmed S. Darwish" <[email protected]>CC "Theodore Y. Ts'o" <[email protected]>CC Willy Tarreau <[email protected]>CC Matthew Garrett <[email protected]>CC Vito Caputo <[email protected]>CC Andreas Dilger <[email protected]>CC Jan Kara <[email protected]>CC Ray Strode <[email protected]>CC William Jon McCann <[email protected]>CC zhangjs <[email protected]>CC Andy Lutomirski <[email protected]>CC Florian Weimer <[email protected]>CC Lennart Poettering <[email protected]>CC Nicolai Stange <[email protected]>Reviewed-by Marcelo Henrique Cerri <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>---
drivers/char/lrng/Kconfig | 11 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_jent.c | 89 +++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 drivers/char/lrng/lrng_jent.cdrivers/char/lrng/Kconfig +0
-0@@ -92,4 +92,15 @@ config LRNG_KCAPI provided by the selected kernel crypto API RNG.
Quoted 7 lines
drivers/char/lrng/Kconfig config LRNG_KCAPI · line 97
Quoted 5 lines
drivers/char/lrng/Kconfig +3
-0endif # LRNG_DRNG_SWITCH +config LRNG_JENT + bool "Enable Jitter RNG as LRNG Seed Source" + select CRYPTO_JITTERENTROPYDon't select unless CRYPTO is already set/enabled.
I added "depends on
Quoted 38 lines
Quoted 38 lines
drivers/char/lrng/Kconfig +8
-0+ help + The Linux RNG may use the Jitter RNG as noise source. Enabling + this option enables the use of the Jitter RNG. Its default + entropy level is 16 bits of entropy per 256 data bits delivered + by the Jitter RNG. This entropy level can be changed at boot + time or at runtime with the lrng_base.jitterrng configuration + variable. + endif # LRNGdrivers/char/lrng/lrng_jent.c new file +16
-0@@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* LRNG Fast Noise Source: Jitter RNG +* +* Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/types.h> +#include <crypto/internal/jitterentropy.h> + +#include "lrng_internal.h" + +/* +* Estimated entropy of data is a 16th of
LRNG_DRNG_SECURITY_STRENGTH_BITS. + * Albeit a full entropy assessment is provided for the noise source indicating + * that it provides high entropy rates and considering that it deactivates + * when it detects insufficient hardware, the chosen under estimation of + * entropy is
Quoted 8 lines
Quoted 6 lines
considered to be acceptable to all reviewers.
+ */drivers/char/lrng/lrng_jent.c new file +3
-0+static u32 jitterrng =LRNG_DRNG_SECURITY_STRENGTH_BITS >>4 ; +module_param (jitterrng, uint,0644 ); +MODULE_PARM_DESC(jitterrng, "Entropy in bits of 256 data bits from Jitter" + "RNG noise source");
One line for the string, please, not split to 2 lines.
Changed.
Thank you.
Ciao
Stephan
PATCH v28 10/12 LRNG - add SP800-90B compliant health tests
In reply to Stephan MüllerImplement health tests for LRNG's slow noise sources as mandated by SP-800-90B The file contains the following health tests:
- stuck test: The stuck test calculates the first, second and third discrete derivative of the time stamp to be processed by the LFSR. Only if all three values are non-zero, the received time delta is considered to be non-stuck.
- SP800-90B Repetition Count Test (RCT): The LRNG uses an enhanced version of the RCT specified in SP800-90B section 4.4.1. Instead of counting identical back-to-back values, the input to the RCT is the counting of the stuck values during the processing of received interrupt events. The RCT is applied with alpha=2^-30 compliant to the recommendation of FIPS 140-2 IG 9.8. During the counting operation, the LRNG always calculates the RCT cut-off value of C. If that value exceeds the allowed cut-off value, the LRNG will trigger the health test failure discussed below. An error is logged to the kernel log that such RCT failure occurred. This test is only applied and enforced in FIPS mode, i.e. when the kernel compiled with CONFIG_CONFIG_FIPS is started with fips=1.
- SP800-90B Adaptive Proportion Test (APT): The LRNG implements the APT as defined in SP800-90B section 4.4.2. The applied significance level again is alpha=2^-30 compliant to the recommendation of FIPS 140-2 IG 9.8.
The aforementioned health tests are applied to the first 1,024 time stamps obtained from interrupt events. In case one error is identified for either the RCT, or the APT, the collected entropy is invalidated and the SP800-90B startup health test is restarted.
As long as the SP800-90B startup health test is not completed, all LRNG random number output interfaces that may block will block and not generate any data. This implies that only those potentially blocking interfaces are defined to provide random numbers that are seeded with the interrupt noise source being SP800-90B compliant. All other output interfaces will not be affected by the SP800-90B startup test and thus are not considered SP800-90B compliant.
At runtime, the SP800-90B APT and RCT are applied to each time stamp generated for a received interrupt. When either the APT and RCT indicates a noise source failure, the LRNG is reset to a state it has immediately after boot:
- all entropy counters are set to zero
- the SP800-90B startup tests are re-performed which implies that getrandom(2) would block again until new entropy was collected
To summarize, the following rules apply:
• SP800-90B compliant output interfaces
- /dev/random
- getrandom(2) system call
- get_random_bytes kernel-internal interface when being triggered by the callback registered with add_random_ready_callback
• SP800-90B non-compliant output interfaces
- /dev/urandom
- get_random_bytes kernel-internal interface called directly
- randomize_page kernel-internal interface
- get_random_u32 and get_random_u64 kernel-internal interfaces
- get_random_u32_wait, get_random_u64_wait, get_random_int_wait, and get_random_long_wait kernel-internal interfaces
If either the RCT, or the APT health test fails irrespective whether during initialization or runtime, the following actions occur:
1. The entropy of the entire entropy pool is invalidated.
2. All DRNGs are reset which imply that they are treated as being not seeded and require a reseed during next invocation.
3. The SP800-90B startup health test are initiated with all implications of the startup tests. That implies that from that point on, new events must be observed and its entropy must be inserted into the entropy pool before random numbers are calculated from the entropy pool.
Further details on the SP800-90B compliance and the availability of all test tools required to perform all tests mandated by SP800-90B are provided at [1].
The entire health testing code is compile-time configurable.
The patch provides a CONFIG_BROKEN configuration of the APT / RCT cutoff values which have a high likelihood to trigger the health test failure. The BROKEN APT cutoff is set to the exact mean of the expected value if the time stamps are equally distributed (512 time stamps divided by 16 possible values due to using the 4 LSB of the time stamp). The BROKEN RCT cutoff value is set to 1 which is likely to be triggered during regular operation.
--- drivers/char/lrng/Kconfig | 56 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_health.c | 409 ++++++++++++++++++++++++++++++++ 3 files changed, 466 insertions(+) create mode 100644 drivers/char/lrng/lrng_health.c
drivers/char/lrng/Kconfig +56 -0
@@ -103,4 +103,60 @@ config LRNG_JENT time or at runtime with the lrng_base.jitterrng configuration variable. +config LRNG_HEALTH_TESTS + bool "Enable noise source online health tests" + help + The online health tests validate the noise source at + runtime for fatal errors. These tests include SP800-90B + compliant tests which are invoked if the system is booted + with fips=1. In case of fatal errors during active + SP800-90B tests, the issue is logged and the noise + data is discarded. These tests are required for full + compliance with SP800-90B. + + If unsure, say Y. + +config LRNG_RCT_BROKEN + bool "SP800-90B RCT with dangerous low cutoff value" + depends on LRNG_HEALTH_TESTS + depends on BROKEN + default n + help + This option enables a dangerously low SP800-90B repetitive + count test (RCT) cutoff value which makes it very likely + that the RCT is triggered to raise a self test failure. + + This option is ONLY intended for developers wanting to + test the effectiveness of the SP800-90B RCT health test. + + If unsure, say N. + +config LRNG_APT_BROKEN + bool "SP800-90B APT with dangerous low cutoff value" + depends on LRNG_HEALTH_TESTS + depends on BROKEN + default n + help + This option enables a dangerously low SP800-90B adaptive + proportion test (APT) cutoff value which makes it very + likely that the RCT is triggered to raise a self test + failure. + + This option is ONLY intended for developers wanting to + test the effectiveness of the SP800-90B APT health test. + + If unsure, say N. + +# Default taken from SP800-90B sec 4.4.1 - significance level 2^-30 +config LRNG_RCT_CUTOFF + int + default 31 if !LRNG_RCT_BROKEN + default 1 if LRNG_RCT_BROKEN + +# Default taken from SP800-90B sec 4.4.2 - significance level 2^-30 +config LRNG_APT_CUTOFF + int + default 325 if !LRNG_APT_BROKEN + default 32 if LRNG_APT_BROKEN + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -14,3 +14,4 @@ obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o obj-$(CONFIG_LRNG_JENT) += lrng_jent.o +obj-$(CONFIG_LRNG_HEALTH_TESTS) += lrng_health.o
drivers/char/lrng/lrng_health.c new file +409 -0
409 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v28 11/12 LRNG - add interface for gathering of raw entropy
In reply to Stephan MüllerThe test interface allows a privileged process to capture the raw unconditioned noise that is collected by the LRNG for statistical analysis. Such testing allows the analysis how much entropy the interrupt noise source provides on a given platform. Extracted noise data is not used to seed the LRNG. This is a test interface and not appropriate for production systems. Yet, the interface is considered to be sufficiently secured for production systems.
Access to the data is given through the lrng_raw debugfs file. The data buffer should be multiples of sizeof(u32) to fill the entire buffer. Using the option lrng_testing.boot_test=1 the raw noise of the first 1000 entropy events since boot can be sampled.
This test interface allows generating the data required for analysis whether the LRNG is in compliance with SP800-90B sections 3.1.3 and 3.1.4.
--- drivers/char/lrng/Kconfig | 16 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_testing.c | 271 +++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+) create mode 100644 drivers/char/lrng/lrng_testing.c
drivers/char/lrng/Kconfig +16 -0
@@ -159,4 +159,20 @@ config LRNG_APT_CUTOFF default 325 if !LRNG_APT_BROKEN default 32 if LRNG_APT_BROKEN +config LRNG_TESTING + bool "Enable entropy test interface to LRNG noise source" + depends on DEBUG_FS + help + The test interface allows a privileged process to capture + the raw unconditioned noise that is collected by the LRNG + for statistical analysis. Extracted noise data is not used + to seed the LRNG. + + The raw noise data can be obtained using the lrng_raw + debugfs file. Using the option lrng_testing.boot_test=1 + the raw noise of the first 1000 entropy events since boot + can be sampled. + + If unsure, say N. + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o obj-$(CONFIG_LRNG_JENT) += lrng_jent.o obj-$(CONFIG_LRNG_HEALTH_TESTS) += lrng_health.o +obj-$(CONFIG_LRNG_TESTING) += lrng_testing.o
drivers/char/lrng/lrng_testing.c new file +271 -0
271 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH v28 11/12] LRNG - add interface for gathering of raw entropy
Quoted 72 lines · Stephan Müller
CC "Eric W. Biederman" <[email protected]>CC "Alexander E. Patrakov" <[email protected]>CC "Ahmed S. Darwish" <[email protected]>CC "Theodore Y. Ts'o" <[email protected]>CC Willy Tarreau <[email protected]>CC Matthew Garrett <[email protected]>CC Vito Caputo <[email protected]>CC Andreas Dilger <[email protected]>CC Jan Kara <[email protected]>CC Ray Strode <[email protected]>CC William Jon McCann <[email protected]>CC zhangjs <[email protected]>CC Andy Lutomirski <[email protected]>CC Florian Weimer <[email protected]>CC Lennart Poettering <[email protected]>CC Nicolai Stange <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>--- drivers/char/lrng/Kconfig | 16 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_testing.c | 271 +++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+) create mode 100644 drivers/char/lrng/lrng_testing.cdrivers/char/lrng/lrng_testing.c new file +36
-0@@ -0,0 +1,271 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* Linux Random Number Generator (LRNG) Raw entropy collection tool +* +* Copyright (C) 2019 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/atomic.h> +#include <linux/bug.h> +#include <linux/debugfs.h> +#include <linux/module.h> +#include <linux/sched.h> +#include <linux/sched/signal.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/types.h> +#include <linux/uaccess.h> +#include <linux/workqueue.h> +#include <asm/errno.h> + +#include "lrng_internal.h" + +#define LRNG_TESTING_RINGBUFFER_SIZE 1024 +#define LRNG_TESTING_RINGBUFFER_MASK (LRNG_TESTING_RINGBUFFER_SIZE - 1) + +static u32 lrng_testing_rb[LRNG_TESTING_RINGBUFFER_SIZE ]; +static u32 lrng_rb_reader =0 ; +static u32 lrng_rb_writer =0 ; +static atomic_t lrng_testing_enabled =ATOMIC_INIT (0 ); + +static DECLARE_WAIT_QUEUE_HEAD (lrng_raw_read_wait); +static DEFINE_SPINLOCK (lrng_raw_lock); + +/*
drivers/char/lrng/lrng_testing.c line 46
Quoted 10 lines
drivers/char/lrng/lrng_testing.c new file +10
-0+* 0 ==> No boot test, gathering of runtime data allowed +* 1 ==> Boot test enabled and ready for collecting data, gathering runtime +* data is disabled +* 2 ==> Boot test completed and disabled, gathering of runtime data is +* disabled +*/ +static u32 boot_test =0 ; +module_param (boot_test, uint,0644 ); +MODULE_PARM_DESC (boot_test,"Enable gathering boot time entropy of the first" +" entropy events" );
One line for the string, please.
Signature · 2 lines
~Randy Reported-by: Randy Dunlap <[email protected]>
Re: [PATCH v28 11/12] LRNG - add interface for gathering of raw entropy
Am Donnerstag, 16. Januar 2020, 01:18:18 CET schrieb Randy Dunlap:
Hi Randy,
Quoted 76 lines · Stephan Müller
Quoted 75 lines
CC "Eric W. Biederman" <[email protected]>CC "Alexander E. Patrakov" <[email protected]>CC "Ahmed S. Darwish" <[email protected]>CC "Theodore Y. Ts'o" <[email protected]>CC Willy Tarreau <[email protected]>CC Matthew Garrett <[email protected]>CC Vito Caputo <[email protected]>CC Andreas Dilger <[email protected]>CC Jan Kara <[email protected]>CC Ray Strode <[email protected]>CC William Jon McCann <[email protected]>CC zhangjs <[email protected]>CC Andy Lutomirski <[email protected]>CC Florian Weimer <[email protected]>CC Lennart Poettering <[email protected]>CC Nicolai Stange <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>---
drivers/char/lrng/Kconfig | 16 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_testing.c | 271 +++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+) create mode 100644 drivers/char/lrng/lrng_testing.c(quoted diff) +0
-0
b/drivers/char/lrng/lrng_testing.cnew file mode 100644 index 000000000000..0e287eccd622drivers/char/lrng/lrng_testing.c new file +38
-0@@ -0,0 +1,271 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* Linux Random Number Generator (LRNG) Raw entropy collection tool +* +* Copyright (C) 2019 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/atomic.h> +#include <linux/bug.h> +#include <linux/debugfs.h> +#include <linux/module.h> +#include <linux/sched.h> +#include <linux/sched/signal.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/types.h> +#include <linux/uaccess.h> +#include <linux/workqueue.h> +#include <asm/errno.h> + +#include "lrng_internal.h" + +#define LRNG_TESTING_RINGBUFFER_SIZE 1024 +#define LRNG_TESTING_RINGBUFFER_MASK (LRNG_TESTING_RINGBUFFER_SIZE - 1) + +static u32 lrng_testing_rb[LRNG_TESTING_RINGBUFFER_SIZE ]; +static u32 lrng_rb_reader =0 ; +static u32 lrng_rb_writer =0 ; +static atomic_t lrng_testing_enabled =ATOMIC_INIT (0 ); + +static DECLARE_WAIT_QUEUE_HEAD (lrng_raw_read_wait); +static DEFINE_SPINLOCK (lrng_raw_lock); + +/* +* 0 ==> No boot test, gathering of runtime data allowed +* 1 ==> Boot test enabled and ready for collecting data, gathering runtime + * data is disabled
+ * 2 ==> Boot test completed and disabled, gathering of runtime data is
Quoted 8 lines
Quoted 6 lines
+ * disabled
+ */drivers/char/lrng/lrng_testing.c new file +3
-0+static u32 boot_test =0 ; +module_param (boot_test, uint,0644 ); +MODULE_PARM_DESC(boot_test, "Enable gathering boot time entropy of thefirst" + " entropy events");
One line for the string, please.
may I ask the question whether this should be done for all lines with printk statements? As checkpatch.pl will complain if you have lines larger than 80 chars and complains about line-broken printk statements, I am always unsure which way to go.
All printk statements in the patch series have line-broken printk statements.
Ciao
Stephan
Re: [PATCH v28 11/12] LRNG - add interface for gathering of raw entropy
Quoted 89 lines · Stephan Mueller
Am Donnerstag, 16. Januar 2020, 01:18:18 CET schrieb Randy Dunlap:
Hi Randy,
Quoted 76 lines · Stephan Müller
Quoted 75 lines
CC "Eric W. Biederman" <[email protected]>CC "Alexander E. Patrakov" <[email protected]>CC "Ahmed S. Darwish" <[email protected]>CC "Theodore Y. Ts'o" <[email protected]>CC Willy Tarreau <[email protected]>CC Matthew Garrett <[email protected]>CC Vito Caputo <[email protected]>CC Andreas Dilger <[email protected]>CC Jan Kara <[email protected]>CC Ray Strode <[email protected]>CC William Jon McCann <[email protected]>CC zhangjs <[email protected]>CC Andy Lutomirski <[email protected]>CC Florian Weimer <[email protected]>CC Lennart Poettering <[email protected]>CC Nicolai Stange <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>---
drivers/char/lrng/Kconfig | 16 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_testing.c | 271 +++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+) create mode 100644 drivers/char/lrng/lrng_testing.c(quoted diff) +0
-0
b/drivers/char/lrng/lrng_testing.cnew file mode 100644 index 000000000000..0e287eccd622drivers/char/lrng/lrng_testing.c new file +38
-0@@ -0,0 +1,271 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* Linux Random Number Generator (LRNG) Raw entropy collection tool +* +* Copyright (C) 2019 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/atomic.h> +#include <linux/bug.h> +#include <linux/debugfs.h> +#include <linux/module.h> +#include <linux/sched.h> +#include <linux/sched/signal.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/types.h> +#include <linux/uaccess.h> +#include <linux/workqueue.h> +#include <asm/errno.h> + +#include "lrng_internal.h" + +#define LRNG_TESTING_RINGBUFFER_SIZE 1024 +#define LRNG_TESTING_RINGBUFFER_MASK (LRNG_TESTING_RINGBUFFER_SIZE - 1) + +static u32 lrng_testing_rb[LRNG_TESTING_RINGBUFFER_SIZE ]; +static u32 lrng_rb_reader =0 ; +static u32 lrng_rb_writer =0 ; +static atomic_t lrng_testing_enabled =ATOMIC_INIT (0 ); + +static DECLARE_WAIT_QUEUE_HEAD (lrng_raw_read_wait); +static DEFINE_SPINLOCK (lrng_raw_lock); + +/* +* 0 ==> No boot test, gathering of runtime data allowed +* 1 ==> Boot test enabled and ready for collecting data, gathering runtime + * data is disabled
+ * 2 ==> Boot test completed and disabled, gathering of runtime data isQuoted 8 lines
Quoted 6 lines
+ * disabled
+ */drivers/char/lrng/lrng_testing.c new file +3
-0+static u32 boot_test =0 ; +module_param (boot_test, uint,0644 ); +MODULE_PARM_DESC(boot_test, "Enable gathering boot time entropy of thefirst" + " entropy events");
One line for the string, please.
Quoted 6 lines
may I ask the question whether this should be done for all lines with printk statements? As checkpatch.pl will complain if you have lines larger than 80 chars and complains about line-broken printk statements, I am always unsure which way to go.
All printk statements in the patch series have line-broken printk statements.
It's for grep-ability of the strings.
grepping for partial strings would work as is, but then one would need to know what partial string to search for.
Signature · 1 line
~Randy
Re: [PATCH v28 11/12] LRNG - add interface for gathering of raw entropy
Am Donnerstag, 16. Januar 2020, 07:48:20 CET schrieb Randy Dunlap:
Hi Randy,
Quoted 59 lines · Stephan Mueller
Quoted 58 lines
Am Donnerstag, 16. Januar 2020, 01:18:18 CET schrieb Randy Dunlap:
Hi Randy,
Quoted 54 lines · Stephan Müller
Quoted 53 lines
CC "Eric W. Biederman" <[email protected]>CC "Alexander E. Patrakov" <[email protected]>CC "Ahmed S. Darwish" <[email protected]>CC "Theodore Y. Ts'o" <[email protected]>CC Willy Tarreau <[email protected]>CC Matthew Garrett <[email protected]>CC Vito Caputo <[email protected]>CC Andreas Dilger <[email protected]>CC Jan Kara <[email protected]>CC Ray Strode <[email protected]>CC William Jon McCann <[email protected]>CC zhangjs <[email protected]>CC Andy Lutomirski <[email protected]>CC Florian Weimer <[email protected]>CC Lennart Poettering <[email protected]>CC Nicolai Stange <[email protected]>Reviewed-by Roman Drahtmueller <[email protected]>Tested-by Roman Drahtmüller <[email protected]>Tested-by Neil Horman <[email protected]>Signed-off-by Stephan Mueller <[email protected]>---
drivers/char/lrng/Kconfig | 16 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_testing.c | 271 +++++++++++++++++++++++++++++++ 3 files changed, 288 insertions(+) create mode 100644 drivers/char/lrng/lrng_testing.c(quoted diff) +0
-0
b/drivers/char/lrng/lrng_testing.cnew file mode 100644 index 000000000000..0e287eccd622drivers/char/lrng/lrng_testing.c new file +18
-0@@ -0,0 +1,271 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +/* +* Linux Random Number Generator (LRNG) Raw entropy collection tool +* +* Copyright (C) 2019 - 2020, Stephan Mueller <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/atomic.h> +#include <linux/bug.h> +#include <linux/debugfs.h> +#include <linux/module.h> +#include <linux/sched.h> +#include <linux/sched/signal.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/types.h>
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/char/lrng/lrng_testing.c
Quoted 8 lines
drivers/char/lrng/lrng_testing.c new file +8
-0+#include <linux/uaccess.h> +#include <linux/workqueue.h> +#include <asm/errno.h> + +#include "lrng_internal.h" + +#define LRNG_TESTING_RINGBUFFER_SIZE 1024 +#define LRNG_TESTING_RINGBUFFER_MASK
(LRNG_TESTING_RINGBUFFER_SIZE - 1)
Quoted 28 lines
Quoted 28 lines
Quoted 14 lines
Quoted 14 lines
drivers/char/lrng/lrng_testing.c new file +12
-0+ +static u32 lrng_testing_rb[LRNG_TESTING_RINGBUFFER_SIZE ]; +static u32 lrng_rb_reader =0 ; +static u32 lrng_rb_writer =0 ; +static atomic_t lrng_testing_enabled =ATOMIC_INIT (0 ); + +static DECLARE_WAIT_QUEUE_HEAD (lrng_raw_read_wait); +static DEFINE_SPINLOCK (lrng_raw_lock); + +/* +* 0 ==> No boot test, gathering of runtime data allowed +* 1 ==> Boot test enabled and ready for collecting data, gathering runtime + * data is disabled
+ * 2 ==> Boot test completed and disabled, gathering of runtime data isQuoted 8 lines
Quoted 6 lines
+ * disabled
+ */drivers/char/lrng/lrng_testing.c new file +3
-0+static u32 boot_test =0 ; +module_param (boot_test, uint,0644 ); +MODULE_PARM_DESC(boot_test, "Enable gathering boot time entropy of thefirst" + " entropy events");
One line for the string, please.
may I ask the question whether this should be done for all lines with printk statements? As checkpatch.pl will complain if you have lines larger than 80 chars and complains about line-broken printk statements, I am always unsure which way to go.
Quoted 5 lines
Quoted 2 lines
All printk statements in the patch series have line-broken printk statements.
It's for grep-ability of the strings.
grepping for partial strings would work as is, but then one would need to know what partial string to search for.
Ok, I am changing all these strings to one-liners even though checkpatch.pl will complain.
Thank you.
Ciao
Stephan
PATCH v28 12/12 LRNG - add power-on and runtime self-tests
In reply to Stephan MüllerParts of the LFSR are already covered by self-tests, including:
* Self-test of SP800-90A DRBG provided by the Linux kernel crypto API.
* Self-test of the PRNG provided by the Linux kernel crypto API.
* Raw noise source data testing including SP800-90B compliant tests when enabling CONFIG_LRNG_HEALTH_TESTS
This patch adds the self-tests for the remaining critical functions of the LRNG that are essential to maintain entropy and provide cryptographic strong random numbers. The following self-tests are implemented:
* Self-test of the time array maintenance. This test verifies whether the time stamp array management to store multiple values in one integer implements a concatenation of the data.
* Self-test of the LFSR operation. This test injects a monotonic increasing counter into the LFSR. After completion of the injection of the counter, 3 pool words are compared with known good values. The known good values are calculated with the newly-developed tool lfsr_testvector_generation provided as part of the LRNG test tool set at [1].
* Self-test of the Hash_DF operation ensures that this function operates compliant to the specification. The self-test performs a Hash_DF operation of a zeroized entropy pool state. The test vectors are generated using the newly-developed tool hash_df_testvector_generation provided as part of the LRNG test tool set at [1].
* Self-test of the ChaCha20 DRNG is based on the self-tests that are already present and implemented with the stand-alone user space ChaCha20 DRNG implementation available at [2]. The self-tests cover different use cases of the DRNG seeded with known seed data.
The status of the LRNG self-tests is provided with the selftest_status SysFS file. If the file contains a zero, the self-tests passed. The value 0xffffffff means that the self-tests were not executed. Any other value indicates a self-test failure.
The self-test may be compiled to panic the system if the self-test fails.
All self-tests operate on private state data structures. This implies that none of the self-tests have any impact on the regular LRNG operations. This allows the self-tests to be repeated at runtime by writing anything into the selftest_status SysFS file.
[1] https://www.chronox.de/lrng.html
[2] https://www.chronox.de/chacha20.html
--- drivers/char/lrng/Kconfig | 25 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_selftest.c | 418 ++++++++++++++++++++++++++++++ 3 files changed, 444 insertions(+) create mode 100644 drivers/char/lrng/lrng_selftest.c
drivers/char/lrng/Kconfig +25 -0
@@ -175,4 +175,29 @@ config LRNG_TESTING If unsure, say N. +config LRNG_SELFTEST + bool "Enable power-on and on-demand self-tests" + help + The power-on self-tests are executed during boot time + covering the ChaCha20 DRNG, the LFSR processing and the + time stamp management of the LRNG. + + The on-demand self-tests are triggered by writing any + value into the SysFS file selftest_status. At the same + time, when reading this file, the test status is + returned. A zero indicates that all tests were executed + successfully. + + If unsure, say Y. + +if LRNG_SELFTEST + +config LRNG_SELFTEST_PANIC + bool "Panic the kernel upon self-test failure" + help + If the option is enabled, the kernel is terminated if an + LRNG power-on self-test failure is detected. + +endif # LRNG_SELFTEST + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -16,3 +16,4 @@ obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o obj-$(CONFIG_LRNG_JENT) += lrng_jent.o obj-$(CONFIG_LRNG_HEALTH_TESTS) += lrng_health.o obj-$(CONFIG_LRNG_TESTING) += lrng_testing.o +obj-$(CONFIG_LRNG_SELFTEST) += lrng_selftest.o
drivers/char/lrng/lrng_selftest.c new file +418 -0
418 lines not on this page · raw message
Signature · 1 line
2.24.1
v29 cover /dev/random - a new approach with full SP800-90B
In reply to Stephan MüllerHi,
The following patch set provides a different approach to /dev/random which is called Linux Random Number Generator (LRNG) to collect entropy within the Linux kernel. The main improvements compared to the existing /dev/random is to provide sufficient entropy during boot time as well as in virtual environments and when using SSDs. A secondary design goal is to limit the impact of the entropy collection on massive parallel systems and also allow the use accelerated cryptographic primitives. Also, all steps of the entropic data processing are testable.
The LRNG patch set allows a user to select use of the existing /dev/random or the LRNG during compile time. As the LRNG provides API and ABI compatible interfaces to the existing /dev/random implementation, the user can freely chose the RNG implementation without affecting kernel or user space operations.
This patch set provides early boot-time entropy which implies that no additional flags to the getrandom(2) system call discussed recently on the LKML is considered to be necessary. Yet, if additional flags are introduced to cover special hardware, the LRNG implementation will also provide them to be fully ABI and API compliant as already discussed on LKML.
The LRNG is fully compliant to SP800-90B requirements and is shipped with a full SP800-90B assessment and all required test tools. The existing /dev/random implementation on the other hand has architectural limitations which does not easily allow to bring the implementation in compliance with SP800-90B. The key statement that causes concern is SP800-90B section 3.1.6. This section denies crediting entropy to multiple similar noise sources. This section explicitly references different noise sources resting on the timing of events and their derivatives (i.e. it is a direct complaint to the existing existing /dev/random implementation). Therefore, SP800-90B now denies the very issue mentioned in [1] with the existing /dev/random implementation for a long time: crediting entropy to interrupts as well as crediting entropy to derivatives of interrupts (HID and disk events). This is not permissible with SP800-90B.
SP800-90B specifies various requirements for the noise source(s) that seed any DRNG including SP800-90A DRBGs. In about a year from now, 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. That means, if we there are no solutions to comply with the requirements of SP800-90B found till one year from now, any random number generation and ciphers based on random numbers on Linux will be considered and treated as not applicable and delivering no entropy! As /dev/urandom, getrandom(2) and /dev/random are the most common and prevalent noise sources for DRNGs, all these DRNGs are affected. This applies across the board for all validations of cryptography executing on Linux (kernel and user space modules).
For users that are not interested in SP800-90B, the entire code for the compliance as well as test interfaces can be deselected at compile time.
The design and implementation is driven by a set of goals described in [1] that the LRNG completely implements. Furthermore, [1] includes the full assessment of the SP800-90B compliance as well as a comparison with RNG design suggestions of SP800-90C, and AIS20/31.
The LRNG provides a complete separation of the noise source maintenance and the collection of entropy into an entropy pool from the post-processing using a pseudo-random number generator. Different DRNGs are supported, including:
* The LRNG can be compile-time enabled to replace the existing /dev/random implementation. When not selecting the LRNG at compile time (default), the existing /dev/random implementation is built.
* Built-in ChaCha20 DRNG which has no dependency to other kernel frameworks.
* SP800-90A DRBG using the kernel crypto API including its accelerated raw cipher implementations. This implies that the output of /dev/random, getrandom(2), /dev/urandom or get_random_bytes is fully compliant to SP800-90A.
* Arbitrary DRNGs registered with the kernel crypto API
* Full compliance with SP800-90B which covers the startup and runtime health tests mandated by SP800-90B as well as providing the test tools and test interfaces to obtain raw noise data securely. The test tools are provided at [1].
Booting the patch with the kernel command line option "dyndbg=file drivers/char/lrng/* +p" generates logs indicating the operation of the LRNG. Each log is pre-pended with "lrng".
The LRNG has a flexible design by allowing an easy replacement of the deterministic random number generator component.
Compared to the existing /dev/random implementation, the compiled binary is smaller when the LRNG is compiled with all options equal to the existing /dev/random (i.e. only CONFIG_LRNG is set): random.o is 52.5 kBytes whereas all LRNG object files are in 49 kBytes in size. The fully SP800-90A/SP800-90B compliant binary code (CONFIG_LRNG, CONFIG_LRNG_DRNG_SWITCH, CONFIG_LRNG_DRBG, CONFIG_LRNG_HEALTH_TESTS) uses some 61 kBytes. In addition, the LRNG is about 50% faster in the performance critical interrupt handler code path compared to the existing /dev/random implementation.
[1] http://www.chronox.de/lrng.html - If the patch is accepted, I would be volunteering to convert the documentation into RST format and contribute it to the Linux kernel documentation directory.
Changes (compared to the previous patch set):
* All grep-able strings are placed on one line as requested by Randy Dunlap.
* Add "depend on CRYPTO" to CONFIG_LRNG_DRBG, CONFIG_LRNG_KCAPI, CONFIG_LRNG_JENT allowing the LRNG to be compiled without the kernel crypto API. A successful compilation of the LRNG with the remaining configure options was performed. Thanks to Randy Dunlap for pointing this out.
This patch requires the presence of patch 75551dbf112c992bc6c99a972990b3f272247e23 from Ted Tso's kernel tree (specifically the addition of GRND_INSECURE to random.h)
As a side node: With the switchable DRNG support offered in this patch set, the following areas could be removed. As the existing /dev/random has no support for switchable DRNGs, however, this is not yet feasible though.
* remove lrng_ready_list and all code around it in lrng_interfaces.c
* remove the kernel crypto API RNG API to avoid having two random number providing APIs - this would imply that all RNGs developed for this API would be converted to the LRNG interface
Stephan Mueller (12):
Linux Random Number Generator
LRNG - allocate one DRNG instance per NUMA node LRNG - sysctls and /proc interface
LRNG - add switchable DRNG support
crypto: DRBG - externalize DRBG functions for LRNG LRNG - add SP800-90A DRBG extension
LRNG - add kernel crypto API PRNG extension
crypto: provide access to a static Jitter RNG state LRNG - add Jitter RNG fast noise source LRNG - add SP800-90B compliant health tests LRNG - add interface for gathering of raw entropy LRNG - add power-on and runtime self-tests
MAINTAINERS | 7 +
crypto/drbg.c | 16 +-
crypto/jitterentropy-kcapi.c | 3 +-
crypto/jitterentropy.c | 25 +-
drivers/char/Kconfig | 2 +
drivers/char/Makefile | 9 +-
drivers/char/lrng/Kconfig | 206 ++++++
drivers/char/lrng/Makefile | 19 +
drivers/char/lrng/lrng_archrandom.c | 93 +++
drivers/char/lrng/lrng_aux.c | 148 ++++
drivers/char/lrng/lrng_chacha20.c | 263 ++++++++
drivers/char/lrng/lrng_chacha20.h | 25 +
drivers/char/lrng/lrng_drbg.c | 257 +++++++
drivers/char/lrng/lrng_drng.c | 400 +++++++++++
drivers/char/lrng/lrng_health.c | 407 +++++++++++
drivers/char/lrng/lrng_interfaces.c | 635 ++++++++++++++++++
drivers/char/lrng/lrng_internal.h | 305 +++++++++
drivers/char/lrng/lrng_jent.c | 88 +++
drivers/char/lrng/lrng_kcapi.c | 321 +++++++++
drivers/char/lrng/lrng_lfsr.h | 152 +++++
drivers/char/lrng/lrng_numa.c | 101 +++
drivers/char/lrng/lrng_pool.c | 586 ++++++++++++++++
drivers/char/lrng/lrng_proc.c | 163 +++++
drivers/char/lrng/lrng_selftest.c | 418 ++++++++++++
drivers/char/lrng/lrng_sw_noise.c | 102 +++
drivers/char/lrng/lrng_sw_noise.h | 57 ++
drivers/char/lrng/lrng_switch.c | 182 +++++
drivers/char/lrng/lrng_testing.c | 269 ++++++++
include/crypto/drbg.h | 7 +
.../crypto/internal}/jitterentropy.h | 3 +
include/linux/lrng.h | 63 ++
31 files changed, 5322 insertions(+), 10 deletions(-)
create mode 100644 drivers/char/lrng/Kconfig
create mode 100644 drivers/char/lrng/Makefile
create mode 100644 drivers/char/lrng/lrng_archrandom.c
create mode 100644 drivers/char/lrng/lrng_aux.c
create mode 100644 drivers/char/lrng/lrng_chacha20.c
create mode 100644 drivers/char/lrng/lrng_chacha20.h
create mode 100644 drivers/char/lrng/lrng_drbg.c
create mode 100644 drivers/char/lrng/lrng_drng.c
create mode 100644 drivers/char/lrng/lrng_health.c
create mode 100644 drivers/char/lrng/lrng_interfaces.c
create mode 100644 drivers/char/lrng/lrng_internal.h
create mode 100644 drivers/char/lrng/lrng_jent.c
create mode 100644 drivers/char/lrng/lrng_kcapi.c
create mode 100644 drivers/char/lrng/lrng_lfsr.h
create mode 100644 drivers/char/lrng/lrng_numa.c
create mode 100644 drivers/char/lrng/lrng_pool.c
create mode 100644 drivers/char/lrng/lrng_proc.c
create mode 100644 drivers/char/lrng/lrng_selftest.c
create mode 100644 drivers/char/lrng/lrng_sw_noise.c
create mode 100644 drivers/char/lrng/lrng_sw_noise.h
create mode 100644 drivers/char/lrng/lrng_switch.c
create mode 100644 drivers/char/lrng/lrng_testing.c
rename {crypto => include/crypto/internal}/jitterentropy.h (84%)
create mode 100644 include/linux/lrng.hSignature · 1 line
2.24.1
PATCH v29 1/12 Linux Random Number Generator
In an effort to provide a flexible implementation for a random number generator that also delivers entropy during early boot time, allows replacement of the deterministic random number generation mechanism, implement the various components in separate code for easier maintenance, and provide compliance to SP800-90[A|B|C], introduce the Linux Random Number Generator (LRNG) framework.
The general design is as follows. Additional implementation details are given in [1]. The LRNG consists of the following components:
1. The LRNG implements a DRNG. The DRNG always generates the requested amount of output. When using the SP800-90A terminology it operates without prediction resistance. The secondary DRNG maintains a counter of how many bytes were generated since last re-seed and a timer of the elapsed time since last re-seed. If either the counter or the timer reaches a threshold, the secondary DRNG is seeded from the entropy pool.
In case the Linux kernel detects a NUMA system, one secondary DRNG instance per NUMA node is maintained.
2. The DRNG is seeded by concatenating the data from the following sources:
(a) the output of the entropy pool,
(b) the Jitter RNG if available and enabled, and
(c) the CPU-based noise source such as Intel RDRAND if available and enabled.
The entropy estimate of the data of all noise sources are added to form the entropy estimate of the data used to seed the DRNG with. The LRNG ensures, however, that the DRNG after seeding is at maximum the security strength of the DRNG.
The LRNG is designed such that none of these noise sources can dominate the other noise sources to provide seed data to the DRNG during due to the following:
(a) During boot time, the amount of received interrupts are the trigger points to (re)seed the DRNG.
(b) At runtime, the available entropy from the slow noise source is concatenated with a pre-defined amount of data from the fast noise sources. In addition, each DRNG reseed operation triggers external noise source providers to deliver one block of data.
3. The entropy pool accumulates entropy obtained from certain events, which will henceforth be collectively called "slow noise sources". The entropy pool collects noise data from slow noise sources. Any data received by the LRNG from the slow noise sources is inserted into the entropy pool using an LFSR with a primitive and irreducible polynomial. The following sources of entropy are used:
(a) When an interrupt occurs, the high-resolution time stamp is mixed
into the LFSR. This time stamp is credited with heuristically implied entropy.
(b) HID event data like the key stroke or the mouse coordinates are
mixed into the LFSR. This data is not credited with entropy by the LRNG.
(c) Device drivers may provide data that is mixed into the LFSR. This
data is not credited with entropy by the LRNG.
(d) After the entropy pool is ``read'' by the DRNG, the data
used to seed the DRNG is mixed back into the entropy pool to stir the pool. This data is not credited with entropy by the LRNG.
Any data provided from user space by either writing to /dev/random, /dev/urandom or the IOCTL of RNDADDENTROPY on both device files are always injected into the entropy pool.
In addition, when a hardware random number generator covered by the Linux kernel HW generator framework wants to deliver random numbers, it is injected into the entropy pool as well. HW generator noise source is handled separately from the other noise source due to the fact that the HW generator framework may decide by itself when to deliver data whereas the other noise sources always requested for data driven by the LRNG operation. Similarly any user space provided data is inserted into the entropy pool.
When the DRNG requires data from the entropy pool, the entire entropy pool is processed with an SP800-90A section 10.3.1 compliant hash_df function to generate random numbers.
To speed up the interrupt handling code of the LRNG, the time stamp collected for an interrupt event is truncated to the 8 least significant bits. 64 truncated time stamps are concatenated and then jointly inserted into the LFSR. During boot time, until the fully seeded stage is reached, each time stamp with its 32 least significant bits is inserted into the LFSR at the time of arrival.
The LRNG allows the DRNG mechanism to be changed at runtime. Per default, a ChaCha20-based DRNG is used. The ChaCha20-DRNG implemented for the LRNG is also provided as a stand-alone user space deterministic random number generator. The LRNG also offers an SP800-90A DRBG based on the Linux kernel crypto API DRBG implementation.
The processing of entropic data from the noise source before injecting them into the DRNG is performed with the following mathematical operations:
1. LFSR: The 8 least significant bits of the time stamp data received from the interrupts are processed with an LFSR. That LFSR is implemented identically to the LSFR used in the existing /dev/random implementation except that it is capable of processing an entire word and that a different polynomial is used. The reason for the different polynomial is performance in a performance sensitive code section, the interrupt handler. The chosen polynomials have 4 taps. Also, this LFSR-approach is used in the OpenBSD /dev/random equivalent.
2. Concatenation: The temporary seed buffer used to seed the DRNG is a concatenation of parts of the entropy pool data, and the CPU noise source output.
The DRNG always tries to seed itself with 256 bits of entropy, except during boot. In any case, if the noise sources cannot deliver that amount, the available entropy is used and the DRNG keeps track on how much entropy it was seeded with. The entropy implied by the LRNG available in the entropy pool may be too conservative. To ensure that during boot time all available entropy from the entropy pool is transferred to the DRNG, the hash_df function always generates 256 data bits during boot to seed the DRNG. During boot, the DRNG is seeded as follows:
1. The DRNG is reseeded from the entropy pool and potentially the fast noise sources if the entropy pool has collected at least 32 bits of entropy from the interrupt noise source. The goal of this step is to ensure that the DRNG receives some initial entropy as early as possible. In addition it receives the entropy available from the fast noise sources.
2. The DRNG is reseeded from the entropy pool and potentially the fast noise sources if all noise sources collectively can provide at least 128 bits of entropy.
3. The DRNG is reseeded from the entropy pool and potentially the fast noise sources if all noise sources collectivel can provide at least 256 bits.
At the time of the reseeding steps, the DRNG requests as much entropy as is available in order to skip certain steps and reach the seeding level of 256 bits. This may imply that one or more of the aforementioned steps are skipped.
In all listed steps, the DRNG is (re)seeded with a number of random bytes from the entropy pool that is at most the amount of entropy present in the entropy pool. This means that when the entropy pool contains 128 or 256 bits of entropy, the DRNG is seeded with that amount of entropy as well.
Before the DRNG is seeded with 256 bits of entropy in step 3, requests of random data from /dev/random are not processed.
The hash_df operation providing random data from the entropy pool will always require that all entropy sources collectively can deliver at least 129 entropy bits as configured with (128 bits of entropy for seeding plus one bit of entropy that is lost with the post processing as defined in SP800-90B).
The DRNG operates as deterministic random number generator with the following properties:
* The maximum number of random bytes that can be generated with one DRNG generate operation is limited to 4096 bytes. When longer random numbers are requested, multiple DRNG generate operations are performed. The ChaCha20 DRNG as well as the SP800-90A DRBGs implement an update of their state after completing a generate request for backtracking resistance.
* The secondary DRNG is reseeded with whatever entropy is available – in the worst case where no additional entropy can be provided by the noise sources, the DRNG is not re-seeded and continues its operation to try to reseed again after again the expiry of one of these thresholds:
- If the last reseeding of the secondary DRNG is more than 600 seconds ago, or
- 2^20 DRNG generate operations are performed, whatever comes first, or
- the secondary DRNG is forced to reseed before the next generation of random numbers if data has been injected into the LRNG by writing data into /dev/random or /dev/urandom.
The chosen values prevent high-volume requests from user space to cause frequent reseeding operations which drag down the performance of the DRNG.
With the automatic reseeding after 600 seconds, the LRNG is triggered to reseed itself before the first request after a suspend that put the hardware to sleep for longer than 600 seconds.
The LRNG uses the following runtime memory using the currently smallest configuration:
* 576 bytes (512 bytes for the entropy pool and 64 for the entropy pool meta data) for the entropy pool management
* 64 bytes per CPU for the time stamp array
To support smaller devices including IoT environments, this patch allows reducing the runtime memory footprint of the LRNG at compile time by selecting smaller entropy pool sizes.
The entropy pool has support for sizes of 256, 128 and 64 bytes supported by primitive and irreducible polynomials.
The time stamp array is reduced to one atomic_t variable per CPU, i.e. 4 bytes when CONFIG_BASE_SMALL is selected during kernel configuration. This implies that after the receipt of 4 interrupts on one CPU, the data is injected into the LFSR. Depending on the behavior of the CPU caches, this may imply that the average interrupt handler execution time increases a bit, since instead of injecting 8 atomic_t values at one given time into the LFSR, only one is processed which may incur cache misses.
When selecting the compilation of a kernel for a small environment, prevent the allocation of a buffer up to 4096 bytes to serve user space requests. In this case, the stack variable of 64 bytes is used to serve all user space requests.
The LRNG has the following properties:
* internal noise source: interrupts timing with fast boot time seeding
* high performance of interrupt handling code: The LRNG impact on the interrupt handling has been reduced to a minimum. On one example system, the LRNG interrupt handling code executes within an average of 65 cycles whereas the existing /dev/random on the same device takes about 97 cycles when measuring the execution time of add_interrupt_randomness().
* lockless LFSR to collect raw entropy supporing concurrency-free use of massive parallel systems
* use of standalone ChaCha20 based RNG with the option to use a different DRNG selectable at compile time
* "atomic" seeding of secondary DRBG to ensure full entropy transport
* instantiate one DRNG per NUMA node
* support for runtime switchable output DRNGs
* use of only well-defined entropy-preserving operations to collect, compress and forward entropy: concatenation, LFSR, SP800-90A hash_df function
* compile-time selectable entropy pool size: the choice also uses the applicable LFSR polynomial to maintain the entropy pool size
* support of small systems by allowing the reduction of the runtime memory needs
Further details including the rationale for the design choices and properties of the LRNG together with testing is provided at [1]. In addition, the documentation explains the conducted regression tests to verify that the LRNG is API and ABI compatible with the existing /dev/random implementation.
[1] https://www.chronox.de/lrng.html
CC: "Eric W. Biederman" <[email protected]>
CC: "Alexander E. Patrakov" <[email protected]>
CC: "Ahmed S. Darwish" <[email protected]>
CC: "Theodore Y. Ts'o" <[email protected]>
CC: Willy Tarreau <[email protected]>
CC: Matthew Garrett <[email protected]>
CC: Vito Caputo <[email protected]>
CC: Andreas Dilger <[email protected]>
CC: Jan Kara <[email protected]>
CC: Ray Strode <[email protected]>
CC: William Jon McCann <[email protected]>
CC: zhangjs <[email protected]>
CC: Andy Lutomirski <[email protected]>
CC: Florian Weimer <[email protected]>
CC: Lennart Poettering <[email protected]>
CC: Nicolai Stange <[email protected]>
Mathematical aspects Reviewed-by: "Peter, Matthias" <[email protected]>
--- MAINTAINERS | 7 + drivers/char/Kconfig | 2 + drivers/char/Makefile | 9 +- drivers/char/lrng/Kconfig | 67 +++ drivers/char/lrng/Makefile | 9 + drivers/char/lrng/lrng_archrandom.c | 93 ++++ drivers/char/lrng/lrng_aux.c | 148 +++++++ drivers/char/lrng/lrng_chacha20.c | 263 ++++++++++++ drivers/char/lrng/lrng_chacha20.h | 25 ++ drivers/char/lrng/lrng_drng.c | 400 +++++++++++++++++ drivers/char/lrng/lrng_interfaces.c | 636 ++++++++++++++++++++++++++++ drivers/char/lrng/lrng_internal.h | 296 +++++++++++++ drivers/char/lrng/lrng_lfsr.h | 152 +++++++ drivers/char/lrng/lrng_pool.c | 586 +++++++++++++++++++++++++ drivers/char/lrng/lrng_sw_noise.c | 102 +++++ drivers/char/lrng/lrng_sw_noise.h | 57 +++ include/linux/lrng.h | 63 +++ 17 files changed, 2914 insertions(+), 1 deletion(-) create mode 100644 drivers/char/lrng/Kconfig create mode 100644 drivers/char/lrng/Makefile create mode 100644 drivers/char/lrng/lrng_archrandom.c create mode 100644 drivers/char/lrng/lrng_aux.c create mode 100644 drivers/char/lrng/lrng_chacha20.c create mode 100644 drivers/char/lrng/lrng_chacha20.h create mode 100644 drivers/char/lrng/lrng_drng.c create mode 100644 drivers/char/lrng/lrng_interfaces.c create mode 100644 drivers/char/lrng/lrng_internal.h create mode 100644 drivers/char/lrng/lrng_lfsr.h create mode 100644 drivers/char/lrng/lrng_pool.c create mode 100644 drivers/char/lrng/lrng_sw_noise.c create mode 100644 drivers/char/lrng/lrng_sw_noise.h create mode 100644 include/linux/lrng.h
MAINTAINERS +7 -0
@@ -9606,6 +9606,13 @@ F: Documentation/core-api/atomic_ops.rst F: Documentation/core-api/refcount-vs-atomic.rst F: Documentation/memory-barriers.txt +LINUX RANDOM NUMBER GENERATOR (LRNG) DRIVER +M: Stephan Mueller <[email protected]> +S: Maintained +W: https://www.chronox.de/lrng.html +F: drivers/char/lrng/* +F: include/linux/lrng.h + LIS3LV02D ACCELEROMETER DRIVER M: Eric Piel <[email protected]> S: Maintained
drivers/char/Kconfig +2 -0
@@ -535,6 +535,8 @@ config ADI and SSM (Silicon Secured Memory). Intended consumers of this driver include crash and makedumpfile. +source "drivers/char/lrng/Kconfig" + endmenu config RANDOM_TRUST_CPU
drivers/char/Makefile +8 -1
@@ -3,7 +3,14 @@ # Makefile for the kernel character device drivers. # -obj-y += mem.o random.o +obj-y += mem.o + +ifeq ($(CONFIG_LRNG),y) + obj-y += lrng/ +else + obj-y += random.o +endif + obj-$(CONFIG_TTY_PRINTK) += ttyprintk.o obj-y += misc.o obj-$(CONFIG_ATARI_DSP56K) += dsp56k.o
drivers/char/lrng/Kconfig new file +67 -0
67 lines not on this page · raw message
drivers/char/lrng/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for the Linux Random Number Generator. +# + +obj-y += lrng_pool.o lrng_aux.o \ + lrng_sw_noise.o lrng_archrandom.o \ + lrng_drng.o lrng_chacha20.o \ + lrng_interfaces.o \
drivers/char/lrng/lrng_archrandom.c new file +93 -0
93 lines not on this page · raw message
drivers/char/lrng/lrng_aux.c new file +148 -0
148 lines not on this page · raw message
drivers/char/lrng/lrng_chacha20.c new file +263 -0
263 lines not on this page · raw message
drivers/char/lrng/lrng_chacha20.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ +/* +* LRNG ChaCha20 definitions +* +* Copyright (C) 2016 - 2020, Stephan Mueller <[email protected]> +*/ + +#include <crypto/chacha.h> + +/* State according to RFC 7539 section 2.3 */ +struct chacha20_block { +u32 constants[4 ]; +union { +#define CHACHA_KEY_SIZE_WORDS (CHACHA_KEY_SIZE / sizeof(u32)) +u32 u[CHACHA_KEY_SIZE_WORDS ]; +u8 b[CHACHA_KEY_SIZE ]; + } key; +u32 counter; +u32 nonce[3 ]; +}; + +static inline void lrng_cc20_init_rfc7539 (struct chacha20_block *chacha20) +{ +memcpy (&chacha20->constants[0 ],"expand 32-byte k" ,16 ); +}
drivers/char/lrng/lrng_drng.c new file +400 -0
400 lines not on this page · raw message
drivers/char/lrng/lrng_interfaces.c new file +636 -0
636 lines not on this page · raw message
drivers/char/lrng/lrng_internal.h new file +296 -0
296 lines not on this page · raw message
drivers/char/lrng/lrng_lfsr.h new file +152 -0
152 lines not on this page · raw message
drivers/char/lrng/lrng_pool.c new file +586 -0
586 lines not on this page · raw message
drivers/char/lrng/lrng_sw_noise.c new file +102 -0
102 lines not on this page · raw message
drivers/char/lrng/lrng_sw_noise.h new file +57 -0
57 lines not on this page · raw message
include/linux/lrng.h new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v29 2/12 LRNG - allocate one DRNG instance per NUMA node
In reply to Stephan MüllerIn order to improve NUMA-locality when serving getrandom(2) requests, allocate one DRNG instance per node.
The DRNG instance that is present right from the start of the kernel is reused as the first per-NUMA-node DRNG. For all remaining online NUMA nodes a new DRNG instance is allocated.
During boot time, the multiple DRNG instances are seeded sequentially. With this, the first DRNG instance (referenced as the initial DRNG in the code) is completely seeded with 256 bits of entropy before the next DRNG instance is completely seeded.
When random numbers are requested, the NUMA-node-local DRNG is checked whether it has been already fully seeded. If this is not the case, the initial DRNG is used to serve the request.
--- drivers/char/lrng/Makefile | 2 + drivers/char/lrng/lrng_internal.h | 5 ++ drivers/char/lrng/lrng_numa.c | 101 ++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 drivers/char/lrng/lrng_numa.c
drivers/char/lrng/Makefile +2 -0
@@ -7,3 +7,5 @@ obj-y += lrng_pool.o lrng_aux.o \ lrng_sw_noise.o lrng_archrandom.o \ lrng_drng.o lrng_chacha20.o \ lrng_interfaces.o \ + +obj-$(CONFIG_NUMA) += lrng_numa.o
drivers/char/lrng/lrng_internal.h +5 -0
@@ -246,8 +246,13 @@ int lrng_drng_get_sleep(u8 *outbuf, u32 outbuflen);void lrng_drng_force_reseed (void );void lrng_drng_seed_work (struct work_struct *dummy); +#ifdef CONFIG_NUMA +struct lrng_drng **lrng_drng_instances (void ); +void lrng_drngs_numa_alloc (void ); +#else /* CONFIG_NUMA */ static inline struct lrng_drng **lrng_drng_instances (void ) {return NULL ; }static inline void lrng_drngs_numa_alloc (void ) {return ; } +#endif /* CONFIG_NUMA */ /************************** Health Test linking code **************************/
drivers/char/lrng/lrng_numa.c new file +101 -0
101 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v29 3/12 LRNG - sysctls and /proc interface
In reply to Stephan MüllerThe LRNG sysctl interface provides the same controls as the existing /dev/random implementation. These sysctls behave identically and are implemented identically. The goal is to allow a possible merge of the existing /dev/random implementation with this implementation which implies that this patch tries have a very close similarity. Yet, all sysctls are documented at [1].
In addition, it provides the file lrng_type which provides details about the LRNG:
- the name of the DRNG that produces the random numbers for /dev/random, /dev/urandom, getrandom(2)
- the hash used to produce random numbers from the entropy pool
- the number of secondary DRNG instances
- indicator whether the LRNG operates SP800-90B compliant
- indicator whether a high-resolution timer is identified - only with a high-resolution timer the interrupt noise source will deliver sufficient entropy
- indicator whether the LRNG has been minimally seeded (i.e. is the secondary DRNG seeded with at least 128 bits of of entropy)
- indicator whether the LRNG has been fully seeded (i.e. is the secondary DRNG seeded with at least 256 bits of entropy)
[1] https://www.chronox.de/lrng.html
--- drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_interfaces.c | 1 - drivers/char/lrng/lrng_internal.h | 4 + drivers/char/lrng/lrng_proc.c | 163 ++++++++++++++++++++++++++++ 4 files changed, 168 insertions(+), 1 deletion(-) create mode 100644 drivers/char/lrng/lrng_proc.c
drivers/char/lrng/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-y += lrng_pool.o lrng_aux.o \ lrng_interfaces.o \ obj-$(CONFIG_NUMA) += lrng_numa.o +obj-$(CONFIG_SYSCTL) += lrng_proc.o
drivers/char/lrng/lrng_interfaces.c +0 -1
@@ -34,7 +34,6 @@ static DECLARE_WAIT_QUEUE_HEAD(lrng_write_wait);static DECLARE_WAIT_QUEUE_HEAD (lrng_init_wait);static struct fasync_struct *fasync; -struct ctl_table random_table[];/********************************** Helper ***********************************/ /* Is the DRNG seed level too low? */
drivers/char/lrng/lrng_internal.h +4 -0
@@ -116,7 +116,11 @@ void lrng_cc20_init_state(struct chacha20_state *state);/********************************** /proc *************************************/ +#ifdef CONFIG_SYSCTL +void lrng_pool_inc_numa_node (void ); +#else static inline void lrng_pool_inc_numa_node (void ) { } +#endif /****************************** LRNG interfaces *******************************/
drivers/char/lrng/lrng_proc.c new file +163 -0
163 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v29 4/12 LRNG - add switchable DRNG support
In reply to Stephan MüllerThe DRNG switch support allows replacing the DRNG mechanism of the LRNG. The switching support rests on the interface definition of include/linux/lrng.h. A new DRNG is implemented by filling in the interface defined in this header file.
In addition to the DRNG, the extension also has to provide a hash implementation that is used to hash the entropy pool for random number extraction.
Note: It is permissible to implement a DRNG whose operations may sleep. However, the hash function must not sleep.
The switchable DRNG support allows replacing the DRNG at runtime. However, only one DRNG extension is allowed to be loaded at any given time. Before replacing it with another DRNG implementation, the possibly existing DRNG extension must be unloaded.
The switchable DRNG extension activates the new DRNG during load time. It is expected, however, that such a DRNG switch would be done only once by an administrator to load the intended DRNG implementation.
It is permissible to compile DRNG extensions either as kernel modules or statically. The initialization of the DRNG extension should be performed with a late_initcall to ensure the extension is available when user space starts but after all other initialization completed. The initialization is performed by registering the function call data structure with the lrng_set_drng_cb function. In order to unload the DRNG extension, lrng_set_drng_cb must be invoked with the NULL parameter.
The DRNG extension should always provide a security strength that is at least as strong as LRNG_DRNG_SECURITY_STRENGTH_BITS.
--- drivers/char/lrng/Kconfig | 7 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_switch.c | 182 ++++++++++++++++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 drivers/char/lrng/lrng_switch.c
drivers/char/lrng/Kconfig +7 -0
@@ -64,4 +64,11 @@ config LRNG_POOL_SIZE default 7 if LRNG_POOL_SIZE_65536 default 8 if LRNG_POOL_SIZE_131072 +menuconfig LRNG_DRNG_SWITCH + bool "Support DRNG runtime switching" + help + The Linux RNG per default uses a ChaCha20 DRNG that is + accessible via the external interfaces. With this configuration + option other DRNGs can be selected and loaded at runtime. + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-y += lrng_pool.o lrng_aux.o \ obj-$(CONFIG_NUMA) += lrng_numa.o obj-$(CONFIG_SYSCTL) += lrng_proc.o +obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o
drivers/char/lrng/lrng_switch.c new file +182 -0
182 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v29 5/12 crypto: DRBG - externalize DRBG functions for LRNG
In reply to Stephan MüllerThis patch allows several DRBG functions to be called by the LRNG kernel code paths outside the drbg.c file.
--- crypto/drbg.c | 16 ++++++++++------ include/crypto/drbg.h | 7 +++++++ 2 files changed, 17 insertions(+), 6 deletions(-)
crypto/drbg.c +10 -6
@@ -113,7 +113,7 @@* the SHA256 / AES 256 over other ciphers. Thus, the favored * DRBGs are the latest entries in this array. */ -static const struct drbg_core drbg_cores[] = { +const struct drbg_core drbg_cores[] = { #ifdef CONFIG_CRYPTO_DRBG_CTR { .flags = DRBG_CTR | DRBG_STRENGTH128,
@@ -190,6 +190,7 @@ static const struct drbg_core drbg_cores[] = { },#endif /* CONFIG_CRYPTO_DRBG_HMAC */ }; +EXPORT_SYMBOL (drbg_cores);static int drbg_uninstantiate (struct drbg_state *drbg);
@@ -205,7 +206,7 @@ static int drbg_uninstantiate(struct drbg_state *drbg);* Return: normalized strength in *bytes* value or 32 as default * to counter programming errors */ -static inline unsigned short drbg_sec_strength (drbg_flag_t flags) +unsigned short drbg_sec_strength (drbg_flag_t flags) {switch (flags &DRBG_STRENGTH_MASK ) {case DRBG_STRENGTH128 :
@@ -218,6 +219,7 @@ static inline unsigned short drbg_sec_strength(drbg_flag_t flags)return 32 ; } } +EXPORT_SYMBOL (drbg_sec_strength);/* * FIPS 140-2 continuous self test for the noise source
@@ -1202,7 +1204,7 @@ static int drbg_seed(struct drbg_state *drbg, struct drbg_string *pers, }/* Free all substructures in a DRBG state without the DRBG state structure */ -static inline void drbg_dealloc_state (struct drbg_state *drbg) +void drbg_dealloc_state (struct drbg_state *drbg) {if (!drbg)return ;
@@ -1223,12 +1225,13 @@ static inline void drbg_dealloc_state(struct drbg_state *drbg) drbg->fips_primed = false; } } +EXPORT_SYMBOL (drbg_dealloc_state);/* * Allocate all sub-structures for a DRBG state. * The DRBG state structure must already be allocated. */ -static inline int drbg_alloc_state (struct drbg_state *drbg) +int drbg_alloc_state (struct drbg_state *drbg) {int ret = -ENOMEM ;unsigned int sb_size =0 ;
@@ -1307,6 +1310,7 @@ static inline int drbg_alloc_state(struct drbg_state *drbg)drbg_dealloc_state (drbg);return ret; } +EXPORT_SYMBOL (drbg_alloc_state);/************************************************************************* * DRBG interface functions
@@ -1874,8 +1878,7 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg,* * return: flags */ -static inline void drbg_convert_tfm_core (const char *cra_driver_name, -int *coreref,bool *pr) +void drbg_convert_tfm_core (const char *cra_driver_name,int *coreref,bool *pr) {int i =0 ;size_t start =0 ;
@@ -1902,6 +1905,7 @@ static inline void drbg_convert_tfm_core(const char *cra_driver_name, } } } +EXPORT_SYMBOL (drbg_convert_tfm_core);static int drbg_kcapi_init (struct crypto_tfm *tfm) {
include/crypto/drbg.h +7 -0
@@ -282,4 +282,11 @@ enum drbg_prefixes {DRBG_PREFIX3 }; +extern int drbg_alloc_state (struct drbg_state *drbg); +extern void drbg_dealloc_state (struct drbg_state *drbg); +extern void drbg_convert_tfm_core (const char *cra_driver_name,int *coreref, +bool *pr); +extern const struct drbg_core drbg_cores[]; +extern unsigned short drbg_sec_strength (drbg_flag_t flags); +#endif /* _DRBG_H */
Signature · 1 line
2.24.1
PATCH v29 6/12 LRNG - add SP800-90A DRBG extension
In reply to Stephan MüllerUsing the LRNG switchable DRNG support, the SP800-90A DRBG extension is implemented.
The DRBG uses the kernel crypto API DRBG implementation. In addition, it uses the kernel crypto API SHASH support to provide the hashing operation.
The DRBG supports the choice of either a CTR DRBG using AES-256, HMAC DRBG with SHA-512 core or Hash DRBG with SHA-512 core. The used core can be selected with the module parameter lrng_drbg_type. The default is the CTR DRBG.
When compiling the DRBG extension statically, the DRBG is loaded at late_initcall stage which implies that with the start of user space, the user space interfaces of getrandom(2), /dev/random and /dev/urandom provide random data produced by an SP800-90A DRBG.
--- drivers/char/lrng/Kconfig | 12 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_drbg.c | 257 ++++++++++++++++++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 drivers/char/lrng/lrng_drbg.c
drivers/char/lrng/Kconfig +12 -0
@@ -71,4 +71,16 @@ menuconfig LRNG_DRNG_SWITCH accessible via the external interfaces. With this configuration option other DRNGs can be selected and loaded at runtime. +if LRNG_DRNG_SWITCH +config LRNG_DRBG + tristate "SP800-90A support for the LRNG" + depends on CRYPTO + select CRYPTO_DRBG_MENU + select CRYPTO_CMAC if CRYPTO_DRBG_CTR + help + Enable the SP800-90A DRBG support for the LRNG. Once the + module is loaded, output from /dev/random, /dev/urandom, + getrandom(2), or get_random_bytes is provided by a DRBG. +endif # LRNG_DRNG_SWITCH + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-y += lrng_pool.o lrng_aux.o \ obj-$(CONFIG_NUMA) += lrng_numa.o obj-$(CONFIG_SYSCTL) += lrng_proc.o obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o +obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o
drivers/char/lrng/lrng_drbg.c new file +257 -0
257 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v29 7/12 LRNG - add kernel crypto API PRNG extension
In reply to Stephan MüllerAdd runtime-pluggable support for all PRNGs that are accessible via the kernel crypto API, including hardware PRNGs. The PRNG is selected with the module parameter drng_name where the name must be one that the kernel crypto API can resolve into an RNG.
This allows using of the kernel crypto API PRNG implementations that provide an interface to hardware PRNGs. Using this extension, the LRNG uses the hardware PRNGs to generate random numbers. An example is the S390 CPACF support providing such a PRNG.
The hash is provided by a kernel crypto API SHASH whose digest size complies with the seedsize of the PRNG.
--- drivers/char/lrng/Kconfig | 11 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_kcapi.c | 321 +++++++++++++++++++++++++++++++++ 3 files changed, 333 insertions(+) create mode 100644 drivers/char/lrng/lrng_kcapi.c
drivers/char/lrng/Kconfig +11 -0
@@ -81,6 +81,17 @@ config LRNG_DRBG Enable the SP800-90A DRBG support for the LRNG. Once the module is loaded, output from /dev/random, /dev/urandom, getrandom(2), or get_random_bytes is provided by a DRBG. + +config LRNG_KCAPI + tristate "Kernel Crypto API support for the LRNG" + depends on CRYPTO + select CRYPTO_RNG + help + Enable the support for generic pseudo-random number + generators offered by the kernel crypto API with the + LRNG. Once the module is loaded, output from /dev/random, + /dev/urandom, getrandom(2), or get_random_bytes is + provided by the selected kernel crypto API RNG. endif # LRNG_DRNG_SWITCH endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -12,3 +12,4 @@ obj-$(CONFIG_NUMA) += lrng_numa.o obj-$(CONFIG_SYSCTL) += lrng_proc.o obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o +obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o
drivers/char/lrng/lrng_kcapi.c new file +321 -0
321 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v29 8/12 crypto: provide access to a static Jitter RNG state
In reply to Stephan MüllerTo support the LRNG operation which uses the Jitter RNG separately from the kernel crypto API, at a time where potentially the regular memory management is not yet initialized, the Jitter RNG needs to provide a state whose memory is defined at compile time. As only once instance will ever be needed by the LRNG, define once static memory block which is solely to be used by the LRNG.
---
crypto/jitterentropy-kcapi.c | 3 +--
crypto/jitterentropy.c | 25 ++++++++++++++++++-
.../crypto/internal}/jitterentropy.h | 3 +++
3 files changed, 28 insertions(+), 3 deletions(-)
rename {crypto => include/crypto/internal}/jitterentropy.h (84%)crypto/jitterentropy-kcapi.c +1 -2
@@ -43,8 +43,7 @@#include <linux/time.h> #include <linux/crypto.h> #include <crypto/internal/rng.h> - -#include "jitterentropy.h" +#include <crypto/internal/jitterentropy.h> /*************************************************************************** * Helper function
crypto/jitterentropy.c +24 -1
@@ -103,7 +103,7 @@ struct rand_data {* Helper functions ***************************************************************************/ -#include "jitterentropy.h" +#include <crypto/internal/jitterentropy.h> /** * Update of the loop count used for the next round of
@@ -639,3 +639,26 @@ int jent_entropy_init(void)return 0 ; } + +struct rand_data *jent_lrng_entropy_collector (void ) +{ +static unsigned char lrng_jent_mem[JENT_MEMORY_SIZE ]; +static struct rand_data lrng_jent_state = { + .data =0 , + .old_data =0 , + .prev_time =0 , + .last_delta =0 , + .last_delta2 =0 , + .osr =1 , + .mem = lrng_jent_mem, + .memlocation =0 , + .memblocks =JENT_MEMORY_BLOCKSIZE , + .memblocksize =JENT_MEMORY_BLOCKS , + .memaccessloops =JENT_MEMORY_ACCESSLOOPS , + }; + +if (jent_entropy_init ()) +return NULL ; + +return &lrng_jent_state; +}
include/crypto/internal/jitterentropy.h renamed from crypto/jitterentropy.h +3 -0
@@ -15,3 +15,6 @@ extern int jent_read_entropy(struct rand_data *ec, unsigned char *data,extern struct rand_data *jent_entropy_collector_alloc (unsigned int osr,unsigned int flags);extern void jent_entropy_collector_free (struct rand_data *entropy_collector); + +/* Access to statically allocated Jitter RNG instance */ +extern struct rand_data *jent_lrng_entropy_collector (void );
Signature · 1 line
2.24.1
PATCH v29 9/12 LRNG - add Jitter RNG fast noise source
In reply to Stephan MüllerThe Jitter RNG fast noise source implemented as part of the kernel crypto API is queried for 256 bits of entropy at the time the seed buffer managed by the LRNG is about to be filled.
--- drivers/char/lrng/Kconfig | 12 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_jent.c | 88 +++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 drivers/char/lrng/lrng_jent.c
drivers/char/lrng/Kconfig +12 -0
@@ -94,4 +94,16 @@ config LRNG_KCAPI provided by the selected kernel crypto API RNG. endif # LRNG_DRNG_SWITCH +config LRNG_JENT + bool "Enable Jitter RNG as LRNG Seed Source" + depends on CRYPTO + select CRYPTO_JITTERENTROPY + help + The Linux RNG may use the Jitter RNG as noise source. Enabling + this option enables the use of the Jitter RNG. Its default + entropy level is 16 bits of entropy per 256 data bits delivered + by the Jitter RNG. This entropy level can be changed at boot + time or at runtime with the lrng_base.jitterrng configuration + variable. + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -13,3 +13,4 @@ obj-$(CONFIG_SYSCTL) += lrng_proc.o obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o +obj-$(CONFIG_LRNG_JENT) += lrng_jent.o
drivers/char/lrng/lrng_jent.c new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v29 10/12 LRNG - add SP800-90B compliant health tests
In reply to Stephan MüllerImplement health tests for LRNG's slow noise sources as mandated by SP-800-90B The file contains the following health tests:
- stuck test: The stuck test calculates the first, second and third discrete derivative of the time stamp to be processed by the LFSR. Only if all three values are non-zero, the received time delta is considered to be non-stuck.
- SP800-90B Repetition Count Test (RCT): The LRNG uses an enhanced version of the RCT specified in SP800-90B section 4.4.1. Instead of counting identical back-to-back values, the input to the RCT is the counting of the stuck values during the processing of received interrupt events. The RCT is applied with alpha=2^-30 compliant to the recommendation of FIPS 140-2 IG 9.8. During the counting operation, the LRNG always calculates the RCT cut-off value of C. If that value exceeds the allowed cut-off value, the LRNG will trigger the health test failure discussed below. An error is logged to the kernel log that such RCT failure occurred. This test is only applied and enforced in FIPS mode, i.e. when the kernel compiled with CONFIG_CONFIG_FIPS is started with fips=1.
- SP800-90B Adaptive Proportion Test (APT): The LRNG implements the APT as defined in SP800-90B section 4.4.2. The applied significance level again is alpha=2^-30 compliant to the recommendation of FIPS 140-2 IG 9.8.
The aforementioned health tests are applied to the first 1,024 time stamps obtained from interrupt events. In case one error is identified for either the RCT, or the APT, the collected entropy is invalidated and the SP800-90B startup health test is restarted.
As long as the SP800-90B startup health test is not completed, all LRNG random number output interfaces that may block will block and not generate any data. This implies that only those potentially blocking interfaces are defined to provide random numbers that are seeded with the interrupt noise source being SP800-90B compliant. All other output interfaces will not be affected by the SP800-90B startup test and thus are not considered SP800-90B compliant.
At runtime, the SP800-90B APT and RCT are applied to each time stamp generated for a received interrupt. When either the APT and RCT indicates a noise source failure, the LRNG is reset to a state it has immediately after boot:
- all entropy counters are set to zero
- the SP800-90B startup tests are re-performed which implies that getrandom(2) would block again until new entropy was collected
To summarize, the following rules apply:
• SP800-90B compliant output interfaces
- /dev/random
- getrandom(2) system call
- get_random_bytes kernel-internal interface when being triggered by the callback registered with add_random_ready_callback
• SP800-90B non-compliant output interfaces
- /dev/urandom
- get_random_bytes kernel-internal interface called directly
- randomize_page kernel-internal interface
- get_random_u32 and get_random_u64 kernel-internal interfaces
- get_random_u32_wait, get_random_u64_wait, get_random_int_wait, and get_random_long_wait kernel-internal interfaces
If either the RCT, or the APT health test fails irrespective whether during initialization or runtime, the following actions occur:
1. The entropy of the entire entropy pool is invalidated.
2. All DRNGs are reset which imply that they are treated as being not seeded and require a reseed during next invocation.
3. The SP800-90B startup health test are initiated with all implications of the startup tests. That implies that from that point on, new events must be observed and its entropy must be inserted into the entropy pool before random numbers are calculated from the entropy pool.
Further details on the SP800-90B compliance and the availability of all test tools required to perform all tests mandated by SP800-90B are provided at [1].
The entire health testing code is compile-time configurable.
The patch provides a CONFIG_BROKEN configuration of the APT / RCT cutoff values which have a high likelihood to trigger the health test failure. The BROKEN APT cutoff is set to the exact mean of the expected value if the time stamps are equally distributed (512 time stamps divided by 16 possible values due to using the 4 LSB of the time stamp). The BROKEN RCT cutoff value is set to 1 which is likely to be triggered during regular operation.
--- drivers/char/lrng/Kconfig | 56 +++++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_health.c | 407 ++++++++++++++++++++++++++++++++ 3 files changed, 464 insertions(+) create mode 100644 drivers/char/lrng/lrng_health.c
drivers/char/lrng/Kconfig +56 -0
@@ -106,4 +106,60 @@ config LRNG_JENT time or at runtime with the lrng_base.jitterrng configuration variable. +config LRNG_HEALTH_TESTS + bool "Enable noise source online health tests" + help + The online health tests validate the noise source at + runtime for fatal errors. These tests include SP800-90B + compliant tests which are invoked if the system is booted + with fips=1. In case of fatal errors during active + SP800-90B tests, the issue is logged and the noise + data is discarded. These tests are required for full + compliance with SP800-90B. + + If unsure, say Y. + +config LRNG_RCT_BROKEN + bool "SP800-90B RCT with dangerous low cutoff value" + depends on LRNG_HEALTH_TESTS + depends on BROKEN + default n + help + This option enables a dangerously low SP800-90B repetitive + count test (RCT) cutoff value which makes it very likely + that the RCT is triggered to raise a self test failure. + + This option is ONLY intended for developers wanting to + test the effectiveness of the SP800-90B RCT health test. + + If unsure, say N. + +config LRNG_APT_BROKEN + bool "SP800-90B APT with dangerous low cutoff value" + depends on LRNG_HEALTH_TESTS + depends on BROKEN + default n + help + This option enables a dangerously low SP800-90B adaptive + proportion test (APT) cutoff value which makes it very + likely that the RCT is triggered to raise a self test + failure. + + This option is ONLY intended for developers wanting to + test the effectiveness of the SP800-90B APT health test. + + If unsure, say N. + +# Default taken from SP800-90B sec 4.4.1 - significance level 2^-30 +config LRNG_RCT_CUTOFF + int + default 31 if !LRNG_RCT_BROKEN + default 1 if LRNG_RCT_BROKEN + +# Default taken from SP800-90B sec 4.4.2 - significance level 2^-30 +config LRNG_APT_CUTOFF + int + default 325 if !LRNG_APT_BROKEN + default 32 if LRNG_APT_BROKEN + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -14,3 +14,4 @@ obj-$(CONFIG_LRNG_DRNG_SWITCH) += lrng_switch.o obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o obj-$(CONFIG_LRNG_JENT) += lrng_jent.o +obj-$(CONFIG_LRNG_HEALTH_TESTS) += lrng_health.o
drivers/char/lrng/lrng_health.c new file +407 -0
407 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v29 11/12 LRNG - add interface for gathering of raw entropy
In reply to Stephan MüllerThe test interface allows a privileged process to capture the raw unconditioned noise that is collected by the LRNG for statistical analysis. Such testing allows the analysis how much entropy the interrupt noise source provides on a given platform. Extracted noise data is not used to seed the LRNG. This is a test interface and not appropriate for production systems. Yet, the interface is considered to be sufficiently secured for production systems.
Access to the data is given through the lrng_raw debugfs file. The data buffer should be multiples of sizeof(u32) to fill the entire buffer. Using the option lrng_testing.boot_test=1 the raw noise of the first 1000 entropy events since boot can be sampled.
This test interface allows generating the data required for analysis whether the LRNG is in compliance with SP800-90B sections 3.1.3 and 3.1.4.
--- drivers/char/lrng/Kconfig | 16 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_testing.c | 269 +++++++++++++++++++++++++++++++ 3 files changed, 286 insertions(+) create mode 100644 drivers/char/lrng/lrng_testing.c
drivers/char/lrng/Kconfig +16 -0
@@ -162,4 +162,20 @@ config LRNG_APT_CUTOFF default 325 if !LRNG_APT_BROKEN default 32 if LRNG_APT_BROKEN +config LRNG_TESTING + bool "Enable entropy test interface to LRNG noise source" + depends on DEBUG_FS + help + The test interface allows a privileged process to capture + the raw unconditioned noise that is collected by the LRNG + for statistical analysis. Extracted noise data is not used + to seed the LRNG. + + The raw noise data can be obtained using the lrng_raw + debugfs file. Using the option lrng_testing.boot_test=1 + the raw noise of the first 1000 entropy events since boot + can be sampled. + + If unsure, say N. + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-$(CONFIG_LRNG_DRBG) += lrng_drbg.o obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o obj-$(CONFIG_LRNG_JENT) += lrng_jent.o obj-$(CONFIG_LRNG_HEALTH_TESTS) += lrng_health.o +obj-$(CONFIG_LRNG_TESTING) += lrng_testing.o
drivers/char/lrng/lrng_testing.c new file +269 -0
269 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v29 12/12 LRNG - add power-on and runtime self-tests
In reply to Stephan MüllerParts of the LRNG are already covered by self-tests, including:
* Self-test of SP800-90A DRBG provided by the Linux kernel crypto API.
* Self-test of the PRNG provided by the Linux kernel crypto API.
* Raw noise source data testing including SP800-90B compliant tests when enabling CONFIG_LRNG_HEALTH_TESTS
This patch adds the self-tests for the remaining critical functions of the LRNG that are essential to maintain entropy and provide cryptographic strong random numbers. The following self-tests are implemented:
* Self-test of the time array maintenance. This test verifies whether the time stamp array management to store multiple values in one integer implements a concatenation of the data.
* Self-test of the LFSR operation. This test injects a monotonic increasing counter into the LFSR. After completion of the injection of the counter, 3 pool words are compared with known good values. The known good values are calculated with the newly-developed tool lfsr_testvector_generation provided as part of the LRNG test tool set at [1].
* Self-test of the Hash_DF operation ensures that this function operates compliant to the specification. The self-test performs a Hash_DF operation of a zeroized entropy pool state. The test vectors are generated using the newly-developed tool hash_df_testvector_generation provided as part of the LRNG test tool set at [1].
* Self-test of the ChaCha20 DRNG is based on the self-tests that are already present and implemented with the stand-alone user space ChaCha20 DRNG implementation available at [2]. The self-tests cover different use cases of the DRNG seeded with known seed data.
The status of the LRNG self-tests is provided with the selftest_status SysFS file. If the file contains a zero, the self-tests passed. The value 0xffffffff means that the self-tests were not executed. Any other value indicates a self-test failure.
The self-test may be compiled to panic the system if the self-test fails.
All self-tests operate on private state data structures. This implies that none of the self-tests have any impact on the regular LRNG operations. This allows the self-tests to be repeated at runtime by writing anything into the selftest_status SysFS file.
[1] https://www.chronox.de/lrng.html
[2] https://www.chronox.de/chacha20.html
--- drivers/char/lrng/Kconfig | 25 ++ drivers/char/lrng/Makefile | 1 + drivers/char/lrng/lrng_selftest.c | 418 ++++++++++++++++++++++++++++++ 3 files changed, 444 insertions(+) create mode 100644 drivers/char/lrng/lrng_selftest.c
drivers/char/lrng/Kconfig +25 -0
@@ -178,4 +178,29 @@ config LRNG_TESTING If unsure, say N. +config LRNG_SELFTEST + bool "Enable power-on and on-demand self-tests" + help + The power-on self-tests are executed during boot time + covering the ChaCha20 DRNG, the LFSR processing and the + time stamp management of the LRNG. + + The on-demand self-tests are triggered by writing any + value into the SysFS file selftest_status. At the same + time, when reading this file, the test status is + returned. A zero indicates that all tests were executed + successfully. + + If unsure, say Y. + +if LRNG_SELFTEST + +config LRNG_SELFTEST_PANIC + bool "Panic the kernel upon self-test failure" + help + If the option is enabled, the kernel is terminated if an + LRNG power-on self-test failure is detected. + +endif # LRNG_SELFTEST + endif # LRNG
drivers/char/lrng/Makefile +1 -0
@@ -16,3 +16,4 @@ obj-$(CONFIG_LRNG_KCAPI) += lrng_kcapi.o obj-$(CONFIG_LRNG_JENT) += lrng_jent.o obj-$(CONFIG_LRNG_HEALTH_TESTS) += lrng_health.o obj-$(CONFIG_LRNG_TESTING) += lrng_testing.o +obj-$(CONFIG_LRNG_SELFTEST) += lrng_selftest.o
drivers/char/lrng/lrng_selftest.c new file +418 -0
418 lines not on this page · raw message
Signature · 1 line
2.24.1