diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-12-17 20:03:41 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-12-18 12:22:46 -0700 |
| commit | 013efaf13987acfa6b41d40f07900c1ea77f5bda (patch) | |
| tree | 14325d114eb66312b3545f3a897142400dfb7c16 /src/main.zig | |
| parent | ce65533985caa9e2da567948e36d7d4ba0185005 (diff) | |
| download | zig-013efaf13987acfa6b41d40f07900c1ea77f5bda.tar.gz zig-013efaf13987acfa6b41d40f07900c1ea77f5bda.zip | |
std: introduce a thread-local CSPRNG for general use
std.crypto.random
* cross platform, even freestanding
* can't fail. on initialization for some systems requires calling
os.getrandom(), in which case there are rare but theoretically
possible errors. The code panics in these cases, however the
application may choose to override the default seed function and then
handle the failure another way.
* thread-safe
* supports the full Random interface
* cryptographically secure
* no syscall required to initialize on Linux (AT_RANDOM)
* calls arc4random on systems that support it
`std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`.
I moved some of the Random implementations into their own files in the
interest of organization.
stage2 no longer requires passing a RNG; instead it uses this API.
Closes #6704
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 15 |
1 files changed, 0 insertions, 15 deletions
diff --git a/src/main.zig b/src/main.zig index 0222d499fa..c54cc6515b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1632,13 +1632,6 @@ fn buildOutputType( }; defer zig_lib_directory.handle.close(); - const random_seed = blk: { - var random_seed: u64 = undefined; - try std.crypto.randomBytes(mem.asBytes(&random_seed)); - break :blk random_seed; - }; - var default_prng = std.rand.DefaultPrng.init(random_seed); - var libc_installation: ?LibCInstallation = null; defer if (libc_installation) |*l| l.deinit(gpa); @@ -1754,7 +1747,6 @@ fn buildOutputType( .single_threaded = single_threaded, .function_sections = function_sections, .self_exe_path = self_exe_path, - .rand = &default_prng.random, .clang_passthrough_mode = arg_mode != .build, .clang_preprocessor_mode = clang_preprocessor_mode, .version = optional_version, @@ -2420,12 +2412,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v .directory = null, // Use the local zig-cache. .basename = exe_basename, }; - const random_seed = blk: { - var random_seed: u64 = undefined; - try std.crypto.randomBytes(mem.asBytes(&random_seed)); - break :blk random_seed; - }; - var default_prng = std.rand.DefaultPrng.init(random_seed); const comp = Compilation.create(gpa, .{ .zig_lib_directory = zig_lib_directory, .local_cache_directory = local_cache_directory, @@ -2441,7 +2427,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v .emit_h = null, .optimize_mode = .Debug, .self_exe_path = self_exe_path, - .rand = &default_prng.random, }) catch |err| { fatal("unable to create compilation: {}", .{@errorName(err)}); }; |
