1 From 0baa8fab334a4d7017235b72fa8a547433572109 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Stephan=20M=C3=BCller?= <smueller@chronox.de>
3 Date: Thu, 21 Sep 2023 13:48:59 +0200
4 Subject: [PATCH] crypto: jitter - Allow configuration of oversampling rate
6 The oversampling rate used by the Jitter RNG allows the configuration of
7 the heuristically implied entropy in one timing measurement. This
8 entropy rate is (1 / OSR) bits of entropy per time stamp.
10 Considering that the Jitter RNG now support APT/RCT health tests for
11 different OSRs, allow this value to be configured at compile time to
12 support systems with limited amount of entropy in their timer.
14 The allowed range of OSR values complies with the APT/RCT cutoff health
15 test values which range from 1 through 15.
17 The default value of the OSR selection support is left at 1 which is the
18 current default. Thus, the addition of the configuration support does
19 not alter the default Jitter RNG behavior.
21 Signed-off-by: Stephan Mueller <smueller@chronox.de>
22 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
24 crypto/Kconfig | 17 +++++++++++++++++
25 crypto/jitterentropy-kcapi.c | 6 ++++--
26 2 files changed, 21 insertions(+), 2 deletions(-)
30 @@ -1340,6 +1340,23 @@ config CRYPTO_JITTERENTROPY_MEMORY_BLOCK
31 default 1024 if CRYPTO_JITTERENTROPY_MEMSIZE_1024
32 default 2048 if CRYPTO_JITTERENTROPY_MEMSIZE_8192
34 +config CRYPTO_JITTERENTROPY_OSR
35 + int "CPU Jitter RNG Oversampling Rate"
38 + depends on CRYPTO_JITTERENTROPY
40 + The Jitter RNG allows the specification of an oversampling rate (OSR).
41 + The Jitter RNG operation requires a fixed amount of timing
42 + measurements to produce one output block of random numbers. The
43 + OSR value is multiplied with the amount of timing measurements to
44 + generate one output block. Thus, the timing measurement is oversampled
45 + by the OSR factor. The oversampling allows the Jitter RNG to operate
46 + on hardware whose timers deliver limited amount of entropy (e.g.
47 + the timer is coarse) by setting the OSR to a higher value. The
48 + trade-off, however, is that the Jitter RNG now requires more time
49 + to generate random numbers.
51 config CRYPTO_JITTERENTROPY_TESTINTERFACE
52 bool "CPU Jitter RNG Test Interface"
53 depends on CRYPTO_JITTERENTROPY
54 --- a/crypto/jitterentropy-kcapi.c
55 +++ b/crypto/jitterentropy-kcapi.c
56 @@ -257,7 +257,9 @@ static int jent_kcapi_init(struct crypto
57 crypto_shash_init(sdesc);
60 - rng->entropy_collector = jent_entropy_collector_alloc(0, 0, sdesc);
61 + rng->entropy_collector =
62 + jent_entropy_collector_alloc(CONFIG_CRYPTO_JITTERENTROPY_OSR, 0,
64 if (!rng->entropy_collector) {
67 @@ -346,7 +348,7 @@ static int __init jent_mod_init(void)
70 crypto_shash_init(desc);
71 - ret = jent_entropy_init(0, 0, desc);
72 + ret = jent_entropy_init(CONFIG_CRYPTO_JITTERENTROPY_OSR, 0, desc);
73 shash_desc_zero(desc);
74 crypto_free_shash(tfm);