ogxd / gxhash

The fastest hashing algorithm 📈
https://docs.rs/gxhash
MIT License
766 stars 26 forks source link

Quality issue: permutations produce the same hashes? #44

Closed Dherse closed 9 months ago

Dherse commented 9 months ago

I have noticed a strange behavior which I am not sure whether it is intended or not:

The hashes of two u8 a and b are the same regardless of order:

This is an issue in my particular use case because it prevents me from distinguishing between two distinct cases only by the hash.

I don't know whether this is actually a bug or no as I am a total noob about cryptography and hashing functions.

Thanks for you help/advice,

Dherse

ogxd commented 9 months ago

Hello @Dherse,

The "standard" hash function gxhash64(input: &[u8], seed: i64) -> u64 is backed by smasher tests which has permutation tests and more. However, the Hasher is a different approach, and while it uses the core of the gxhash algorithm, it is not backed by smasher and is covered by very few tests regarding quality (only a few sanity checks).

Given that the rust's default Hasher seems to generate order-dependent hashes, I'd say that the fact that GxHasher is currently order-independent is a bug (I easily reproduced).

Fixing this will only affect GxHasher so I think it can be addressed as part of a hotfix version, I'll see what can be done. Also, some time must be put into adding a few more quality tests on this Hasher side.

Dherse commented 9 months ago

Thank you, I am a large contributor to https://github.com/typst/typst and I am trying to see whether gxhash could replace Siphash 1-3 that we're currently using since it has so much higher performance hence #7 and this issue!

Anyway, looking forward to it 🎉

ogxd commented 9 months ago

My bad, issue is still open, I only tackled the quality bench part for now

ogxd commented 9 months ago

Fixed and published in v2.3.1 🎉