All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] random Remove setting of chacha state to constant values.
@ 2022-06-16  5:18 Sandy Harris
  2022-06-16  9:58 ` Jason A. Donenfeld
  0 siblings, 1 reply; 6+ messages in thread
From: Sandy Harris @ 2022-06-16  5:18 UTC (permalink / raw)
  To: Linux Crypto Mailing List, LKML, Ted Ts'o, Jason A. Donenfeld

Setting parts of the state to known constants is needed in
some Chacha applications to ensure that blocks can be processed
in parallel and that when needed (e.g. when encrypting disk
blocks) the algorithm can jump to an arbitrary part of the
output stream. In an RNG these are not required, and setting
the constants wastes cycles.

If (as we hope) the enemy does not know the state, then
this is more secure since it makes the chacha outputs
depend on more unknown bits.

If they can peek at the state or infer parts of it from
outputs, knowable values cannot possibly be worse than
known ones. This at least prevents them from using
pre-computed tables based on the known constants.

Signed-off-by: Sandy Harris <sandyinchina@gmail.com>
---
 drivers/char/random.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 655e327d425e..6df9e656a157 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -249,9 +249,7 @@ static void crng_fast_key_erasure(u8 key[CHACHA_KEY_SIZE],

     BUG_ON(random_data_len > 32);

-    chacha_init_consts(chacha_state);
     memcpy(&chacha_state[4], key, CHACHA_KEY_SIZE);
-    memset(&chacha_state[12], 0, sizeof(u32) * 4);
     chacha20_block(chacha_state, first_block);

     memcpy(key, first_block, CHACHA_KEY_SIZE);
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-06-18  9:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-16  5:18 [PATCH] random Remove setting of chacha state to constant values Sandy Harris
2022-06-16  9:58 ` Jason A. Donenfeld
2022-06-17 23:17   ` Sandy Harris
2022-06-17 23:37     ` Jason A. Donenfeld
2022-06-18  0:38       ` Sandy Harris
2022-06-18  9:49         ` Jason A. Donenfeld

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.