]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commit
random: use chacha20 for get_random_int/long
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 6 Jan 2017 18:32:01 +0000 (19:32 +0100)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 21 Apr 2017 08:12:30 +0000 (10:12 +0200)
commit502666bea4cc03b9967e7cce80f69170489140a4
treee3c134bf91269f8990800cdf74c1f425c094fd74
parent1e78d67ff9c634d46ad2df06039627f231861849
random: use chacha20 for get_random_int/long

BugLink: http://bugs.launchpad.net/bugs/1682130
commit f5b98461cb8167ba362ad9f74c41d126b7becea7 upstream.

Now that our crng uses chacha20, we can rely on its speedy
characteristics for replacing MD5, while simultaneously achieving a
higher security guarantee. Before the idea was to use these functions if
you wanted random integers that aren't stupidly insecure but aren't
necessarily secure either, a vague gray zone, that hopefully was "good
enough" for its users. With chacha20, we can strengthen this claim,
since either we're using an rdrand-like instruction, or we're using the
same crng as /dev/urandom. And it's faster than what was before.

We could have chosen to replace this with a SipHash-derived function,
which might be slightly faster, but at the cost of having yet another
RNG construction in the kernel. By moving to chacha20, we have a single
RNG to analyze and verify, and we also already get good performance
improvements on all platforms.

Implementation-wise, rather than use a generic buffer for both
get_random_int/long and memcpy based on the size needs, we use a
specific buffer for 32-bit reads and for 64-bit reads. This way, we're
guaranteed to always have aligned accesses on all platforms. While
slightly more verbose in C, the assembly this generates is a lot
simpler than otherwise.

Finally, on 32-bit platforms where longs and ints are the same size,
we simply alias get_random_int to get_random_long.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Suggested-by: Theodore Ts'o <tytso@mit.edu>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
drivers/char/random.c
include/linux/random.h
init/main.c