pub fn verify_mac(&self, message: &[u8], cmac: &[u8; 16]) -> Result<bool, CommandResult> {
        // A length of 0 is interpreted by SHE to compare all bits of `mac`.
        if message.len() == 0 || message.len() > u32::max_value() as usize {
            return Err(CommandResult::GeneralError);
        }

        // Write how long our message is (in bits)
        self.write_command_words(MAC_MESSAGE_LENGTH_OFFSET, &[(message.len() * 8) as u32]);

        // Write the number of bits of the CMAC to be compared
        self.write_command_halfword(MAC_LENGTH_OFFSET, (cmac.len() * 8) as u16);

        // Write all n data blocks first, and write expected CMAC on page n + 1.
        fn process_blocks(
            cse: &CSEc,
            message: &[u8],
            cmac: &[u8],
            sequence: Sequence,
            mut mac_written: bool,
        ) -> Result<bool, CommandResult> {
            // How many bytes are we processing this round?
            let bytes = core::cmp::min(message.len(), MAX_PAGES * PAGE_SIZE_IN_BYTES);

            // Write our `message` bytes
            cse.write_command_bytes(PAGE_1_OFFSET, &message[..bytes]);

            // Which page is the next, rounded up?
            let next_page = (PAGE_1_OFFSET + bytes + PAGE_SIZE_IN_BYTES - 1) / PAGE_SIZE_IN_BYTES;
            if !mac_written && next_page < MAX_PAGES {
                // All data blocks has been written, append the expected CMAC.
                cse.write_command_bytes(next_page * PAGE_SIZE_IN_BYTES, &cmac);
                mac_written = true;
            }

            cse.write_command_header(Command::VerifyMac, Format::Copy, sequence, KeyID::RamKey)?;

            // Read verification status bits
            let success = cse.read_command_halfword(MAC_VERIFICATION_BITS_OFFSET) == 0;

            // Process remaining blocks until expected CMAC has been written.
            if !mac_written {
                process_blocks(
                    cse,
                    &message[bytes..],
                    cmac,
                    Sequence::Subsequent,
                    mac_written,
                )
            } else {
                Ok(success)
            }
        }

        process_blocks(self, message, cmac, Sequence::First, false)
    }
/// Verify a message against a 128-bit Message Authentication Code.
Verify a message against a 128-bit Message Authentication Code.
Verify a message against a 128 - bit Message Authentication Code .
pub fn verify_mac(&self, message: &[u8], cmac: &[u8; 16]) -> Result<bool, CommandResult> {
        // A length of 0 is interpreted by SHE to compare all bits of `mac`.
        if message.len() == 0 || message.len() > u32::max_value() as usize {
            return Err(CommandResult::GeneralError);
        }
        // Write how long our message is (in bits)
        self.write_command_words(MAC_MESSAGE_LENGTH_OFFSET, &[(message.len() * 8) as u32]);
        // Write the number of bits of the CMAC to be compared
        self.write_command_halfword(MAC_LENGTH_OFFSET, (cmac.len() * 8) as u16);
        // Write all n data blocks first, and write expected CMAC on page n + 1.
        fn process_blocks(
            cse: &CSEc,
            message: &[u8],
            cmac: &[u8],
            sequence: Sequence,
            mut mac_written: bool,
        ) -> Result<bool, CommandResult> {
            // How many bytes are we processing this round?
            let bytes = core::cmp::min(message.len(), MAX_PAGES * PAGE_SIZE_IN_BYTES);
            // Write our `message` bytes
            cse.write_command_bytes(PAGE_1_OFFSET, &message[..bytes]);
            // Which page is the next, rounded up?
            let next_page = (PAGE_1_OFFSET + bytes + PAGE_SIZE_IN_BYTES - 1) / PAGE_SIZE_IN_BYTES;
            if !mac_written && next_page < MAX_PAGES {
                // All data blocks has been written, append the expected CMAC.
                cse.write_command_bytes(next_page * PAGE_SIZE_IN_BYTES, &cmac);
                mac_written = true;
            }
            cse.write_command_header(Command::VerifyMac, Format::Copy, sequence, KeyID::RamKey)?;
            // Read verification status bits
            let success = cse.read_command_halfword(MAC_VERIFICATION_BITS_OFFSET) == 0;
            // Process remaining blocks until expected CMAC has been written.
            if !mac_written {
                process_blocks(
                    cse,
                    &message[bytes..],
                    cmac,
                    Sequence::Subsequent,
                    mac_written,
                )
            } else {
                Ok(success)
            }
        }
        process_blocks(self, message, cmac, Sequence::First, false)
    }
pub fn verify_mac ( & self , message : & [ u8 ] , cmac : & [ u8 ; 16 ] ) -> Result < bool , CommandResult > { // A length of 0 is interpreted by SHE to compare all bits of `mac`. if message . len ( ) == 0 || message . len ( ) > u32 :: max_value ( ) as usize { return Err ( CommandResult :: GeneralError ) ; } // Write how long our message is (in bits) self . write_command_words ( MAC_MESSAGE_LENGTH_OFFSET , & [ ( message . len ( ) * 8 ) as u32 ] ) ; // Write the number of bits of the CMAC to be compared self . write_command_halfword ( MAC_LENGTH_OFFSET , ( cmac . len ( ) * 8 ) as u16 ) ; // Write all n data blocks first, and write expected CMAC on page n + 1. fn process_blocks ( cse : & CSEc , message : & [ u8 ] , cmac : & [ u8 ] , sequence : Sequence , mut mac_written : bool , ) -> Result < bool , CommandResult > { // How many bytes are we processing this round? let bytes = core :: cmp :: min ( message . len ( ) , MAX_PAGES * PAGE_SIZE_IN_BYTES ) ; // Write our `message` bytes cse . write_command_bytes ( PAGE_1_OFFSET , & message [ .. bytes ] ) ; // Which page is the next, rounded up? let next_page = ( PAGE_1_OFFSET + bytes + PAGE_SIZE_IN_BYTES - 1 ) / PAGE_SIZE_IN_BYTES ; if ! mac_written && next_page < MAX_PAGES { // All data blocks has been written, append the expected CMAC. cse . write_command_bytes ( next_page * PAGE_SIZE_IN_BYTES , & cmac ) ; mac_written = true ; } cse . write_command_header ( Command :: VerifyMac , Format :: Copy , sequence , KeyID :: RamKey ) ? ; // Read verification status bits let success = cse . read_command_halfword ( MAC_VERIFICATION_BITS_OFFSET ) == 0 ; // Process remaining blocks until expected CMAC has been written. if ! mac_written { process_blocks ( cse , & message [ bytes .. ] , cmac , Sequence :: Subsequent , mac_written , ) } else { Ok ( success ) } } process_blocks ( self , message , cmac , Sequence :: First , false ) }
Verify a message against a 128-bit Message Authentication Code.
Verify a message against a 128 - bit Message Authentication Code .
&self
message
&[u8]
cmac
&[u8; 16]