[PATCH 30/38] crypto: drbg - Fold drbg_instantiate() into drbg_kcapi_seed()
From: Eric Biggers
Date: Mon Apr 20 2026 - 02:44:00 EST
Fold drbg_instantiate() into its only caller.
Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
---
crypto/drbg.c | 107 ++++++++++++++++++++------------------------------
1 file changed, 43 insertions(+), 64 deletions(-)
diff --git a/crypto/drbg.c b/crypto/drbg.c
index ef9c3e9fdf6e..763c14e3786c 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -524,27 +524,60 @@ static int drbg_prepare_hrng(struct drbg_state *drbg)
return 0;
}
/*
- * 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;
pr_devel("DRBG: Initializing DRBG with prediction resistance %s\n",
str_enabled_disabled(pr));
@@ -587,64 +620,10 @@ static int drbg_instantiate(struct drbg_state *drbg,
mutex_unlock(&drbg->drbg_mutex);
drbg_uninstantiate(drbg);
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)
{
return drbg_kcapi_seed(tfm, seed, slen, /* pr= */ true);
}
--
2.53.0