# Add the POLYVAL universal hash function · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/c45c6cd492e9a5f351fa9290c7f7385d743b3818)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: c45c6cd492e9a5f351fa9290c7f7385d743b3818

Requested commit: c45c6cd492e9a5f351fa9290c7f7385d743b3818

Commit: c45c6cd492e9a5f351fa9290c7f7385d743b3818

Tree: 9241dad5efc01f386b448ed102a0a44123b1235b

Author: Frank Denis

Committer: Andrew Kelley

## Message

```
Add the POLYVAL universal hash function

POLYVAL is GHASH's little brother, required by the AES-GCM-SIV
construction. It's defined in RFC8452.

The irreducible polynomial is a mirror of GHASH's (which doesn't
change anything in our implementation that didn't reverse the raw
bits to start with).

But most importantly, POLYVAL encodes byte strings as little-endian
instead of big-endian, which makes it a little bit faster on the
vast majority of modern CPUs.

So, both share the same code, just with comptime magic to use the
correct endianness and only double the key for GHASH.

```

## Parents

- [79bba5a9e639ddfb89af95ccf22501d974bd7fe3](https://git.cafe/gitcafe/zig/commit/79bba5a9e639ddfb89af95ccf22501d974bd7fe3?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/c45c6cd492e9a5f351fa9290c7f7385d743b3818?format=markdown)
