aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
authorEric Biggers <ebiggers@kernel.org>2026-04-19 23:34:13 -0700
committerHerbert Xu <herbert@gondor.apana.org.au>2026-05-07 16:10:01 +0800
commitfb2d8b7003467b4c893afd6f4be579d08f8360ce (patch)
treed4dae2ada4b1d20b13c83831cde898a1e1cd2a35 /crypto
parent7ba94ec2d896590d2200ac7999f6a7fae970e72b (diff)
downloadlinux-next-history-fb2d8b7003467b4c893afd6f4be579d08f8360ce.tar.gz
crypto: drbg - Put rng_alg methods in logical order
Put the DRBG implementation of the rng_alg methods in the order in which they're called (cra_init => set_ent => seed => generate => cra_exit) so that it's easier to understand the flow. Also rename drbg_kcapi_random to drbg_kcapi_generate, and drbg_kcapi_cleanup to drbg_kcapi_exit, so they match the method names. 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.c82
1 files changed, 36 insertions, 46 deletions
diff --git a/crypto/drbg.c b/crypto/drbg.c
index 9ff1a0e1b129c..ef9c3e9fdf6ea 100644
--- a/crypto/drbg.c
+++ b/crypto/drbg.c
@@ -609,13 +609,20 @@ static int drbg_uninstantiate(struct drbg_state *drbg)
return 0;
}
-/*
- * Helper function for setting the test data in the DRBG
- *
- * @drbg DRBG state handle
- * @data test data
- * @len test data length
- */
+/***************************************************************
+ * 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)
{
@@ -627,22 +634,25 @@ static void drbg_kcapi_set_entropy(struct crypto_rng *tfm,
mutex_unlock(&drbg->drbg_mutex);
}
-/***************************************************************
- * Kernel crypto API interface to register DRBG
- ***************************************************************/
-
-static int drbg_kcapi_init(struct crypto_tfm *tfm)
+/* 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_tfm_ctx(tfm);
+ struct drbg_state *drbg = crypto_rng_ctx(tfm);
- mutex_init(&drbg->drbg_mutex);
+ return drbg_instantiate(drbg, seed, slen, pr);
+}
- return 0;
+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 void drbg_kcapi_cleanup(struct crypto_tfm *tfm)
+static int drbg_kcapi_seed_nopr(struct crypto_rng *tfm,
+ const u8 *seed, unsigned int slen)
{
- drbg_uninstantiate(crypto_tfm_ctx(tfm));
+ return drbg_kcapi_seed(tfm, seed, slen, /* pr= */ false);
}
/*
@@ -653,9 +663,9 @@ static void drbg_kcapi_cleanup(struct crypto_tfm *tfm)
* dst is the output buffer where random data is to be stored.
* dlen is the length of dst.
*/
-static int drbg_kcapi_random(struct crypto_rng *tfm,
- const u8 *src, unsigned int slen,
- u8 *dst, unsigned int dlen)
+static int drbg_kcapi_generate(struct crypto_rng *tfm,
+ const u8 *src, unsigned int slen,
+ u8 *dst, unsigned int dlen)
{
struct drbg_state *drbg = crypto_rng_ctx(tfm);
@@ -678,31 +688,11 @@ static int drbg_kcapi_random(struct crypto_rng *tfm,
return 0;
}
-/* 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)
+static void drbg_kcapi_exit(struct crypto_tfm *tfm)
{
- 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);
-}
-
-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);
+ drbg_uninstantiate(crypto_tfm_ctx(tfm));
}
-/***************************************************************
- * Kernel module: code to load the module
- ***************************************************************/
-
/*
* Tests as defined in 11.3.2 in addition to the cipher tests: testing
* of the error handling.
@@ -769,8 +759,8 @@ static struct rng_alg drbg_algs[] = {
.base.cra_init = drbg_kcapi_init,
.set_ent = drbg_kcapi_set_entropy,
.seed = drbg_kcapi_seed_pr,
- .generate = drbg_kcapi_random,
- .base.cra_exit = drbg_kcapi_cleanup,
+ .generate = drbg_kcapi_generate,
+ .base.cra_exit = drbg_kcapi_exit,
},
{
.base.cra_name = "stdrng",
@@ -781,8 +771,8 @@ static struct rng_alg drbg_algs[] = {
.base.cra_init = drbg_kcapi_init,
.set_ent = drbg_kcapi_set_entropy,
.seed = drbg_kcapi_seed_nopr,
- .generate = drbg_kcapi_random,
- .base.cra_exit = drbg_kcapi_cleanup,
+ .generate = drbg_kcapi_generate,
+ .base.cra_exit = drbg_kcapi_exit,
},
};