Add common hash/checksum functions #900
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rationale behind each inclusion and rough performance metrics using the
throughput_test.zig
instd/crypto
with minor modifications. Using a i5-6500,--release-fast
, best time taken.SipHash
We should provide a collision resistant keyed hash function for hash tables which accept data from external users over a network that aids in avoiding hash flood attacks.
SipHash64(2, 4)
- 875Mb/sSipHash128(2, 4)
- 862 Mb/sI expect this performance is only on par with Fnv since the test program is dealing in large blocks. SipHash would likely get a fair slow down on smaller keys.
Crc32
Very common. Used as the specified checksum in various other algorithms (such as the gzip file format). I've included two variants since if you only need to do a one-off checksum, the 8Kb table may not be that desired.
Crc32
- 2366 Mb/sCrc32Small
- 217 Mb/sI haven't included a generic CRC abstracted over different sizes (i.e. CRC64, CRC16) since I'd like to first see a need for it.
Adler32
Very fast checksum. Only included since it is the specified checksum function for the zlib file format which will likely be in
std
at some point (side note: working on a INFLATE implementation).Adler32
- 2402 Mb/sFnv1a
Non cryptographic generic hash function useful for small keys where a good distribution is wanted and input is from a controlled environment (no hash flood possibility).
Fnv1a-32
- 882 Mb/sFnv1a-64
- 881 Mb/sFnv1-128
- 803 Mb/s