diff options
| author | Eric Biggers <ebiggers@kernel.org> | 2026-04-19 23:34:08 -0700 |
|---|---|---|
| committer | Herbert Xu <herbert@gondor.apana.org.au> | 2026-05-07 16:10:00 +0800 |
| commit | 7f0ef29864ebf2ab5fea04523cc0bd8f1c7d1ccd (patch) | |
| tree | b5f5433c863cdfb53254ae6b9f944fe43fa060a5 /crypto | |
| parent | e8806e2e97dc769e03c1fc50ed32622dad476dfb (diff) | |
| download | linux-next-7f0ef29864ebf2ab5fea04523cc0bd8f1c7d1ccd.tar.gz linux-next-7f0ef29864ebf2ab5fea04523cc0bd8f1c7d1ccd.zip | |
crypto: drbg - Install separate seed functions for pr and nopr
Set rng_alg::seed to different functions for the prediction-resistant
and non-prediction-resistant algorithms, so that the function does not
need to parse the algorithm name to figure out which algorithm it is.
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 | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/crypto/drbg.c b/crypto/drbg.c index 161070b10f85..c29f4ca93d1b 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c @@ -733,16 +733,11 @@ static int drbg_kcapi_random(struct crypto_rng *tfm, return drbg_generate_long(drbg, dst, dlen, addtl); } -/* - * Seed the DRBG invoked by the kernel crypto API - */ +/* Seed (i.e. instantiate) or re-seed the DRBG. */ static int drbg_kcapi_seed(struct crypto_rng *tfm, - const u8 *seed, unsigned int slen) + const u8 *seed, unsigned int slen, bool pr) { struct drbg_state *drbg = crypto_rng_ctx(tfm); - struct crypto_tfm *tfm_base = crypto_rng_tfm(tfm); - bool pr = memcmp(crypto_tfm_alg_driver_name(tfm_base), - "drbg_nopr_", 10) != 0; struct drbg_string string; struct drbg_string *seed_string = NULL; @@ -754,6 +749,18 @@ static int drbg_kcapi_seed(struct crypto_rng *tfm, return drbg_instantiate(drbg, seed_string, 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); +} + +static int drbg_kcapi_seed_nopr(struct crypto_rng *tfm, + const u8 *seed, unsigned int slen) +{ + return drbg_kcapi_seed(tfm, seed, slen, /* pr= */ false); +} + /*************************************************************** * Kernel module: code to load the module ***************************************************************/ @@ -827,7 +834,7 @@ static struct rng_alg drbg_algs[] = { .base.cra_module = THIS_MODULE, .base.cra_init = drbg_kcapi_init, .set_ent = drbg_kcapi_set_entropy, - .seed = drbg_kcapi_seed, + .seed = drbg_kcapi_seed_pr, .generate = drbg_kcapi_random, .base.cra_exit = drbg_kcapi_cleanup, }, @@ -839,7 +846,7 @@ static struct rng_alg drbg_algs[] = { .base.cra_module = THIS_MODULE, .base.cra_init = drbg_kcapi_init, .set_ent = drbg_kcapi_set_entropy, - .seed = drbg_kcapi_seed, + .seed = drbg_kcapi_seed_nopr, .generate = drbg_kcapi_random, .base.cra_exit = drbg_kcapi_cleanup, }, |
