From: Markus Theil <theil.markus@gmail.com>
To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: davem@davemloft.net, akpm@linux-foundation.org, Jason@zx2c4.com,
Markus Theil <theil.markus@gmail.com>
Subject: [PATCH v2 1/4] prandom: add usage comments for cryptography
Date: Fri, 4 Jul 2025 14:52:30 +0200 [thread overview]
Message-ID: <20250704125233.2653779-2-theil.markus@gmail.com> (raw)
In-Reply-To: <20250704125233.2653779-1-theil.markus@gmail.com>
Make it more explicit, that the PRNG must not
be used for cryptographic purposes.
Future code may also check such things in checkpatch.pl,
but it is probably hard to differentiate valid testing
code only by looking at paths. Therefore this is left
out here by intention.
Signed-off-by: Markus Theil <theil.markus@gmail.com>
---
include/linux/prandom.h | 2 ++
lib/random32.c | 6 ++++++
2 files changed, 8 insertions(+)
diff --git a/include/linux/prandom.h b/include/linux/prandom.h
index ff7dcc3fa105..63d1fe4b30c8 100644
--- a/include/linux/prandom.h
+++ b/include/linux/prandom.h
@@ -17,7 +17,9 @@ struct rnd_state {
__u32 s1, s2, s3, s4;
};
+/* WARNING: this API MUST NOT be used for cryptographic purposes! */
u32 prandom_u32_state(struct rnd_state *state);
+/* WARNING: this API MUST NOT be used for cryptographic purposes! */
void prandom_bytes_state(struct rnd_state *state, void *buf, size_t nbytes);
void prandom_seed_full_state(struct rnd_state __percpu *pcpu_state);
diff --git a/lib/random32.c b/lib/random32.c
index 24e7acd9343f..c808745a4b53 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/*
+ * WARNING: this API MUST NOT be used for cryptographic purposes!
+ *
* This is a maximally equidistributed combined Tausworthe generator
* based on code from GNU Scientific Library 1.5 (30 Jun 2004)
*
@@ -48,6 +50,8 @@
*
* This is used for pseudo-randomness with no outside seeding.
* For more random results, use get_random_u32().
+ *
+ * WARNING: this API MUST NOT be used for cryptographic purposes!
*/
u32 prandom_u32_state(struct rnd_state *state)
{
@@ -70,6 +74,8 @@ EXPORT_SYMBOL(prandom_u32_state);
*
* This is used for pseudo-randomness with no outside seeding.
* For more random results, use get_random_bytes().
+ *
+ * WARNING: this API MUST NOT be used for cryptographic purposes!
*/
void prandom_bytes_state(struct rnd_state *state, void *buf, size_t bytes)
{
--
2.49.0
next prev parent reply other threads:[~2025-07-04 12:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-04 12:52 [PATCH v2 0/4] add usage hints to prandom and switch to Xoshiro Markus Theil
2025-07-04 12:52 ` Markus Theil [this message]
2025-07-04 12:52 ` [PATCH v2 2/4] prandom/random32: switch to Xoshiro256++ Markus Theil
2025-07-04 12:52 ` [PATCH v2 3/4] prandom/random32: add checks against invalid state Markus Theil
2025-07-04 12:52 ` [PATCH v2 4/4] test_hash.c: replace custom PRNG by prandom Markus Theil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250704125233.2653779-2-theil.markus@gmail.com \
--to=theil.markus@gmail.com \
--cc=Jason@zx2c4.com \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®