ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.46k stars 2.52k forks source link

`std.options.crypto_always_getrandom` ignores overridden `std.options.cryptoRandomSeed` #19943

Open Khitiara opened 5 months ago

Khitiara commented 5 months ago

Zig Version

0.13.0-dev.46+3648d7df1

Steps to Reproduce and Observed Behavior

I'm using std_options.cryptoRandomSeed to provide a hardware secure random source for my hobby os, and I'd like to use crypto_always_getrandom to allow me to compile without the single_threaded flag since there is no syscall overhead on getting the random value when in kernel mode already anyway, but when i set crypto_always_getrandom = true the program fails to compile due to that branch always calling posix getrandom directly.

Expected Behavior

The program should compile and use my provided cryptoRandomSeed for all cryptographic random calls. or this behavior should be documented better if intentional.

insalt-glitch commented 5 months ago

To me, it looks like this would require a change here: https://github.com/ziglang/zig/blob/c77afca957b53f148b566a2b0d1f7e582a0888de/lib/std/crypto/tlcsprng.zig#L72-L77

Where the call to defaultRandomSeed has to be replaced by calling std.options.cryptoRandomSeed.

Unfortunately, I'm quite new to this, so I don't know how to install Zig from source and perform the testing :/ (I'm aware that there is a HowTo, but I'm a total noob).

rohlem commented 5 months ago

@insalt-glitch Note that you can edit the standard library (in lib/std) of a built/downloaded Zig distribution and the changes will immediately take effect for all subsequent builds; no need to rebuild the compiler itself from source.