Skip to content

Commit 23d2211

Browse files
committed
Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.
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
1 parent 2477e24 commit 23d2211

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/libstd/sys/unix/rand.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn hashmap_random_keys() -> (u64, u64) {
1515
not(target_os = "ios"),
1616
not(target_os = "openbsd"),
1717
not(target_os = "freebsd"),
18+
not(target_os = "netbsd"),
1819
not(target_os = "fuchsia"),
1920
not(target_os = "redox")))]
2021
mod imp {
@@ -142,7 +143,7 @@ mod imp {
142143
}
143144
}
144145

145-
#[cfg(target_os = "freebsd")]
146+
#[cfg(target_os = "freebsd", target_os = "netbsd")]
146147
mod imp {
147148
use crate::ptr;
148149

0 commit comments

Comments
 (0)