add storage for the swap encryption key

This is set to 0 in the image creator, but the keying ceremony
should set this to something more secure after the device has
been initialized (and likewise, re-encrypt the swap region
to match the new, secure key).
This commit is contained in:
bunnie 2024-04-04 18:45:16 +08:00
parent bac8e4ff4d
commit 798566e6d2

View file

@ -14,6 +14,10 @@ pub struct Swap {
/// Region name (as a type) /// Region name (as a type)
pub name: XousArgumentCode, pub name: XousArgumentCode,
/// Encryption key. Set to 0 by the image creator, but set to something more interesting
/// by the device upon completion of the keying ceremony.
pub key: [u8; 32],
/// Unused /// Unused
_padding: u32, _padding: u32,
} }
@ -21,28 +25,36 @@ pub struct Swap {
impl fmt::Display for Swap { impl fmt::Display for Swap {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, " Swap: {:08x} - {:08x}", self.offset, self.offset + self.size)?; writeln!(f, " Swap: {:08x} - {:08x}", self.offset, self.offset + self.size)?;
writeln!(f, " key: {:x?}", self.key)?;
Ok(()) Ok(())
} }
} }
impl Swap { impl Swap {
pub fn new(offset: XousSize, size: XousSize) -> Self { pub fn new(offset: XousSize, size: XousSize) -> Self {
Swap { offset, size, name: u32::from_le_bytes(*b"Swap") as XousArgumentCode, _padding: 0 } Swap {
offset,
size,
name: u32::from_le_bytes(*b"Swap") as XousArgumentCode,
key: [0u8; 32],
_padding: 0,
}
} }
} }
impl XousArgument for Swap { impl XousArgument for Swap {
fn code(&self) -> XousArgumentCode { self.name } fn code(&self) -> XousArgumentCode { self.name }
fn length(&self) -> XousSize { 16 as XousSize } fn length(&self) -> XousSize { (16 + 32) as XousSize }
fn serialize(&self, output: &mut dyn io::Write) -> io::Result<usize> { fn serialize(&self, output: &mut dyn io::Write) -> io::Result<usize> {
let mut written = 0; let mut written = 0;
output.write_all(&self.offset.to_le_bytes())?; output.write_all(&self.offset.to_le_bytes())?;
output.write_all(&self.size.to_le_bytes())?; output.write_all(&self.size.to_le_bytes())?;
output.write_all(&self.name.to_le_bytes())?; output.write_all(&self.name.to_le_bytes())?;
output.write_all(&self.key)?;
output.write_all(&0u32.to_le_bytes())?; output.write_all(&0u32.to_le_bytes())?;
written += 4 * 4; written += 4 * 4 + 32;
Ok(written) Ok(written)
} }
} }