22 lines
632 B
Rust
22 lines
632 B
Rust
//! Implementation using getentropy(2)
|
|
//!
|
|
//! Available since:
|
|
//! - macOS 10.12
|
|
//! - OpenBSD 5.6
|
|
//! - Emscripten 2.0.5
|
|
//! - vita newlib since Dec 2021
|
|
//!
|
|
//! For these targets, we use getentropy(2) because getrandom(2) doesn't exist.
|
|
use crate::{util_libc::last_os_error, Error};
|
|
use core::mem::MaybeUninit;
|
|
|
|
pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
|
|
for chunk in dest.chunks_mut(256) {
|
|
let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) };
|
|
if ret != 0 {
|
|
return Err(last_os_error());
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|