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)
            }
        }
// Write all n data blocks first, and write expected CMAC on page n + 1.
Write all n data blocks first, and write expected CMAC on page n + 1.
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)
            }
        }
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 ) } }
Write all n data blocks first, and write expected CMAC on page n + 1.
Write all n data blocks first and write expected CMAC on page n + 1 .
cse
&CSEc
message
&[u8]
cmac
&[u8]
sequence
Sequence
mac_written
bool