ogxd / gxhash

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

Unexpected wite_u8 vs write discrepancy #96

Closed daedric closed 2 months ago

daedric commented 2 months ago

Hi, It seems counterintuitive and "dangerous" not to have the same result whether you're streaming byte or whether you hash at once:

        let mut hasher = GxHasher::with_seed(0);
        hasher.write(b"toto");
        println!("{}", hasher.finish());

        let mut hasher = GxHasher::with_seed(0);
        hasher.write_u8(b't');
        hasher.write_u8(b'o');
        hasher.write_u8(b't');
        hasher.write_u8(b'o');
        println!("{}", hasher.finish());

Output:

3646514962586498231
18322645476817907199

Is it because of the compress stage?

daedric commented 2 months ago

I see that Rust does not commit on having the same hash using different write method. While it is something that I hardly agree with it is then not a bug. I would have rather liked different interface than this kind of behavior

ogxd commented 2 months ago

Hello @daedric !

There is already an issue about this subject, here was my answer: https://github.com/ogxd/gxhash/issues/94#issuecomment-2262329989

TL;DR: It would be "nice" if generated hashes were the same using the two ways, but for performance reasons it's currently not the case (it's the same problem with many hash functions in Rust).