Another batched entropy idea

From: George Spelvin
Date: Sun Mar 29 2020 - 22:45:19 EST


Posting all those patches has depressurized my brain and let me think of
additional ways to speed up batched random number generation, taking
advantage of the fact that we don't have to anti-backtrack the key.

Rather than using the primary_crng and its lock, use a global 256-bit key,
and give each CPU a disjoint 64-bit sequence number space.
(for (seq = raw_smp_processor_id(); ; seq += NR_CPUS).)

Then, when a CPU needs to refill its batched pool, copy over the constant,
the global key, the per-cpu sequence number, do something TBD with the
nonce, and run ChaCha on the result.

And voila, no global locking ever, unless a reseed interval has elapsed.

(We could also consider using 12 <= r < 20 ChaCha rounds for the batch.
After all, the best attack is <8 rounds and eSTREAM recommends 12.
16 might be reasonable.)