Skip to content

Commit

Permalink
emscripten: use getentropy from libc
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed May 20, 2023
1 parent 53cf0cc commit 394e602
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Expand Up @@ -78,6 +78,7 @@ jobs:
with:
targets: ${{ matrix.target }}
- name: Install multilib
run: sudo apt-get update
run: sudo apt-get install gcc-multilib
- uses: Swatinem/rust-cache@v2
- run: cargo test --target=${{ matrix.target }} --features=std
Expand Down
7 changes: 1 addition & 6 deletions src/emscripten.rs
Expand Up @@ -2,15 +2,10 @@
use crate::{util_libc::last_os_error, Error};
use core::mem::MaybeUninit;

// Not yet defined in libc crate.
extern "C" {
fn getentropy(buffer: *mut libc::c_void, length: usize) -> libc::c_int;
}

pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
// Emscripten 2.0.5 added getentropy, so we can use it unconditionally.
// Unlike other getentropy implementations, there is no max buffer length.
let ret = unsafe { getentropy(dest.as_mut_ptr() as *mut libc::c_void, dest.len()) };
let ret = unsafe { libc::getentropy(dest.as_mut_ptr() as *mut libc::c_void, dest.len()) };
if ret < 0 {
return Err(last_os_error());
}
Expand Down

0 comments on commit 394e602

Please sign in to comment.