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§
Sourceconst BLOCK_SIZE: usize = 16usize
const BLOCK_SIZE: usize = 16usize
Processing block size (always 16 bytes for AES).
Sourceconst REQUIRES_PADDING: bool = false
const REQUIRES_PADDING: bool = false
Indicates whether the cipher requires the application to provide padding.
Required Methods§
Provided Methods§
Sourcefn datatype(&self) -> u8
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.
Sourcefn prepare_key(&self, _p: Aes, _dir: Direction)
fn prepare_key(&self, _p: Aes, _dir: Direction)
Performs any key preparation within the processor, if necessary.
Sourcefn init_phase_blocking<T: Instance, M: Mode>(
&self,
_p: Aes,
_aes: &Aes<'_, T, M>,
)
fn init_phase_blocking<T: Instance, M: Mode>( &self, _p: Aes, _aes: &Aes<'_, T, M>, )
Performs any cipher-specific initialization.
Sourceasync fn init_phase<T: Instance>(&self, _p: Aes, _aes: &mut Aes<'_, T, Async>)
async fn init_phase<T: Instance>(&self, _p: Aes, _aes: &mut Aes<'_, T, Async>)
Performs any cipher-specific initialization (async).
Sourcefn pre_final(&self, _p: Aes, _dir: Direction, _padding_len: usize) -> [u32; 4]
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.
Sourcefn 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],
)
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.
Sourceasync 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],
)
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).
Sourcefn get_header_block(&self) -> &[u8]
fn get_header_block(&self) -> &[u8]
Returns the AAD header block as required by the cipher (for authenticated modes).
Sourcefn uses_gcm_phases(&self) -> bool
fn uses_gcm_phases(&self) -> bool
Indicates whether this cipher mode uses GCM/CCM phases (init, header, payload, final).
Sourcefn is_ccm_mode(&self) -> bool
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.
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.