]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: drbg - Fold drbg_instantiate() into drbg_kcapi_seed()
authorEric Biggers <ebiggers@kernel.org>
Mon, 20 Apr 2026 06:34:14 +0000 (23:34 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 7 May 2026 08:10:01 +0000 (16:10 +0800)
Fold drbg_instantiate() 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 ef9c3e9fdf6eaf76780c02c88b67dae23f69b2f8..763c14e3786c61374bb76ac79eef807a48ecba2c 100644 (file)
@@ -526,23 +526,56 @@ static int drbg_prepare_hrng(struct drbg_state *drbg)
 }
 
 /*
- * DRBG instantiation function as required by SP800-90A - this function
- * sets up the DRBG handle, performs the initial seeding and all sanity
- * checks required by SP800-90A
+ * DRBG uninstantiate function as required by SP800-90A - this function
+ * frees all buffers and the DRBG handle
  *
- * @drbg memory of state -- if NULL, new memory is allocated
- * @pers Optional personalization string that is mixed into state
- * @pers_len Length of personalization string in bytes, may be 0
- * @pr prediction resistance enabled
+ * @drbg DRBG state handle
  *
  * return
  *     0 on success
- *     error value otherwise
  */
-static int drbg_instantiate(struct drbg_state *drbg,
-                           const u8 *pers, size_t pers_len, bool pr)
+static int drbg_uninstantiate(struct drbg_state *drbg)
+{
+       if (!IS_ERR_OR_NULL(drbg->jent))
+               crypto_free_rng(drbg->jent);
+       drbg->jent = NULL;
+
+       drbg_dealloc_state(drbg);
+       /* no scrubbing of test_data -- this shall survive an uninstantiate */
+       return 0;
+}
+
+/***************************************************************
+ * Kernel crypto API interface to DRBG
+ ***************************************************************/
+
+static int drbg_kcapi_init(struct crypto_tfm *tfm)
+{
+       struct drbg_state *drbg = crypto_tfm_ctx(tfm);
+
+       mutex_init(&drbg->drbg_mutex);
+
+       return 0;
+}
+
+/* Set test entropy in the DRBG. */
+static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,
+                                  const u8 *data, unsigned int len)
+{
+       struct drbg_state *drbg = crypto_rng_ctx(tfm);
+
+       mutex_lock(&drbg->drbg_mutex);
+       drbg->test_entropy = data;
+       drbg->test_entropylen = len;
+       mutex_unlock(&drbg->drbg_mutex);
+}
+
+/* Seed (i.e. instantiate) or re-seed the DRBG. */
+static int drbg_kcapi_seed(struct crypto_rng *tfm,
+                          const u8 *pers, size_t pers_len, bool pr)
 {
        static const u8 initial_key[DRBG_STATE_LEN]; /* all zeroes */
+       struct drbg_state *drbg = crypto_rng_ctx(tfm);
        int ret;
        bool reseed = true;
 
@@ -589,60 +622,6 @@ free_everything:
        return ret;
 }
 
-/*
- * DRBG uninstantiate function as required by SP800-90A - this function
- * frees all buffers and the DRBG handle
- *
- * @drbg DRBG state handle
- *
- * return
- *     0 on success
- */
-static int drbg_uninstantiate(struct drbg_state *drbg)
-{
-       if (!IS_ERR_OR_NULL(drbg->jent))
-               crypto_free_rng(drbg->jent);
-       drbg->jent = NULL;
-
-       drbg_dealloc_state(drbg);
-       /* no scrubbing of test_data -- this shall survive an uninstantiate */
-       return 0;
-}
-
-/***************************************************************
- * Kernel crypto API interface to DRBG
- ***************************************************************/
-
-static int drbg_kcapi_init(struct crypto_tfm *tfm)
-{
-       struct drbg_state *drbg = crypto_tfm_ctx(tfm);
-
-       mutex_init(&drbg->drbg_mutex);
-
-       return 0;
-}
-
-/* Set test entropy in the DRBG. */
-static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,
-                                  const u8 *data, unsigned int len)
-{
-       struct drbg_state *drbg = crypto_rng_ctx(tfm);
-
-       mutex_lock(&drbg->drbg_mutex);
-       drbg->test_entropy = data;
-       drbg->test_entropylen = len;
-       mutex_unlock(&drbg->drbg_mutex);
-}
-
-/* Seed (i.e. instantiate) or re-seed the DRBG. */
-static int drbg_kcapi_seed(struct crypto_rng *tfm,
-                          const u8 *seed, unsigned int slen, bool pr)
-{
-       struct drbg_state *drbg = crypto_rng_ctx(tfm);
-
-       return drbg_instantiate(drbg, seed, slen, pr);
-}
-
 static int drbg_kcapi_seed_pr(struct crypto_rng *tfm,
                              const u8 *seed, unsigned int slen)
 {