pub fn generate_mac(&self, message: &[u8]) -> Result<[u8; 16], CommandResult> {
        if 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]);

        fn process_blocks(
            cse: &CSEc,
            message: &[u8],
            sequence: Sequence,
        ) -> Result<(), CommandResult> {
            // How many bytes are we processing this round?
            let bytes = core::cmp::min(message.len(), MAX_PAGES * PAGE_SIZE_IN_BYTES);

            // Write out message bytes from `message` and process them.
            cse.write_command_bytes(PAGE_1_OFFSET, &message[..bytes]);
            cse.write_command_header(Command::GenerateMac, Format::Copy, sequence, KeyID::RamKey)?;

            // Process remaining bytes, if any
            if message.len() - bytes != 0 {
                process_blocks(cse, &message[bytes..], Sequence::Subsequent)
            } else {
                Ok(())
            }
        }

        process_blocks(self, message, Sequence::First)?;

        // Read out calculated MAC
        let mut cmac: [u8; 16] = [0; 16];
        self.read_command_bytes(PAGE_2_OFFSET, &mut cmac);

        Ok(cmac)
    }
/// Generate a 128-bit Message Authentication Code for `input`.
Generate a 128-bit Message Authentication Code for `input`.
Generate a 128 - bit Message Authentication Code for ` input ` .
pub fn generate_mac(&self, message: &[u8]) -> Result<[u8; 16], CommandResult> {
        if 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]);
        fn process_blocks(
            cse: &CSEc,
            message: &[u8],
            sequence: Sequence,
        ) -> Result<(), CommandResult> {
            // How many bytes are we processing this round?
            let bytes = core::cmp::min(message.len(), MAX_PAGES * PAGE_SIZE_IN_BYTES);
            // Write out message bytes from `message` and process them.
            cse.write_command_bytes(PAGE_1_OFFSET, &message[..bytes]);
            cse.write_command_header(Command::GenerateMac, Format::Copy, sequence, KeyID::RamKey)?;
            // Process remaining bytes, if any
            if message.len() - bytes != 0 {
                process_blocks(cse, &message[bytes..], Sequence::Subsequent)
            } else {
                Ok(())
            }
        }
        process_blocks(self, message, Sequence::First)?;
        // Read out calculated MAC
        let mut cmac: [u8; 16] = [0; 16];
        self.read_command_bytes(PAGE_2_OFFSET, &mut cmac);
        Ok(cmac)
    }
pub fn generate_mac ( & self , message : & [ u8 ] ) -> Result < [ u8 ; 16 ] , CommandResult > { if 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 ] ) ; fn process_blocks ( cse : & CSEc , message : & [ u8 ] , sequence : Sequence , ) -> Result < ( ) , CommandResult > { // How many bytes are we processing this round? let bytes = core :: cmp :: min ( message . len ( ) , MAX_PAGES * PAGE_SIZE_IN_BYTES ) ; // Write out message bytes from `message` and process them. cse . write_command_bytes ( PAGE_1_OFFSET , & message [ .. bytes ] ) ; cse . write_command_header ( Command :: GenerateMac , Format :: Copy , sequence , KeyID :: RamKey ) ? ; // Process remaining bytes, if any if message . len ( ) - bytes != 0 { process_blocks ( cse , & message [ bytes .. ] , Sequence :: Subsequent ) } else { Ok ( ( ) ) } } process_blocks ( self , message , Sequence :: First ) ? ; // Read out calculated MAC let mut cmac : [ u8 ; 16 ] = [ 0 ; 16 ] ; self . read_command_bytes ( PAGE_2_OFFSET , & mut cmac ) ; Ok ( cmac ) }
Generate a 128-bit Message Authentication Code for `input`.
Generate a 128 - bit Message Authentication Code for ` input ` .
&self
message
&[u8]