Re: [PATCH 1/2] random: use chacha20 for get_random_int/long

From: Theodore Ts'o
Date: Fri Jan 20 2017 - 19:10:28 EST


On Fri, Jan 20, 2017 at 04:38:59PM +0100, Jason A. Donenfeld wrote:
> I was thinking that the issue isn't merely cache line and a slow down,
> but that on some platforms, this could be an _illegal unaligned
> access_. That means we'd need to rewrite the code to use the unaligned
> access helpers or memcpy, and then it's really suboptimal, not to
> mention ugly, since just indexing into an array like we do now is so
> clean.

Why would there be an unaligned access? What I was suggesting was an
array of u32, and we just do two separate u32 accesses with a shift in
the case of get_random_u64. There's nothing illegal about that.

u64 retval;

retval = (array[pointer] << 32) + array[pointer+1];
pointer += 2;

This is not terribly suboptimal nor terribly ugly.

- Ted