crypto: jitter - Offer compile-time options
cover crypto: jitter - Offer compile-time options
Hi,
the following patchset offers a set of compile-time options to accommodate different hardware with different entropy rates implied in their timers. This allows configuring the Jitter RNG in systems which exhibits insufficient entropy with the default parameters. The default parameters defined by the patches, however, are identical to the existing code and thus do not alter the Jitter RNG behavior.
The first patch sets the state by allowing the configuration of different oversampling rates. The second patch allows the configuration of different memory sizes and the third allows the configuration of differnet oversampling rates.
The update of the power up test with the first patch also addresses reports that the Jitter RNG did not initialize due to it detected insufficient entropy.
Stephan Mueller (3):
crypto: jitter - add RCT/APT support for different OSRs
crypto: jitter - Allow configuration of memory size
crypto: jitter - Allow configuration of oversampling rate
crypto/Kconfig | 60 +++++++++ crypto/jitterentropy-kcapi.c | 17 ++- crypto/jitterentropy.c | 249 ++++++++++++++++++----------------- crypto/jitterentropy.h | 5 +- 4 files changed, 207 insertions(+), 124 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/3 crypto: jitter - add RCT/APT support for different OSRs
The oversampling rate (OSR) value specifies the heuristically implied entropy in the recorded data - H_submitter = 1/osr. A different entropy estimate implies a different APT/RCT cutoff value. This change adds support for OSRs 1 through 15. This OSR can be selected by the caller of the Jitter RNG.
For this patch, the caller still uses one hard-coded OSR. A subsequent patch allows this value to be configured.
In addition, the power-up self test is adjusted as follows:
* It allows the caller to provide an oversampling rate that should be tested with - commonly it should be the same as used for the actual runtime operation. This makes the power-up testing therefore consistent with the runtime operation.
* It calls now jent_measure_jitter (i.e. collects the full entropy that can possibly be harvested by the Jitter RNG) instead of only jent_condition_data (which only returns the entropy harvested from the conditioning component). This should now alleviate reports where the Jitter RNG initialization thinks there is too little entropy.
* The power-up test now solely relies on the (enhanced) APT and RCT test that is used as a health test at runtime.
The code allowing the different OSRs as well as the power-up test changes are present in the user space version of the Jitter RNG 3.4.1 and thus was already in production use for some time.
Reported-by "Ospan, Abylay" <[email protected]>
--- crypto/jitterentropy-kcapi.c | 4 +- crypto/jitterentropy.c | 233 ++++++++++++++++++----------------- crypto/jitterentropy.h | 3 +- 3 files changed, 123 insertions(+), 117 deletions(-)
crypto/jitterentropy-kcapi.c +2 -2
@@ -245,7 +245,7 @@ static int jent_kcapi_init(struct crypto_tfm *tfm)crypto_shash_init (sdesc); rng->sdesc = sdesc; - rng->entropy_collector =jent_entropy_collector_alloc (1 ,0 , sdesc); + rng->entropy_collector =jent_entropy_collector_alloc (0 ,0 , sdesc);if (!rng->entropy_collector) { ret = -ENOMEM ; goto err;
@@ -334,7 +334,7 @@ static int __init jent_mod_init(void) desc->tfm = tfm;crypto_shash_init (desc); - ret =jent_entropy_init (desc); + ret =jent_entropy_init (0 ,0 , desc);shash_desc_zero (desc);crypto_free_shash (tfm);if (ret) {
crypto/jitterentropy.c +119 -114
353 lines not on this page · raw message
crypto/jitterentropy.h +2 -1
@@ -9,7 +9,8 @@ extern int jent_hash_time(void *hash_state, __u64 time, u8 *addtl,int jent_read_random_block (void *hash_state,char *dst,unsigned int dst_len);struct rand_data ; -extern int jent_entropy_init (void *hash_state); +extern int jent_entropy_init (unsigned int osr,unsigned int flags, +void *hash_state);extern int jent_read_entropy (struct rand_data *ec,unsigned char *data,unsigned int len);
Signature · 1 line
2.42.0
PATCH 2/3 crypto: jitter - Allow configuration of memory size
In reply to Stephan MüllerThe memory size consumed by the Jitter RNG is one contributing factor in the amount of entropy that is gathered. As the amount of entropy directly correlates with the distance of the memory from the CPU, the caches that are possibly present on a given system have an impact on the collected entropy.
Thus, the kernel compile time should offer a means to configure the amount of memory used by the Jitter RNG. Although this option could be turned into a runtime option (e.g. a kernel command line option), it should remain a compile time option as otherwise adminsitrators who may not have performed an entropy assessment may select a value that is inappropriate.
The default value selected by the configuration is identical to the current Jitter RNG value. Thus, the patch should not lead to any change in the Jitter RNG behavior.
To accommodate larger memory buffers, kvzalloc / kvfree is used.
--- crypto/Kconfig | 43 ++++++++++++++++++++++++++++++++++++ crypto/jitterentropy-kcapi.c | 11 +++++++++ crypto/jitterentropy.c | 16 ++++++++------ crypto/jitterentropy.h | 2 ++ 4 files changed, 65 insertions(+), 7 deletions(-)
crypto/Kconfig +43 -0
@@ -1296,6 +1296,49 @@ config CRYPTO_JITTERENTROPY See https://www.chronox.de/jent.html +choice + prompt "CPU Jitter RNG Memory Size" + default CRYPTO_JITTERENTROPY_MEMSIZE_2 + depends on CRYPTO_JITTERENTROPY + help + The Jitter RNG measures the execution time of memory accesses. + Multiple consecutive memory accesses are performed. If the memory + size fits into a cache (e.g. L1), only the memory access timing + to that cache is measured. The closer the cache is to the CPU + the less variations are measured and thus the less entropy is + obtained. Thus, if the memory size fits into the L1 cache, the + obtained entropy is less than if the memory size fits within + L1 + L2, which in turn is less if the memory fits into + L1 + L2 + L3. Thus, by selecting a different memory size, + the entropy rate produced by the Jitter RNG can be modified. + + config CRYPTO_JITTERENTROPY_MEMSIZE_2 + bool "2048 Bytes (default)" + + config CRYPTO_JITTERENTROPY_MEMSIZE_128 + bool "128 kBytes" + + config CRYPTO_JITTERENTROPY_MEMSIZE_1024 + bool "1024 kBytes" + + config CRYPTO_JITTERENTROPY_MEMSIZE_8192 + bool "8192 kBytes" +endchoice + +config CRYPTO_JITTERENTROPY_MEMORY_BLOCKS + int + default 64 if CRYPTO_JITTERENTROPY_MEMSIZE_2 + default 512 if CRYPTO_JITTERENTROPY_MEMSIZE_128 + default 1024 if CRYPTO_JITTERENTROPY_MEMSIZE_1024 + default 4096 if CRYPTO_JITTERENTROPY_MEMSIZE_8192 + +config CRYPTO_JITTERENTROPY_MEMORY_BLOCKSIZE + int + default 32 if CRYPTO_JITTERENTROPY_MEMSIZE_2 + default 256 if CRYPTO_JITTERENTROPY_MEMSIZE_128 + default 1024 if CRYPTO_JITTERENTROPY_MEMSIZE_1024 + default 2048 if CRYPTO_JITTERENTROPY_MEMSIZE_8192 + config CRYPTO_JITTERENTROPY_TESTINTERFACE bool "CPU Jitter RNG Test Interface" depends on CRYPTO_JITTERENTROPY
crypto/jitterentropy-kcapi.c +11 -0
@@ -54,6 +54,17 @@* Helper function ***************************************************************************/ +void *jent_kvzalloc (unsigned int len) +{ +return kvzalloc (len,GFP_KERNEL ); +} + +void jent_kvzfree (void *ptr,unsigned int len) +{ +memzero_explicit (ptr, len); +kvfree (ptr); +} +void *jent_zalloc (unsigned int len) {return kzalloc (len,GFP_KERNEL );
crypto/jitterentropy.c +9 -7
@@ -75,10 +75,10 @@ struct rand_data {unsigned int flags;/* Flags used to initialize */ unsigned int osr;/* Oversample rate */ -#define JENT_MEMORY_BLOCKS 64 -#define JENT_MEMORY_BLOCKSIZE 32#define JENT_MEMORY_ACCESSLOOPS 128 -#define JENT_MEMORY_SIZE (JENT_MEMORY_BLOCKS*JENT_MEMORY_BLOCKSIZE) +#define JENT_MEMORY_SIZE \ + (CONFIG_CRYPTO_JITTERENTROPY_MEMORY_BLOCKS * \ + CONFIG_CRYPTO_JITTERENTROPY_MEMORY_BLOCKSIZE)unsigned char *mem;/* Memory access location with size of * memblocks * memblocksize */ unsigned int memlocation;/* Pointer to byte in *mem */
@@ -650,13 +650,15 @@ struct rand_data *jent_entropy_collector_alloc(unsigned int osr,/* Allocate memory for adding variations based on memory * access */ - entropy_collector->mem =jent_zalloc (JENT_MEMORY_SIZE ); + entropy_collector->mem =jent_kvzalloc (JENT_MEMORY_SIZE );if (!entropy_collector->mem) {jent_zfree (entropy_collector);return NULL ; } - entropy_collector->memblocksize =JENT_MEMORY_BLOCKSIZE ; - entropy_collector->memblocks =JENT_MEMORY_BLOCKS ; + entropy_collector->memblocksize = +CONFIG_CRYPTO_JITTERENTROPY_MEMORY_BLOCKSIZE ; + entropy_collector->memblocks = +CONFIG_CRYPTO_JITTERENTROPY_MEMORY_BLOCKS ; entropy_collector->memaccessloops =JENT_MEMORY_ACCESSLOOPS ; }
@@ -679,7 +681,7 @@ struct rand_data *jent_entropy_collector_alloc(unsigned int osr,void jent_entropy_collector_free (struct rand_data *entropy_collector) { -jent_zfree (entropy_collector->mem); +jent_kvzfree (entropy_collector->mem,JENT_MEMORY_SIZE ); entropy_collector->mem =NULL ;jent_zfree (entropy_collector); }
crypto/jitterentropy.h +2 -0
@@ -1,5 +1,7 @@// SPDX-License-Identifier: GPL-2.0-or-later +extern void *jent_kvzalloc (unsigned int len); +extern void jent_kvzfree (void *ptr,unsigned int len);extern void *jent_zalloc (unsigned int len);extern void jent_zfree (void *ptr);extern void jent_get_nstime (__u64 *out);
Signature · 1 line
2.42.0
PATCH 3/3 crypto: jitter - Allow configuration of oversampling rate
In reply to Stephan MüllerThe oversampling rate used by the Jitter RNG allows the configuration of the heuristically implied entropy in one timing measurement. This entropy rate is (1 / OSR) bits of entropy per time stamp.
Considering that the Jitter RNG now support APT/RCT health tests for different OSRs, allow this value to be configured at compile time to support systems with limited amount of entropy in their timer.
The allowed range of OSR values complies with the APT/RCT cutoff health test values which range from 1 through 15.
The default value of the OSR selection support is left at 1 which is the current default. Thus, the addition of the configuration support does not alter the default Jitter RNG behavior.
--- crypto/Kconfig | 17 +++++++++++++++++ crypto/jitterentropy-kcapi.c | 6 ++++-- 2 files changed, 21 insertions(+), 2 deletions(-)
crypto/Kconfig +17 -0
@@ -1339,6 +1339,23 @@ config CRYPTO_JITTERENTROPY_MEMORY_BLOCKSIZE default 1024 if CRYPTO_JITTERENTROPY_MEMSIZE_1024 default 2048 if CRYPTO_JITTERENTROPY_MEMSIZE_8192 +config CRYPTO_JITTERENTROPY_OSR + int "CPU Jitter RNG Oversampling Rate" + range 1 15 + default 1 + depends on CRYPTO_JITTERENTROPY + help + The Jitter RNG allows the specification of an oversampling rate (OSR). + The Jitter RNG operation requires a fixed amount of timing + measurements to produce one output block of random numbers. The + OSR value is multiplied with the amount of timing measurements to + generate one output block. Thus, the timing measurement is oversampled + by the OSR factor. The oversampling allows the Jitter RNG to operate + on hardware whose timers deliver limited amount of entropy (e.g. + the timer is coarse) by setting the OSR to a higher value. The + trade-off, however, is that the Jitter RNG now requires more time + to generate random numbers. + config CRYPTO_JITTERENTROPY_TESTINTERFACE bool "CPU Jitter RNG Test Interface" depends on CRYPTO_JITTERENTROPY
crypto/jitterentropy-kcapi.c +4 -2
@@ -256,7 +256,9 @@ static int jent_kcapi_init(struct crypto_tfm *tfm)crypto_shash_init (sdesc); rng->sdesc = sdesc; - rng->entropy_collector =jent_entropy_collector_alloc (0 ,0 , sdesc); + rng->entropy_collector = +jent_entropy_collector_alloc (CONFIG_CRYPTO_JITTERENTROPY_OSR ,0 , + sdesc);if (!rng->entropy_collector) { ret = -ENOMEM ; goto err;
@@ -345,7 +347,7 @@ static int __init jent_mod_init(void) desc->tfm = tfm;crypto_shash_init (desc); - ret =jent_entropy_init (0 ,0 , desc); + ret =jent_entropy_init (CONFIG_CRYPTO_JITTERENTROPY_OSR ,0 , desc);shash_desc_zero (desc);crypto_free_shash (tfm);if (ret) {
Signature · 1 line
2.42.0
Hi Stephan,
We ran tests with your patches on our bare metal platform (AMD Epyc CPU) and saw an improvement in boot time entropy after analyzing the collected jitter deltas. Patches looks good to me.
Thanks for your work!
-----Original Message-----
From: Stephan Müller <[email protected]>
Sent: Thursday, September 21, 2023 7:48 AM
To: [email protected]
Cc: [email protected]; Ospan, Abylay <[email protected]>
Subject: [EXTERNAL] [PATCH 0/3] crypto: jitter - Offer compile-time options
CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.
Hi,
the following patchset offers a set of compile-time options to accommodate different hardware with different entropy rates implied in their timers. This allows configuring the Jitter RNG in systems which exhibits insufficient entropy with the default parameters. The default parameters defined by the patches, however, are identical to the existing code and thus do not alter the Jitter RNG behavior.
The first patch sets the state by allowing the configuration of different oversampling rates. The second patch allows the configuration of different memory sizes and the third allows the configuration of differnet oversampling rates.
The update of the power up test with the first patch also addresses reports that the Jitter RNG did not initialize due to it detected insufficient entropy.
Stephan Mueller (3):
crypto: jitter - add RCT/APT support for different OSRs
crypto: jitter - Allow configuration of memory size
crypto: jitter - Allow configuration of oversampling rate
crypto/Kconfig | 60 +++++++++ crypto/jitterentropy-kcapi.c | 17 ++- crypto/jitterentropy.c | 249 ++++++++++++++++++----------------- crypto/jitterentropy.h | 5 +- 4 files changed, 207 insertions(+), 124 deletions(-)
--
2.42.0
Herbert Xu
maintainerQuoted 23 lines · Stephan Müller
Hi,
the following patchset offers a set of compile-time options to accommodate different hardware with different entropy rates implied in their timers. This allows configuring the Jitter RNG in systems which exhibits insufficient entropy with the default parameters. The default parameters defined by the patches, however, are identical to the existing code and thus do not alter the Jitter RNG behavior.
The first patch sets the state by allowing the configuration of different oversampling rates. The second patch allows the configuration of different memory sizes and the third allows the configuration of differnet oversampling rates.
The update of the power up test with the first patch also addresses reports that the Jitter RNG did not initialize due to it detected insufficient entropy.
Stephan Mueller (3):
crypto: jitter - add RCT/APT support for different OSRs
crypto: jitter - Allow configuration of memory size
crypto: jitter - Allow configuration of oversampling rate
Quoted 8 lines
crypto/Kconfig | 60 +++++++++ crypto/jitterentropy-kcapi.c | 17 ++- crypto/jitterentropy.c | 249 ++++++++++++++++++----------------- crypto/jitterentropy.h | 5 +- 4 files changed, 207 insertions(+), 124 deletions(-)Signature · 1 line
2.42.0
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt