linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH v3] siphash: add cryptographically secure hashtable function
@ 2016-12-12 23:04 Jason A. Donenfeld
  2016-12-13 19:25 ` Linus Torvalds
  0 siblings, 1 reply; 8+ messages in thread
From: Jason A. Donenfeld @ 2016-12-12 23:04 UTC (permalink / raw)
  To: Andi Kleen
  Cc: Linus Torvalds, kernel-hardening, LKML,
	Linux Crypto Mailing List, George Spelvin, Scott Bauer,
	Andy Lutomirski, Greg KH, Eric Biggers, Jean-Philippe Aumasson,
	Daniel J . Bernstein

On Tue, Dec 13, 2016 at 12:01 AM, Andi Kleen <ak@linux.intel.com> wrote:
> It would be nice if the network code could be converted to use siphash
> for the secure sequence numbers. Right now it pulls in a lot of code
> for bigger secure hashes just for that, which is a problem for tiny
> kernels.

Indeed this would be a great first candidate. There are lots of places
where MD5 (!!) is pulled in for this sort of thing, when SipHash could
be a faster and leaner replacement (and arguably more secure than
rusty MD5).

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [PATCH v2] siphash: add cryptographically secure hashtable function
@ 2016-12-12 21:37 Linus Torvalds
  2016-12-12 22:18 ` [PATCH v3] " Jason A. Donenfeld
  0 siblings, 1 reply; 8+ messages in thread
From: Linus Torvalds @ 2016-12-12 21:37 UTC (permalink / raw)
  To: Jason A. Donenfeld
  Cc: kernel-hardening, LKML, Linux Crypto Mailing List,
	George Spelvin, Scott Bauer, Andi Kleen, Andy Lutomirski,
	Greg KH, Jean-Philippe Aumasson, Daniel J . Bernstein

On Sun, Dec 11, 2016 at 9:48 PM, Jason A. Donenfeld <Jason@zx2c4.com> wrote:
> I modified the test to hash data of size 0 through 7 repeatedly
> 100000000 times, and benchmarked that a few times on a Skylake laptop.
> The `load_unaligned_zeropad & bytemask_from_count` version was
> consistently 7% slower.
>
> I then modified it again to simply hash a 4 byte constant repeatedly
> 1000000000 times. The `load_unaligned_zeropad & bytemask_from_count`
> version was around 6% faster. I tried again with a 7 byte constant and
> got more or less a similar result.
>
> Then I tried with a 1 byte constant, and found that the
> `load_unaligned_zeropad & bytemask_from_count` version was slower.
>
> So, it would seem that between the `if (left)` and the `switch
> (left)`, there's the same number of branches.

Interesting.

For the dcache code (which is where that trick comes from), we used to
have a loop (rather than the duff's device thing), and it performed
badly due to the consistently badly predicted branch of the loop. But
I never compared it against the duff's device version.

I guess you could try to just remove the "if (left)" test entirely, if
it is at least partly the mispredict. It should do the right thing
even with a zero count, and it might schedule the code better. Code
size _should_ be better with the byte mask model (which won't matter
in the hot loop example, since it will all be cached, possibly even in
the uop cache for really tight benchmark loops).

             Linus

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-12-13 23:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-12 23:04 [PATCH v3] siphash: add cryptographically secure hashtable function Jason A. Donenfeld
2016-12-13 19:25 ` Linus Torvalds
2016-12-13 23:36   ` Jason A. Donenfeld
  -- strict thread matches above, loose matches on Subject: below --
2016-12-12 21:37 [PATCH v2] " Linus Torvalds
2016-12-12 22:18 ` [PATCH v3] " Jason A. Donenfeld
2016-12-12 23:01   ` Andi Kleen
2016-12-13  8:39   ` Eric Biggers
2016-12-13 19:26     ` Linus Torvalds
2016-12-13 22:43     ` Jason A. Donenfeld

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).