This is an automated email from the ASF dual-hosted git repository. yuanz pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-crates.git
commit 0b32769514e38ec1d04c3d4b5f8999e82cbf67c2 Author: Yuan Zhuang <[email protected]> AuthorDate: Fri Aug 15 07:47:52 2025 +0000 getrandom: call raw libutee API for optee target --- getrandom-0.2.16/Cargo.toml | 3 --- getrandom-0.2.16/src/lib.rs | 3 ++- getrandom-0.2.16/src/optee.rs | 18 ++++++------------ 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/getrandom-0.2.16/Cargo.toml b/getrandom-0.2.16/Cargo.toml index 2fd3c8a..0365734 100644 --- a/getrandom-0.2.16/Cargo.toml +++ b/getrandom-0.2.16/Cargo.toml @@ -23,9 +23,6 @@ libc = { version = "0.2.154", default-features = false } [target.'cfg(target_os = "wasi")'.dependencies] wasi = { version = "0.11", default-features = false } -[target.'cfg(target_os = "optee")'.dependencies] -optee-utee = { version = "0.4.0" } - [target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dependencies] wasm-bindgen = { version = "0.2.62", default-features = false, optional = true } js-sys = { version = "0.3", optional = true } diff --git a/getrandom-0.2.16/src/lib.rs b/getrandom-0.2.16/src/lib.rs index 4ea576e..a7ddcc9 100644 --- a/getrandom-0.2.16/src/lib.rs +++ b/getrandom-0.2.16/src/lib.rs @@ -31,7 +31,7 @@ //! | QNX Neutrino | `*‑nto-qnx*` | [`/dev/urandom`][14] (identical to `/dev/random`) //! | AIX | `*-ibm-aix` | [`/dev/urandom`][15] //! | Cygwin | `*-cygwin` | [`getrandom`][19] (based on [`RtlGenRandom`]) -//! | OP-TEE | `*-optee` | [`Random::generate`] from OP-TEE UTEE API +//! | OP-TEE | `*-optee` | [`TEE_GenerateRandom`] from OP-TEE UTEE API //! //! Pull Requests that add support for new targets to `getrandom` are always welcome. //! @@ -200,6 +200,7 @@ //! [CommonJS modules]: https://nodejs.org/api/modules.html //! [ES modules]: https://nodejs.org/api/esm.html //! [`sys_read_entropy`]: https://github.com/hermit-os/kernel/blob/315f58ff5efc81d9bf0618af85a59963ff55f8b1/src/syscalls/entropy.rs#L47-L55 +//! [`TEE_GenerateRandom`]: https://github.com/OP-TEE/optee_os/blob/master/lib/libutee/include/tee_internal_api.h //! [platform-support]: https://doc.rust-lang.org/stable/rustc/platform-support.html #![doc( diff --git a/getrandom-0.2.16/src/optee.rs b/getrandom-0.2.16/src/optee.rs index c6651b5..e5bad04 100644 --- a/getrandom-0.2.16/src/optee.rs +++ b/getrandom-0.2.16/src/optee.rs @@ -2,18 +2,12 @@ use crate::Error; use core::mem::MaybeUninit; +#[link(name = "utee")] +extern "C" { + fn TEE_GenerateRandom(randomBuffer: *mut core::ffi::c_void, randomBufferLen: usize); +} + pub fn getrandom_inner(dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> { - // Convert MaybeUninit slice to a regular slice for optee_utee::Random::generate - // This is safe because we're about to initialize the entire slice - let dest_slice = unsafe { - core::slice::from_raw_parts_mut( - dest.as_mut_ptr() as *mut u8, - dest.len() - ) - }; - - // Use OP-TEE's random number generator - optee_utee::Random::generate(dest_slice); - + unsafe { TEE_GenerateRandom(dest.as_mut_ptr() as *mut core::ffi::c_void, dest.len()) } Ok(()) } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
