Add arc4random_buf() in NetBSD libc, use it to implement getrandom()

This commit is contained in:
nia 2020-05-01 17:22:27 +01:00
parent b23a87953a
commit 14a954f350
2 changed files with 5 additions and 0 deletions

View File

@ -9,6 +9,7 @@ pub const _errno = __errno;
pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize, data: ?*c_void) c_int;
pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;
pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int;
pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int;

View File

@ -153,6 +153,10 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
}
return;
}
if (builtin.os.tag == .netbsd) {
netbsd.arc4random_buf(buffer.ptr, buffer.len);
return;
}
if (builtin.os.tag == .wasi) {
switch (wasi.random_get(buffer.ptr, buffer.len)) {
0 => return,