825 Commits

Author SHA1 Message Date
Meghan Denny fce6dbb890 std.crypto: argon2/scrypt: cleanup VerifyOptions 2026-06-11 01:36:18 +02:00
Frank Denis 1ea73060bb crypto.ff: fix operator priority
Exponentiation with short, public exponents doesn't use a
precomputation table. Building the table would take more time
that it would eventually save.

However without explicit parenthesis the test for that parsed as
"(public and e.len < 3) or (e.len == 3 and top_byte <= 0x0f)"

and not "public and (e.len < 3 or...)" as intended.

Not a practical issue since a secret exponent is never going to be
short, but we're still supposed to use the constant-time path for
non-public exponents.
2026-05-31 09:37:31 +02:00
Frank Denis 99c2792b5e tls: reject undersized TLS 1.2 AEAD records in readIndirect (#31973)
Don't crash when a peer send a short record (the handshake is fine)

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31973
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-05-31 09:36:25 +02:00
Andrew Kelley d4a295a9de Merge pull request 'std.crypto.codecs.asn1: fix. compilation after IO changes and improve correctness' (#35326) from jedisct1/zig:asn1der into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35326
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-05-29 05:53:30 +02:00
Andrew Kelley d534cfa787 Merge pull request 'std.crypto.aes-siv: Add an assertion for the number of AD inputs' (#31977) from jedisct1/zig:associated-data-vector-length-can-overrun-fixed-stack-buffer into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31977
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
2026-05-29 05:51:20 +02:00
Frank Denis ff3fcb0290 Fix leftover from the older StructField 2026-05-28 16:42:21 +02:00
Frank Denis b1240e1387 aes-siv: update the comment to mention the max number of AD inputs 2026-05-28 16:34:04 +02:00
Frank Denis 03fbadbf3a std.crypto.aes-siv: Add an assertion for the number of AD inputs
AES-SIV supports "only" up to 126 AD fields.

Passing more than that never happens in any real-world protocol
(it's typically 1-3), but an assert() doesn't hurt.
2026-05-28 16:34:04 +02:00
Frank Denis 944b55fb68 der.Encoder: skip null optionals and restore outer field tag
Null optional struct fields were emitted as empty TLVs.

They should be omitted instead.

The outer field tag should also be restored after encoding struct
fields.
2026-05-28 16:28:27 +02:00
Frank Denis 415c574b92 der.Decoder: respect the bounds of the target type on int values 2026-05-28 16:28:27 +02:00
Frank Denis 3086628e7b codecs.asn1: add tests against X.690 examples 2026-05-28 16:28:27 +02:00
Frank Denis 761f8d2f8a der.Decoder: fix int slice and sign-extension 2026-05-28 16:28:27 +02:00
Frank Denis 5ab3a21e39 std.crypto.codecs: include asn1 tests
Make sure the asn1 code compiles and runs.
2026-05-28 16:28:27 +02:00
Frank Denis f6deade4e0 std.crypto.codecs.asn1: fix high-tag-number encoding
The encoder was writing 15 in the low five bits to mark a high tag
number insetad of 31.

Emit the correct marker and as many continuation bytes as the tag
number requires, and expose encodeToSlice so a Writer is not needed
any more.

And return proper errors.

Fixes #32069 and supersedes #32139
2026-05-28 16:28:27 +02:00
Frank Denis af1f91cadf std.crypto.codecs.asn1.der.Encoder: rewrite with prependBytes
Drop the writer wrapper since ArrayListReverse no longer exposes one,
and use prependBytes consistently.

Also rewrite length encoding so the high-bit length-of-length byte is
placed last as expected by X.690.

And always derive the leading-zero pad from the sign bit of the
first encoded byte.
2026-05-28 16:28:27 +02:00
Frank Denis 87e0dc7dea std.crypto.codecs.asn1.Oid: align toDot with the new Writer API
Take a *std.Io.Writer instead of an anytype writer, and read the test
output via stream.buffered() now that .written() is gone.
2026-05-28 16:28:27 +02:00
Frank Denis 7a755c4d2d Add AES tests for or/xor/and blocks 2026-05-28 16:27:45 +02:00
Frank Denis b70c1ad89f std.crypto.aes: fix BlockVec xorBytes and orBlocks signatures
Both methods had wrong parameter or return types that would cause
compilation failures.
2026-05-28 16:27:45 +02:00
Krzysztof Wolicki 9e80795623 all: update to use new std.lang.Type definitions 2026-05-27 10:03:51 +01:00
Alex Rønne Petersen 0d4f3cc675 re-enable some tests on RISC-V that no longer fail
Miscompilations appear to have been fixed with LLVM 22.

closes https://github.com/ziglang/zig/issues/24299
closes https://github.com/ziglang/zig/issues/24300
closes https://github.com/ziglang/zig/issues/24301
closes https://github.com/ziglang/zig/issues/25083
2026-05-21 20:37:11 +02:00
Linus Groh 991f56fd6b std.meta: Remove Int in favor of @Int 2026-05-03 21:42:06 +01:00
Matthew Lugg 72d954e7d3 compiler: remove array multiplication from the language
Resolves: https://github.com/ziglang/zig/issues/24738
2026-04-30 09:03:58 +01:00
Matthew Lugg fdac89d6cd remove uses of array multiplication
In preparation for its removal as accepted in
https://github.com/ziglang/zig/issues/24738.
2026-04-30 08:57:51 +01:00
GasInfinity 1deb029a66 std: rename bit_set variants and deprecate the managed one.
* aliases and deprecates the previous names.
* also update callsites to use the non-deprecated declarations.
2026-04-27 16:46:26 +02:00
Alex Rønne Petersen 4eb9db0b24 std: re-enable some tests on loongarch64 2026-04-26 21:22:34 +02:00
Alex Rønne Petersen fc56124fac std: re-enable some tests on s390x
closes https://github.com/ziglang/zig/issues/25957
2026-04-26 21:22:31 +02:00
Ryan Liptak 3252a05531 Prefer <err> => |e| return e over <err> => return <err>
Avoids the potential for a typo on the `return <err>` side of the prong
2026-04-20 18:03:14 -07:00
Frank Denis 98cc059622 crypto.asn1.Oid: Reject empty OID encodings (#31983)
The DER decoder accepted zero-length OID payloads producing an Oid value that would panic later.

Co-authored-by: Frank Denis <github@pureftpd.org>
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31983
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Frank Denis <jedisct1@noreply.codeberg.org>
Co-committed-by: Frank Denis <jedisct1@noreply.codeberg.org>
2026-04-20 21:54:04 +02:00
Frank Denis 98ddebc380 std.crypto.Certificate: fix UTCTime year interpretation
UTCTime years in the range 50-99 must map to 1950-1999, but the
parser unconditionally added 2000, producing dates 100 years in the
future.

This caused verify() to accept certificates whose validity actually
expired decades ago.

Change that to match what OpenSSL, BoringSSL, etc. do
2026-04-20 21:45:08 +02:00
Frank Denis 525aff6048 std.crypto.ascon: fix streaming XOF/CXOF
AsconXof128 and AsconCxof128 were applying the padding in update()
calls. That was totally fine for one-shot hashing, but not for
streaming (multiple update() calls before finalization).
2026-04-20 18:29:46 +02:00
Frank Denis 3a07f50dab std.crypto.ml_kem tests: simplify incV
We don't need to reimplement 16-byte subtraction, just use a
u128. As a bonus, that handles the theoretical case of an all-0xff
value properly.
2026-04-20 18:27:22 +02:00
Frank Denis ac7e895df0 tls.Client: reject empty TLS 1.3 inner plaintext and short records
After decryption, TLS 1.3 plaintext is trimmed of zero padding, then
the last byte is read as the content type.

But when the plaintext was entirely zero padding, we got a
"thread panic: integer overflow at msg.len - 1" error. That could be
triggered by any server to crash the client.
2026-04-20 12:07:51 +02:00
Frank Denis bc08199ef1 crypto TLS bundle: make AddCertsFromDirPathError compile
It's calling `addCertsFromDir`, which now requires a timestamp,
so it didn't compile any more.

Add a test by the way.
2026-04-12 00:13:59 +02:00
nekogirl ac6fb0b59a Correct Element and Tag in crypto.codecs.asn1 (#31511)
Previously, `std.crypto.codecs.asn1.der.decode` failed to compile because of `std.Io.Reader` usage in `Element.decode` and `Tag.decode` and `DecodeError` not being compatible with `std.Io.Reader.Error`.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31511
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: nekogirl <nekogirl@noreply.codeberg.org>
Co-committed-by: nekogirl <nekogirl@noreply.codeberg.org>
2026-04-09 17:59:16 +02:00
nektro e73257dec2 lib/std: BitSet,EnumSet: replace initEmpty/initFull with decl literals (#31469)
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31469
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: nektro <hello@nektro.net>
Co-committed-by: nektro <hello@nektro.net>
2026-04-05 05:12:13 +02:00
Frank Denis dcb33abc2c crypto.base64: use "-" instead of "+" character in URL-safe mode
/ was turned into _, but + also needs to be turned into -
2026-03-29 09:33:22 +02:00
akhildevelops eec244c5a2 std.crypto.tls.Client: expose InitError (#31610)
Fixes: https://codeberg.org/ziglang/zig/issues/31581
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31610
Co-authored-by: akhildevelops <akhildevelops@noreply.codeberg.org>
Co-committed-by: akhildevelops <akhildevelops@noreply.codeberg.org>
2026-03-25 00:56:22 +01:00
David Rubin 8efd539305 crypto: correct aes-siv s2v
The first issue is that when len(Sn) >= 128,
we perform Sn xor D instead of the Sn xorend D
that is specified in RFC 5297.

The second issue is that we truncate the Sn
if it is larger than 4096 bytes, which could
lead to collisions between inputs. We solve
this by absoring the Sn into the CMAC state
perform the last 16 bytes, xoring those 16
bytes with D as described in the first issue,
and then updating and squeezing the CMAC.
2026-03-22 07:21:41 -07:00
Jacob Young 83c7aba127 windows: trigger automatic fetching of root certificates 2026-03-20 19:23:48 +01:00
UraniaZPM 485b996b61 Make benchmarking use std.Io.Clock.awake for timing (#31553)
In #31086, the `std.time.Timer` struct was removed, but this broke the last few programs that used it, those being the benchmarking programs for `std.Random`, `std.hash`, `std.crypto` and `std.unicode`. One more is `zig/perf_test.zig`, but as far as I can tell, that one is broken due to changes in file import rules too, unless I'm launching it wrong.

I also spotted some performance and benchmarking issues with the RNGs, detailed in #31554.

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31553
Reviewed-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: UraniaZPM <uraniazpm@noreply.codeberg.org>
Co-committed-by: UraniaZPM <uraniazpm@noreply.codeberg.org>
2026-03-18 21:00:08 +01:00
Alex Rønne Petersen e0d38561f0 std.crypto.argon2: disable flaky test kdf derived key length
https://codeberg.org/ziglang/zig/issues/31504
2026-03-14 05:55:24 +01:00
Kendall Condon 02e8339ca7 zig build fmt 2026-03-12 17:44:03 -04:00
Alex Rønne Petersen b778826df5 std.crypto.argon2: disable kdf test
https://codeberg.org/ziglang/zig/issues/31402
2026-03-05 18:49:31 +01:00
Frank Denis e8ca9229c8 Expose the elligator map for Curve25519
This is the same as for Edwards25519 without the y coordinate,
since it returns Montgomery coordinates, but it can be confusing
to call the Edwards25519 function while working on the
Curve25519 representation.

New protocols such as CPACE requires the map over Curve25519.
2026-02-23 13:04:58 +01:00
Andrew Kelley 54eb03cbf6 std.Io.Select: remove "outstanding" field
it is not fundamentally part of this abstraction
2026-02-20 16:42:37 -08:00
IntegratedQuantum 0bed4fb384 crypto: Allow arbitrary types for secureZeroes
also removed some related ptrCasts
2026-02-13 17:07:03 +01:00
Andrew Kelley 922ab8b8bc std: finish moving time to Io interface
Importantly, adds ability to get Clock resolution, which may be zero.
This allows error.Unexpected and error.ClockUnsupported to be removed
from timeout and clock reading error sets.
2026-02-02 23:02:31 -08:00
Andrew Kelley e56563ce3f std.Io.File.MultiReader: implementation fixes 2026-01-30 22:03:14 -08:00
Frank Denis 8709f53d44 crypto.ff: allow seamless chaining regardless of representation (#30913)
Finite field elements can be in regular or Montgomery form, and
chaining different operations use to require manual and error-prone
conversions.

Now:

- `add`, `sub` and `mul` convert the second operand to match the
first operand's form
- `sq` and `pow` preserve the input's Montgomery form
- `toPrimitive` and `toBytes` return `UnexpectedRepresentation` if
the element is in Montgomery form, preventing incorrect serialization

This is fully backwards compatible and allows seamless chaining of
operations regardless of their representation.
2026-01-25 17:42:01 +01:00
Alex Rønne Petersen 9dd2716229 std.crypto.kangarootwelve: disable more flaky tests
https://codeberg.org/ziglang/zig/issues/30676
2026-01-13 09:19:08 +01:00