Re: [PATCH v2] Allow hwrng to initialize crng.
From: Theodore Y. Ts'o
Date: Thu Dec 13 2018 - 22:58:41 EST
On Thu, Dec 13, 2018 at 10:48:07AM +0100, Ard Biesheuvel wrote:
> > @@ -64,13 +65,19 @@ static size_t rng_buffer_size(void)
> > static void add_early_randomness(struct hwrng *rng)
> > {
> > int bytes_read;
> > - size_t size = min_t(size_t, 16, rng_buffer_size());
> > + /* Read enough to initialize crng. */
> > + size_t size = min_t(size_t,
> > + 2*CHACHA20_KEY_SIZE,
>
> This should be as symbolic constant that retains its meaning even if
> we move away from ChaCha20 or modify the current implementation
Also, rng_buffer_size() could be less than 2*hCHACHA20_KEY_SIZE, at
which point your goal wouldn't be realized. What I'd recommend is to
keep the line:
size_t size = min_t(size_t, 16, rng_buffer_size());
But to loop until rng_is_initialized() returns true or bytes_read is
0. If you want to be paranoid, you could also break out of the loop
it isn't initialized after, say, 8 times through the loop.
Cheers,
- Ted