mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
track address of the decrypt buffer
This commit is contained in:
parent
a478af445d
commit
26efde0a71
2 changed files with 12 additions and 1 deletions
|
|
@ -35,6 +35,7 @@ pub struct SwapHal {
|
||||||
swap_mac_start: usize,
|
swap_mac_start: usize,
|
||||||
swap_mac_len: usize,
|
swap_mac_len: usize,
|
||||||
dst_cipher: Aes256GcmSiv,
|
dst_cipher: Aes256GcmSiv,
|
||||||
|
buf_addr: usize,
|
||||||
buf: RawPage,
|
buf: RawPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,6 +275,7 @@ impl SwapHal {
|
||||||
swap_mac_start: ram_size_actual,
|
swap_mac_start: ram_size_actual,
|
||||||
swap_mac_len: mac_size,
|
swap_mac_len: mac_size,
|
||||||
dst_cipher: Aes256GcmSiv::new((&dest_key).into()),
|
dst_cipher: Aes256GcmSiv::new((&dest_key).into()),
|
||||||
|
buf_addr: 0,
|
||||||
buf,
|
buf,
|
||||||
};
|
};
|
||||||
hal.aad_storage[..ssh.aad_len as usize].copy_from_slice(&ssh.aad[..ssh.aad_len as usize]);
|
hal.aad_storage[..ssh.aad_len as usize].copy_from_slice(&ssh.aad[..ssh.aad_len as usize]);
|
||||||
|
|
@ -289,6 +291,7 @@ impl SwapHal {
|
||||||
|
|
||||||
pub fn decrypt_src_page_at(&mut self, offset: usize) -> &[u8] {
|
pub fn decrypt_src_page_at(&mut self, offset: usize) -> &[u8] {
|
||||||
assert!((offset & 0xFFF) == 0, "offset is not page-aligned");
|
assert!((offset & 0xFFF) == 0, "offset is not page-aligned");
|
||||||
|
self.buf_addr = offset;
|
||||||
self.flash_spim.mem_read((self.image_start + offset) as u32, &mut self.buf.data);
|
self.flash_spim.mem_read((self.image_start + offset) as u32, &mut self.buf.data);
|
||||||
let mut nonce = [0u8; size_of::<Nonce>()];
|
let mut nonce = [0u8; size_of::<Nonce>()];
|
||||||
nonce[..4].copy_from_slice(&(offset as u32).to_be_bytes());
|
nonce[..4].copy_from_slice(&(offset as u32).to_be_bytes());
|
||||||
|
|
@ -312,6 +315,8 @@ impl SwapHal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn decrypt_page_addr(&self) -> usize { self.buf_addr }
|
||||||
|
|
||||||
pub fn buf_as_mut(&mut self) -> &mut [u8] { &mut self.buf.data }
|
pub fn buf_as_mut(&mut self) -> &mut [u8] { &mut self.buf.data }
|
||||||
|
|
||||||
pub fn buf_as_ref(&self) -> &[u8] { &self.buf.data }
|
pub fn buf_as_ref(&self) -> &[u8] { &self.buf.data }
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ pub struct SwapHal {
|
||||||
dst_data_area: &'static mut [u8],
|
dst_data_area: &'static mut [u8],
|
||||||
dst_mac_area: &'static mut [u8],
|
dst_mac_area: &'static mut [u8],
|
||||||
dst_cipher: Aes256GcmSiv,
|
dst_cipher: Aes256GcmSiv,
|
||||||
|
buf_addr: usize,
|
||||||
buf: RawPage,
|
buf: RawPage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -80,6 +81,7 @@ impl SwapHal {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
dst_cipher: Aes256GcmSiv::new(&ram_swap_key.into()),
|
dst_cipher: Aes256GcmSiv::new(&ram_swap_key.into()),
|
||||||
|
buf_addr: 0,
|
||||||
buf: RawPage { data: [0u8; 4096] },
|
buf: RawPage { data: [0u8; 4096] },
|
||||||
};
|
};
|
||||||
hal.partial_nonce.copy_from_slice(&ssh.parital_nonce);
|
hal.partial_nonce.copy_from_slice(&ssh.parital_nonce);
|
||||||
|
|
@ -91,7 +93,8 @@ impl SwapHal {
|
||||||
|
|
||||||
pub fn decrypt_src_page_at(&mut self, offset: usize) -> &[u8] {
|
pub fn decrypt_src_page_at(&mut self, offset: usize) -> &[u8] {
|
||||||
assert!((offset & 0xFFF) == 0, "offset is not page-aligned");
|
assert!((offset & 0xFFF) == 0, "offset is not page-aligned");
|
||||||
// println!("data area: {:x?}", &self.data_area[..4]);
|
self.buf_addr = offset;
|
||||||
|
// println!("data area: {:x?}", &self.src_data_area[..4]);
|
||||||
// println!("offset: {:x}", offset);
|
// println!("offset: {:x}", offset);
|
||||||
self.buf.data.copy_from_slice(&self.src_data_area[offset..offset + 4096]);
|
self.buf.data.copy_from_slice(&self.src_data_area[offset..offset + 4096]);
|
||||||
let mut nonce = [0u8; size_of::<Nonce>()];
|
let mut nonce = [0u8; size_of::<Nonce>()];
|
||||||
|
|
@ -114,6 +117,8 @@ impl SwapHal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn decrypt_page_addr(&self) -> usize { self.buf_addr }
|
||||||
|
|
||||||
pub fn buf_as_mut(&mut self) -> &mut [u8] { &mut self.buf.data }
|
pub fn buf_as_mut(&mut self) -> &mut [u8] { &mut self.buf.data }
|
||||||
|
|
||||||
pub fn buf_as_ref(&self) -> &[u8] { &self.buf.data }
|
pub fn buf_as_ref(&self) -> &[u8] { &self.buf.data }
|
||||||
|
|
@ -121,6 +126,7 @@ impl SwapHal {
|
||||||
/// Swap count is fixed at 0 by this routine. The data to be encrypted is provided in
|
/// 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.
|
/// `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) {
|
pub fn encrypt_swap_to(&mut self, buf: &mut [u8], dest_offset: usize, src_vaddr: usize, src_pid: u8) {
|
||||||
|
println!("enc_to: pid: {}, src_vaddr: {:x} dest_offset: {:x}", src_pid, src_vaddr, dest_offset);
|
||||||
assert!(buf.len() == PAGE_SIZE);
|
assert!(buf.len() == PAGE_SIZE);
|
||||||
assert!(dest_offset & (PAGE_SIZE - 1) == 0);
|
assert!(dest_offset & (PAGE_SIZE - 1) == 0);
|
||||||
let mut nonce = [0u8; size_of::<Nonce>()];
|
let mut nonce = [0u8; size_of::<Nonce>()];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue