Repository navigation
Commit f5b9846
random: use chacha20 for get_random_int/long
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>1 parent 5d0e5ea commit f5b9846
3 files changed
Lines changed: 43 additions & 43 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2016 | 2016 | | |
2017 | 2017 | | |
2018 | 2018 | | |
2019 | | - | |
2020 | | - | |
2021 | | - | |
2022 | | - | |
2023 | | - | |
2024 | | - | |
2025 | | - | |
2026 | | - | |
2027 | | - | |
2028 | | - | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
2029 | 2026 | | |
2030 | 2027 | | |
2031 | | - | |
2032 | | - | |
2033 | | - | |
2034 | | - | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
2035 | 2031 | | |
2036 | | - | |
| 2032 | + | |
| 2033 | + | |
2037 | 2034 | | |
2038 | | - | |
2039 | | - | |
| 2035 | + | |
| 2036 | + | |
2040 | 2037 | | |
2041 | | - | |
| 2038 | + | |
2042 | 2039 | | |
2043 | 2040 | | |
2044 | | - | |
2045 | | - | |
2046 | | - | |
2047 | | - | |
2048 | | - | |
2049 | | - | |
2050 | | - | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
2051 | 2048 | | |
2052 | 2049 | | |
2053 | | - | |
| 2050 | + | |
2054 | 2051 | | |
2055 | | - | |
2056 | | - | |
2057 | | - | |
2058 | | - | |
| 2052 | + | |
| 2053 | + | |
2059 | 2054 | | |
2060 | | - | |
2061 | | - | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
2062 | 2063 | | |
2063 | | - | |
| 2064 | + | |
2064 | 2065 | | |
2065 | 2066 | | |
2066 | | - | |
2067 | | - | |
2068 | | - | |
2069 | | - | |
2070 | | - | |
2071 | | - | |
2072 | | - | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
2073 | 2074 | | |
2074 | 2075 | | |
2075 | | - | |
| 2076 | + | |
| 2077 | + | |
2076 | 2078 | | |
2077 | 2079 | | |
2078 | 2080 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | 40 | | |
42 | 41 | | |
43 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
879 | 879 | | |
880 | 880 | | |
881 | 881 | | |
882 | | - | |
883 | 882 | | |
884 | 883 | | |
885 | 884 | | |
| |||
0 commit comments