diff options
| author | Eric Biggers <ebiggers@kernel.org> | 2026-04-19 23:34:14 -0700 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2026-05-07 16:10:01 +0800 |
| commit | 810ba022870bfdf7b7ac0e04db98b2891e80f59e (patch) | |
| tree | 38b99e4e887c05bb60d165c972035f4ec884796b /crypto | |
| parent | fb2d8b7003467b4c893afd6f4be579d08f8360ce (diff) | |
| download | linux-next-history-810ba022870bfdf7b7ac0e04db98b2891e80f59e.tar.gz | |
crypto: drbg - Fold drbg_instantiate() into drbg_kcapi_seed()
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>
Diffstat (limited to 'crypto')
| -rw-r--r-- | crypto/drbg.c | 107 |
1 files changed, 43 insertions, 64 deletions
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) { |
