From: Eric Biggers Date: Mon, 20 Apr 2026 06:34:14 +0000 (-0700) Subject: crypto: drbg - Fold drbg_instantiate() into drbg_kcapi_seed() X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=810ba022870bfdf7b7ac0e04db98b2891e80f59e;p=thirdparty%2Fkernel%2Flinux.git crypto: drbg - Fold drbg_instantiate() into drbg_kcapi_seed() Fold drbg_instantiate() into its only caller. Signed-off-by: Eric Biggers Signed-off-by: Herbert Xu --- diff --git a/crypto/drbg.c b/crypto/drbg.c index ef9c3e9fdf6ea..763c14e3786c6 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -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) {