diff mbox series

random: Use 64 bits from get_random_long() in extract_crng()

Message ID CACXcFmnKhYyjHNzu_MxZ2qup1jxp4CWT09HzBu=h5D2Ur9LjWQ@mail.gmail.com (mailing list archive)
State Not Applicable
Delegated to: Herbert Xu
Headers show
Series random: Use 64 bits from get_random_long() in extract_crng() | expand

Commit Message

Sandy Harris Nov. 10, 2021, 9:25 a.m. UTC
---
drivers/char/random.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

--

Comments

Jason A. Donenfeld Nov. 10, 2021, 10:55 a.m. UTC | #1
Any rationale? Commit message is a bit short.
diff mbox series

Patch

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 605969ed0f96..bf644b594fb7 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -989,14 +989,20 @@  static void _extract_crng(struct crng_state *crng,
                         __u8 out[CHACHA_BLOCK_SIZE])
{
       unsigned long v, flags;
+        u32 *p, *q ;
+        p = crng->state ;
+        q = (u32 *) &v ;

       if (crng_ready() &&
           (time_after(crng_global_init_time, crng->init_time) ||
            time_after(jiffies, crng->init_time + CRNG_RESEED_INTERVAL)))
               crng_reseed(crng, crng == &primary_crng ? &input_pool : NULL);
       spin_lock_irqsave(&crng->lock, flags);
-       if (arch_get_random_long(&v))
-               crng->state[14] ^= v;
+       if (arch_get_random_long(&v))  {
+               p[14] ^= q[0];
+                if (sizeof(v) == 8)
+                        p[15] ^= q[1];
+        }
       chacha20_block(&crng->state[0], out);
       if (crng->state[12] == 0)
               crng->state[13]++;