5 Commits

Author SHA1 Message Date
Andrew Kelley
6261c13731 update codebase to use @memset and @memcpy 2023-04-28 13:24:43 -07:00
Frank Denis
134e5748e0
Fix incorrect SHA-3 computation with the streaming API (#14852)
* Fix SHA3 with streaming

Leftover bytes should be added to the buffer, not to the state.

(or, always to the state; we can and probably should eventually get
rid of the buffer)

Fixes #14851

* Add a test for SHA-3 with streaming
2023-03-09 05:18:15 +00:00
Frank Denis
36d47dd199
std.crypto.hash.sha3: add TurboSHAKE (#14824) 2023-03-07 10:04:45 +01:00
Frank Denis
4789cc0249
crypto.KeccakF: compute rotations at comptime, add a test with f=800 (#14760) 2023-03-02 19:14:41 +00:00
Frank Denis
28364166e8
crypto.hash.sha3: make permutation generic and public, add SHAKE (#14756)
Make the Keccak permutation public, as it's useful for more than
SHA-3 (kMAC, SHAKE, TurboSHAKE, TupleHash, etc).

Our Keccak implementation was accepting f as a comptime parameter,
but always used 64-bit words and 200 byte states, so it actually
didn't work with anything besides f=1600.

That has been fixed. The ability to use reduced-round versions
was also added in order to support M14 and K12.

The state was constantly converted back and forth between bytes
and words, even though only a part of the state is actually used
for absorbing and squeezing bytes. It was changed to something
similar to the other permutations we have, so we can avoid extra
copies, and eventually add vectorized implementations.

In addition, the SHAKE extendable output function (XOF) was
added (SHAKE128, SHAKE256). It is required by newer schemes,
such as the Kyber post-quantum key exchange mechanism, whose
implementation is currently blocked by SHAKE missing from our
standard library.

Breaking change: `Keccak_256` and `Keccak_512` were renamed to
`Keccak256` and `Keccak512` for consistency with all other
hash functions.
2023-03-02 06:13:40 +00:00