[PATCH 32/38] crypto: drbg - Fold drbg_prepare_hrng() into drbg_kcapi_seed()

From: Eric Biggers

Date: Mon Apr 20 2026 - 02:44:25 EST


Fold drbg_prepare_hrng() into its only caller.

Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
---
crypto/drbg.c | 34 ++++++++++++----------------------
1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/crypto/drbg.c b/crypto/drbg.c
index a9d586107ebe..45d97f3ba4ef 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -504,29 +504,10 @@ static int drbg_generate(struct drbg_state *drbg,
len = 0;
err:
return len;
}

-static int drbg_prepare_hrng(struct drbg_state *drbg)
-{
- /* We do not need an HRNG in test mode. */
- if (drbg->test_entropylen != 0)
- return 0;
-
- drbg->jent = crypto_alloc_rng("jitterentropy_rng", 0, 0);
- if (IS_ERR(drbg->jent)) {
- const int err = PTR_ERR(drbg->jent);
-
- drbg->jent = NULL;
- if (fips_enabled)
- return err;
- pr_info("DRBG: Continuing without Jitter RNG\n");
- }
-
- return 0;
-}
-
/*
* DRBG uninstantiate function as required by SP800-90A - this function
* frees all buffers and the DRBG handle
*
* @drbg DRBG state handle
@@ -600,13 +581,22 @@ static int drbg_kcapi_seed(struct crypto_rng *tfm,
drbg->last_seed_time = 0;
drbg->reseed_threshold = DRBG_MAX_REQUESTS;
memset(drbg->V, 1, DRBG_STATE_LEN);
hmac_sha512_preparekey(&drbg->key, initial_key, DRBG_STATE_LEN);

- ret = drbg_prepare_hrng(drbg);
- if (ret)
- goto free_everything;
+ /* Allocate jitterentropy_rng if not in test mode. */
+ if (drbg->test_entropylen == 0) {
+ drbg->jent = crypto_alloc_rng("jitterentropy_rng", 0, 0);
+ if (IS_ERR(drbg->jent)) {
+ ret = PTR_ERR(drbg->jent);
+ drbg->jent = NULL;
+ if (fips_enabled)
+ goto free_everything;
+ pr_info("DRBG: Continuing without Jitter RNG\n");
+ }
+ }
+
ret = drbg_seed(drbg, pers, pers_len, /* reseed= */ false);
if (ret)
goto free_everything;

return ret;
--
2.53.0