diff --git a/src/lib.rs b/src/lib.rs index 31c18001..d44d87f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ //! | Windows | `*‑windows‑*` | [`BCryptGenRandom`] //! | macOS | `*‑apple‑darwin` | [`getentropy`][3] //! | iOS, tvOS, watchOS | `*‑apple‑ios`, `*-apple-tvos`, `*-apple-watchos` | [`CCRandomGenerateBytes`] -//! | FreeBSD | `*‑freebsd` | [`getrandom`][5] if available, otherwise [`kern.arandom`][6] +//! | FreeBSD | `*‑freebsd` | [`getrandom`][5] //! | OpenBSD | `*‑openbsd` | [`getentropy`][7] //! | NetBSD | `*‑netbsd` | [`getrandom`][16] if available, otherwise [`kern.arandom`][8] //! | Dragonfly BSD | `*‑dragonfly` | [`getrandom`][9] @@ -173,7 +173,6 @@ //! [3]: https://www.unix.com/man-page/mojave/2/getentropy/ //! [4]: https://www.unix.com/man-page/mojave/4/urandom/ //! [5]: https://www.freebsd.org/cgi/man.cgi?query=getrandom&manpath=FreeBSD+12.0-stable -//! [6]: https://www.freebsd.org/cgi/man.cgi?query=random&sektion=4 //! [7]: https://man.openbsd.org/getentropy.2 //! [8]: https://man.netbsd.org/sysctl.7 //! [9]: https://leaf.dragonflybsd.org/cgi/web-man?command=getrandom @@ -240,6 +239,7 @@ cfg_if! { #[path = "use_file.rs"] mod imp; } else if #[cfg(any( target_os = "dragonfly", + target_os = "freebsd", target_os = "hurd", // Check for target_arch = "arm" to only include the 3DS. Does not // include the Nintendo Switch (which is target_arch = "aarch64"). @@ -298,9 +298,9 @@ cfg_if! { mod util_libc; mod use_file; #[path = "solaris_illumos.rs"] mod imp; - } else if #[cfg(any(target_os = "freebsd", target_os = "netbsd"))] { + } else if #[cfg(target_os = "netbsd")] { mod util_libc; - #[path = "bsd_arandom.rs"] mod imp; + #[path = "netbsd.rs"] mod imp; } else if #[cfg(target_os = "fuchsia")] { #[path = "fuchsia.rs"] mod imp; } else if #[cfg(any(target_os = "ios", target_os = "visionos", target_os = "watchos", target_os = "tvos"))] { diff --git a/src/bsd_arandom.rs b/src/netbsd.rs similarity index 86% rename from src/bsd_arandom.rs rename to src/netbsd.rs index 6e133d89..b8a770f5 100644 --- a/src/bsd_arandom.rs +++ b/src/netbsd.rs @@ -1,4 +1,4 @@ -//! Implementation for FreeBSD and NetBSD +//! Implementation for NetBSD use crate::{ util_libc::{sys_fill_exact, Weak}, Error, @@ -28,7 +28,7 @@ fn kern_arnd(buf: &mut [MaybeUninit]) -> libc::ssize_t { type GetRandomFn = unsafe extern "C" fn(*mut u8, libc::size_t, libc::c_uint) -> libc::ssize_t; pub fn getrandom_inner(dest: &mut [MaybeUninit]) -> Result<(), Error> { - // getrandom(2) was introduced in FreeBSD 12.0 and NetBSD 10.0 + // getrandom(2) was introduced in NetBSD 10.0 static GETRANDOM: Weak = unsafe { Weak::new("getrandom\0") }; if let Some(fptr) = GETRANDOM.ptr() { let func: GetRandomFn = unsafe { core::mem::transmute(fptr) }; @@ -37,7 +37,7 @@ pub fn getrandom_inner(dest: &mut [MaybeUninit]) -> Result<(), Error> { }); } - // Both FreeBSD and NetBSD will only return up to 256 bytes at a time, and + // NetBSD will only return up to 256 bytes at a time, and // older NetBSD kernels will fail on longer buffers. for chunk in dest.chunks_mut(256) { sys_fill_exact(chunk, kern_arnd)?