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.
This commit is contained in:
bunnie 2024-05-02 22:13:11 +08:00
parent 51dd3b897b
commit cd43157d1e
2 changed files with 8 additions and 0 deletions

View file

@ -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) {

View file

@ -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) {