[PATCH next 1/7] random32: Improve security of prandom_u32_state()
From: David Laight
Date: Mon Nov 02 2026 - 15:07:26 EST
While security isn't that important in can easily be made a lot better.
The four LFSR are linear are reversable.
Combining the outputs with xor is still linear.
This means that the initial state of the prng can be trivially determined
from 113 output bits that have a known distance from that state.
(Each state bit is just the xor of some combination of the output bits.)
Replace the final xor with add making it non-linear and nothing like
as easy to invert.
Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
---
lib/random32.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/random32.c b/lib/random32.c
index dad90219c351..34f08f6540e6 100644
--- a/lib/random32.c
+++ b/lib/random32.c
@@ -58,7 +58,7 @@ u32 prandom_u32_state(struct rnd_state *state)
state->s3 = TAUSWORTHE(state->s3, 13U, 21U, 4294967280U, 7U);
state->s4 = TAUSWORTHE(state->s4, 3U, 12U, 4294967168U, 13U);
- return (state->s1 ^ state->s2 ^ state->s3 ^ state->s4);
+ return (state->s1 + state->s2 + state->s3 + state->s4);
}
EXPORT_SYMBOL(prandom_u32_state);
--
2.39.5