Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common hash/checksum functions #900

Merged
merged 1 commit into from Apr 6, 2018
Merged

Add common hash/checksum functions #900

merged 1 commit into from Apr 6, 2018

Conversation

tiehuis
Copy link
Member

@tiehuis tiehuis commented Apr 6, 2018

  • SipHash64, SipHash128
  • Crc32 (fast + small variants)
  • Adler32
  • Fnv1a (32, 64 and 128 bit variants)

Rationale behind each inclusion and rough performance metrics using the throughput_test.zig in std/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/s
  • SipHash128(2, 4) - 862 Mb/s

I 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/s
  • Crc32Small - 217 Mb/s

I 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/s

Fnv1a

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/s
  • Fnv1a-64 - 881 Mb/s
  • Fnv1-128 - 803 Mb/s

 - SipHash64, SipHash128
 - Crc32 (fast + small variants)
 - Adler32
 - Fnv1a (32, 64 and 128 bit variants)
@Hejsil
Copy link
Sponsor Contributor

Hejsil commented Apr 6, 2018

I 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.

A need for it: https://github.com/Hejsil/pokemon-randomizer/blob/60365a24e7790b019df4beb68ef85f7749e3d6aa/src/nds/header.zig#L18

Though, it doesn't matter too much, as I'm already using something I wrote my self.

@tiehuis
Copy link
Member Author

tiehuis commented Apr 6, 2018

Good enough for me. I won't do anything just yet, but I'll keep that on my list of things to do.

@andrewrk andrewrk merged commit 7186e92 into master Apr 6, 2018
@tiehuis tiehuis deleted the hash-and-checksums branch April 24, 2018 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants