mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
fix pointer issue in resolving swap config
also a bunch of latent debug in case we need to muck around again
This commit is contained in:
parent
8f94ecaf6c
commit
c7e1f22cfa
1 changed files with 14 additions and 8 deletions
|
|
@ -3,6 +3,7 @@ use core::mem::size_of;
|
|||
use aes_gcm_siv::{AeadInPlace, Aes256GcmSiv, KeyInit, Nonce, Tag};
|
||||
|
||||
use crate::bootconfig::BootConfig;
|
||||
use crate::println;
|
||||
use crate::swap::*;
|
||||
|
||||
pub struct SwapHal {
|
||||
|
|
@ -17,12 +18,11 @@ pub struct SwapHal {
|
|||
impl SwapHal {
|
||||
pub fn new(cfg: &BootConfig) -> Option<SwapHal> {
|
||||
if let Some(swap) = cfg.swap {
|
||||
// sanity check this structure
|
||||
assert_eq!(core::mem::size_of::<SwapSourceHeader>(), 4096);
|
||||
// safety: the swap source header is guaranteed to be aligned and initialized in memory
|
||||
// by the image creator.
|
||||
let ssh: &SwapSourceHeader = unsafe { &*(swap.flash_offset as *const &SwapSourceHeader) };
|
||||
let swap_len = ssh.mac_offset as usize - (swap.flash_offset as usize + 4096);
|
||||
let ssh: &SwapSourceHeader =
|
||||
unsafe { (swap.flash_offset as *const SwapSourceHeader).as_ref().unwrap() };
|
||||
let swap_len = ssh.mac_offset as usize;
|
||||
let mut hal = SwapHal {
|
||||
// safety: the swap raw array is guaranteed to be correctly aligned by the image maker
|
||||
data_area: unsafe {
|
||||
|
|
@ -31,7 +31,7 @@ impl SwapHal {
|
|||
// safety: the mac raw array is guaranteed to be correctly aligned by the image maker
|
||||
mac_area: unsafe {
|
||||
core::slice::from_raw_parts(
|
||||
ssh.mac_offset as *const u8,
|
||||
(ssh.mac_offset + swap.flash_offset + 4096) as *const u8,
|
||||
(swap_len / 4096) * size_of::<Tag>(),
|
||||
)
|
||||
},
|
||||
|
|
@ -49,17 +49,23 @@ impl SwapHal {
|
|||
|
||||
pub fn decrypt_page_at(&mut self, offset: usize) -> &[u8] {
|
||||
assert!((offset & 0xFFF) == 0, "offset is not page-aligned");
|
||||
// println!("data area: {:x?}", &self.data_area[..4]);
|
||||
// println!("offset: {:x}", offset);
|
||||
self.buf.data.copy_from_slice(&self.data_area[offset..offset + 4096]);
|
||||
let mut nonce = [0u8; size_of::<Nonce>()];
|
||||
nonce[..4].copy_from_slice(&(offset as u32).to_be_bytes());
|
||||
nonce[4..].copy_from_slice(&self.partial_nonce);
|
||||
let tag = &self.mac_area
|
||||
[(offset / 4096) * size_of::<Tag>()..(offset / 4096) * size_of::<Tag>() + size_of::<Tag>()];
|
||||
// println!("nonce: {:x?}", nonce);
|
||||
// println!("tag: {:x?}", tag);
|
||||
// println!("aad: {:x?}", self.aad);
|
||||
// println!("data: {:x?}", &self.buf.data[0..32]);
|
||||
match self.cipher.decrypt_in_place_detached(
|
||||
Nonce::from_slice(&nonce),
|
||||
self.aad,
|
||||
&mut self.buf.data,
|
||||
(&self.mac_area
|
||||
[(offset / 4096) * size_of::<Tag>()..(offset / 4096) * size_of::<Tag>() + size_of::<Tag>()])
|
||||
.into(),
|
||||
tag.into(),
|
||||
) {
|
||||
Ok(_) => &self.buf.data,
|
||||
Err(e) => panic!("Decryption error in swap: {:?}", e),
|
||||
|
|
|
|||
Loading…
Reference in a new issue