Re: [kernel-hardening] Re: [PATCH 4/3] random: use siphash24 instead of md5 for get_random_int/long
Hey Ted, On Wed, Dec 14, 2016 at 8:12 PM, Jason A. Donenfeldwrote: > I think this opens up a big window for optimizing it even > further. I optimized it a bit further and siphash is now the clear winner over chacha: [1.784801] random benchmark!! [1.785161] get_random_long # cycles: 415983 [1.785595] get_random_long_chacha # cycles: 242047 [1.785997] get_random_long_siphash # cycles: 137130 [1.787450] get_random_bytes # cycles: 1452985 [1.787947] get_random_int # cycles: 343323 [1.788282] get_random_int_chacha # cycles: 170767 [1.788656] get_random_int_siphash # cycles: 86384 [1.789764] get_random_bytes # cycles: 2279519 And even still, there is more that could be optimized. Therefore, I'll continue to keep this patch in the series and will CC you on the next patch set that goes out. Jason
Re: [kernel-hardening] Re: [PATCH 4/3] random: use siphash24 instead of md5 for get_random_int/long
Hi again, On Wed, Dec 14, 2016 at 5:37 PM, Theodore Ts'owrote: > [3.606139] random benchmark!! > [3.606276] get_random_int # cycles: 326578 > [3.606317] get_random_int_new # cycles: 95438 > [3.607423] get_random_bytes # cycles: 2653388 Looks to me like my siphash implementation is much faster for get_random_long, and more or less tied for get_random_int: [1.729370] random benchmark!! [1.729710] get_random_long # cycles: 349771 [1.730128] get_random_long_chacha # cycles: 359660 [1.730457] get_random_long_siphash # cycles: 94255 [1.731307] get_random_bytes # cycles: 1354894 [1.731707] get_random_int # cycles: 305640 [1.732095] get_random_int_chacha # cycles: 80726 [1.732425] get_random_int_siphash # cycles: 94265 [1.733278] get_random_bytes # cycles: 1315873 Given the increasing usage of get_random_long for ASLR and related, I think this makes the siphash approach worth pursuing. The chacha approach is also not significantly different from the md5 approach in terms of speed for get_rand_long. Additionally, since siphash is a PRF, I think this opens up a big window for optimizing it even further. Benchmark here: https://git.zx2c4.com/linux-dev/commit/?h=rng-bench Jason
Re: [kernel-hardening] Re: [PATCH 4/3] random: use siphash24 instead of md5 for get_random_int/long
Hey Ted, On Wed, Dec 14, 2016 at 5:37 PM, Theodore Ts'owrote: > One somewhat undesirable aspect of the current algorithm is that we > never change random_int_secret. Why exactly would this be a problem? So long as the secret is kept secret, the PRF is secure. If an attacker can read arbitrary kernel memory, there are much much bigger issues to be concerned about. As well, the "chaining" variable I introduce ensures that the random numbers are, per-cpu, related to the uniqueness of timing of subsequent calls. > So I've been toying with the > following, which is 4 times faster than md5. (I haven't tried > benchmarking against siphash yet.) > > [3.606139] random benchmark!! > [3.606276] get_random_int # cycles: 326578 > [3.606317] get_random_int_new # cycles: 95438 > [3.607423] get_random_bytes # cycles: 2653388 Cool, I'll benchmark it against the siphash implementation. I like what you did with batching up lots of chacha output, and doling it out bit by bit. I suspect this will be quite fast, because with chacha20 you get an entire block. > P.S. It's interesting to note that siphash24 and chacha20 are both > add-rotate-xor based algorithms. Quite! Lots of nice shiny things are turning out be be ARX -- ChaCha, BLAKE2, Siphash, NORX. The simplicity is really appealing. Jason