Thread (2 messages) 2 messages, 2 authors, 2021-12-31

Re: [PATCH v2] random: early initialization of ChaCha constants

From: "Jason A. Donenfeld" <Jason@zx2c4.com>
Date: 2021-12-31 11:31:40
Also in: lkml
Subsystem: random number driver, the rest · Maintainers: "Theodore Ts'o", Jason A. Donenfeld, Linus Torvalds

Thanks, looks good. I tried briefly to break it with the following
assertion thing, but didn't come up with any hits, so it looks like
we're all set. Prior to applying this patch, I found the easiest way
of triggering the below crash was by enabling
CONFIG_SLAB_FREELIST_RANDOM.
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 4de0feb69781..0d9ac045943f 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1035,6 +1035,10 @@ static void _extract_crng(struct crng_state *crng,
  spin_lock_irqsave(&crng->lock, flags);
  if (arch_get_random_long(&v))
  crng->state[14] ^= v;
+ BUG_ON(crng->state[0] != CHACHA_CONSTANT_EXPA);
+ BUG_ON(crng->state[1] != CHACHA_CONSTANT_ND_3);
+ BUG_ON(crng->state[2] != CHACHA_CONSTANT_2_BY);
+ BUG_ON(crng->state[3] != CHACHA_CONSTANT_TE_K);
  chacha20_block(&crng->state[0], out);
  if (crng->state[12] == 0)
  crng->state[13]++;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help