tests: Use libopen_dice_clear_memory
Stop re-implementing DiceClearMemory() wherever needed and use the
standalone implementation provided by upstream open-dice in our tests.
Note that the following tests:
- libservice_vm_requests.test
- libdiced_open_dice_nostd.integration_test
ues libdiced_open_dice_nostd but don't seem to require a definition of
DiceClearMemory(), which _could_ mean that one of their dependencies is
providing it e.g. libopen_dice_cbor or libopen_dice_cbor_p384.
Bug: 357008987
Test: m libpvmfw.dice.test
Test: m libdiced_sample_inputs_nostd.integration_test
Change-Id: I4b4ef61705ced42747fe5ddf3ebad13d91122554
diff --git a/guest/pvmfw/Android.bp b/guest/pvmfw/Android.bp
index 4e4dcd6..cd09579 100644
--- a/guest/pvmfw/Android.bp
+++ b/guest/pvmfw/Android.bp
@@ -121,6 +121,7 @@
"libzerocopy_nostd",
"libhex",
],
+ static_libs: ["libopen_dice_clear_memory"],
}
genrule {
diff --git a/guest/pvmfw/src/dice.rs b/guest/pvmfw/src/dice.rs
index 3c22e40..470711f 100644
--- a/guest/pvmfw/src/dice.rs
+++ b/guest/pvmfw/src/dice.rs
@@ -192,20 +192,6 @@
flushed_zeroize(region)
}
-/// Flushes data caches over the provided address range in open-dice.
-///
-/// This function allows the tests below to go through the same nostd open-dice library as pvmfw.
-#[no_mangle]
-#[cfg(test)]
-unsafe extern "C" fn DiceClearMemory(
- _ctx: *mut core::ffi::c_void,
- size: usize,
- addr: *mut core::ffi::c_void,
-) {
- // SAFETY: The caller ensures that the address and size are valid for write.
- unsafe { core::ptr::write_bytes(addr as *mut u8, 0, size) };
-}
-
#[cfg(test)]
mod tests {
use crate::{
diff --git a/libs/dice/sample_inputs/Android.bp b/libs/dice/sample_inputs/Android.bp
index 36fe8c7..c1c4566 100644
--- a/libs/dice/sample_inputs/Android.bp
+++ b/libs/dice/sample_inputs/Android.bp
@@ -78,4 +78,5 @@
"libdiced_open_dice_nostd",
"libdiced_sample_inputs_nostd",
],
+ static_libs: ["libopen_dice_clear_memory"],
}
diff --git a/libs/dice/sample_inputs/tests/api_test.rs b/libs/dice/sample_inputs/tests/api_test.rs
index d713168..c627824 100644
--- a/libs/dice/sample_inputs/tests/api_test.rs
+++ b/libs/dice/sample_inputs/tests/api_test.rs
@@ -146,21 +146,3 @@
let public_key = chain.leaf().subject_public_key();
public_key.verify(&signature, MESSAGE)
}
-
-/// Flushes data caches over the provided address range in open-dice.
-///
-/// # Safety
-///
-/// The provided address and size must be to an address range that is valid for read and write
-/// (typically on the stack, .bss, .data, or provided BCC) from a single allocation
-/// (e.g. stack array).
-#[cfg(not(feature = "std"))]
-#[no_mangle]
-unsafe extern "C" fn DiceClearMemory(
- _ctx: *mut core::ffi::c_void,
- size: usize,
- addr: *mut core::ffi::c_void,
-) {
- // SAFETY: The caller ensures that the address and size are valid for write.
- unsafe { core::ptr::write_bytes(addr as *mut u8, 0, size) };
-}