From cd43157d1ead784733ed86d566b22f851521e9e8 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 2 May 2024 22:13:11 +0800 Subject: [PATCH] refactor loader mac accessor interfaces traits are kind of awful in Rust...it's true, they don't know how big they are at compile time, so they have to be dyn, reference, lifetimes, etc... lot of baggage for a static structure. I guess there's probably some idk bounds I could put on the traits to make it less poopy but also just as easy to make it a static structure and not deal with traits. --- loader/src/platform/cramium/swap.rs | 2 ++ loader/src/platform/precursor/swap.rs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/loader/src/platform/cramium/swap.rs b/loader/src/platform/cramium/swap.rs index 71dd01d68..54fe1d0ee 100644 --- a/loader/src/platform/cramium/swap.rs +++ b/loader/src/platform/cramium/swap.rs @@ -376,6 +376,8 @@ impl SwapHal { pub fn buf_as_ref(&self) -> &[u8] { &self.buf.data } + pub fn mac_base_bounds(&self) -> (u32, u32) { (self.swap_mac_start as u32, self.swap_mac_len as u32) } + /// Swap count is fixed at 0 by this routine. The data to be encrypted is /// assumed to already be in `self.buf` pub fn encrypt_swap_to(&mut self, buf: &mut [u8], dest_offset: usize, src_vaddr: usize, src_pid: u8) { diff --git a/loader/src/platform/precursor/swap.rs b/loader/src/platform/precursor/swap.rs index 6c0279f53..b71d356bd 100644 --- a/loader/src/platform/precursor/swap.rs +++ b/loader/src/platform/precursor/swap.rs @@ -20,6 +20,8 @@ pub struct SwapHal { dst_cipher: Aes256GcmSiv, buf_addr: usize, buf: RawPage, + mac_offset: u32, + mac_len: u32, } impl SwapHal { @@ -92,6 +94,8 @@ impl SwapHal { dst_cipher: Aes256GcmSiv::new(&ram_swap_key.into()), buf_addr: 0, buf: RawPage { data: [0u8; 4096] }, + mac_offset: ssh.mac_offset, + mac_len: mac_size as u32, }; hal.partial_nonce.copy_from_slice(&ssh.parital_nonce); Some(hal) @@ -135,6 +139,8 @@ impl SwapHal { pub fn buf_as_ref(&self) -> &[u8] { &self.buf.data } + pub fn mac_base_bounds(&self) -> (u32, u32) { (self.mac_offset as u32, self.mac_len as u32) } + /// Swap count is fixed at 0 by this routine. The data to be encrypted is provided in /// `buf`, and is replaced with part of the encrypted data upon completion of the routine. pub fn encrypt_swap_to(&mut self, buf: &mut [u8], dest_offset: usize, src_vaddr: usize, src_pid: u8) {