interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / getrandom / src / apple-other.rs

24 lines · 1104 bytes Raw Blame History
1//! Implementation for iOS, tvOS, and watchOS where `getentropy` is unavailable.
2use crate::Error;
3use core::{ffi::c_void, mem::MaybeUninit};
4
5// libsystem contains the libc of Darwin, and every binary ends up linked against it either way. This
6// makes it a more lightweight choice compared to `Security.framework`.
7extern "C" {
8 // This RNG uses a thread-local CSPRNG to provide data, which is seeded by the operating system's root CSPRNG.
9 // Its the best option after `getentropy` on modern Darwin-based platforms that also avoids the
10 // high startup costs and linking of Security.framework.
11 //
12 // While its just an implementation detail, `Security.framework` just calls into this anyway.
13 fn CCRandomGenerateBytes(bytes: *mut c_void, size: usize) -> i32;
14}
15
16pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
17 let ret = unsafe { CCRandomGenerateBytes(dest.as_mut_ptr() as *mut c_void, dest.len()) };
18 // kCCSuccess (from CommonCryptoError.h) is always zero.
19 if ret != 0 {
20 Err(Error::IOS_SEC_RANDOM)
21 } else {
22 Ok(())
23 }
24}