Skip to content

Commit

Permalink
Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.
Browse files Browse the repository at this point in the history
This system call is present on all supported NetBSD versions and
provides an endless stream of non-blocking random data from the
kernel's ChaCha20-based CSPRNG. It doesn't require a file descriptor
to be opened.

The system call is documented here (under kern.arandom):
https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+7+NetBSD-7.0

And defined here:
https://nxr.netbsd.org/xref/src/sys/sys/sysctl.h#273

The semantics are the same as FreeBSD so reading 256 bytes per call
is fine.

Similar change for getrandom crate: rust-random/getrandom#115
  • Loading branch information
alarixnia committed Nov 4, 2019
1 parent 2477e24 commit 23d2211
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/libstd/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub fn hashmap_random_keys() -> (u64, u64) {
not(target_os = "ios"),
not(target_os = "openbsd"),
not(target_os = "freebsd"),
not(target_os = "netbsd"),
not(target_os = "fuchsia"),
not(target_os = "redox")))]
mod imp {
Expand Down Expand Up @@ -142,7 +143,7 @@ mod imp {
}
}

#[cfg(target_os = "freebsd")]
#[cfg(target_os = "freebsd", target_os = "netbsd")]
mod imp {
use crate::ptr;

Expand Down

0 comments on commit 23d2211

Please sign in to comment.