• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Implementation using getentropy(2)
2 //!
3 //! Available since:
4 //!   - macOS 10.12
5 //!   - OpenBSD 5.6
6 //!   - Emscripten 2.0.5
7 //!   - vita newlib since Dec 2021
8 //!
9 //! For these targets, we use getentropy(2) because getrandom(2) doesn't exist.
10 use crate::{util_libc::last_os_error, Error};
11 use core::mem::MaybeUninit;
12 
getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error>13 pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
14     for chunk in dest.chunks_mut(256) {
15         let ret = unsafe { libc::getentropy(chunk.as_mut_ptr() as *mut libc::c_void, chunk.len()) };
16         if ret != 0 {
17             return Err(last_os_error());
18         }
19     }
20     Ok(())
21 }
22