Skip to content

Commit 924c88d

Browse files
authored
Unconditionally use libc::getrandom on Illumos and libc::geentropy on Solaris (#417)
1 parent 20c2213 commit 924c88d

File tree

4 files changed

+26
-69
lines changed

4 files changed

+26
-69
lines changed

src/getrandom.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
//! Implementation using libc::getrandom
1+
//! Implementation using `libc::getrandom`.
2+
//!
3+
//! Available since:
4+
//! - Linux Kernel 3.17, Glibc 2.25, Musl 1.1.20
5+
//! - Android API level 23 (Marshmallow)
6+
//! - NetBSD 10.0
7+
//! - FreeBSD 12.0
8+
//! - Solaris 11.3
9+
//! - Illumos since Dec 2018
10+
//! - DragonFly 5.7
11+
//! - Hurd Glibc 2.31
12+
//! - shim-3ds since Feb 2022
213
use crate::{util_libc::sys_fill_exact, Error};
314
use core::mem::MaybeUninit;
415

src/lib.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
//! | OpenBSD | `*‑openbsd` | [`getentropy`][7]
1313
//! | NetBSD | `*‑netbsd` | [`getrandom`][16] if available, otherwise [`kern.arandom`][8]
1414
//! | Dragonfly BSD | `*‑dragonfly` | [`getrandom`][9]
15-
//! | Solaris, illumos | `*‑solaris`, `*‑illumos` | [`getrandom`][11] if available, otherwise [`/dev/random`][12]
15+
//! | Solaris | `*‑solaris` | [`getentropy`][11]
16+
//! | Illumos | `*‑illumos` | [`getrandom`][12]
1617
//! | Fuchsia OS | `*‑fuchsia` | [`cprng_draw`]
1718
//! | Redox | `*‑redox` | `/dev/urandom`
1819
//! | Haiku | `*‑haiku` | `/dev/urandom` (identical to `/dev/random`)
@@ -25,15 +26,11 @@
2526
//! | WASI | `wasm32‑wasi` | [`random_get`]
2627
//! | Web Browser and Node.js | `wasm*‑*‑unknown` | [`Crypto.getRandomValues`] if available, then [`crypto.randomFillSync`] if on Node.js, see [WebAssembly support]
2728
//! | SOLID | `*-kmc-solid_*` | `SOLID_RNG_SampleRandomBytes`
28-
//! | Nintendo 3DS | `armv6k-nintendo-3ds` | [`getrandom`][1]
29+
//! | Nintendo 3DS | `*-nintendo-3ds` | [`getrandom`][18]
2930
//! | PS Vita | `*-vita-*` | [`getentropy`][13]
3031
//! | QNX Neutrino | `*‑nto-qnx*` | [`/dev/urandom`][14] (identical to `/dev/random`)
3132
//! | AIX | `*-ibm-aix` | [`/dev/urandom`][15]
3233
//!
33-
//! There is no blanket implementation on `unix` targets that reads from
34-
//! `/dev/urandom`. This ensures all supported targets are using the recommended
35-
//! interface and respect maximum buffer sizes.
36-
//!
3734
//! Pull Requests that add support for new targets to `getrandom` are always welcome.
3835
//!
3936
//! ## Unsupported targets
@@ -176,13 +173,14 @@
176173
//! [7]: https://man.openbsd.org/getentropy.2
177174
//! [8]: https://man.netbsd.org/sysctl.7
178175
//! [9]: https://leaf.dragonflybsd.org/cgi/web-man?command=getrandom
179-
//! [11]: https://docs.oracle.com/cd/E88353_01/html/E37841/getrandom-2.html
180-
//! [12]: https://docs.oracle.com/cd/E86824_01/html/E54777/random-7d.html
176+
//! [11]: https://docs.oracle.com/cd/E88353_01/html/E37841/getentropy-2.html
177+
//! [12]: https://illumos.org/man/2/getrandom
181178
//! [13]: https://github.com/emscripten-core/emscripten/pull/12240
182179
//! [14]: https://www.qnx.com/developers/docs/7.1/index.html#com.qnx.doc.neutrino.utilities/topic/r/random.html
183180
//! [15]: https://www.ibm.com/docs/en/aix/7.3?topic=files-random-urandom-devices
184181
//! [16]: https://man.netbsd.org/getrandom.2
185182
//! [17]: https://www.gnu.org/software/libc/manual/html_mono/libc.html#index-getrandom
183+
//! [18]: https://github.com/rust3ds/shim-3ds/commit/b01d2568836dea2a65d05d662f8e5f805c64389d
186184
//!
187185
//! [`BCryptGenRandom`]: https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom
188186
//! [`Crypto.getRandomValues`]: https://www.w3.org/TR/WebCryptoAPI/#Crypto-method-getRandomValues
@@ -240,6 +238,7 @@ cfg_if! {
240238
} else if #[cfg(any(
241239
target_os = "macos",
242240
target_os = "openbsd",
241+
target_os = "solaris",
243242
target_os = "vita",
244243
target_os = "emscripten",
245244
))] {
@@ -249,6 +248,7 @@ cfg_if! {
249248
target_os = "dragonfly",
250249
target_os = "freebsd",
251250
target_os = "hurd",
251+
target_os = "illumos",
252252
// Check for target_arch = "arm" to only include the 3DS. Does not
253253
// include the Nintendo Switch (which is target_arch = "aarch64").
254254
all(target_os = "horizon", target_arch = "arm"),
@@ -302,10 +302,6 @@ cfg_if! {
302302
} else if #[cfg(any(target_os = "android", target_os = "linux"))] {
303303
mod util_libc;
304304
#[path = "linux_android.rs"] mod imp;
305-
} else if #[cfg(any(target_os = "illumos", target_os = "solaris"))] {
306-
mod util_libc;
307-
mod use_file;
308-
#[path = "solaris_illumos.rs"] mod imp;
309305
} else if #[cfg(target_os = "netbsd")] {
310306
mod util_libc;
311307
#[path = "netbsd.rs"] mod imp;

src/solaris_illumos.rs

-41
This file was deleted.

src/use_file.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,12 @@ use core::{
99
sync::atomic::{AtomicUsize, Ordering::Relaxed},
1010
};
1111

12-
// We prefer using /dev/urandom and only use /dev/random if the OS
13-
// documentation indicates that /dev/urandom is insecure.
14-
// On Solaris/Illumos, see src/solaris_illumos.rs
15-
// On Dragonfly, Haiku, and QNX Neutrino the devices are identical.
16-
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
17-
const FILE_PATH: &str = "/dev/random\0";
18-
#[cfg(any(
19-
target_os = "aix",
20-
target_os = "android",
21-
target_os = "linux",
22-
target_os = "redox",
23-
target_os = "dragonfly",
24-
target_os = "haiku",
25-
target_os = "nto",
26-
))]
12+
/// For all platforms, we use `/dev/urandom` rather than `/dev/random`.
13+
/// For more information see the linked man pages in lib.rs.
14+
/// - On Linux, "/dev/urandom is preferred and sufficient in all use cases".
15+
/// - On Redox, only /dev/urandom is provided.
16+
/// - On AIX, /dev/urandom will "provide cryptographically secure output".
17+
/// - On Haiku and QNX Neutrino they are identical.
2718
const FILE_PATH: &str = "/dev/urandom\0";
2819
const FD_UNINIT: usize = usize::max_value();
2920

0 commit comments

Comments
 (0)