From: Eric Biggers Date: Mon, 20 Apr 2026 06:34:08 +0000 (-0700) Subject: crypto: drbg - Install separate seed functions for pr and nopr X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=7f0ef29864ebf2ab5fea04523cc0bd8f1c7d1ccd;p=thirdparty%2Fkernel%2Flinux.git 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 Signed-off-by: Herbert Xu --- diff --git a/crypto/drbg.c b/crypto/drbg.c index 161070b10f85a..c29f4ca93d1b3 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, },