diff --git a/libs/bao1x-hal/src/buram.rs b/libs/bao1x-hal/src/buram.rs index 43112a5d0..636e2fd97 100644 --- a/libs/bao1x-hal/src/buram.rs +++ b/libs/bao1x-hal/src/buram.rs @@ -6,6 +6,8 @@ const HASH_LOC: usize = 0; #[allow(dead_code)] const RESERVED_LOC: usize = 1; +pub const ERASURE_PROOF_RANGE_BYTES: Range = 0..32; + use crate::buram::murmur3::murmur3_32; const fn range_len(r: Range) -> usize { r.end - r.start } @@ -86,9 +88,28 @@ impl BackupManager { } } - pub fn bu_ram_as_slice(&self) -> &[u8] { unsafe { self.bu_ram.as_slice() } } + pub fn store_slice(&mut self, input: &[T], byte_offset: usize) { + let type_offset = byte_offset / size_of::(); + // safety: safe because make_valid() is called after the slice is accessed + let dest: &mut [T] = unsafe { &mut self.bu_ram_as_mut()[type_offset..type_offset + input.len()] }; + dest.copy_from_slice(&input); - pub fn bu_ram_as_mut(&mut self) -> &mut [u8] { unsafe { self.bu_ram.as_slice_mut() } } + self.make_valid(); + } + + pub fn get_slice(&self, byte_range: core::ops::Range) -> &[T] { + let type_offset = byte_range.start / size_of::(); + let type_len = (byte_range.end - byte_range.start) / size_of::(); + &self.bu_ram_as_slice()[type_offset..type_offset + type_len] + } + + pub fn bu_ram_as_slice(&self) -> &[T] { unsafe { self.bu_ram.as_slice::() } } + + /// Safety: modifications to the backup RAM array need a follow-up call to `make_valid` + /// in order for the boot check to pass. + /// + /// Could try to get clever and implement a `Drop` trait which includes a make_valid() call? maybe? + pub unsafe fn bu_ram_as_mut(&mut self) -> &mut [T] { self.bu_ram.as_slice_mut::() } } pub mod murmur3 { diff --git a/libs/bao1x-hal/src/hardening.rs b/libs/bao1x-hal/src/hardening.rs index d92f87d19..c85bd0edd 100644 --- a/libs/bao1x-hal/src/hardening.rs +++ b/libs/bao1x-hal/src/hardening.rs @@ -97,7 +97,7 @@ impl Csprng { word.copy_from_slice(&ro_trng.get_raw().to_ne_bytes()); } - crate::println!("seed: {:x?}", seed); // used to eyeball that things are working correctly + // crate::println!("seed: {:x?}", seed); // used to eyeball that things are working correctly let mut csprng = ChaCha8Rng::from_seed(seed); let entropy_bank = csprng.next_u64(); diff --git a/libs/bao1x-hal/src/rram.rs b/libs/bao1x-hal/src/rram.rs index 11760a60c..5a1e7e29e 100644 --- a/libs/bao1x-hal/src/rram.rs +++ b/libs/bao1x-hal/src/rram.rs @@ -188,8 +188,12 @@ impl<'a> Reram { assert!(data.len() % 8 == 0, "unaligned source data!"); // crate::print!("@ {:x} > ", addr); for (outer, d) in data.chunks_exact(8).enumerate() { + #[cfg(not(feature = "kernel"))] + bao1x_api::bollard!(crate::sigcheck::die_no_std, 4); // write the data to the buffer for (inner, &datum) in d.iter().enumerate() { + #[cfg(not(feature = "kernel"))] + bao1x_api::bollard!(crate::sigcheck::die_no_std, 4); // crate::print!(" {:x}", datum); self.array .as_mut_ptr() @@ -199,6 +203,8 @@ impl<'a> Reram { } // crate::println!(""); + #[cfg(not(feature = "kernel"))] + bao1x_api::bollard!(crate::sigcheck::die_no_std, 4); self.csr.rmwf(utra::rrc::SFR_RRCCR_SFR_RRCCR, RRC_CR_WRITE_CMD | SECURITY_MODE); self.array .as_mut_ptr()