summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@kernel.org>2026-03-26 03:14:57 +0300
committerHerbert Xu <herbert@gondor.apana.org.au>2026-04-03 03:56:11 +0300
commit52b84667bbdc656b380983262ac6303caf49ef2c (patch)
treeb13889710c1319529ecb6b3b15a5ac3f094c374f /include
parent590fa5d69c27cfaecd2e8287aec78f902417c877 (diff)
downloadlinux-52b84667bbdc656b380983262ac6303caf49ef2c.tar.xz
crypto: rng - Add crypto_stdrng_get_bytes()
All callers of crypto_get_default_rng() use the following sequence: crypto_get_default_rng() crypto_rng_get_bytes(crypto_default_rng, ...) crypto_put_default_rng() While it may have been intended that callers amortize the cost of getting and putting the "default RNG" (i.e. "stdrng") over multiple calls, in practice that optimization is never used. The callers just want a function that gets random bytes from the "stdrng". Therefore, add such a function: crypto_stdrng_get_bytes(). Importantly, this decouples the callers from the crypto_rng API. That allows a later commit to make this function simply call get_random_bytes_wait() unless the kernel is in "FIPS mode". Signed-off-by: Eric Biggers <ebiggers@kernel.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'include')
-rw-r--r--include/crypto/rng.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/crypto/rng.h b/include/crypto/rng.h
index d451b54b322a..db6c3962a7df 100644
--- a/include/crypto/rng.h
+++ b/include/crypto/rng.h
@@ -63,6 +63,19 @@ int crypto_get_default_rng(void);
void crypto_put_default_rng(void);
/**
+ * crypto_stdrng_get_bytes() - get cryptographically secure random bytes
+ * @buf: output buffer holding the random numbers
+ * @len: length of the output buffer
+ *
+ * This function fills the caller-allocated buffer with random numbers using the
+ * highest-priority "stdrng" algorithm in the crypto_rng subsystem.
+ *
+ * Context: May sleep
+ * Return: 0 function was successful; < 0 if an error occurred
+ */
+int crypto_stdrng_get_bytes(void *buf, unsigned int len);
+
+/**
* DOC: Random number generator API
*
* The random number generator API is used with the ciphers of type