Zero-Allocation-Hashing icon indicating copy to clipboard operation
Zero-Allocation-Hashing copied to clipboard

Add SipHash implementation

Open wkuranowski opened this issue 10 years ago • 3 comments

Can you add SipHash to your library? It is very popular function, fast, secure and immune to Hash DoS attacks.

https://en.wikipedia.org/wiki/SipHash

wkuranowski avatar Sep 30 '15 13:09 wkuranowski

On the speed issue, Hash-Bench tests over 100 hash implementations on the JVM and finds Zero-Allocation-Hashing's XXH64 is the fastest. Feel free to check the published results for yourself for the buffer sizes and types you wish to hash (ie direct ByteBuffer, on-heap ByteBuffer, plain byte[]) but SipHash is consistently slower. For example, a standard byte[32] with XXH64 hashes in 9 ns vs 52, 114, and 127 ns for the three Java SipHash implementations that Hash-Bench tests.

I don't see much reason to add extra hashers to Zero-Allocation-Hashing unless the algorithm has a material speed or functional advantage. To this end maybe Daniel Lemire's CLHash is worth exploration (see here which also includes a SipHash performance comparison).

benalexau avatar Jan 12 '16 23:01 benalexau

I agree that SipHash is slower than other simple hash functions. Speed is important but you need to look at other aspects. SipHash is a cryptographic hash function. It's really fast when you compare it to other cryptographic hash functions. Maybe we can gain even better performance with a new implementation.

SipHash is also immune to Hash DoS attacks, so it is used as default hash function in many languages: Perl, Python, Ruby, Haskell, Rust... etc.

In my opinion it's really nice to have a secure hash function, especially when one of the authors is DJB. I am not telling that everyone needs SipHash. But it has unique properties and is complementary to others.

wkuranowski avatar Jan 13 '16 13:01 wkuranowski

I agree XXH64 and SipHash aim at different problems. The Hash-Bench Scope section lists some other considerations too when comparing hash algos.

If SipHash is what you would like, the three implementations currently available in Java might be sufficient for you:

  • https://github.com/nahi/siphash-java-inline
  • http://www.forward.com.au/pfod/SipHashJavaLibrary/index.html
  • https://github.com/google/guava/wiki/HashingExplained

See Hash-Bench's 32 byte SipHash Report if you'd like graphs comparing their performance (summary: siphash-java-inline is more than twice as fast as the next fastest alternative).

benalexau avatar Jan 13 '16 23:01 benalexau