AesDmaBackend

Struct AesDmaBackend 

Source
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>

Source

pub fn new(aes: AES<'d>, dma: impl DmaChannelFor<AES<'d>>) -> Self

Creates a new DMA-enabled AES backend.

The backend needs to be started before it can execute AES operations.

§Example
use esp_hal::aes::dma::AesDmaBackend;

let dma_channel = peripherals.DMA_CH0;
let mut aes = AesDmaBackend::new(peripherals.AES, dma_channel);
Source

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§

Source§

impl Send for AesDmaBackend<'_>

Available on crate feature unstable only.
Source§

impl Sync for AesDmaBackend<'_>

Available on crate feature unstable only.

Auto Trait Implementations§

§

impl<'d> Freeze for AesDmaBackend<'d>

§

impl<'d> RefUnwindSafe for AesDmaBackend<'d>

§

impl<'d> Unpin for AesDmaBackend<'d>

§

impl<'d> !UnwindSafe for AesDmaBackend<'d>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.