10582 Commits

Author SHA1 Message Date
Linus Groh
4b0f77cc1f std.crypto.tlcsprng: Fix hardcoded use of defaultRandomSeed()
Instead of hardcoding a call to defaultRandomSeed() use the customizable
std.options.cryptoRandomSeed() like in the rest of the function.

Closes #19943.
2025-02-22 22:39:40 -05:00
Alex Rønne Petersen
6ba785584a
compiler: Implement @disableIntrinsics() builtin function.
Closes #21833.
Closes #22110.
2025-02-23 04:08:56 +01:00
Andrew Kelley
8683f25d24 std.heap.DebugAllocator: default wasm to 64K page size
including on freestanding
2025-02-22 21:06:00 -05:00
Andrew Kelley
dd54c48aa2 std.crypto.asn1: fix merge conflicts 2025-02-22 17:44:11 -08:00
Andrew Kelley
ed7004a2ee
Merge pull request #19976 from clickingbuttons/asn1
std.crypto: Add ASN1 module with OIDs and DER
2025-02-22 20:21:09 -05:00
Andrew Kelley
eb3c7f5706 zig build fmt 2025-02-22 17:09:20 -08:00
Andrew Kelley
c0c911bfa7 zig fmt: fix invalid alignment on frees 2025-02-22 17:09:20 -08:00
Andrew Kelley
ed55b2ef17 update to new pop API 2025-02-22 17:09:20 -08:00
87flowers
8469a44c9c std/http/Client: Remove TODO comments on indentation 2025-02-22 17:09:20 -08:00
87flowers
87172ee4e6 std/zig/render: Add doc comments to AutoIndentingStream 2025-02-22 17:09:20 -08:00
87flowers
fdf68c2f2e std/zig/parser: Add indentation tests 2025-02-22 17:09:20 -08:00
87flowers
c724e157d6 std/zig/render: implement fixes for unit tests 2025-02-22 17:09:20 -08:00
87flowers
a702dc31cc std/zig/render: assigns are .after_equals 2025-02-22 17:09:20 -08:00
87flowers
6013b53702 std/zig/render: Collapse one level of indentation in binop after equals sign 2025-02-22 17:09:20 -08:00
87flowers
9b2677c639 std/zig/render: Implement space mode to fix comment indentation 2025-02-22 17:09:20 -08:00
87flowers
ec3e4cc14b std/zig/render: Initial implementation of indentation 2025-02-22 17:09:20 -08:00
87flowers
1b0584fd02 std/zig/render: Implement AutoIndentingStream.init 2025-02-22 17:09:19 -08:00
geemili
6ef2384c07 std.DynLib: add support for DT_GNU_HASH sections in elf files 2025-02-22 17:33:49 -05:00
Chris Covington
b7512c3e5d
Add rapidhash (#22085) 2025-02-22 14:32:48 -08:00
Wyatt Radkiewicz
33ffbb32c9
std.zig.system.NativePaths: Add Homebrew paths (#22738) 2025-02-22 14:22:54 -08:00
David Rubin
36fc2d2607 AstGen: make layout specifiers on opaque containers a compile error 2025-02-22 17:21:34 -05:00
Andrew Kelley
6fe1993d80 fix ArrayHashMap setKey when store_hash=true 2025-02-22 00:44:35 -05:00
Alex Rønne Petersen
f87b443af1 link.MachO: Add support for the -x flag (discard local symbols).
This can also be extended to ELF later as it means roughly the same thing there.

This addresses the main issue in #21721 but as I don't have a macOS machine to
do further testing on, I can't confirm whether zig cc is able to pass the entire
cgo test suite after this commit. It can, however, cross-compile a basic program
that uses cgo to x86_64-macos-none which previously failed due to lack of -x
support. Unlike previously, the resulting symbol table does not contain local
symbols (such as C static functions).

I believe this satisfies the related donor bounty: https://ziglang.org/news/second-donor-bounty
2025-02-22 06:35:19 +01:00
Andrew Kelley
a7467b9bb2
Merge pull request #22941 from Techatrix/config-header
std.Build.Step.ConfigHeader: improve handling of autoconf style headers
2025-02-22 00:25:09 -05:00
Kiëd Llaentenn
d31bda13cb std.atomic: make cache_line const a comptime_int
This fixes potential issues and unintended coercions in other areas,
such as std.ArrayList.
2025-02-22 03:48:09 +01:00
Mason Remaley
339b628d4c
Output zig targets as ZON instead of JSON (#22939)
* Adds startTupleField/startStructField, makes pattern in print targets less verbose

* Makes some enums into strings

* Start/finish renamed to begin/end

I feel bad changing this, but I don't know why I named them this way in the first place.
Begin/end is consistent with the json API, and with other APIs in the wild that follow this pattern.
Better to change now than later.
2025-02-21 21:40:57 -05:00
Frank Denis
65e7ede499 crypto.Ed25519.KeyPair: return an error rather than assert
When runtime safety is turned on, `Ed25519.fromSecretKey()` can
currently hit an assertion if the format of the secret key is
invalid.

Return an error instead, so that applications can recover.
2025-02-21 22:45:38 +01:00
Constantin Bilz
af2b6893e2 std.Build.Step.ConfigHeader: Add tests for Autoconf @FOO@ variables 2025-02-21 15:22:39 +01:00
Constantin Bilz
62e388e73e std.Build.Step.ConfigHeader: Add support for Autoconf @FOO@ variables
Add the new style `Style.autoconf_at`. Rename the existing
`Style.autoconf` (which uses `#undef` directives) to
`Style.autoconf_undef`.
2025-02-21 15:22:39 +01:00
Alex Rønne Petersen
31e7c95bd2 std.time: Make tests less flaky.
For the Timer decltest in particular, the margin check is not going to help if
the kernel just decides not to schedule the thread for a while after we call
timer.reset().

Failure observed here: https://github.com/ziglang/zig/actions/runs/13443634035/job/37563803341?pr=22909
2025-02-21 09:03:46 +01:00
Pat Tullmann
8d9bb97461 posix: access/accessZ/faccessat/faccessatZ can return AccessDenied or PermissionDenied
`EACCES` is returned if the file mode bit (i.e., user/group/other rwx
bits) disallow access.  `EPERM` is returned if something else denies
access (immutable bit, SELinux, capabilities, etc).  This somewhat subtle
no-access distinction is part of POSIX.  For now map both to
`error.PermissionDenied` to keep the error signature unchanged.  See
duopoly.

This PR is effecitvely an update/simplification of PR #19193.

Tested locally with an immutable file.

Fixes #22733 and #19162.
2025-02-21 07:29:15 +01:00
Jari Vetoniemi
aa5c6c027c linux: add UDP socket options 2025-02-21 06:05:04 +01:00
Ryan Liptak
bbd13ab961 rescanMac: Avoid overallocating/overreading by millions of bytes
readAtLeast is greedy and will read the entire length of the buffer if it can. However, reading past the end of the cert in this case is useless, so reading the full length of the buffer just puts an increasingly large (due to the growth algorithm of ArrayList) collection of wasted bytes after each cert in cb.bytes.

In practical terms, this ends up saving potentially millions of bytes of wasted reads/allocations. In my testing, after reading the keychain files on my machine, cb.bytes ends up with these capacities:

- Before: cb.bytes.capacity = 32720747
- After: cb.bytes.capacity = 251937

That's a decrease of 99.2%

Additionally, swaps to readNoEof since it should be an error to hit EOF without reading the full cert size.
2025-02-20 22:16:05 +01:00
Gabriel Borrelli
8e293ea8bd std.c: define MADV for darwin 2025-02-20 20:42:24 +01:00
Christian Fillion
dbc886fd04 translate-c: fix division and modulo of >8-bit stdint.h types in macros
Broke in c616141241047d6d6c811d43f644eb1b7d2b26ce and e64eef366c68592f6daf063a8b8f85b8626a1598
2025-02-20 13:33:59 +02:00
Frank Denis
84cdb62159
std.crypto: add the ability to explicitly tag a value as secret (#19907)
* std.crypto: add the ability to explicitly tag a value as secret

It turns out that Valgrind can be a very useful tool to check that secrets
are not leaked via side channels involving lookups or conditional jumps.

Valgrind tracks uninitialized data, and memcheck reports operations
involving uninitialized values. By permanently or temporarily telling
Valgrind that a memory region containing secrets is uninitialized, we can
detect common side-channel vulnerabilities.

For example, the following code snippets would immediately report that the
result is not computed in constant time:

```zig
classify(&key);
const len = std.mem.indexOfScalar(u8, &key, 0);
```

```zig
classify(&key);
const idx = key[0];
x += idx;
```

```zig
var x: [4]u8 = undefined;
std.crypto.random.bytes(&x);
classify(&x);
if (std.mem.eql(u8, "test", &x)) return;
```

This is not fool-proof, but it can help a lot to detect unwanted compiler
optimizations.

Also, right now, this is relying on Valgrind primitives, but these
annotations can be used to do more interesting things later, especially with
our own code generation backends.

* Update for Zig 0.14

* Remove checks for Valgrind enablement
2025-02-20 12:32:37 +01:00
Jari Vetoniemi
c41bc20ec7 linux: add IORING_RECVSEND_BUNDLE 2025-02-20 12:09:38 +01:00
Frank Denis
541d54a37d Clarify that ed25519.generateDeterministic() can be used outside tests
Fixes #22946
2025-02-20 09:01:13 +01:00
Pat Tullmann
d0e288ab18 lib/std/posix/test.zig: enable disabled tests using CWD
Four tests in lib/std/posix/test.zig were disabled because they created
fixed-name files in the current working directory, and this caused
problems if tests were running in parallel with other build's tests.

This PR fixes those tests to all use `std.testing.tmpDir` to create unique
temporary names and directories.

Also clean the tests up to more consistently use `defer` to clean up, or
to just rely on tmpDir cleanup to remove individual files.

Working on these tests revealed a bunch of stale WASI code paths in
posix.zig, fixed by replacing stale `wast.AT.FDCWD` references with just
`AT.FDCWD`.

Fixes #14968.
2025-02-20 08:44:09 +01:00
Frank Denis
8d824dfdd0
crypto.pwhash.bcrypt: make silently_truncate_password a member of Params (#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
2025-02-19 22:37:51 +01:00
Andrew Kelley
bd237bced4
Merge pull request #22932 from jacobly0/x86_64-rewrite
x86_64: start rewriting bit counting operations
2025-02-19 11:37:40 -08:00
Techatrix
c1c6f08296
std.Build.Step.ConfigHeader: permit inserting enum values 2025-02-19 09:34:46 +01:00
Techatrix
344db9e26b
std.Build.Step.ConfigHeader: skip trailing whitespace in autoconf header 2025-02-19 09:34:26 +01:00
Techatrix
7e548af8b1
std.Build.Step.ConfigHeader: allow using autoconf values multiple times 2025-02-19 09:34:26 +01:00
Nico Elbers
0cf6ae290b zon.stringify: Correctly serialize unions with void fields
Closes #22933
2025-02-19 07:21:59 +01:00
sidharta
59dc15fa0a docs: update old reference from builtin.Type.Struct to builtin.Type.@"struct" 2025-02-18 23:35:16 +01:00
Jacob Young
ebea56d279 x86_64: rewrite scalar @ctz 2025-02-18 09:47:44 -05:00
Ali Cheraghi
d5e1cb3ea2
spirv: ziggify and remove unknown spirv features
`OpCapability` and `OpExtension` now can also be emitted from inline assembly
2025-02-18 18:08:47 +03:30
Ali Cheraghi
1b0c7f51ef
target: update spirv features 2025-02-18 18:07:48 +03:30
Ali Cheraghi
7bbeac7f17
std.gpu: stop using comptimePrint 2025-02-18 18:07:31 +03:30