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 c35dc47683ef49699579d81f160ab96d65f861d4
Author: Yuan Zhuang <[email protected]>
AuthorDate: Wed Aug 13 08:12:06 2025 +0000

    getrandom: add optee target
---
 getrandom-0.2.16/Cargo.toml   |  3 +++
 getrandom-0.2.16/src/lib.rs   |  3 +++
 getrandom-0.2.16/src/optee.rs | 19 +++++++++++++++++++
 3 files changed, 25 insertions(+)

diff --git a/getrandom-0.2.16/Cargo.toml b/getrandom-0.2.16/Cargo.toml
index 0365734..2fd3c8a 100644
--- a/getrandom-0.2.16/Cargo.toml
+++ b/getrandom-0.2.16/Cargo.toml
@@ -23,6 +23,9 @@ 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 68b5af9..4ea576e 100644
--- a/getrandom-0.2.16/src/lib.rs
+++ b/getrandom-0.2.16/src/lib.rs
@@ -31,6 +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
 //!
 //! Pull Requests that add support for new targets to `getrandom` are always 
welcome.
 //!
@@ -326,6 +327,8 @@ cfg_if! {
         #[path = "solid.rs"] mod imp;
     } else if #[cfg(target_os = "espidf")] {
         #[path = "espidf.rs"] mod imp;
+    } else if #[cfg(target_os = "optee")] {
+        #[path = "optee.rs"] mod imp;
     } else if #[cfg(windows)] {
         #[path = "windows.rs"] mod imp;
     } else if #[cfg(all(target_arch = "x86_64", target_env = "sgx"))] {
diff --git a/getrandom-0.2.16/src/optee.rs b/getrandom-0.2.16/src/optee.rs
new file mode 100644
index 0000000..c6651b5
--- /dev/null
+++ b/getrandom-0.2.16/src/optee.rs
@@ -0,0 +1,19 @@
+//! Implementation for OP-TEE TrustZone SDK
+use crate::Error;
+use core::mem::MaybeUninit;
+
+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);
+    
+    Ok(())
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to