aboutsummaryrefslogtreecommitdiff
path: root/lib/std/crypto/benchmark.zig
AgeCommit message (Collapse)Author
2025-11-02crypto.kt128: when using incremental hashing, use SIMD when possible (#25783)Frank Denis
Also add plain kt128 (without threading) to the benchmarks
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-11-01Implement threaded BLAKE3 (#25587)Frank Denis
Allows BLAKE3 to be computed using multiple threads.
2025-09-18Remove usages of deprecatedWriterandrewkraevskii
2025-09-17std.crypto: add Ascon-AEAD, Ascon-Hash, Ascon-CHash (#25239)Frank Denis
Ascon is the family of cryptographic constructions standardized by NIST for lightweight cryptography. The Zig standard library already included the Ascon permutation itself, but higher-level constructions built on top of it were intentionally postponed until NIST released the final specification. That specification has now been published as NIST SP 800-232: https://csrc.nist.gov/pubs/sp/800/232/final With this publication, we can now confidently include these constructions in the standard library.
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-07-07std.io: move getStdIn, getStdOut, getStdErr functions to fs.FileAndrew Kelley
preparing to rearrange std.io namespace into an interface how to upgrade: std.io.getStdIn() -> std.fs.File.stdin() std.io.getStdOut() -> std.fs.File.stdout() std.io.getStdErr() -> std.fs.File.stderr()
2025-02-19crypto.pwhash.bcrypt: make silently_truncate_password a member of Params ↵Frank Denis
(#22792) * bcrypt: make silently_truncate_password a member of Params This removes the need for having both `bcrypt()` and `bcryptWithTruncation()` in the public API. And whether truncation happens or not becomes even more explicit. * Update crypto benchmark
2024-12-11Reinstantiates AEGIS-MAC with the final construction (#22205)Frank Denis
This reverts commit c9d6f8b5058ba0df3bf281a3be3a3570c2219754.
2024-12-04Remove parallel variants of AEGIS-MAC (#22146)Frank Denis
The construction is likely to change before standardization
2024-11-22std.crypto.aes: introduce AES block vectors (#22023)Frank Denis
* std.crypto.aes: introduce AES block vectors Modern Intel CPUs with the VAES extension can handle more than a single AES block per instruction. So can some ARM and RISC-V CPUs. Software implementations with bitslicing can also greatly benefit from this. Implement low-level operations on AES block vectors, and the parallel AEGIS variants on top of them. AMD Zen4: aegis-128x4: 73225 MiB/s aegis-128x2: 51571 MiB/s aegis-128l: 25806 MiB/s aegis-256x4: 46742 MiB/s aegis-256x2: 30227 MiB/s aegis-256: 8436 MiB/s aes128-gcm: 5926 MiB/s aes256-gcm: 5085 MiB/s AES-GCM, and anything based on AES-CTR are also going to benefit from this later. * Make AEGIS-MAC twice a fast
2024-11-19std.crypto: make the key pair API creation consistent (#21955)Frank Denis
Our key pair creation API was ugly and inconsistent between ecdsa keys and other keys. The same `generate()` function can now be used to generate key pairs, and that function cannot fail. For deterministic keys, a `generateDeterministic()` function is available for all key types. Fix comments and compilation of the benchmark by the way. Fixes #21002
2024-04-14std.crypto.pcurves.*: simpler, smaller, faster u64 addition with carry (#19644)Frank Denis
signature/s: Algorithm Before After ---------------+---------+------- ecdsa-p256 3707 4396 ecdsa-p384 1067 1332 ecdsa-secp256k1 4490 5147 Add ECDSA to the benchmark by the way.
2024-03-22Change std.os.exit to std.process.exitregeliv
2024-02-08Replace std.rand references with std.Randome4m2
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-02Fix std.hash benchmarks (#15917)Frank Denis
2023-04-28update codebase to use `@memset` and `@memcpy`Andrew Kelley
2023-03-21Remove Gimli and Xoodoo from the standard library (#14928)Frank Denis
These are great permutations, and there's nothing wrong with them from a practical security perspective. However, both were competing in the NIST lightweight crypto competition. Gimli didn't pass the 3rd selection round, and is not much used in the wild besides Zig and libhydrogen. It will never be standardized and is unlikely to get more traction in the future. Xoodyak, that Xoodoo is the permutation of, was a finalist. It has a lot of advantages and *might* be standardized without NIST. But this is too early to tell, and too risky to commit to it in a standard library. For lightweight crypto, Ascon is the one that we know NIST will standardize and that we can safely rely on from a usage perspective. Switch to a traditional ChaCha-based CSPRNG, with an Ascon-based one as an option for constrained systems. Add a RNG benchmark by the way. Gimli and Xoodoo served us well. Their code will be maintained, but outside the standard library.
2023-03-15Add Kyber post-quantum key encapsulation mechanism (#14902)Bas Westerbaan
Implementation of the IND-CCA2 post-quantum secure key encapsulation mechanism (KEM) CRYSTALS-Kyber, as submitted to the third round of the NIST Post-Quantum Cryptography (v3.02/"draft00"), and selected for standardisation. Co-authored-by: Frank Denis <124872+jedisct1@users.noreply.github.com>
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-24crypto/benchmark.zig: fix pointer capture of non pointer type (#14722)Frank Denis
2023-02-16crypto: add AES-CMAC (RFC 4493) (#14545)Chris Boesch
* crypto: add AES-CMAC Co-authored-by: Frank Denis <124872+jedisct1@users.noreply.github.com>
2022-12-05std.crypto benchmark: don't use a relative path to import std (#13772)Frank Denis
2022-11-22std.crypto.auth: add AEGIS MAC (#13607)Frank Denis
* Update the AEGIS specification URL to the current draft * std.crypto.auth: add AEGIS MAC The Pelican-based authentication function of the AEGIS construction can be used independently from authenticated encryption, as a faster and more secure alternative to GHASH/POLYVAL/Poly1305. We already expose GHASH, POLYVAL and Poly1305 for use outside AES-GCM and ChaChaPoly, so there are no reasons not to expose the MAC from AEGIS as well. Like other 128-bit hash functions, finding a collision only requires ~2^64 attempts or inputs, which may still be acceptable for many practical applications. Benchmark (Apple M1): siphash128-1-3: 3222 MiB/s ghash: 8682 MiB/s aegis-128l mac: 12544 MiB/s Benchmark (Zen 2): siphash128-1-3: 4732 MiB/s ghash: 5563 MiB/s aegis-128l mac: 19270 MiB/s
2022-11-20Add the POLYVAL universal hash functionFrank Denis
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.
2022-10-27Revamp the ed25519 API (#13309)Frank Denis
2022-10-20crypto/benchmark - replace testing allocatorMatheus C. França
Fix error: Cannot use testing allocator outside of test block
2022-04-24std: fix crypto and hash benchmarkjagt
2022-02-01stage2: remove anytype fields from the languageAndrew Kelley
closes #10705
2021-11-30allocgate: renamed getAllocator function to allocatorLee Cannon
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-11-15add argon2 kdf (#9756)lucky
2021-10-27std.rand: Refactor `Random` interfaceOminitay
These changes have been made to resolve issue #10037. The `Random` interface was implemented in such a way that causes significant slowdown when calling the `fill` function of the rng used. The `Random` interface is no longer stored in a field of the rng, and is instead returned by the child function `random()` of the rng. This avoids the performance issues caused by the interface.
2021-10-04migrate from `std.Target.current` to `@import("builtin").target`Andrew Kelley
closes #9388 closes #9321
2021-09-19Update `hash` & `crypto` benchmarks run comment (#9790)Ali Chraghi
* sync function arguments name with other same functions
2021-09-13fix missing paths (#9754)lucky
increase bcrypt benchmark rounds Co-authored-by: lucky <>
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-08-24add scrypt kdf (#9577)lucky
add phc encoding parser add password hash functions to benchmark change bcrypt to be consistent with scrypt Co-authored-by: lucky <>
2021-06-14CLI: rename --override-lib-dir to --zig-lib-dirAndrew Kelley
This breaking change disambiguates between overriding the lib dir when performing an installation with the Zig Build System, and overriding the lib dir that the Zig installation itself uses.
2021-03-17std/crypto/chacha20: add round-reduced versions & cleanup internalsFrank Denis
See https://eprint.iacr.org/2019/1492.pdf for justification. 8 rounds ChaCha20 provides a 2.5x speedup, and is still believed to be safe. Round-reduced versions are actually deployed (ex: Android filesystem encryption), and thanks to the magic of comptime, it doesn't take much to support them. This also makes the ChaCha20 code more consistent with the Salsa20 code, removing internal functions that were not part of the public API any more. No breaking changes; the public API remains backwards compatible.
2021-02-28std/crypto: add AES-OCBFrank Denis
OCB has been around for a long time. It's simpler, faster and more secure than AES-GCM. RFC 7253 was published in 2014. OCB also won the CAESAR competition along with AEGIS. It's been implemented in OpenSSL and other libraries for years. So, why isn't everybody using it instead of GCM? And why don't we have it in Zig already? The sad reason for this was patents. GCM was invented only to work around these patents, and for all this time, OCB was that nice thing that everybody knew existed but that couldn't be freely used. That just changed. The OCB patents are now abandoned, and OCB's author just announced that OCB was officially public domain.
2021-02-28std/crypto/benchmark: update format stringsFrank Denis
Use the s formatter to format strings.
2021-01-07Reduce use of deprecated IO typesJay Petacat
Related: #4917
2020-12-31Year++Frank Denis
2020-11-16std/crypto: add ISAPv2 (ISAP-A-128a) AEADFrank Denis
We currently have ciphers optimized for performance, for compatibility, for size and for specific CPUs. However we lack a class of ciphers that is becoming increasingly important, as Zig is being used for embedded systems, but also as hardware-level side channels keep being found on (Intel) CPUs. Here is ISAPv2, a construction specifically designed for resilience against leakage and fault attacks. ISAPv2 is obviously not optimized for performance, but can be an option for highly sensitive data, when the runtime environment cannot be trusted.
2020-11-05std.crypto: namespace constructions a bit moreFrank Denis
With the simple rule that whenever we have or will have 2 similar functions, they should be in their own namespace. Some of these new namespaces currently contain a single function. This is to prepare for reduced-round versions that are likely to be added later.