diff --git a/Cargo.toml b/Cargo.toml index 6ac94dda55..f2d3d34cb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -311,6 +311,9 @@ libc = { version = "0.2.45" } [target.'cfg(any(target_os = "redox", all(unix, not(any(target_os = "macos", target_os = "ios")))))'.dependencies] lazy_static = "1.2" +[target.'cfg(target_os = "fuchsia")'.dependencies] +fuchsia-cprng = "0.1.0" + # Keep this in sync with `[dependencies]` in pregenerate_asm/Cargo.toml. [build-dependencies] cc = "1.0.26" diff --git a/src/rand.rs b/src/rand.rs index 4912b8d718..7b3112b4cb 100644 --- a/src/rand.rs +++ b/src/rand.rs @@ -95,7 +95,13 @@ impl sealed::Sealed for SystemRandom {} #[cfg(all( feature = "use_heap", - not(any(target_os = "linux", target_os = "macos", target_os = "ios", windows)) + not(any( + target_os = "linux", + target_os = "macos", + target_os = "ios", + target_os = "fuchsia", + windows + )) ))] use self::urandom::fill as fill_impl; @@ -110,6 +116,10 @@ use self::sysrand_or_urandom::fill as fill_impl; #[cfg(any(target_os = "macos", target_os = "ios"))] use self::darwin::fill as fill_impl; + +#[cfg(any(target_os = "fuchsia"))] +use self::fuchsia::fill as fill_impl; + use crate::sealed; #[cfg(target_os = "linux")] @@ -188,7 +198,8 @@ mod sysrand { feature = "use_heap", any(target_os = "redox", unix), not(any(target_os = "macos", target_os = "ios")), - not(all(target_os = "linux", not(feature = "dev_urandom_fallback"))) + not(all(target_os = "linux", not(feature = "dev_urandom_fallback"))), + not(any(target_os = "fuchsia")), ))] mod urandom { use crate::error; @@ -279,6 +290,16 @@ mod darwin { } } +#[cfg(any(target_os = "fuchsia"))] +mod fuchsia { + use crate::error; + + pub fn fill(dest: &mut [u8]) -> Result<(), error::Unspecified> { + fuchsia_cprng::cprng_draw(dest); + Ok(()) + } +} + #[cfg(test)] mod tests { use crate::rand::{self, SecureRandom};