Commit 4243ab09 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

sim: Capture payload in TLV code

Since the signing code will also need a copy of the message, make a
local copy of it in the signature verification code, and compute the
digest all in one shot.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 8054ce28
Loading
Loading
Loading
Loading
+4 −4
Changes for sim/src/tlv.rs: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ pub struct TlvGen {
    flags: Flags,
    kinds: Vec<TlvKinds>,
    size: u16,
    hasher: digest::Context,
    payload: Vec<u8>,
}

impl TlvGen {
@@ -47,7 +47,7 @@ impl TlvGen {
            flags: Flags::SHA256,
            kinds: vec![TlvKinds::SHA256],
            size: 4 + 32,
            hasher: digest::Context::new(&digest::SHA256),
            payload: vec![],
        }
    }

@@ -63,7 +63,7 @@ impl TlvGen {

    /// Add bytes to the covered hash.
    pub fn add_bytes(&mut self, bytes: &[u8]) {
        self.hasher.update(bytes);
        self.payload.extend_from_slice(bytes);
    }

    /// Compute the TLV given the specified block of data.
@@ -71,7 +71,7 @@ impl TlvGen {
        let mut result: Vec<u8> = vec![];

        if self.kinds.contains(&TlvKinds::SHA256) {
            let hash = self.hasher.finish();
            let hash = digest::digest(&digest::SHA256, &self.payload);
            let hash = hash.as_ref();

            assert!(hash.len() == 32);