Re: [PATCH v2] siphash: add cryptographically secure hashtable function

2016-12-12 Thread Jason A. Donenfeld
On Mon, Dec 12, 2016 at 10:44 PM, Jason A. Donenfeld wrote: > #if defined(CONFIG_DCACHE_WORD_ACCESS) && BITS_PER_LONG == 64 >switch (left) { >case 0: break; >case 1: b |= data[0]; break; >case 2: b |= get_unaligned_le16(data); break; >case 4: b |= get_unalig

Re: [PATCH v2] siphash: add cryptographically secure hashtable function

2016-12-12 Thread Jason A. Donenfeld
Hi Linus, > 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

Re: [PATCH v2] siphash: add cryptographically secure hashtable function

2016-12-12 Thread Linus Torvalds
On Sun, Dec 11, 2016 at 9:48 PM, Jason A. Donenfeld wrote: > I modified the test to hash data of size 0 through 7 repeatedly > 1 times, and benchmarked that a few times on a Skylake laptop. > The `load_unaligned_zeropad & bytemask_from_count` version was > consistently 7% slower. > > I the

Re: [PATCH v2] siphash: add cryptographically secure hashtable function

2016-12-12 Thread Jason A. Donenfeld
Hey Eric, Lots of good points; thanks for the review. Responses are inline below. On Mon, Dec 12, 2016 at 6:42 AM, Eric Biggers wrote: > Maybe add to the help text for CONFIG_TEST_HASH that it now tests siphash too? Good call. Will do. > This assumes the key and message buffers are aligned to

Re: [PATCH v2] siphash: add cryptographically secure hashtable function

2016-12-11 Thread Jason A. Donenfeld
Hey Linus, On Mon, Dec 12, 2016 at 5:01 AM, Linus Torvalds wrote: > The above is extremely inefficient. Considering that most kernel data > would be expected to be smallish, that matters (ie the usual benchmark > would not be about hashing megabytes of data, but instead millions of > hashes of sm

Re: [PATCH v2] siphash: add cryptographically secure hashtable function

2016-12-11 Thread Eric Biggers
On Mon, Dec 12, 2016 at 04:48:17AM +0100, Jason A. Donenfeld wrote: > > diff --git a/lib/Makefile b/lib/Makefile > index 50144a3aeebd..71d398b04a74 100644 > --- a/lib/Makefile > +++ b/lib/Makefile > @@ -22,7 +22,8 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ >sha1.o chacha20.o md5.o

Re: [PATCH v2] siphash: add cryptographically secure hashtable function

2016-12-11 Thread Linus Torvalds
On Sun, Dec 11, 2016 at 7:48 PM, Jason A. Donenfeld wrote: > + switch (left) { > + case 7: b |= ((u64)data[6]) << 48; > + case 6: b |= ((u64)data[5]) << 40; > + case 5: b |= ((u64)data[4]) << 32; > + case 4: b |= ((u64)data[3]) << 24; >

[PATCH v2] siphash: add cryptographically secure hashtable function

2016-12-11 Thread Jason A. Donenfeld
SipHash is a 64-bit keyed hash function that is actually a cryptographically secure PRF, like HMAC. Except SipHash is super fast, and is meant to be used as a hashtable keyed lookup function. SipHash isn't just some new trendy hash function. It's been around for a while, and there really isn't any