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 595fe19d9d03ad91c2b0ef986b6be2ba3e166355
Author: Yuan Zhuang <[email protected]>
AuthorDate: Wed Jul 23 13:03:37 2025 +0000

    trustzone-sdk: port ring 0.17.14 for optee
---
 ring-0.17.14/Cargo.toml.orig |  7 ++++++-
 ring-0.17.14/build.rs        |  1 +
 ring-0.17.14/src/lib.rs      |  3 +++
 ring-0.17.14/src/rand.rs     | 13 +++++++++++--
 4 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/ring-0.17.14/Cargo.toml.orig b/ring-0.17.14/Cargo.toml.orig
index 8f8da17..273383e 100644
--- a/ring-0.17.14/Cargo.toml.orig
+++ b/ring-0.17.14/Cargo.toml.orig
@@ -159,9 +159,11 @@ name = "ring"
 
 [dependencies]
 cfg-if = { version = "1.0.0", default-features = false }
-getrandom = { version = "0.2.10" }
 untrusted = { version = "0.9" }
 
+[target.'cfg(not(target_os = "optee"))'.dependencies]
+getrandom = { version = "0.2.10" }
+
 [target.'cfg(all(any(all(target_arch = "aarch64", target_endian = "little"), 
all(target_arch = "arm", target_endian = "little")), any(target_os = "android", 
target_os = "linux")))'.dependencies]
 libc = { version = "0.2.148", default-features = false }
 
@@ -171,6 +173,9 @@ libc = { version = "0.2.155", default-features = false }
 [target.'cfg(all(all(target_arch = "aarch64", target_endian = "little"), 
target_os = "windows"))'.dependencies]
 windows-sys = { version = "0.52", features = ["Win32_Foundation", 
"Win32_System_Threading"] }
 
+[target.'cfg(target_os="optee")'.dependencies]
+optee-utee = { version = "0.4.0" }
+
 [target.'cfg(all(target_arch = "wasm32", target_os = 
"unknown"))'.dev-dependencies]
 wasm-bindgen-test = { version = "0.3.37", default-features = false, features = 
["std"] }
 
diff --git a/ring-0.17.14/build.rs b/ring-0.17.14/build.rs
index 9843ad8..2441037 100644
--- a/ring-0.17.14/build.rs
+++ b/ring-0.17.14/build.rs
@@ -254,6 +254,7 @@ const LINUX_ABI: &[&str] = &[
     "linux",
     "redox",
     "solaris",
+    "optee",
 ];
 
 const WIN32N: &str = "win32n";
diff --git a/ring-0.17.14/src/lib.rs b/ring-0.17.14/src/lib.rs
index 8881809..5d33f39 100644
--- a/ring-0.17.14/src/lib.rs
+++ b/ring-0.17.14/src/lib.rs
@@ -91,6 +91,9 @@
 )]
 #![no_std]
 
+#[cfg(all(target_arch = "aarch64", not(target_os="optee")))]
+extern crate libc;
+
 #[cfg(feature = "alloc")]
 extern crate alloc;
 
diff --git a/ring-0.17.14/src/rand.rs b/ring-0.17.14/src/rand.rs
index a451c8f..dc1c2a2 100644
--- a/ring-0.17.14/src/rand.rs
+++ b/ring-0.17.14/src/rand.rs
@@ -121,7 +121,7 @@ impl crate::sealed::Sealed for SystemRandom {}
 // Use the `getrandom` crate whenever it is using the environment's (operating
 // system's) CSPRNG. Avoid using it on targets where it uses the `rdrand`
 // implementation.
-#[cfg(any(
+#[cfg(all(not(target_os = "optee"), any(
     all(feature = "less-safe-getrandom-custom-or-rdrand", target_os = "none"),
     all(feature = "less-safe-getrandom-espidf", target_os = "espidf"),
     target_os = "aix",
@@ -158,10 +158,19 @@ impl crate::sealed::Sealed for SystemRandom {}
             all(target_os = "unknown", feature = "wasm32_unknown_unknown_js")
         )
     ),
-))]
+)))]
 impl sealed::SecureRandom for SystemRandom {
     #[inline(always)]
     fn fill_impl(&self, dest: &mut [u8]) -> Result<(), error::Unspecified> {
         getrandom::getrandom(dest).map_err(|_| error::Unspecified)
     }
 }
+
+#[cfg(target_os = "optee")]
+impl sealed::SecureRandom for SystemRandom {
+    #[inline(always)]
+    fn fill_impl(&self, dest: &mut [u8]) -> Result<(), error::Unspecified> {
+        optee_utee::Random::generate(dest);
+        Ok(())
+    }
+}
\ No newline at end of file


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

Reply via email to