aboutsummaryrefslogtreecommitdiff
path: root/lib/std
AgeCommit message (Collapse)Author
2025-09-18Remove usages of deprecatedWriterandrewkraevskii
2025-09-19std.fmt: migrate bufPrintZ to bufPrintSentinel (#25260)John Benediktsson
2025-09-19std.simd: suggest more sensible vector sizes across the boardAlex Rønne Petersen
2025-09-17Merge pull request #25195 from blblack/netdefsAndrew Kelley
std: Add several sockopt-related constants and structs
2025-09-17Merge pull request #25197 from rootbeer/24380-flaky-sigset-testAndrew Kelley
Re-enable std.posix "sigset_t bits" test
2025-09-17Merge pull request #25217 from blblack/setsiderrAndrew Kelley
std.os.linux.setsid(): return raw syscall0 result
2025-09-17Merge pull request #25225 from Justus2308/darwin-fixesAndrew Kelley
std.*.ptrace: support more platforms and features more correctly
2025-09-17mem.replace: Document that input/output cannot overlapRyan Liptak
2025-09-17Merge pull request #25249 from jedisct1/sivAndrew Kelley
std.crypto: add AES-SIV and AES-GCM-SIV
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-09-17std.sort.pdq: fix out-of-bounds access in partialInsertionSort (#25253)Frank Denis
* std.sort.pdq: fix out-of-bounds access in partialInsertionSort When sorting a sub-range that doesn't start at index 0, the partialInsertionSort function could access indices below the range start. The loop condition `while (j >= 1)` didn't respect the arbitrary range boundaries [a, b). This changes the condition to `while (j > a)` to ensure indices never go below the range start, fixing the issue where pdqContext would access out-of-bounds indices. Fixes #25250
2025-09-17use block break instead of returnmarko
2025-09-17Avoid logic where we return success in case of an error (#25251)Frank Denis
In ed25519.zig, we checked if a test succeeds, in which case we returned an error. This was confusing, and Andrew pointed out that Zig weights branches against errors by default.
2025-09-16Parallelize deriveKeysFrank Denis
2025-09-16Import crypto/aes_gcm_siv.zigFrank Denis
2025-09-16std.crypto: add AES-SIV and AES-GCM-SIVFrank Denis
The Zig standard library lacked schemes that resist nonce reuse. AES-SIV and AES-GCM-SIV are the standard options for this. AES-GCM-SIV can be very useful when Zig is used to target embedded systems, and AES-SIV is especially useful for key wrapping. Also take it as an opportunity to add a bunch of test vectors to modes.ctr and make sure it works with block ciphers whose size is not 16.
2025-09-15bpf: use bitCast instead of intCast in ld_imm_implGeorge Huebner
Any 32 bit immediate is allowed in a BPF instruction, including those greater than the largest positive i32 value.
2025-09-15std.net.Ip6Address: format numerical scope iddatabase64128
2025-09-13std.math.big.int: normalize zero result for small multiplicationsmlugg
Resolves: #25221
2025-09-13std.os.linux.ptrace: add PTRACE_EVENT_* and PTRACE_O_* valuesJustus Klausecker
2025-09-13std.posix.ptrace: support more platforms more correctlyJustus Klausecker
2025-09-12linux: Doc and check retval for no-fail pid callsBrandon Black
The switch from @bitCast() to @intCast() here safety-checks Linux's assertion that these 3 calls never return errors (negative values as pid_t). getppid() can legally return 0 if the parent is in a different pid namespace, but this is not an error.
2025-09-12std.os.linux.setsid(): return raw syscall0 resultBrandon Black
When not linking libc on 64-bit Linux and calling posix.setsid(), we get a type error at compile time inside of posix.errno(). This is because posix.errno()'s non-libc branch expects a usize-sized value, which is what all the error-returning os.linux syscalls return, and linux.setsid() instead returned a pid_t, which is only 32 bits wide. This and the other 3 pid-related calls just below it (getpid(), getppid(), and gettid()) are the only Linux syscall examples here that are casting their return values to pid_t. For the other 3 this makes sense: those calls are documented to have no possible errors and always return a valid pid_t value. However, setsid() actually can return the error EPERM, and therefore needs to return the raw value from syscall0 for posix.errno() to process like normal. Additionally, posix.setsid() needs an @intCast(rc) for the success case as a result, like most other such cases.
2025-09-12std.os.linux.socketpair(): switch to unsigned argsBrandon Black
We need std.os.linux and std.c to agree on the types here, or else we'd have to pointlessly cast across the difference up in the std.posix wrapper. I ran into this as a type error the first time I tried to compile my code that calls posix.socketpair() on Linux without libc. All of our existing socket calls with these kinds of arguments in std (including the existing c.socketpair as well as os.linux.socket in this same file) use unsigned for all of these parameters, and so this brings linux.socketpair() into alignment with everything else.
2025-09-11use pointer subtractionmarko
2025-09-10Merge pull request #24968 from ifreund/dequeAndrew Kelley
std: add a Deque data structure
2025-09-09standalone posix tests for sigactionPat Tullmann
Fixes #24380
2025-09-09standalone posix tests for relative path linkingPat Tullmann
2025-09-09standalone posix test for env varsPat Tullmann
2025-09-09standalone posix test for current working directoryPat Tullmann
2025-09-09posix/test.zig: "sigset_t bits" test fixesPat Tullmann
Re-enable the test. Will trigger #24380 as-is, but follow-on change moes this code over to test/standalone. Make the test a bit easier to debug by stashing the "seen" signal number in the shared `seen_sig` (instead of just incrementing a counter for each hit). And only doing so if the `seen_sig` is zero.
2025-09-09Move some Thread tests out of posix/test.zig into Thread.zigPat Tullmann
These tests aren't (directly) using Posix APIs, so they don't need to be in posix/test.zig. Put them over with the code and tests in Thread.zig. Since the spawn/join test in the posix code was redundant, just dropped that one.
2025-09-09std: add IP, IPV6, IPTOS sockopt constantsBrandon Black
Because these lists are very long in several cases and quite varied, I opted to place them in the existing c/foo.zig files. There are many other sets of network-related constants like this to add over time across all the OSes. For now I picked these because I needed a few constants from each of these namespaces for my own project, so I tried to flesh out these namespaces completely as best I could, at least for basic sockopt purposes. Note windows has some of these already defined in ws2_32 as individual constants rather than contained in a namespacing struct. I'm not sure what to do with that in the long run (break it and namespace them?), but this doesn't change the status quo for windows in any case.
2025-09-09std: add linger struct for SO.LINGERBrandon Black
2025-09-09std: add in_pktinfo and in6_pktinfo structs defsBrandon Black
in_pktinfo is only used on a few targets for the IP_PKTINFO sockopt, as many BSDs use an alternate mechanism (IP_RECVDSTADDR) that doesn't require a special struct. in6_pktinfo is more universal.
2025-09-09std.c: Add accept_filter_arg for some BSDsBrandon Black
This is the struct type used as set/getsockopt() option data with SO.ACCEPTFILTER, which is also only declared on this same limited set of BSD-ish targets. In theory this could be aliased over to std.posix as well, but I think for a corner case like this, it's not unreasonable for a user that is avoiding uneccessary std.c references to access it as "posix.system.accept_filter_arg" (which would still work fine if, in the future, FreeBSD escapes its libc dep and defines it in std.os.freebsd).
2025-09-09std: Add SCM constants for socket control messagesBrandon Black
2025-09-09Merge pull request #25191 from ziglang/fix-linker-undef-memoryAndrew Kelley
fix linker writing undefined memory to output file
2025-09-08Merge pull request #25190 from blblack/netcallsAndrew Kelley
Add missing posix wrappers for socketpair() and recvmsg()
2025-09-08std.Io.Writer.writeSliceEndian: add compile errorAndrew Kelley
check when an auto-layout struct is attempted to be memory reinterpreted and written out. it would be writing undefined memory
2025-09-08std.crypto.ed25519: support cofactorless verificationFrank Denis
Add verifyStrict() functions for cofactorless verification. Also: - Support messages < 64 characters in the test vectors - Allow mulDoubleBasePublic to return the identity as a regular value. There are valid use cases for this.
2025-09-08ECDSA signature der encoding should produce smallest number of octets (#25177)Igor Anić
I noticed this by stress testing my tls server implementation. From time to time curl (and other tools: ab, vegeta) will report invalid signature. I trace the problem to the way how std lib is encoding raw signature into der format. Using raw signature I got in some cases different encoding using std and openssl. Std is not producing minimal der when signature `r` or `s` integers has leading zero(es). Here is an example to illustrate difference. Notice leading 00 in `s` integer which is removed in openssl encoding but not in std encoding. ```Zig const std = @import("std"); test "ecdsa signature to der" { // raw signature r and s bytes const raw = hexToBytes( \\ 49 63 0c 94 95 2e ff 4b 02 bf 35 c4 97 9e a7 24 \\ 20 dc 94 de aa 1b 17 ff e1 49 25 3e 34 ef e8 d0 \\ c4 43 aa 7b a9 f3 9c b9 f8 72 7d d7 0c 9a 13 1e \\ \\ 00 56 85 43 d3 d4 05 62 a1 1d d8 a1 45 44 b5 dd \\ 62 9f d1 e0 ab f1 cd 4a 85 d0 1f 5d 11 d9 f8 89 \\ 89 d4 59 0c b0 6e ea 3c 19 6a f7 0b 1a 4a ce f1 ); // encoded by openssl const expected = hexToBytes( \\ 30 63 02 30 \\ 49 63 0c 94 95 2e ff 4b 02 bf 35 c4 97 9e a7 24 \\ 20 dc 94 de aa 1b 17 ff e1 49 25 3e 34 ef e8 d0 \\ c4 43 aa 7b a9 f3 9c b9 f8 72 7d d7 0c 9a 13 1e \\ \\ 02 2f \\ 56 85 43 d3 d4 05 62 a1 1d d8 a1 45 44 b5 dd \\ 62 9f d1 e0 ab f1 cd 4a 85 d0 1f 5d 11 d9 f8 89 \\ 89 d4 59 0c b0 6e ea 3c 19 6a f7 0b 1a 4a ce f1 ); // encoded by std const actual = hexToBytes( \\ 30 64 02 30 \\ 49 63 0c 94 95 2e ff 4b 02 bf 35 c4 97 9e a7 24 \\ 20 dc 94 de aa 1b 17 ff e1 49 25 3e 34 ef e8 d0 \\ c4 43 aa 7b a9 f3 9c b9 f8 72 7d d7 0c 9a 13 1e \\ \\ 02 30 \\ 00 56 85 43 d3 d4 05 62 a1 1d d8 a1 45 44 b5 dd \\ 62 9f d1 e0 ab f1 cd 4a 85 d0 1f 5d 11 d9 f8 89 \\ 89 d4 59 0c b0 6e ea 3c 19 6a f7 0b 1a 4a ce f1 ); _ = actual; const Ecdsa = std.crypto.sign.ecdsa.EcdsaP384Sha384; const sig = Ecdsa.Signature.fromBytes(raw); var buf: [Ecdsa.Signature.der_encoded_length_max]u8 = undefined; const encoded = sig.toDer(&buf); try std.testing.expectEqualSlices(u8, &expected, encoded); } pub fn hexToBytes(comptime hex: []const u8) [removeNonHex(hex).len / 2]u8 { @setEvalBranchQuota(1000 * 100); const hex2 = comptime removeNonHex(hex); comptime var res: [hex2.len / 2]u8 = undefined; _ = comptime std.fmt.hexToBytes(&res, hex2) catch unreachable; return res; } fn removeNonHex(comptime hex: []const u8) []const u8 { @setEvalBranchQuota(1000 * 100); var res: [hex.len]u8 = undefined; var i: usize = 0; for (hex) |c| { if (std.ascii.isHex(c)) { res[i] = c; i += 1; } } return res[0..i]; } ``` Trimming leading zeroes from signature integers fixes encoding.
2025-09-08recvmsg: posix wrapper, void on windowsBrandon Black
Also, added EPIPE to recvfrom() error set (it's a documented error for unix and tcp sockets, at least), which recvmsg() largely shares. Windows has an odd, callback-based form of recvmsg() that doesn't fit the normal interface here.
2025-09-08socketpair: posix wrapper, void on windowsBrandon Black
socketpair is something like a pipe2() for sockets, and generally only works for AF_UNIX sockets for most platforms. Winsock2 explicitly does not support this call, even though it does have AF_UNIX sockets.
2025-09-07std.mem.indexOfSentinel: eliminate unnecessary `@ptrCast`Andrew Kelley
it was always unnecessary but now it's illegal
2025-09-07std.debug.assertAligned: support const pointersAndrew Kelley
2025-09-06std.http.Client.Connection: make host() publicbaltevl
Closes #25153
2025-09-06Document std.mem.* functions (#25168)Frank Denis
* Document std.mem.* functions Functions in std.mem are essential for virtually all applications, yet many of them lacked documentation. Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-09-06Merge pull request #25163 from ziglang/packed-union-unusedAndrew Kelley
forbid unused bits in packed unions
2025-09-05remove ResponseStoragerpkak
unused since 5ce8e9325b7aa15cbcc77221fc7075b6c46619cc