From 798566e6d287f6b752b9de599d47ba1cdbd7b3a6 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 4 Apr 2024 18:45:16 +0800 Subject: [PATCH] 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). --- tools/src/tags/swap.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tools/src/tags/swap.rs b/tools/src/tags/swap.rs index e734858e0..83a6b101b 100644 --- a/tools/src/tags/swap.rs +++ b/tools/src/tags/swap.rs @@ -14,6 +14,10 @@ pub struct Swap { /// Region name (as a type) 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 _padding: u32, } @@ -21,28 +25,36 @@ pub struct Swap { impl fmt::Display for Swap { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { writeln!(f, " Swap: {:08x} - {:08x}", self.offset, self.offset + self.size)?; + writeln!(f, " key: {:x?}", self.key)?; Ok(()) } } impl Swap { 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 { 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 { let mut written = 0; output.write_all(&self.offset.to_le_bytes())?; output.write_all(&self.size.to_le_bytes())?; output.write_all(&self.name.to_le_bytes())?; + output.write_all(&self.key)?; output.write_all(&0u32.to_le_bytes())?; - written += 4 * 4; + written += 4 * 4 + 32; Ok(written) } }