vmbase: Replace CRYPTO_sysrand() with getentropy()
As the library is replacing the internal CRYPTO_sysrand() functions with
the more standard getentropy, expose our source of entropy through the
new symbol.
Bug: 290898063
Bug: 291102972
Test: -
Change-Id: I7e42a51b15aef14800bc82dca8cd67df5b5730cb
diff --git a/vmbase/src/bionic.rs b/vmbase/src/bionic.rs
index 29fa0ff..f8db1fe 100644
--- a/vmbase/src/bionic.rs
+++ b/vmbase/src/bionic.rs
@@ -24,9 +24,11 @@
use crate::console;
use crate::cstr;
use crate::eprintln;
+use crate::rand::fill_with_entropy;
use crate::read_sysreg;
const EOF: c_int = -1;
+const EIO: c_int = 5;
/// Bionic thread-local storage.
#[repr(C)]
@@ -85,6 +87,21 @@
unsafe { ERRNO }
}
+#[no_mangle]
+extern "C" fn getentropy(buffer: *mut c_void, length: usize) -> c_int {
+ if length > 256 {
+ // The maximum permitted value for the length argument is 256.
+ set_errno(EIO);
+ return -1;
+ }
+
+ // SAFETY: Just like libc, we need to assume that `ptr` is valid.
+ let buffer = unsafe { slice::from_raw_parts_mut(buffer.cast::<u8>(), length) };
+ fill_with_entropy(buffer).unwrap();
+
+ 0
+}
+
/// Reports a fatal error detected by Bionic.
///
/// # Safety
diff --git a/vmbase/src/rand.rs b/vmbase/src/rand.rs
index 2acc390..b31bd4b 100644
--- a/vmbase/src/rand.rs
+++ b/vmbase/src/rand.rs
@@ -153,15 +153,3 @@
fill_with_entropy(&mut arr)?;
Ok(arr)
}
-
-#[no_mangle]
-extern "C" fn CRYPTO_sysrand_for_seed(out: *mut u8, req: usize) {
- CRYPTO_sysrand(out, req)
-}
-
-#[no_mangle]
-extern "C" fn CRYPTO_sysrand(out: *mut u8, req: usize) {
- // SAFETY: We need to assume that out points to valid memory of size req.
- let s = unsafe { core::slice::from_raw_parts_mut(out, req) };
- fill_with_entropy(s).unwrap()
-}