embassy-stm32

Crates

git

Versions

stm32h533he

Flavors

Cipher

Trait Cipher 

Source
pub trait Cipher<'c> {
    const BLOCK_SIZE: usize = 16usize;
    const REQUIRES_PADDING: bool = false;
Show 16 methods // Required methods fn key(&self) -> &[u8]; fn iv(&self) -> &[u8]; fn set_mode(&self, p: Aes); // Provided methods fn key_size(&self) -> KeySize { ... } fn datatype(&self) -> u8 { ... } fn prepare_key(&self, _p: Aes, _dir: Direction) { ... } fn init_phase_blocking<T: Instance, M: Mode>( &self, _p: Aes, _aes: &Aes<'_, T, M>, ) { ... } async fn init_phase<T: Instance>( &self, _p: Aes, _aes: &mut Aes<'_, T, Async>, ) { ... } fn pre_final( &self, _p: Aes, _dir: Direction, _padding_len: usize, ) -> [u32; 4] { ... } fn post_final_blocking<T: Instance, M: Mode>( &self, _p: Aes, _aes: &Aes<'_, T, M>, _dir: Direction, _int_data: &mut [u8; 16], _temp1: [u32; 4], _padding_mask: [u8; 16], ) { ... } async fn post_final<T: Instance>( &self, _p: Aes, _aes: &mut Aes<'_, T, Async>, _dir: Direction, _int_data: &mut [u8; 16], _temp1: [u32; 4], _padding_mask: [u8; 16], ) { ... } fn get_header_block(&self) -> &[u8] { ... } fn uses_gcm_phases(&self) -> bool { ... } fn is_ccm_mode(&self) -> bool { ... } fn ccm_b0(&self) -> Option<&[u8; 16]> { ... } fn ccm_format_aad_header(&self, aad_len: usize) -> ([u8; 10], usize) { ... }
}
Expand description

This trait encapsulates all cipher-specific behavior.

Provided Associated Constants§

Source

const BLOCK_SIZE: usize = 16usize

Processing block size (always 16 bytes for AES).

Source

const REQUIRES_PADDING: bool = false

Indicates whether the cipher requires the application to provide padding.

Required Methods§

Source

fn key(&self) -> &[u8]

Returns the symmetric key.

Source

fn iv(&self) -> &[u8]

Returns the initialization vector.

Source

fn set_mode(&self, p: Aes)

Sets the cipher mode (CHMOD field).

Provided Methods§

Source

fn key_size(&self) -> KeySize

Returns the key size.

Source

fn datatype(&self) -> u8

Returns the data type setting for this cipher mode.

  • 0 = NO_SWAP (32-bit words, no swapping) - Default for all modes

Note: The ST HAL uses different DATATYPE values (BYTE_SWAP for CBC, BIT_SWAP for CTR) with pre-swapped test vectors. This driver uses NO_SWAP consistently with big-endian byte conversion (from_be_bytes/to_be_bytes) for direct NIST test vector compatibility.

Source

fn prepare_key(&self, _p: Aes, _dir: Direction)

Performs any key preparation within the processor, if necessary.

Source

fn init_phase_blocking<T: Instance, M: Mode>( &self, _p: Aes, _aes: &Aes<'_, T, M>, )

Performs any cipher-specific initialization.

Source

async fn init_phase<T: Instance>(&self, _p: Aes, _aes: &mut Aes<'_, T, Async>)

Performs any cipher-specific initialization (async).

Source

fn pre_final(&self, _p: Aes, _dir: Direction, _padding_len: usize) -> [u32; 4]

Called prior to processing the last data block for cipher-specific operations.

Source

fn post_final_blocking<T: Instance, M: Mode>( &self, _p: Aes, _aes: &Aes<'_, T, M>, _dir: Direction, _int_data: &mut [u8; 16], _temp1: [u32; 4], _padding_mask: [u8; 16], )

Called after processing the last data block for cipher-specific operations.

Source

async fn post_final<T: Instance>( &self, _p: Aes, _aes: &mut Aes<'_, T, Async>, _dir: Direction, _int_data: &mut [u8; 16], _temp1: [u32; 4], _padding_mask: [u8; 16], )

Called after processing the last data block for cipher-specific operations (async).

Source

fn get_header_block(&self) -> &[u8]

Returns the AAD header block as required by the cipher (for authenticated modes).

Source

fn uses_gcm_phases(&self) -> bool

Indicates whether this cipher mode uses GCM/CCM phases (init, header, payload, final).

Source

fn is_ccm_mode(&self) -> bool

Indicates whether this is CCM mode (which has different final phase handling). CCM doesn’t use a length block in the final phase, unlike GCM.

Source

fn ccm_b0(&self) -> Option<&[u8; 16]>

Returns the pre-computed B0 block for CCM mode (None for other modes).

Source

fn ccm_format_aad_header(&self, aad_len: usize) -> ([u8; 10], usize)

Returns the formatted AAD length prefix for CCM mode. CCM requires AAD to be prefixed with its length encoding.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesCbc<'c, KEY_SIZE>

Source§

impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesCtr<'c, KEY_SIZE>

Source§

impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesEcb<'c, KEY_SIZE>

Source§

impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGcm<'c, KEY_SIZE>

Source§

impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGmac<'c, KEY_SIZE>

Source§

impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize, const TAG_SIZE: usize> Cipher<'c> for AesCcm<'c, KEY_SIZE, IV_SIZE, TAG_SIZE>