74 points · by wangyi_fudan · 5y ago · 36 comments
It’s not clear to me that that probability of collision assumptions hold. It’s basically assuming that the hashing is perfect and distributes any inputs to the full 64-bit space with uniform probability. That’s the usual hash map / randomized algorithm hope, but does BigCrush or similar avalanche testing really prove that? (Presumably not, otherwise there wouldn’t be image attacks for things like md5).
[1] https://github.com/wangyi-fudan/wyhash/blob/d2a305811972f391...
I think that's fine if you actually use a really good hash (e.g. a 128-bit cryptographic PRF). But I wouldn't be comfortable with hashes shorter than that or which aren't crypto quality.
People already make such assumptions when assuming uniqueness v4 UUIDs.
Big crush and smhasher give a good indication of uniform distribution, but nothing can guarantee no collisions because you're always going to have collisions it's always a possibility. Even if you have a perfect permutation of the 64 bit space, the minute you go beyond 64 bits of keys you're going to collide within 64 bits of hash.
By all the tests they run md5 is a much poorer hash than many others. But it's a or it was a cryptographic hash. It's different.
Even without relying on the pigeonhole principle though you still have the birthday paradox. As a ballpark estimate, if you have N keys then you'd expect a 50/50 chance of at least one collision with sqrt(N) hashes -- 2^32 for this problem.
64 bit is not good enough for that claim. 128 would be good, 256 perfect for production use. Regardless of the hash function quality. wyhash is a very good hash, the best and fastest portable one.
You can get this guarantee by using a random hash function if you don't support insertion and are fine with using a relatively larger amounts of memory.
The API this presents is not really inspiring either.
And there are a bunch of other good suggestions here in the comments looking at around the same 50-60gb/sec speed
[1] https://github.com/injinj/smhasher/
[2] Section 5.4 of Introduction to Cryptography by Trappe and Washington -- It can be shown that two rounds are sufficient to obtain full diffusion, namely, each of the 128 output bits depends on each of the 128 input bits.
[3] https://github.com/raitechnology/raikv/blob/3ce2b23e0d9853fe...
https://github.com/tkaitchuck/aHash/blob/master/compare/read...
Did anything change?
https://github.com/tkaitchuck/aHash/tree/master/smhasher
There are also ahash's own benchmarks here:
https://github.com/tkaitchuck/aHash/blob/master/compare/test...
They use the wyhash Rust crate, so if wyhash itself was updated doing a head to head comparison would boil down to updating the wyhash crate and rerunning ahash's benchmark suite.
Very interesting is his claim to create wyhash collisions at will. Even with bad keys, not bad seeds!
A what now? https://github.com/wangyi-fudan/wyhash/blob/master/wyhash.h#...
extra protection against entropy loss
A little brogramming and some google translate and here we are.