mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
add debug provisions to encryption; limit AAD to 64 bytes
This commit is contained in:
parent
71336ebf3e
commit
3079da3a57
1 changed files with 5 additions and 0 deletions
|
|
@ -42,6 +42,7 @@ impl SwapHeader {
|
||||||
data.write(&(self.mac_offset as u32).to_le_bytes())?; // LE because this is a size field
|
data.write(&(self.mac_offset as u32).to_le_bytes())?; // LE because this is a size field
|
||||||
|
|
||||||
// serialize the AAD
|
// serialize the AAD
|
||||||
|
assert!(self.aad.len() < 64, "AAD is limited to 64 bytes");
|
||||||
data.write(&(self.aad.len() as u32).to_le_bytes())?; // LE because this is a size field
|
data.write(&(self.aad.len() as u32).to_le_bytes())?; // LE because this is a size field
|
||||||
data.write(&self.aad)?; // BE because this is cryptographic matter
|
data.write(&self.aad)?; // BE because this is cryptographic matter
|
||||||
|
|
||||||
|
|
@ -82,10 +83,14 @@ impl SwapWriter {
|
||||||
nonce_vec.extend_from_slice(&(offset as u32).to_be_bytes());
|
nonce_vec.extend_from_slice(&(offset as u32).to_be_bytes());
|
||||||
nonce_vec.extend_from_slice(&header.partial_nonce.to_be_bytes());
|
nonce_vec.extend_from_slice(&header.partial_nonce.to_be_bytes());
|
||||||
let nonce = Nonce::from_slice(&nonce_vec);
|
let nonce = Nonce::from_slice(&nonce_vec);
|
||||||
|
// println!("nonce: {:x?}", nonce);
|
||||||
|
// println!("aad: {:x?}", header.aad);
|
||||||
let enc = cipher
|
let enc = cipher
|
||||||
.encrypt(nonce, Payload { aad: &header.aad, msg: &padded_block })
|
.encrypt(nonce, Payload { aad: &header.aad, msg: &padded_block })
|
||||||
.expect("couldn't encrypt block");
|
.expect("couldn't encrypt block");
|
||||||
assert!(enc.len() == 0x1010);
|
assert!(enc.len() == 0x1010);
|
||||||
|
// println!("data: {:x?}", &enc[..32]);
|
||||||
|
// println!("tag: {:x?}", &enc[0x1000..]);
|
||||||
f.write(&enc[..0x1000])?;
|
f.write(&enc[..0x1000])?;
|
||||||
macs.extend_from_slice(&enc[0x1000..]);
|
macs.extend_from_slice(&enc[0x1000..]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue