Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ env:

jobs:
macos:
name: Apple Other
name: Apple
# visionOS requires Xcode 15.2+, which is only available on the arm64 runners.
runs-on: macos-15
steps:
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/nopanic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,12 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: aarch64-apple-ios
- uses: Swatinem/rust-cache@v2

# We do not need the grep check since linker fails
# if `panic_nonexistent` can not be eliminated
- name: Build (getentropy.rs)
- name: Build (apple.rs)
run: cargo build --release --target=aarch64-apple-darwin
- name: Build (apple-other.rs)
run: cargo build --release --target=aarch64-apple-ios

windows:
name: Windows
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
env:
RUSTFLAGS: -Dwarnings --cfg getrandom_backend="custom"
run: cargo clippy -Zbuild-std=core --target riscv32i-unknown-none-elf
- name: iOS (apple-other.rs)
- name: iOS (apple.rs)
run: cargo clippy -Zbuild-std=core --target x86_64-apple-ios
- name: ESP-IDF (espidf.rs)
env:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bumped `r-efi` dependency to v7 ([#869])
- Removed `wasm-bindgen-test` dev dependency ([#870])
- Use `libc::getrandom` on Redox instead of reading `/dev/urandom` ([#871])
- Use `CCRandomGenerateBytes` on macOS instead of `getentropy` ([#879])

[0.4.4]: https://github.com/rust-random/getrandom/compare/v0.4.3...master
[#861]: https://github.com/rust-random/getrandom/pull/861
Expand All @@ -25,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#870]: https://github.com/rust-random/getrandom/pull/870
[#871]: https://github.com/rust-random/getrandom/pull/871
[#876]: https://github.com/rust-random/getrandom/pull/876
[#879]: https://github.com/rust-random/getrandom/pull/879

## [0.4.3] - 2026-06-17
### Added
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ rand_core = { version = "0.10.0", optional = true }
[target.'cfg(all(any(target_os = "linux", target_os = "android"), not(any(all(target_os = "linux", target_env = ""), getrandom_backend = "custom", getrandom_backend = "linux_raw", getrandom_backend = "rdrand", getrandom_backend = "rndr"))))'.dependencies]
libc = { version = "0.2.176", default-features = false }

# apple-other
[target.'cfg(any(target_os = "ios", target_os = "visionos", target_os = "watchos", target_os = "tvos"))'.dependencies]
# apple
[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "visionos", target_os = "watchos", target_os = "tvos"))'.dependencies]
Comment thread
newpavlov marked this conversation as resolved.
Resolved
libc = { version = "0.2.176", default-features = false }

# efi_rng
[target.'cfg(all(target_os = "uefi", getrandom_backend = "efi_rng"))'.dependencies]
r-efi = { version = "7", default-features = false }

# getentropy
[target.'cfg(any(target_os = "macos", target_os = "openbsd", target_os = "vita", target_os = "emscripten"))'.dependencies]
[target.'cfg(any(target_os = "openbsd", target_os = "vita", target_os = "emscripten"))'.dependencies]
libc = { version = "0.2.176", default-features = false }

# getrandom
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn get_random_u128() -> Result<u128, getrandom::Error> {
| Linux, Android | `*‑linux‑*` | [`getrandom`][1] system call if available, otherwise [`/dev/urandom`][2] after successfully polling `/dev/random`
| Windows 10+ | `*‑windows‑*` | [`ProcessPrng`]
| Windows 7, 8 | `*-win7‑windows‑*` | [`RtlGenRandom`]
| macOS | `*‑apple‑darwin` | [`getentropy`][3]
| macOS | `*‑apple‑darwin` | [`CCRandomGenerateBytes`]
| iOS, tvOS, watchOS | `*‑apple‑{ios,tvos,watchos}` | [`CCRandomGenerateBytes`]
| FreeBSD | `*‑freebsd` | [`getrandom`][5]
| OpenBSD | `*‑openbsd` | [`getentropy`][7]
Expand Down Expand Up @@ -365,8 +365,6 @@ dual licensed as above, without any additional terms or conditions.

[1]: https://manned.org/getrandom.2
[2]: https://manned.org/urandom.4
[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
[7]: https://man.openbsd.org/getentropy.2
[8]: https://man.netbsd.org/sysctl.7
Expand Down
6 changes: 3 additions & 3 deletions src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ cfg_if! {
mod use_file;
pub use use_file::*;
} else if #[cfg(any(
target_os = "macos",
target_os = "openbsd",
target_os = "vita",
target_os = "emscripten",
Expand Down Expand Up @@ -130,13 +129,14 @@ cfg_if! {
mod fuchsia;
pub use fuchsia::*;
} else if #[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "watchos",
target_os = "tvos",
))] {
mod apple_other;
pub use apple_other::*;
mod apple;
pub use apple::*;
} else if #[cfg(all(target_arch = "wasm32", target_os = "wasi"))] {
cfg_if! {
if #[cfg(target_env = "p1")] {
Expand Down
4 changes: 2 additions & 2 deletions src/backends/apple_other.rs → src/backends/apple.rs
Comment thread
josephlr marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Implementation for iOS, tvOS, and watchOS where `getentropy` is unavailable.
//! Implementation for Apple targets using `CCRandomGenerateBytes`.
use crate::Error;
use core::{ffi::c_void, mem::MaybeUninit};

Expand All @@ -11,6 +11,6 @@ pub fn fill_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
if ret == libc::kCCSuccess {
Ok(())
} else {
Err(Error::IOS_RANDOM_GEN)
Err(Error::APPLE_RANDOM_GEN)
}
}
1 change: 0 additions & 1 deletion src/backends/getentropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getentropy.html>.
//!
//! Available since:
//! - macOS 10.12
//! - OpenBSD 5.6
//! - Emscripten 2.0.5
//! - vita newlib since Dec 2021
Expand Down
6 changes: 4 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,13 @@ impl Error {
Error::UNEXPECTED => "unexpected situation",

#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "watchos",
target_os = "tvos",
))]
Error::IOS_RANDOM_GEN => "SecRandomCopyBytes: iOS Security framework failure",
Error::APPLE_RANDOM_GEN => "CCRandomGenerateBytes: Apple CommonCrypto failure",
#[cfg(target_os = "vxworks")]
Error::VXWORKS_RAND_SECURE => "randSecure: VxWorks RNG module is not initialized",
#[cfg(any(
Expand Down Expand Up @@ -221,12 +222,13 @@ impl Error {
impl Error {
/// Call to `CCRandomGenerateBytes` failed.
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "visionos",
target_os = "watchos",
target_os = "tvos",
))]
pub(crate) const IOS_RANDOM_GEN: Error = Self::new_internal(10);
pub(crate) const APPLE_RANDOM_GEN: Error = Self::new_internal(10);

/// Call to VxWorks `randSecure` failed (random number generator is not yet initialized).
#[cfg(target_os = "vxworks")]
Expand Down
2 changes: 1 addition & 1 deletion src/utils/get_errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cfg_if! {
use libc::__errno_location as errno_location;
} else if #[cfg(target_os = "illumos")] {
use libc::___errno as errno_location;
} else if #[cfg(any(target_os = "macos", target_os = "freebsd"))] {
} else if #[cfg(target_os = "freebsd")] {
use libc::__error as errno_location;
} else if #[cfg(target_os = "haiku")] {
use libc::_errnop as errno_location;
Expand Down
Loading