pub struct AesBackend<'d> { /* private fields */ }Expand description
CPU-driven AES processing backend.
§Example
use esp_hal::aes::{AesBackend, AesContext, Operation, cipher_modes::Ecb};
let mut aes = AesBackend::new(peripherals.AES);
// Start the backend, which allows processing AES operations.
let _backend = aes.start();
// Create a new context with a 128-bit key. The context will use the ECB block cipher mode.
// The key length must be supported by the hardware.
let mut ecb_encrypt = AesContext::new(Ecb, Operation::Encrypt, *b"SUp4SeCp@sSw0rd\0");
// Process a block of data in this context. The ECB mode of operation requires that
// the length of the data is a multiple of the block (16 bytes) size.
let input_buffer: [u8; 16] = *b"message\0\0\0\0\0\0\0\0\0";
let mut output_buffer: [u8; 16] = [0; 16];
let operation_handle = ecb_encrypt
    .process(&input_buffer, &mut output_buffer)
    .unwrap();
operation_handle.wait_blocking();
// output_buffer now contains the ciphertext
assert_eq!(
    output_buffer,
    [
        0xb3, 0xc8, 0xd2, 0x3b, 0xa7, 0x36, 0x5f, 0x18, 0x61, 0x70, 0x0, 0x3e, 0xd9, 0x3a,
        0x31, 0x96,
    ]
);Implementations§
Source§impl<'d> AesBackend<'d>
 
impl<'d> AesBackend<'d>
Sourcepub fn start(&mut self) -> AesWorkQueueDriver<'_, 'd>
 
pub fn start(&mut self) -> AesWorkQueueDriver<'_, 'd>
Registers the CPU-driven AES driver to process AES operations.
The driver stops operating when the returned object is dropped.
§Example
use esp_hal::aes::AesBackend;
let mut aes = AesBackend::new(peripherals.AES);
// Start the backend, which allows processing AES operations.
let _backend = aes.start();