]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: drbg - Fold drbg_prepare_hrng() into drbg_kcapi_seed()
authorEric Biggers <ebiggers@kernel.org>
Mon, 20 Apr 2026 06:34:16 +0000 (23:34 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 7 May 2026 08:10:01 +0000 (16:10 +0800)
Fold drbg_prepare_hrng() into its only caller.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/drbg.c

index a9d586107ebede94f386bd9512eafd0713b7489d..45d97f3ba4efee6e959682dfe0fe847b9e956411 100644 (file)
@@ -506,25 +506,6 @@ 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
@@ -602,9 +583,18 @@ static int drbg_kcapi_seed(struct crypto_rng *tfm,
        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;