Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I recently implemented this, great write-up. Regarding the hashing function, I’m curious about opinions. In my implementation I went for a cheap but weak cryptographic hash at first. Then I got worried that some auditor would flag it and time would be wasted convincing them to change their mind. But then I stumbled upon FNV [1], a non-cryptographic hash and part of Go’s standard library and went for it. Any thoughts?

[1]: https://en.m.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93...



I recommend checking out XXHash[0], FNV is simple but not really optimized and relatively low quality (often still good enough). From the readme page:

Hash Name, Bandwidth, Small Velocity, Quality, Comment

XXH3 (SSE2), 31.5 GB/s, 133.1, 10,

FNV64, 1.2 GB/s, 62.7, 5, Poor avalanche properties

[0]: https://github.com/Cyan4973/xxHash

Also ETag is exactly the kind of thing non-cryptographic hashes are meant for, but if you can't convince them Blake3 is a very fast modern cryptographic hash function.


I feel like people tend to overthink in this regard. If SHA-256 hashing is good enough for GitHub's REST endpoints, it's good enough for me.

If you're implementing weak validation, then you might need to preprocess the payload before running it through the hash function. For example, if your payload is JSON and you want to make it format-agnostic, then you'll need to normalize the payload and then compute the hash.

In either case, the hashing algo probably doesn't matter as much.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: