pub struct AesDmaBackend<'d> { /* private fields */ }Expand description
DMA-enabled AES processing backend.
The backend will try its best to use hardware acceleration as much as possible. It will
fall back to CPU-driven processing (equivalent to AesBackend) in some
cases, including:
- When the block cipher is not implemented in hardware.
- When the data is not correctly aligned to the needs of the hardware (e.g. when using a stream cipher mode, the data length is not an integer multiple of 16 bytes).
§Example
use esp_hal::aes::{AesContext, Operation, cipher_modes::Ecb, dma::AesDmaBackend};
let dma_channel = peripherals.DMA_CH0;
let mut aes = AesDmaBackend::new(peripherals.AES, dma_channel);
// 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> AesDmaBackend<'d>
 
impl<'d> AesDmaBackend<'d>
Sourcepub fn new(aes: AES<'d>, dma: impl DmaChannelFor<AES<'d>>) -> Self
 
pub fn new(aes: AES<'d>, dma: impl DmaChannelFor<AES<'d>>) -> Self
Sourcepub fn start(&mut self) -> AesDmaWorkQueueDriver<'_, 'd>
 
pub fn start(&mut self) -> AesDmaWorkQueueDriver<'_, 'd>
Registers the DMA-driven AES driver to process AES operations.
The driver stops operating when the returned object is dropped.
§Example
use esp_hal::aes::dma::AesDmaBackend;
let dma_channel = peripherals.DMA_CH0;
let mut aes = AesDmaBackend::new(peripherals.AES, dma_channel);
let _handle = aes.start();Trait Implementations§
impl Send for AesDmaBackend<'_>
Available on crate feature 
unstable only.impl Sync for AesDmaBackend<'_>
Available on crate feature 
unstable only.