aboutsummaryrefslogtreecommitdiff
path: root/lib/std/crypto/sha3.zig
AgeCommit message (Collapse)Author
2025-11-01Add std.crypto.hash.sha3.{KT128,KT256} - RFC 9861. (#25593)Frank Denis
KT128 and KT256 are fast, secure cryptographic hash functions based on Keccak (SHA-3). They can be seen as the modern version of SHA-3, and evolution of SHAKE, with better performance. After the SHA-3 competition, the Keccak team proposed these variants in 2016, and the constructions underwent 8 years of public scrutiny before being standardized in October 2025 as RFC 9861. They uses a tree-hashing mode on top of TurboSHAKE, providing both high security and excellent performance, especially on large inputs. They support arbitrary-length output and optional customization strings. Hashing of very large inputs can be done using multiple threads, for high throughput. KT128 provides 128-bit security strength, equivalent to AES-128 and SHAKE128, which is sufficient for virtually all applications. KT256 provides 256-bit security strength, equivalent to SHA-512. For virtually all applications, KT128 is enough (equivalent to SHA-256 or BLAKE3). For small inputs, TurboSHAKE128 and TurboSHAKE256 (which KT128 and KT256 are based on) can be used instead as they have less overhead.
2025-08-30std: disable `sha3-512 single` test on RISC-V with V supportAlex Rønne Petersen
https://github.com/ziglang/zig/issues/25083
2025-08-28std.Io: delete GenericWriterAndrew Kelley
2025-07-07std.io: deprecated Reader/Writer; introduce new APIAndrew Kelley
2024-10-28closes #21824 (#21832)Bruno Franca dos Reis
2024-05-03Delete compile errors for deprecated declsRyan Liptak
2024-04-09crypto.sha3: implement constructions from NIST SP 800-185 (#19533)Frank Denis
https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf This adds useful standard SHA3-based constructions from the NIST SP 800-185 document: - cSHAKE: similar to the SHAKE extensible hash function, but with the addition of a context parameter. - KMAC: SHAKE-based authentication / keyed XOF - TupleHash: unambiguous hashing of tuples These are required by recent protocols and specifications. They also offer properties that none of the currently available constructions in the stdlib offer, especially the ability to safely hash tuples. Other keyed hash functions/XOFs will fall back to using HMAC, which is suboptimal from a performance perspective, but fine from a security perspective.
2023-07-14std.crypto.sha3: Minor TurboSHAKE/Keccak fixes (#16408)e4m2
2023-06-16migration: std.math.{min, min3, max, max3} -> `@min` & `@max`r00ster91
2023-04-28update codebase to use `@memset` and `@memcpy`Andrew Kelley
2023-03-09TurboSHAKE: change default delimiter to 0x1F (#14857)Frank Denis
The TurboSHAKE paper just got published: https://eprint.iacr.org/2023/342.pdf and unlike the previous K12 paper, suggests 0x1F instead of 0x01 as the default value for "D".
2023-03-09Fix incorrect SHA-3 computation with the streaming API (#14852)Frank Denis
* 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-07std.crypto.hash.sha3: add TurboSHAKE (#14824)Frank Denis
2023-03-02crypto.hash.sha3: make permutation generic and public, add SHAKE (#14756)Frank Denis
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-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2022-12-30sha3: define block_length as the rate, not as the state size (#14132)Frank Denis
In sponge-based constructions, the block size is not the same as the state size. For practical purposes, it's the same as the rate. Size this is a constant for a given type, we don't need to keep a copy of that value in the state itself. Just use the constant directly. This saves some bytes and may even be slightly faster. More importantly: Fixes #14128
2022-06-03std: update tests to stage2 semanticsVeikka Tuominen
2021-11-20std: add `writer` methods on all crypto.hash types (#10168)Meghan
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-06-21fix code broken from previous commitJacob G-W
2021-05-08std: update usage of std.testingVeikka Tuominen
2021-01-15crypto: add legacy keccak hash functionsGuillaume Ballet
2020-12-31Year++Frank Denis
2020-10-17std/crypto: make the whole APIs more consistentFrank Denis
- use `PascalCase` for all types. So, AES256GCM is now Aes256Gcm. - consistently use `_length` instead of mixing `_size` and `_length` for the constants we expose - Use `minimum_key_length` when it represents an actual minimum length. Otherwise, use `key_length`. - Require output buffers (for ciphertexts, macs, hashes) to be of the right size, not at least of that size in some functions, and the exact size elsewhere. - Use a `_bits` suffix instead of `_length` when a size is represented as a number of bits to avoid confusion. - Functions returning a constant-sized slice are now defined as a slice instead of a pointer + a runtime assertion. This is the case for most hash functions. - Use `camelCase` for all functions instead of `snake_case`. No functional changes, but these are breaking API changes.
2020-09-08std: clean up bitrotten imports in cryptoxackus
2020-08-21Hash functions now accept an option setFrank Denis
- This avoids having multiple `init()` functions for every combination of optional parameters - The API is consistent across all hash functions - New options can be added later without breaking existing applications. For example, this is going to come in handy if we implement parallelization for BLAKE2 and BLAKE3. - We don't have a mix of snake_case and camelCase functions any more, at least in the public crypto API Support for BLAKE2 salt and personalization (more commonly called context) parameters have been implemented by the way to illustrate this.
2020-08-20Remove the reset() function from hash functionsFrank Denis
Justification: - reset() is unnecessary; states that have to be reused can be copied - reset() is error-prone. Copying a previous state prevents forgetting struct members. - reset() forces implementation to store sensitive data (key, initial state) in memory even when they are not needed. - reset() is confusing as it has a different meaning elsewhere in Zig.
2020-08-20Repair crypto/benchmark; add BLAKE2b256Frank Denis
Some MACs have a 64-bit output
2020-08-20Breaking: sort std/crypto functions into categoriesFrank Denis
Instead of having all primitives and constructions share the same namespace, they are now organized by category and function family. Types within the same category are expected to share the exact same API.
2020-08-20add license header to all std lib filesAndrew Kelley
add SPDX license identifier copyright ownership is zig contributors
2020-03-19update std lib to take advantage of slicing with comptime indexesAndrew Kelley
2019-11-27remove type coercion from array values to referencesAndrew Kelley
* Implements #3768. This is a sweeping breaking change that requires many (trivial) edits to Zig source code. Array values no longer coerced to slices; however one may use `&` to obtain a reference to an array value, which may then be coerced to a slice. * Adds `IrInstruction::dump`, for debugging purposes. It's useful to call to inspect the instruction when debugging Zig IR. * Fixes bugs with result location semantics. See the new behavior test cases, and compile error test cases. * Fixes bugs with `@typeInfo` not properly resolving const values. * Behavior tests are passing but std lib tests are not yet. There is more work to do before merging this branch.
2019-11-08update the codebase to use `@as`Andrew Kelley
2019-09-25mv std/ lib/Andrew Kelley
that's all this commit does. further commits will fix cli flags and such. see #2221