Skip to contentSkip to conversation

Common entropy source and DRNG management

PATCH In review Stephan Müller 4 participants 15 messages Jan 26, 2022 – Feb 6, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Common entropy source and DRNG management

The current code base of the kernel crypto API random number support leaves the task to seed and reseed the DRNG to either the caller or the DRNG implementation. The code in crypto/drbg.c implements its own seeding strategy. crypto/ansi_cprng.c does not contain any seeding operation. The implementation in arch/s390/crypto/prng.c has yet another approach for seeding. Albeit the crypto_rng_reset() contains a seeding logic from get_random_bytes, there is no management of the DRNG to ensure proper reseeding or control which entropy sources are used for pulling data from.

The task of seeding and reseeding a DRNG including the controlling of the state of the entropy sources is security sensitive as the strength of the data obtained from the DRNG rests in large parts on the proper seeding. In addition, various aspects need to be considered when (re)seeding a DRNG. This gap is filled with the Entropy Source and DRNG Manager (ESDM) proposed by this patch set.

The ESDM consists of two managers: the manager for the DRNG(s) and manager for the entropy sources. The DRNG manager ensures that DRNGs are properly seeded before random numbers are obtained from them. Similarly, the entropy source manager ensures that the available entropy sources are properly initialized if needed, and that data is obtained with an appropriately considered entropy rate.

Both, the DRNG and entropy source managers offer a pluggable interface allowing to use different DRNG implementations as well as various entropy sources. Each provided entropy source may be enabled during compile time. The ESDM therefore provides flexibility in the future to extend the set of entropy sources or the supported DRNGs to the required algorithms.

The patch set consists of the following changes:

- Patch 1 removes the seeding and reseeding logic from the DRBG transforming it into a pure deterministic implementation.

- Patch 2 removes the special AF_ALG interface used to test the DRBG implementation which requires bypassing of the DRBG automated seeding from entropy sources. With patch 1 this is not needed any more.

- Patch 3 adds the ESDM with its DRNG and entropy source managers. It contains the support to use the kernel crypto API's DRNG implementations.

- Patches 4 and 5 use the existing Jitter RNG as an entropy source for the ESDM.

- Patch 6 provides the glue code to use the get_random_bytes function as entropy source to the ESDM.

- Patch 7 adds the ESDM interface to register it with the kernel crypto API RNG framework as "stdrng" with the highest priority. This way, the ESDM is used per default when using the call crypto_get_default_rng().

With this patch series, callers to the kernel crypto API would not experience any difference. When using the RNG framework, the function crypto_get_default_rng is commonly used. Instead of providing the DRBG implementation, the ESDM is used which returns random numbers from a properly seeded DRBG.

Stephan Mueller (7):
crypto: DRBG - remove internal reseeding operation
crypto: AF_ALG - remove ALG_SET_DRBG_ENTROPY interface
crypto: Entropy Source and DRNG Manager
crypto: move Jitter RNG header include dir
crypto: ESDM - add Jitter RNG entropy source
crypto: ESDM - add Kernel RNG entropy source
crypto: ESDM - add kernel crypto API RNG interface

 crypto/Kconfig                                |  11 +-
 crypto/Makefile                               |   1 +
 crypto/af_alg.c                               |   7 -
 crypto/algif_rng.c                            |  74 +-
 crypto/drbg.c                                 | 640 ++++-------------
 crypto/esdm/Kconfig                           | 166 +++++
 crypto/esdm/Makefile                          |  15 +
 crypto/esdm/esdm_definitions.h                | 141 ++++
 crypto/esdm/esdm_drng_kcapi.c                 | 202 ++++++
 crypto/esdm/esdm_drng_kcapi.h                 |  13 +
 crypto/esdm/esdm_drng_mgr.c                   | 398 +++++++++++
 crypto/esdm/esdm_drng_mgr.h                   |  85 +++
 crypto/esdm/esdm_es_aux.c                     | 332 +++++++++
 crypto/esdm/esdm_es_aux.h                     |  44 ++
 crypto/esdm/esdm_es_jent.c                    | 128 ++++
 crypto/esdm/esdm_es_jent.h                    |  17 +
 crypto/esdm/esdm_es_krng.c                    | 120 ++++
 crypto/esdm/esdm_es_krng.h                    |  17 +
 crypto/esdm/esdm_es_mgr.c                     | 372 ++++++++++
 crypto/esdm/esdm_es_mgr.h                     |  46 ++
 crypto/esdm/esdm_es_mgr_cb.h                  |  73 ++
 crypto/esdm/esdm_interface_kcapi.c            |  91 +++
 crypto/esdm/esdm_sha.h                        |  14 +
 crypto/esdm/esdm_sha256.c                     |  72 ++
 crypto/jitterentropy-kcapi.c                  |   3 +-
 crypto/jitterentropy.c                        |   2 +-
 crypto/testmgr.c                              | 104 +--
 crypto/testmgr.h                              | 641 +-----------------
 include/crypto/drbg.h                         |  84 ---
 include/crypto/esdm.h                         | 115 ++++
 include/crypto/if_alg.h                       |   1 -
 .../crypto/internal}/jitterentropy.h          |   0
 include/crypto/internal/rng.h                 |   6 -
 include/crypto/rng.h                          |   4 -
 include/uapi/linux/if_alg.h                   |   2 +-
 35 files changed, 2615 insertions(+), 1426 deletions(-)
 create mode 100644 crypto/esdm/Kconfig
 create mode 100644 crypto/esdm/Makefile
 create mode 100644 crypto/esdm/esdm_definitions.h
 create mode 100644 crypto/esdm/esdm_drng_kcapi.c
 create mode 100644 crypto/esdm/esdm_drng_kcapi.h
 create mode 100644 crypto/esdm/esdm_drng_mgr.c
 create mode 100644 crypto/esdm/esdm_drng_mgr.h
 create mode 100644 crypto/esdm/esdm_es_aux.c
 create mode 100644 crypto/esdm/esdm_es_aux.h
 create mode 100644 crypto/esdm/esdm_es_jent.c
 create mode 100644 crypto/esdm/esdm_es_jent.h
 create mode 100644 crypto/esdm/esdm_es_krng.c
 create mode 100644 crypto/esdm/esdm_es_krng.h
 create mode 100644 crypto/esdm/esdm_es_mgr.c
 create mode 100644 crypto/esdm/esdm_es_mgr.h
 create mode 100644 crypto/esdm/esdm_es_mgr_cb.h
 create mode 100644 crypto/esdm/esdm_interface_kcapi.c
 create mode 100644 crypto/esdm/esdm_sha.h
 create mode 100644 crypto/esdm/esdm_sha256.c
 create mode 100644 include/crypto/esdm.h
 rename {crypto => include/crypto/internal}/jitterentropy.h (100%)
Signature · 1 line
2.33.1
#1 lore raw

PATCH 1/7 crypto: DRBG - remove internal reseeding operation

The DRBG's internal seeding support is completely removed. When initializing the DRBG, it is now completely unseeded. The caller must provide the seed data and perform the reseeding as needed using the standard API of crypto_rng_reset.

The seeding and reseeding is a security-critical task which is provided with a separate framework, the entropy source and DRNG manager (ESDM). When using the ESDM, the DRBG may be integrated to offer a fully seeded DRBG. The output of the ESDM in this case is generated from the DRBG, but the ESDM ensures the DRBG is appropriately seeded and reseeded.

The change removes the "prediction resistance" variants of the DRBG. Those variants would cause the DRBG to constantly reseed from the entropy sources. As the seeding is appropriately performed by the ESDM, the prediction resistance variants are not needed.

Due to the limitations of the kernel crypto API RNG framework, adding a personalization string is not supported during initial seeding. In addition, providing an additional information string during reseeding is not supported by the DRBG. If a user wants to still apply either string, the caller must concatenate it to the seed that is submitted to the DRBG. Yet, using an additional information string during the generation of random numbers is supported. The patch implies that the DRBG fully complies with the kernel crypto API RNG framework interfaces. All auxiliary interfaces are removed.

The change also simplifies the drbg_instantiate function: the resolution of the coreref is now performed in the drbg_instantiate function as it is only needed during initial seeding. Subsequent reseeding operations flowing through this function do not need to perform this resolution.

The DRBG code now rejects the initial instantiation with an empty seed buffer. An empty seed buffer during initial instantiation implies that the DRBG will not be seeded and does not have any internal state based on seed. Thus, a crypto_rng_reset(tfm, NULL, 0) immediately after an crypto_alloc_rng() will now fail.

In addition, the patch removes FIPS 140-2 continuous test as its more sane equivalent is handled by the ESDM by applying a proper health test to the entropy sources that deliver entropy.

The change is validated with the NIST ACVP reference implementation. The testing covered:

- Hash DRBG with SHA-1, SHA-256, SHA-384, SHA-512

- HMAC DRBG with SHA-1, SHA-256, SHA-384, SHA-512

- CTR DRBG with AES-128, AES-192, AES-256

- reseeding, but without additional information

- no reseeding, but with additional information

---
 crypto/algif_rng.c    |   3 +-
 crypto/drbg.c         | 640 ++++++++---------------------------------
 crypto/testmgr.c      |  96 +------
 crypto/testmgr.h      | 641 +-----------------------------------------
 include/crypto/drbg.h |  84 ------
 5 files changed, 140 insertions(+), 1324 deletions(-)
crypto/algif_rng.c +2 -1
index 407408c43730..b204f1427542 100644
@@ -305,7 +305,8 @@ static int __maybe_unused rng_setentropy(void *private, sockptr_t entropy,
 			return PTR_ERR(kentropy);
 	}
 
-	crypto_rng_alg(pctx->drng)->set_ent(pctx->drng, kentropy, len);
+	if (crypto_rng_alg(pctx->drng)->set_ent)
+		crypto_rng_alg(pctx->drng)->set_ent(pctx->drng, kentropy, len);
 	/*
 	 * Since rng doesn't perform any memory management for the entropy
 	 * buffer, save kentropy pointer to pctx now to free it after use.
crypto/drbg.c +125 -515

897 lines not on this page · raw message

crypto/testmgr.c +8 -88

146 lines not on this page · raw message

crypto/testmgr.h +5 -636

715 lines not on this page · raw message

include/crypto/drbg.h +0 -84

110 lines not on this page · raw message

Signature · 1 line
2.33.1
#2 lore raw

Re: [PATCH 1/7] crypto: DRBG - remove internal reseeding operation

Thank you for the patch! Yet something to improve:

Hi "Stephan,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on herbert-cryptodev-2.6/master]
[also build test ERROR on herbert-crypto-2.6/master linus/master v5.17-rc1 next-20220125] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Stephan-M-ller/Common-entropy-source-and-DRNG-management/20220126-150911
base:   https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master
config: hexagon-buildonly-randconfig-r003-20220124 (https://download.01.org/0day-ci/archive/20220126/202201262050.xFgnR1Kx-lkp(a)intel.com/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 2a1b7aa016c0f4b5598806205bdfbab1ea2d92c4)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/14ec08bbd20e04299353eb31a9d43d4ac9af2b22
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Stephan-M-ller/Common-entropy-source-and-DRNG-management/20220126-150911 git checkout 14ec08bbd20e04299353eb31a9d43d4ac9af2b22
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

crypto/drbg.c:204:30: warning: unused function 'drbg_sec_strength' [-Wunused-function] static inline unsigned short drbg_sec_strength(drbg_flag_t flags)

                                ^
>> crypto/drbg.c:1742:2: error: call to __compiletime_assert_223 declared with 'error' attribute: BUILD_BUG_ON failed: ARRAY_SIZE(drbg_cores) != ARRAY_SIZE(drbg_algs)
           BUILD_BUG_ON(ARRAY_SIZE(drbg_cores) != ARRAY_SIZE(drbg_algs));
           ^
   include/linux/build_bug.h:50:2: note: expanded from macro 'BUILD_BUG_ON'
           BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
           ^
   include/linux/build_bug.h:39:37: note: expanded from macro 'BUILD_BUG_ON_MSG'
   #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                       ^
   include/linux/compiler_types.h:335:2: note: expanded from macro 'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
           ^
   include/linux/compiler_types.h:323:2: note: expanded from macro '_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:316:4: note: expanded from macro '__compiletime_assert'
                           prefix ## suffix();                             \
                           ^

<scratch space>:63:1: note: expanded from here
__compiletime_assert_223
^
1 warning and 1 error generated.

vim +/error +1742 crypto/drbg.c

1732
1733 static int __init drbg_init(void)
1734 {
1735 unsigned int i;
1736 int ret;
1737
1738 ret = drbg_healthcheck_sanity();
1739 if (ret)
1740 return ret;
1741

> 1742		BUILD_BUG_ON(ARRAY_SIZE(drbg_cores) != ARRAY_SIZE(drbg_algs));

1743
1744 /*
1745 * As the order of placing them into the drbg_algs array matters
1746 * (the later DRBGs receive a higher cra_priority) we register the
1747 * prediction resistance DRBGs first as the should not be too
1748 * interesting.
1749 */
1750 for (i = 0; i < ARRAY_SIZE(drbg_cores); i++)
1751 drbg_fill_array(&drbg_algs[i], &drbg_cores[i]);
1752 return crypto_register_rngs(drbg_algs, ARRAY_SIZE(drbg_cores));
1753 }
1754

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

#3 lore raw

Re: [PATCH 1/7] crypto: DRBG - remove internal reseeding operation

Am Mittwoch, 26. Januar 2022, 13:15:04 CET schrieb kernel test robot:

Hi,

Quoted 3 lines

crypto/drbg.c:204:30: warning: unused function 'drbg_sec_strength'
[-Wunused-function] static inline unsigned short drbg_sec_strength(drbg_flag_t flags) ^

It is interesting that Sparse did not complain about this. Anyhow, this function is not needed and will be removed.

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines

crypto/drbg.c:1742:2: error: call to __compiletime_assert_223 declared with 'error' attribute: BUILD_BUG_ON failed: ARRAY_SIZE(drbg_cores) != ARRAY_SIZE(drbg_algs)

           BUILD_BUG_ON(ARRAY_SIZE(drbg_cores) != ARRAY_SIZE(drbg_algs));

Correct, it should be > instead of != :-)

This will be fixed in the new code base

Thanks!

Ciao
Stephan

#4 lore raw

PATCH 2/7 crypto: AF_ALG - remove ALG_SET_DRBG_ENTROPY interface

In reply to Stephan Müller

The ALG_SET_DRBG_ENTROPY was added to test the DRBG implementation provided with the kernel crypto API. This interface was used to set a "test entropy" string to bypass the DRBG-internal seeding mechanism.

Since the DRBG-internal seeding mechanism is completely removed, the special bypass is not needed any more. The entropy string for the DRBG can be set with the crypto_rng_reset() function that is invoked with the ALG_SET_KEY interface.

The change enables the sendmsg implementation in AF_ALG RNG for a general use. The sendmsg allows user space to set the input data to the crypto_rng_generate function call.

The change still allows the full testing of the DRBG which was verified with libkcapi version 1.5.0 covering the following aspects:

- Hash DRBG with SHA-1, SHA-256, SHA-384, SHA-512

- HMAC DRBG with SHA-1, SHA-256, SHA-384, SHA-512

- CTR DRBG with AES-128, AES-192, AES-256

- reseeding, but without additional information

- no reseeding, but with additional information

The limitation of the test is defined with algif_rng.c:MAXSIZE which restricts the allowed output size for testing to 128 bytes.

---
 crypto/Kconfig                |  9 -----
 crypto/af_alg.c               |  7 ----
 crypto/algif_rng.c            | 75 +----------------------------------
 include/crypto/if_alg.h       |  1 -
 include/crypto/internal/rng.h |  6 ---
 include/crypto/rng.h          |  4 --
 include/uapi/linux/if_alg.h   |  2 +-
 7 files changed, 3 insertions(+), 101 deletions(-)
crypto/Kconfig +0 -9
index 442765219c37..a0de01ab6f0c 100644
@@ -1879,15 +1879,6 @@ config CRYPTO_USER_API_RNG
 	  This option enables the user-spaces interface for random
 	  number generator algorithms.
 
-config CRYPTO_USER_API_RNG_CAVP
-	bool "Enable CAVP testing of DRBG"
-	depends on CRYPTO_USER_API_RNG && CRYPTO_DRBG
-	help
-	  This option enables extra API for CAVP testing via the user-space
-	  interface: resetting of DRBG entropy, and providing Additional Data.
-	  This should only be enabled for CAVP testing. You should say
-	  no unless you know what this is.
-
 config CRYPTO_USER_API_AEAD
 	tristate "User-space interface for AEAD cipher algorithms"
 	depends on NET
crypto/af_alg.c +0 -7
index e1ea18536a5f..6e5222fd10e2 100644
@@ -259,13 +259,6 @@ static int alg_setsockopt(struct socket *sock, int level, int optname,
 			goto unlock;
 		err = type->setauthsize(ask->private, optlen);
 		break;
-	case ALG_SET_DRBG_ENTROPY:
-		if (sock->state == SS_CONNECTED)
-			goto unlock;
-		if (!type->setentropy)
-			goto unlock;
-
-		err = type->setentropy(ask->private, optval, optlen);
 	}
 
 unlock:
crypto/algif_rng.c +2 -73

120 lines not on this page · raw message

include/crypto/if_alg.h +0 -1
index a5db86670bdf..ee6412314f8f 100644
@@ -46,7 +46,6 @@ struct af_alg_type {
 	void *(*bind)(const char *name, u32 type, u32 mask);
 	void (*release)(void *private);
 	int (*setkey)(void *private, const u8 *key, unsigned int keylen);
-	int (*setentropy)(void *private, sockptr_t entropy, unsigned int len);
 	int (*accept)(void *private, struct sock *sk);
 	int (*accept_nokey)(void *private, struct sock *sk);
 	int (*setauthsize)(void *private, unsigned int authsize);
include/crypto/internal/rng.h +0 -6
index e0711b6a597f..bf6da44f9e82 100644
@@ -31,10 +31,4 @@ static inline void *crypto_rng_ctx(struct crypto_rng *tfm)
 	return crypto_tfm_ctx(&tfm->base);
 }
 
-static inline void crypto_rng_set_entropy(struct crypto_rng *tfm,
-					  const u8 *data, unsigned int len)
-{
-	crypto_rng_alg(tfm)->set_ent(tfm, data, len);
-}
-
 #endif
include/crypto/rng.h +0 -4
index 17bb3673d3c1..85312ea12274 100644
@@ -28,8 +28,6 @@ struct crypto_rng;
  *		up a new state, the seed must be provided by the
  *		consumer while invoking this function. The required
  *		size of the seed is defined with @seedsize .
- * @set_ent:	Set entropy that would otherwise be obtained from
- *		entropy source.  Internal use only.
  * @seedsize:	The seed size required for a random number generator
  *		initialization defined with this variable. Some
  *		random number generators does not require a seed
@@ -43,8 +41,6 @@ struct rng_alg {
 			const u8 *src, unsigned int slen,
 			u8 *dst, unsigned int dlen);
 	int (*seed)(struct crypto_rng *tfm, const u8 *seed, unsigned int slen);
-	void (*set_ent)(struct crypto_rng *tfm, const u8 *data,
-			unsigned int len);
 
 	unsigned int seedsize;
 
include/uapi/linux/if_alg.h +1 -1
index dc52a11ba6d1..e8d676350c8f 100644
@@ -51,7 +51,7 @@ struct af_alg_iv {
 #define ALG_SET_OP			3
 #define ALG_SET_AEAD_ASSOCLEN		4
 #define ALG_SET_AEAD_AUTHSIZE		5
-#define ALG_SET_DRBG_ENTROPY		6
+#define ALG_SET_DRBG_ENTROPY		6 /* Not implemented any more */
 
 /* Operations */
 #define ALG_OP_DECRYPT			0
Signature · 1 line
2.33.1
#5 lore raw

PATCH 3/7 crypto: Entropy Source and DRNG Manager

In reply to Stephan Müller

The kernel crypto API contains deterministic random number generators (DRNG) which a caller must seed and reseed. The task of seeding a DRNG is a non-trivial task requiring the consideration of a significant number of aspects. The Entropy Source and DRNG Manager (ESDM) fills that gap to transparently seed and reseed DRNGs. A user of the ESDM obtains random numbers from an appropriately seeded and initialized DRNG. Further, the ESDM controls various entropy sources guaranteeing that they are properly initialized and managed.

The ESDM consists of two main parts:

- The entropy source (ES) manager implemented in esdm_es_mgr.c controls the available entropy sources including pulling appropritate amount of data from them for the DRNG manager.

- The DRNG manager provided with esdm_drng_mgr.c controls the DRNG(s) and ensures proper seeding and reseeding.

The entropy source manager controls the entropy sources registered in the esdm_es array. The entropy sources provide a function pointer data structure that is used to obtain the services from it.

The ES manager triggers the initial seeding of the DRNGs during boot time in three stages:

1. The DRNG is seeded from the entropy sources if all entropy sources collectively have at least 32 bits of entropy available. The goal of this step is to ensure that the DRNG receive some initial entropy as early as possible.

2. The DRNG is reseeded from the entropy sources if all entropy sources collectively have at least 128 bits of entropy available.

3. The DRNG is reseeded from the entropy sources if all entropy sources collectively have at least 256 bits of entropy available.

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 for example when the entropy pool contains 128 or more bits of entropy, the DRNG is seeded with that amount of entropy as well.

Entropy sources (ES) inform the ES manager when new entropy has been collected using the esdm_es_add_entropy() function. That function schedules a DRNG (re)seed with the DRNG manager. When the DRNG manager requests entropy data, the function esdm_fill_seed_buffer fills the seed buffer by iterating through all available ES. The output of all entropy sources is concatenated with each other. Further, the seed buffer contains the amount of entropy each entropy credits its data. Finally a time stamp is added.

The ES trigger such (re)seeding events only as long as not all DRNGs are fully seeded with 256 bits of entropy. Once that seeding level is reached, the triggers are not further processed.

The DRNG manager initializes the initial DRNG instance during late stage of the kernel boot process before user space is triggered. The DRNG is seeded at the following occasions:

- when the DRNG is initialized, the available amount of entropy is used,

- during boot time until the DRNG is fully initialized, the reaching of the aforementioned seeding steps of 32/128/256 bits of entropy trigger a reseed of the DRNG.

- at runtime after the elapse of 600 seconds since the last seeding, the DRNG reseeding flag is raised

- at runtime when more than 2^20 generate operations were performed by the given DRNG since last reseeding, the reseeding flag is raised

Raising the reseeding flag implies that the DRNG is seeded in process context the next time a caller requests random numbers.

At runtime, the DRNG manager requires at least 128 bits of entropy from the entropy sources (or 256 bits when the FIPS mode is active to be SP800-90C compliant). It may be possible that the entropy sources may not deliver that amount. The DRNG is reseeded with the available amount of entropy and continues to operate. Yet, when after 2^30 generate requests since the last seeding with 128 bits (or 256 bits in FIPS mode) the DRNG cannot be seeded with 128 bits (or 256 bits), the DRNG becomes unseeded which means it will not produce random numbers until it is fully reseeded again.

To support the DRNG manager, a DRNG implementation is provided with esdm_drng_kcapi.c. It uses the kernel crypto API RNG framework and allows the specification of the used DRNG with the kernel command line option of esdm_drng_kcapi.drng_name. If no reference is given, the default is the SP800-90A DRBG. In case the chosen DRNG requires the seed to have a certain length, a hash is used bring the entropy buffer into the proper size.

In addition, the DRNG manager controls the message digest implementation offered to entropy sources when they want to perform a conditioning operation. As entropy sources may require the conditioning operation at any time, the default is a SHA-256 software hash implementation that neither sleeps nor does it need any memory allocation operation. Therefore, this hash is available even for the earliest kernel operations.

The initial drop of the ESDM includes the entropy source of the "auxiliary" pool. This entropy source must always be present. It is an entropy pool that is based on the state of a message digest. Every insertion of data is a hash update operation. In order to obtain data, a hash final operation is performed. The purpose of this auxiliary pool is twofold:

- Provide a general interface to inject an arbitrary amount of data from any external source. When providing such data, the caller may specify the amount of entropy it contains.

- The auxiliary pool also provides the backtracking resistance for all entropy sources. Once a seed buffer is filled from all entropy sources it is re-inserted into the auxiliary pool at the same time it is used for seeding the DRNG. Naturally, the insertion of the seed buffer into the auxiliary pool is not credited with any entropy.

If enabled during compile time with the option of CONFIG_CRYPTO_ESDM_OVERSAMPLE_ENTROPY_SOURCES, the entropy source oversampling is activated. However, this oversampling is only enforced if the kernel is booted with fips=1. The oversampling pulls 128 more bits of entropy than originally requested. This implies that when 256 bits of entropy are requested for a (re)seed of a DRNG, the ES are queried for 384 bits. This oversampling complies with SP800-90C.

---
 crypto/Kconfig                 |   2 +
 crypto/Makefile                |   1 +
 crypto/esdm/Kconfig            |  79 +++++++
 crypto/esdm/Makefile           |  10 +
 crypto/esdm/esdm_definitions.h | 141 ++++++++++++
 crypto/esdm/esdm_drng_kcapi.c  | 201 +++++++++++++++++
 crypto/esdm/esdm_drng_kcapi.h  |  13 ++
 crypto/esdm/esdm_drng_mgr.c    | 398 +++++++++++++++++++++++++++++++++
 crypto/esdm/esdm_drng_mgr.h    |  85 +++++++
 crypto/esdm/esdm_es_aux.c      | 332 +++++++++++++++++++++++++++
 crypto/esdm/esdm_es_aux.h      |  44 ++++
 crypto/esdm/esdm_es_mgr.c      | 364 ++++++++++++++++++++++++++++++
 crypto/esdm/esdm_es_mgr.h      |  46 ++++
 crypto/esdm/esdm_es_mgr_cb.h   |  67 ++++++
 crypto/esdm/esdm_sha.h         |  14 ++
 crypto/esdm/esdm_sha256.c      |  72 ++++++
 include/crypto/esdm.h          | 115 ++++++++++
 17 files changed, 1984 insertions(+)
 create mode 100644 crypto/esdm/Kconfig
 create mode 100644 crypto/esdm/Makefile
 create mode 100644 crypto/esdm/esdm_definitions.h
 create mode 100644 crypto/esdm/esdm_drng_kcapi.c
 create mode 100644 crypto/esdm/esdm_drng_kcapi.h
 create mode 100644 crypto/esdm/esdm_drng_mgr.c
 create mode 100644 crypto/esdm/esdm_drng_mgr.h
 create mode 100644 crypto/esdm/esdm_es_aux.c
 create mode 100644 crypto/esdm/esdm_es_aux.h
 create mode 100644 crypto/esdm/esdm_es_mgr.c
 create mode 100644 crypto/esdm/esdm_es_mgr.h
 create mode 100644 crypto/esdm/esdm_es_mgr_cb.h
 create mode 100644 crypto/esdm/esdm_sha.h
 create mode 100644 crypto/esdm/esdm_sha256.c
 create mode 100644 include/crypto/esdm.h
crypto/Kconfig +2 -0
index a0de01ab6f0c..91f5ed9aab4f 100644
@@ -1790,6 +1790,8 @@ config CRYPTO_ZSTD
 
 comment "Random Number Generation"
 
+source "crypto/esdm/Kconfig"
+
 config CRYPTO_ANSI_CPRNG
 	tristate "Pseudo Random Number Generation for Cryptographic modules"
 	select CRYPTO_AES
crypto/Makefile +1 -0
index d76bff8d0ffd..2b9aadbb5c69 100644
@@ -159,6 +159,7 @@ obj-$(CONFIG_CRYPTO_LZ4HC) += lz4hc.o
 obj-$(CONFIG_CRYPTO_XXHASH) += xxhash_generic.o
 obj-$(CONFIG_CRYPTO_842) += 842.o
 obj-$(CONFIG_CRYPTO_RNG2) += rng.o
+obj-$(CONFIG_CRYPTO_ESDM) += esdm/
 obj-$(CONFIG_CRYPTO_ANSI_CPRNG) += ansi_cprng.o
 obj-$(CONFIG_CRYPTO_DRBG) += drbg.o
 obj-$(CONFIG_CRYPTO_JITTERENTROPY) += jitterentropy_rng.o
crypto/esdm/Kconfig new file +79 -0

79 lines not on this page · raw message

crypto/esdm/Makefile new file +10 -0
new file mode 100644
index 000000000000..24dc7af234b6
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for the Entropy Source and DRNG Manager.
+#
+
+obj-y					+= esdm_es_mgr.o esdm_drng_mgr.o \
+					   esdm_es_aux.o
+obj-$(CONFIG_CRYPTO_ESDM_SHA256)	+= esdm_sha256.o
+
+obj-$(CONFIG_CRYPTO_ESDM_DRNG_KCAPI)	+= esdm_drng_kcapi.o
crypto/esdm/esdm_definitions.h new file +141 -0

141 lines not on this page · raw message

crypto/esdm/esdm_drng_kcapi.c new file +201 -0

201 lines not on this page · raw message

crypto/esdm/esdm_drng_kcapi.h new file +13 -0
new file mode 100644
index 000000000000..0950a15fdfaa
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/*
+ * ESDM kernel crypto API DRNG definition
+ *
+ * Copyright (C) 2022, Stephan Mueller <[email protected]>
+ */
+
+#ifndef _ESDM_KCAPI_DRNG_H
+#define _ESDM_KCAPI_DRNG_H
+
+extern const struct esdm_drng_cb esdm_kcapi_drng_cb;
+
+#endif /* _ESDM_KCAPI_DRNG_H */
crypto/esdm/esdm_drng_mgr.c new file +398 -0

398 lines not on this page · raw message

crypto/esdm/esdm_drng_mgr.h new file +85 -0

85 lines not on this page · raw message

crypto/esdm/esdm_es_aux.c new file +332 -0

332 lines not on this page · raw message

crypto/esdm/esdm_es_aux.h new file +44 -0

44 lines not on this page · raw message

crypto/esdm/esdm_es_mgr.c new file +364 -0

364 lines not on this page · raw message

crypto/esdm/esdm_es_mgr.h new file +46 -0

46 lines not on this page · raw message

crypto/esdm/esdm_es_mgr_cb.h new file +67 -0

67 lines not on this page · raw message

crypto/esdm/esdm_sha.h new file +14 -0
new file mode 100644
index 000000000000..c71662881b8d
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/*
+ * ESDM SHA definition usable in atomic contexts right from the start of the
+ * kernel.
+ *
+ * Copyright (C) 2022, Stephan Mueller <[email protected]>
+ */
+
+#ifndef _ESDM_SHA_H
+#define _ESDM_SHA_H
+
+extern const struct esdm_hash_cb esdm_sha_hash_cb;
+
+#endif /* _ESDM_SHA_H */
crypto/esdm/esdm_sha256.c new file +72 -0

72 lines not on this page · raw message

include/crypto/esdm.h new file +115 -0

115 lines not on this page · raw message

Signature · 1 line
2.33.1
#6 lore raw

PATCH 4/7 crypto: move Jitter RNG header include dir

In reply to Stephan Müller

To support the ESDM operation which uses the Jitter RNG separately from the kernel crypto API, the header file must be accessible to the ESDM code.

---
 crypto/jitterentropy-kcapi.c                        | 3 +--
 crypto/jitterentropy.c                              | 2 +-
 {crypto => include/crypto/internal}/jitterentropy.h | 0
 3 files changed, 2 insertions(+), 3 deletions(-)
 rename {crypto => include/crypto/internal}/jitterentropy.h (100%)
crypto/jitterentropy-kcapi.c +1 -2
index 2d115bec15ae..40bc51f32432 100644
@@ -41,10 +41,9 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/time.h>
+#include <crypto/internal/jitterentropy.h>
 #include <crypto/internal/rng.h>
 
-#include "jitterentropy.h"
-
 /***************************************************************************
  * Helper function
  ***************************************************************************/
crypto/jitterentropy.c +1 -1
index 93bff3213823..81b80a4d3d3a 100644
@@ -133,7 +133,7 @@ struct rand_data {
 #define JENT_ENTROPY_SAFETY_FACTOR	64
 
 #include <linux/fips.h>
-#include "jitterentropy.h"
+#include <crypto/internal/jitterentropy.h>
 
 /***************************************************************************
  * Adaptive Proportion Test
include/crypto/internal/jitterentropy.h renamed from crypto/jitterentropy.h +0 -0
similarity index 100%
rename from crypto/jitterentropy.h
rename to include/crypto/internal/jitterentropy.h
Signature · 1 line
2.33.1
#7 lore raw

PATCH 5/7 crypto: ESDM - add Jitter RNG entropy source

In reply to Stephan Müller

The Jitter RNG entropy source provided as part of the kernel crypto API is used as a separate entropy source for the ESDM. It can be enabled at compile time together with its implied entropy rate.

The entropy rate states how many bits of entropy are present in 256 bits of data from that entropy source. If a different amount of data is pulled from the entropy source, the entropy ratio is scaled accordingly.

In FIPS mode, the amount of entropy is set to 256 bits considering that this entropy source is provided with an entropy analysis demonstrating its compliance with SP800-90B and thus allowing to claim full strength.

When the entropy ratio is set to zero, the Jitter RNG provides data but without claiming any entropy for it.

In addition, the patch offers the compile time option to allow setting the entropy rate with the kernel command line using the parameter of esdm_es_jent.jent_entropy.

---
 crypto/esdm/Kconfig          |  45 ++++++++++++
 crypto/esdm/Makefile         |   2 +
 crypto/esdm/esdm_es_jent.c   | 128 +++++++++++++++++++++++++++++++++++
 crypto/esdm/esdm_es_jent.h   |  17 +++++
 crypto/esdm/esdm_es_mgr.c    |   4 ++
 crypto/esdm/esdm_es_mgr_cb.h |   3 +
 6 files changed, 199 insertions(+)
 create mode 100644 crypto/esdm/esdm_es_jent.c
 create mode 100644 crypto/esdm/esdm_es_jent.h
crypto/esdm/Kconfig +45 -0
index 1351d4d146dc..eeef71546bc3 100644
@@ -68,6 +68,51 @@ config CRYPTO_ESDM_SEED_BUFFER_INIT_ADD_BITS
 
 endmenu # "Specific DRNG seeding strategies"
 
+menu "Entropy Source Configuration"
+
+config CRYPTO_ESDM_RUNTIME_ES_CONFIG
+	bool "Enable runtime configuration of entropy sources"
+	help
+	  When enabling this option, the ESDM provides the mechanism
+	  allowing to alter the entropy rate of each entropy source
+	  during boot time and runtime.
+
+	  Each entropy source allows its entropy rate changed with
+	  a kernel command line option. When not providing any
+	  option, the default specified during kernel compilation
+	  is applied.
+
+comment "Jitter RNG Entropy Source"
+
+config CRYPTO_ESDM_JENT
+	bool "Enable Jitter RNG as ESDM Seed Source"
+	depends on CRYPTO
+	select CRYPTO_JITTERENTROPY
+	help
+	  The Linux RNG may use the Jitter RNG as entropy 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 esdm_base.jitterrng configuration
+	  variable.
+
+config CRYPTO_ESDM_JENT_ENTROPY_RATE
+	int "Jitter RNG Entropy Source Entropy Rate"
+	depends on CRYPTO_ESDM_JENT
+	range 0 256
+	default 16
+	help
+	  The option defines the amount of entropy the ESDM applies to 256
+	  bits of data obtained from the Jitter RNG entropy source. The
+	  ESDM enforces the limit that this value must be in the range
+	  between 0 and 256.
+
+	  When configuring this value to 0, the Jitter RNG entropy source
+	  will provide 256 bits of data without being credited to contain
+	  entropy.
+
+endmenu # "Entropy Source Configuration"
+
 config CRYPTO_ESDM_DRNG_KCAPI
 	bool
 	depends on CRYPTO
crypto/esdm/Makefile +2 -0
index 24dc7af234b6..99a86ce3e3af 100644
@@ -8,3 +8,5 @@ obj-y					+= esdm_es_mgr.o esdm_drng_mgr.o \
 obj-$(CONFIG_CRYPTO_ESDM_SHA256)	+= esdm_sha256.o
 
 obj-$(CONFIG_CRYPTO_ESDM_DRNG_KCAPI)	+= esdm_drng_kcapi.o
+
+obj-$(CONFIG_CRYPTO_ESDM_JENT)		+= esdm_es_jent.o
crypto/esdm/esdm_es_jent.c new file +128 -0

128 lines not on this page · raw message

crypto/esdm/esdm_es_jent.h new file +17 -0
new file mode 100644
index 000000000000..d6a48f267018
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/*
+ * Copyright (C) 2022, Stephan Mueller <[email protected]>
+ */
+
+#ifndef _ESDM_ES_JENT_H
+#define _ESDM_ES_JENT_H
+
+#include "esdm_es_mgr_cb.h"
+
+#ifdef CONFIG_CRYPTO_ESDM_JENT
+
+extern struct esdm_es_cb esdm_es_jent;
+
+#endif /* CONFIG_CRYPTO_ESDM_JENT */
+
+#endif /* _ESDM_ES_JENT_H */
crypto/esdm/esdm_es_mgr.c +4 -0
index 8bdef5a934a8..b7b1a4151137 100644
@@ -13,6 +13,7 @@
 
 #include "esdm_drng_mgr.h"
 #include "esdm_es_aux.h"
+#include "esdm_es_jent.h"
 #include "esdm_es_mgr.h"
 
 struct esdm_state {
@@ -54,6 +55,9 @@ u32 esdm_write_wakeup_bits = (ESDM_WRITE_WAKEUP_ENTROPY << 3);
  * enum enum esdm_external_es
  */
 struct esdm_es_cb *esdm_es[] = {
+#ifdef CONFIG_CRYPTO_ESDM_JENT
+	&esdm_es_jent,
+#endif
 	&esdm_es_aux
 };
 
crypto/esdm/esdm_es_mgr_cb.h +3 -0
index 41b39983196f..18f0e4317691 100644
@@ -14,6 +14,9 @@
 #include "esdm_drng_mgr.h"
 
 enum esdm_external_es {
+#ifdef CONFIG_CRYPTO_ESDM_JENT
+	esdm_ext_es_jitter,			/* Jitter RNG */
+#endif
 	esdm_ext_es_aux,			/* MUST BE LAST ES! */
 	esdm_ext_es_last			/* MUST be the last entry */
 };
Signature · 1 line
2.33.1
#8 lore raw

PATCH 6/7 crypto: ESDM - add Kernel RNG entropy source

In reply to Stephan Müller

The Kernel RNG entropy source is used as a separate entropy source for the ESDM. It can be enabled at compile time together with its implied entropy rate. If the FIPS mode is enabled, the entropy rate is automatically set to 0 since the entropy source is not SP800-90B compliant and thus must be considered to deliver no entropy.

As long as the Kernel RNG is not fully initialized, the entropy rate is also forced to 0.

The entropy rate states how many bits of entropy are present in 256 bits of data from that entropy source. If a different amount of data is pulled from the entropy source, the entropy ratio is scaled accordingly.

When the entropy ratio is set to zero, the Kernel RNG provides data but without claiming any entropy for it.

When the compile time switch for enabling runtime setting of the entropy rate is enabled (CONFIG_CRYPTO_ESDM_RUNTIME_ES_CONFIG), the entropy rate can be configured at the kernel command line with the option esdm_es_random.krng_entropy. If this option is not set, the default value set during compile time is used.

---
 crypto/esdm/Kconfig          |  28 ++++++++
 crypto/esdm/Makefile         |   1 +
 crypto/esdm/esdm_es_krng.c   | 120 +++++++++++++++++++++++++++++++++++
 crypto/esdm/esdm_es_krng.h   |  17 +++++
 crypto/esdm/esdm_es_mgr.c    |   4 ++
 crypto/esdm/esdm_es_mgr_cb.h |   3 +
 6 files changed, 173 insertions(+)
 create mode 100644 crypto/esdm/esdm_es_krng.c
 create mode 100644 crypto/esdm/esdm_es_krng.h
crypto/esdm/Kconfig +28 -0
index eeef71546bc3..43e11484e95c 100644
@@ -111,6 +111,34 @@ config CRYPTO_ESDM_JENT_ENTROPY_RATE
 	  will provide 256 bits of data without being credited to contain
 	  entropy.
 
+comment "Kernel RNG Entropy Source"
+
+config CRYPTO_ESDM_KERNEL_RNG
+	bool "Enable Kernel RNG as ESDM Seed Source"
+	help
+	  The Linux RNG may use the kernel RNG (random.c) as entropy
+	  source.
+
+config CRYPTO_ESDM_KERNEL_RNG_ENTROPY_RATE
+	int "Kernel RNG Entropy Source Entropy Rate"
+	depends on CRYPTO_ESDM_KERNEL_RNG
+	range 0 256
+	default 256
+	help
+	  The option defines the amount of entropy the ESDM applies to 256
+	  bits of data obtained from the kernel RNG entropy source. The
+	  ESDM enforces the limit that this value must be in the range
+	  between 0 and 256.
+
+	  When configuring this value to 0, the kernel RNG entropy source
+	  will provide 256 bits of data without being credited to contain
+	  entropy.
+
+	  Note: This value is set to 0 automatically when booting the
+	  kernel in FIPS mode (with fips=1 kernel command line option).
+	  This is due to the fact that random.c is not SP800-90B
+	  compliant.
+
 endmenu # "Entropy Source Configuration"
 
 config CRYPTO_ESDM_DRNG_KCAPI
crypto/esdm/Makefile +1 -0
index 99a86ce3e3af..404436de0aa2 100644
@@ -9,4 +9,5 @@ obj-$(CONFIG_CRYPTO_ESDM_SHA256)	+= esdm_sha256.o
 
 obj-$(CONFIG_CRYPTO_ESDM_DRNG_KCAPI)	+= esdm_drng_kcapi.o
 
+obj-$(CONFIG_CRYPTO_ESDM_KERNEL_RNG)	+= esdm_es_krng.o
 obj-$(CONFIG_CRYPTO_ESDM_JENT)		+= esdm_es_jent.o
crypto/esdm/esdm_es_krng.c new file +120 -0

120 lines not on this page · raw message

crypto/esdm/esdm_es_krng.h new file +17 -0
new file mode 100644
index 000000000000..b164594bfe79
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/*
+ * Copyright (C) 2022, Stephan Mueller <[email protected]>
+ */
+
+#ifndef _ESDM_ES_RANDOM_H
+#define _ESDM_ES_RANDOM_H
+
+#include "esdm_es_mgr_cb.h"
+
+#ifdef CONFIG_CRYPTO_ESDM_KERNEL_RNG
+
+extern struct esdm_es_cb esdm_es_krng;
+
+#endif /* CONFIG_CRYPTO_ESDM_KERNEL_RNG */
+
+#endif /* _ESDM_ES_RANDOM_H */
crypto/esdm/esdm_es_mgr.c +4 -0
index b7b1a4151137..0a65aafac8d2 100644
@@ -14,6 +14,7 @@
 #include "esdm_drng_mgr.h"
 #include "esdm_es_aux.h"
 #include "esdm_es_jent.h"
+#include "esdm_es_krng.h"
 #include "esdm_es_mgr.h"
 
 struct esdm_state {
@@ -57,6 +58,9 @@ u32 esdm_write_wakeup_bits = (ESDM_WRITE_WAKEUP_ENTROPY << 3);
 struct esdm_es_cb *esdm_es[] = {
 #ifdef CONFIG_CRYPTO_ESDM_JENT
 	&esdm_es_jent,
+#endif
+#ifdef CONFIG_CRYPTO_ESDM_KERNEL_RNG
+	&esdm_es_krng,
 #endif
 	&esdm_es_aux
 };
crypto/esdm/esdm_es_mgr_cb.h +3 -0
index 18f0e4317691..a94ad28f7d0f 100644
@@ -16,6 +16,9 @@
 enum esdm_external_es {
 #ifdef CONFIG_CRYPTO_ESDM_JENT
 	esdm_ext_es_jitter,			/* Jitter RNG */
+#endif
+#ifdef CONFIG_CRYPTO_ESDM_KERNEL_RNG
+	esdm_ext_es_krng,			/* random.c */
 #endif
 	esdm_ext_es_aux,			/* MUST BE LAST ES! */
 	esdm_ext_es_last			/* MUST be the last entry */
Signature · 1 line
2.33.1
#9 lore raw

PATCH 7/7 crypto: ESDM - add kernel crypto API RNG interface

In reply to Stephan Müller

The ESDM export interfaces that allow obtaining random numbers from a fully seeded DRNG as specified in crypto/esdm.h. By using the interface function esdm_get_random_bytes_full, the ESDM is registered as a random number generator with the kernel crypto API's RNG framework. This registered RNG provides random numbers from an always appropriately seeded and initialized DRNG.

When a caller performs a crypto_rng_reset() call on the ESDM, the ESDM injects the provided data into the auxiliary pool and flags a reseed. This reseed is performed by the immediate subsequent DRNG generation operation.

The RNG registered by the ESDM with the kernel crypto API is accessible via the name "esdm". In addition, the ESDM is registered as "stdrng" with the highest priority which implies that the kernel crypto API call of crypto_get_default_rng accesses the ESDM.

The ESDM is marked as fips_allowed = 1 in the testmgr because it complies with the FIPS 140 rules as follows:

- SP800-90A: The ESDM uses the kernel crypto API's DRBG and thus provides access to a fully seeded and SP800-90A DRBG.

- SP800-90B: The ESDM manages entropy sources via its plugins. Currently there is no internal entropy source provided which means that the used entropy sources must provide their own SP800-90B analysis. For the Jitter RNG, a separate SP800-90B analysis is provided. The ESDM only ensures that the Jitter RNG is appropriately initialized before it is used as an entropy source. The kernel RNG (random.c) entropy source on the other hand is not SP800-90B compliant. Thus, in FIPS mode, the ESDM credits its data with zero bits of entropy.

- SP800-90C: The ESDM follows the current draft of SP800-90C when compiled with the option CONFIG_CRYPTO_ESDM_OVERSAMPLE_ENTROPY_SOURCES. The DRBG is initially seeded with at least 384 bits of entropy before it is marked as fully seeded (and thus produces random numbers via the esdm_get_random_bytes_full call. Subsequent reseeds are performed with at least 256 bits of entropy. The conditioning operation performed in the auxiliary pool requires 64 more bits of entropy to be fed into the conditioner function provide the respective entropy output (e.g. 256 bits of entropy are fed into the SHA-256 conditioner resulting in the output of 192 bits of entropy provided by the entropy source to the ESDM). With the given entropy sources, the ESDM follows the RBG2(NP) construction method.

---
 crypto/esdm/Kconfig                | 14 +++++
 crypto/esdm/Makefile               |  2 +
 crypto/esdm/esdm_drng_kcapi.c      |  1 +
 crypto/esdm/esdm_interface_kcapi.c | 91 ++++++++++++++++++++++++++++++
 crypto/testmgr.c                   |  8 +++
 5 files changed, 116 insertions(+)
 create mode 100644 crypto/esdm/esdm_interface_kcapi.c
crypto/esdm/Kconfig +14 -0
index 43e11484e95c..3636c1c79602 100644
@@ -27,6 +27,20 @@ config CRYPTO_ESDM_SHA256
 	bool
 	default y if CRYPTO_LIB_SHA256
 
+menu "ESDM Interfaces"
+
+config CRYPTO_ESDM_KCAPI_IF
+	tristate "Interface with Kernel Crypto API"
+	depends on CRYPTO_RNG
+	help
+	  The ESDM can be registered with the kernel crypto API's
+	  random number generator framework. This offers a random
+	  number generator with the name "esdm" and a priority that
+	  is intended to be higher than the existing RNG
+	  implementations.
+
+endmenu # "ESDM Interfaces"
+
 menu "Specific DRNG seeding strategies"
 
 config CRYPTO_ESDM_OVERSAMPLE_ENTROPY_SOURCES
crypto/esdm/Makefile +2 -0
index 404436de0aa2..0bf8d65dd5fa 100644
@@ -11,3 +11,5 @@ obj-$(CONFIG_CRYPTO_ESDM_DRNG_KCAPI)	+= esdm_drng_kcapi.o
 
 obj-$(CONFIG_CRYPTO_ESDM_KERNEL_RNG)	+= esdm_es_krng.o
 obj-$(CONFIG_CRYPTO_ESDM_JENT)		+= esdm_es_jent.o
+
+obj-$(CONFIG_CRYPTO_ESDM_KCAPI_IF)	+= esdm_interface_kcapi.o
crypto/esdm/esdm_drng_kcapi.c +1 -0
index ae8d2be91b37..03135337196b 100644
@@ -99,6 +99,7 @@ static void *esdm_kcapi_drng_alloc(u32 sec_strength)
 	}
 
 	if (!memcmp(drng_name, "stdrng", 6) ||
+	    !memcmp(drng_name, "esdm", 4) ||
 	    !memcmp(drng_name, "jitterentropy_rng", 17)) {
 		pr_err("Refusing to load the requested random number generator\n");
 		return ERR_PTR(-EINVAL);
crypto/esdm/esdm_interface_kcapi.c new file +91 -0

91 lines not on this page · raw message

crypto/testmgr.c +8 -0
index 2ce698eb14b6..0865105f9377 100644
@@ -4878,6 +4878,14 @@ static const struct alg_test_desc alg_test_descs[] = {
 		.suite = {
 			.akcipher = __VECS(ecrdsa_tv_template)
 		}
+	}, {
+		.alg = "esdm",
+		.test = alg_test_null,
+#ifdef CONFIG_CRYPTO_ESDM_OVERSAMPLE_ENTROPY_SOURCES
+		.fips_allowed = 1,
+#else
+		.fips_allowed = 0,
+#endif
 	}, {
 		.alg = "essiv(authenc(hmac(sha256),cbc(aes)),sha256)",
 		.test = alg_test_aead,
Signature · 1 line
2.33.1
#10 lore raw
In reply to Stephan Müller
Quoted 9 lines · Stephan Müller

The current code base of the kernel crypto API random number support leaves the task to seed and reseed the DRNG to either the caller or the DRNG implementation. The code in crypto/drbg.c implements its own seeding strategy. crypto/ansi_cprng.c does not contain any seeding operation. The implementation in arch/s390/crypto/prng.c has yet another approach for seeding. Albeit the crypto_rng_reset() contains a seeding logic from get_random_bytes, there is no management of the DRNG to ensure proper reseeding or control which entropy sources are used for pulling data from.

ansi_cprng looks like unused code that should be removed, as does the s390 prng.

With that being the case, what is the purpose of this patchset?

- Eric

#11 lore raw

Am Mittwoch, 26. Januar 2022, 23:49:03 CET schrieb Eric Biggers:

Hi Eric,

Quoted 11 lines · Stephan Müller
Quoted 9 lines

The current code base of the kernel crypto API random number support leaves the task to seed and reseed the DRNG to either the caller or the DRNG implementation. The code in crypto/drbg.c implements its own seeding strategy. crypto/ansi_cprng.c does not contain any seeding operation. The implementation in arch/s390/crypto/prng.c has yet another approach for seeding. Albeit the crypto_rng_reset() contains a seeding logic from get_random_bytes, there is no management of the DRNG to ensure proper reseeding or control which entropy sources are used for pulling data from.

Quoted 4 lines

ansi_cprng looks like unused code that should be removed, as does the s390 prng.

With that being the case, what is the purpose of this patchset?

I would agree that ansi_csprng could be eliminated at this stage. However, the S390 DRBG code base provides access to the CPACF DRBG implemented in the IBM Z processors. That implementation must be seeded from software. See the function invocation of cpacf_klmd or cpacf_kmc in the prng.c file.

The extraction of the entropy source and DRNG management into its own component separates out the security sensitive implementation currently found in multiple locations following the strategy found in the crypto API where each moving part is separated and encapsulated.

The current implementation of the ESDM allows an easy addition of new entropy sources which are properly encapsulated in self-contained code allowing self- contained entropy analyses to be performed for each. These entropy sources would provide their seed data completely separate from other entropy sources to the DRNG preventing any mutual entanglement and thus challenges in the entropy assessment. I have additional entropy sources already available that I would like to contribute at a later stage. These entropy sources can be enabled, disabled or its entropy rate set as needed by vendors depending on their entropy source analysis. Proper default values would be used for the common case where a vendor does not want to perform its own analysis or a distro which want to provide a common kernel binary for many users.

The conditioning hash that is available to the entropy sources is currently fixed to a SHA-256 software implementation. To support conveying more entropy through the conditioning hash, I would like to contribute an extension that allows the use of the kernel crypto API's set of message digest implementations to be used. This would not only allow using larger message digests, but also hashes other than SHA.

Depending on use cases, it is possible that different initial seeding strategies are required to be considered for the DRNG. The initial patch set provides the oversampling of entropy sources and of the initial seed string in addition to the conventional approach of providing at least as much entropy as the security strength of the DRNG. There is a different seeding strategy in the pipeline that is considered by other cryptographers for which I would like to contribute the respective patch.

NUMA-awareness is another aspect that should be considered. The DRNG manager is prepared to instantiate one DRNG per node. The respective handler code, however, is not part of the initial code drop.

In addition to the different DRNG implementations discussed before, there is the possibility to add an implementation to support atomic operations. The current DRBG does not guarantee to be suitable for such use cases.

Ciao
Stephan

#12 lore raw
Quoted 18 lines · Stephan Mueller

Am Mittwoch, 26. Januar 2022, 23:49:03 CET schrieb Eric Biggers:

Hi Eric,

Quoted 14 lines · Stephan Müller
Quoted 9 lines

The current code base of the kernel crypto API random number support leaves the task to seed and reseed the DRNG to either the caller or the DRNG implementation. The code in crypto/drbg.c implements its own seeding strategy. crypto/ansi_cprng.c does not contain any seeding operation. The implementation in arch/s390/crypto/prng.c has yet another approach for seeding. Albeit the crypto_rng_reset() contains a seeding logic from get_random_bytes, there is no management of the DRNG to ensure proper reseeding or control which entropy sources are used for pulling data from.

ansi_cprng looks like unused code that should be removed, as does the s390 prng.

Quoted 6 lines
Quoted 1 line

With that being the case, what is the purpose of this patchset?

I would agree that ansi_csprng could be eliminated at this stage. However, the S390 DRBG code base provides access to the CPACF DRBG implemented in the IBM Z processors. That implementation must be seeded from software. See the function invocation of cpacf_klmd or cpacf_kmc in the prng.c file.

We should still just get rid of that, since equivalent functionality is available in software, is better tested, and isn't performance-critical.

Quoted 5 lines

The extraction of the entropy source and DRNG management into its own component separates out the security sensitive implementation currently found in multiple locations following the strategy found in the crypto API where each moving part is separated and encapsulated.

Quoted 11 lines

The current implementation of the ESDM allows an easy addition of new entropy sources which are properly encapsulated in self-contained code allowing self- contained entropy analyses to be performed for each. These entropy sources would provide their seed data completely separate from other entropy sources to the DRNG preventing any mutual entanglement and thus challenges in the entropy assessment. I have additional entropy sources already available that I would like to contribute at a later stage. These entropy sources can be enabled, disabled or its entropy rate set as needed by vendors depending on their entropy source analysis. Proper default values would be used for the common case where a vendor does not want to perform its own analysis or a distro which want to provide a common kernel binary for many users.

What is the actual point of this? The NIST DRBGs are already seeded from random.c, which is sufficient by itself but doesn't play well with certifications, and from Jitterentropy which the certification side is happy with. And the NIST DRBGs are only present for certification purposes anyway; all real users use random.c instead. So what problem still needs to be solved?

Quoted 7 lines

The conditioning hash that is available to the entropy sources is currently fixed to a SHA-256 software implementation. To support conveying more entropy through the conditioning hash, I would like to contribute an extension that allows the use of the kernel crypto API's set of message digest implementations to be used. This would not only allow using larger message digests, but also hashes other than SHA.

This doesn't need to be configurable, and shouldn't be; just choose an appropriate hash.

Quoted 7 lines

Depending on use cases, it is possible that different initial seeding strategies are required to be considered for the DRNG. The initial patch set provides the oversampling of entropy sources and of the initial seed string in addition to the conventional approach of providing at least as much entropy as the security strength of the DRNG. There is a different seeding strategy in the pipeline that is considered by other cryptographers for which I would like to contribute the respective patch.

It would be better to standardize on one way of doing it so that people can't choose the wrong way.

Quoted 3 lines

NUMA-awareness is another aspect that should be considered. The DRNG manager is prepared to instantiate one DRNG per node. The respective handler code, however, is not part of the initial code drop.

random.c is already NUMA-optimized.

Quoted 3 lines

In addition to the different DRNG implementations discussed before, there is the possibility to add an implementation to support atomic operations. The current DRBG does not guarantee to be suitable for such use cases.

random.c already supports atomic operations.

- Eric

maintainer
#13 lore raw
Quoted 18 lines · Eric Biggers
Quoted 6 lines

The extraction of the entropy source and DRNG management into its own component separates out the security sensitive implementation currently found in multiple locations following the strategy found in the crypto API where each moving part is separated and encapsulated.

Quoted 11 lines

The current implementation of the ESDM allows an easy addition of new entropy sources which are properly encapsulated in self-contained code allowing self- contained entropy analyses to be performed for each. These entropy sources would provide their seed data completely separate from other entropy sources to the DRNG preventing any mutual entanglement and thus challenges in the entropy assessment. I have additional entropy sources already available that I would like to contribute at a later stage. These entropy sources can be enabled, disabled or its entropy rate set as needed by vendors depending on their entropy source analysis. Proper default values would be used for the common case where a vendor does not want to perform its own analysis or a distro which want to provide a common kernel binary for many users.

Quoted 5 lines

What is the actual point of this? The NIST DRBGs are already seeded from random.c, which is sufficient by itself but doesn't play well with certifications, and from Jitterentropy which the certification side is happy with. And the NIST DRBGs are only present for certification purposes anyway; all real users use random.c instead. So what problem still needs to be solved?

Indeed. Stephan, could you please explain exactly what additional seeding sources are needed over the current jitter+/dev/random sources (and why). Or even better, add those seeding sources that we must have in your patch series so that they can be evaluated together.

As it stands this patch series seems to be adding a lot of code without any uses.

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
#14 lore raw

Am Samstag, 5. Februar 2022, 04:50:48 CET schrieb Herbert Xu:

Hi Herbert,

Quoted 25 lines · Eric Biggers
Quoted 18 lines
Quoted 5 lines

The extraction of the entropy source and DRNG management into its own component separates out the security sensitive implementation currently found in multiple locations following the strategy found in the crypto API where each moving part is separated and encapsulated.

Quoted 13 lines

The current implementation of the ESDM allows an easy addition of new entropy sources which are properly encapsulated in self-contained code allowing self- contained entropy analyses to be performed for each. These entropy sources would provide their seed data completely separate from other entropy sources to the DRNG preventing any mutual entanglement and thus challenges in the entropy assessment. I have additional entropy sources already available that I would like to contribute at a later stage. These entropy sources can be enabled, disabled or its entropy rate set as needed by vendors depending on their entropy source analysis. Proper default values would be used for the common case where a vendor does not want to perform its own analysis or a distro which want to provide a common kernel binary for many users.>

Quoted 6 lines

What is the actual point of this? The NIST DRBGs are already seeded from random.c, which is sufficient by itself but doesn't play well with certifications, and from Jitterentropy which the certification side is happy with. And the NIST DRBGs are only present for certification purposes anyway; all real users use random.c instead. So what problem still needs to be solved?

Quoted 7 lines

Indeed. Stephan, could you please explain exactly what additional seeding sources are needed over the current jitter+/dev/random sources (and why). Or even better, add those seeding sources that we must have in your patch series so that they can be evaluated together.

As it stands this patch series seems to be adding a lot of code without any uses.

Thank you for the clarification. I will provide that information.

Quoted 2 lines

Thanks,

Ciao
Stephan