move the MAC (i.e. tag) above the variable length AAD field.

This commit is contained in:
bunnie 2024-04-06 22:55:39 +08:00
parent 588e7aaf0a
commit d9b29c2d06

View file

@ -38,13 +38,13 @@ impl SwapHeader {
// note that the nonce is in big-endian format, as is expected for cryptographic matter
data.write(&self.partial_nonce.to_be_bytes())?;
// serialize the MAC data offset
data.write(&(self.mac_offset as u32).to_le_bytes())?; // LE because this is a size field
// serialize the AAD
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
// serialize the MAC data offset
data.write(&(self.mac_offset as u32).to_le_bytes())?; // LE because this is a size field
output[..data.position() as usize].copy_from_slice(&data.into_inner());
Ok(output)