diff --git a/CHANGELOG.md b/CHANGELOG.md index d7995cb0..b65a1ddc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Added +- `disable_urandom_fallback` crate feature to disable `/dev/urandom`-based fallback on Linux targets. + Enabling this feature bumps minimum supported Linux kernel version to 4.17. [#396] + ### Changed - Disable `/dev/urandom`-based fallback for all Android targets and for Linux targets outside of the following `target_arch`es: `x86`, `x86_64`, `arm`, `armv7`, `i586`, `i686`, diff --git a/Cargo.toml b/Cargo.toml index ea57331d..b0720a85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,8 @@ wasm-bindgen-test = "0.3.18" [features] # Implement std-only traits for getrandom::Error std = [] +# Disable `/dev/urandom` fallback for Linux targets (requires 4.17+ kernel) +disable_urandom_fallback = [] # Feature to enable fallback RDRAND-based implementation on x86/x86_64 rdrand = [] # Feature to enable JavaScript bindings on wasm*-unknown-unknown diff --git a/src/lib.rs b/src/lib.rs index 7d3b7afc..061b5bf2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -220,17 +220,21 @@ cfg_if! { if #[cfg(any(target_os = "haiku", target_os = "redox", target_os = "nto", target_os = "aix"))] { mod util_libc; #[path = "use_file.rs"] mod imp; - } else if #[cfg(all(target_os = "linux", any( - target_arch = "i586", - target_arch = "i686", - target_arch = "x86", - target_arch = "x86_64", - target_arch = "arm", - target_arch = "armv7", - target_arch = "powerpc", - target_arch = "powerpc64le", - target_arch = "s390x", - )))] { + } else if #[cfg(all( + not(feature = "disable_urandom_fallback"), + target_os = "linux", + any( + target_arch = "i586", + target_arch = "i686", + target_arch = "x86", + target_arch = "x86_64", + target_arch = "arm", + target_arch = "armv7", + target_arch = "powerpc", + target_arch = "powerpc64le", + target_arch = "s390x", + ), + ))] { mod util_libc; mod use_file; mod lazy;