pub struct AesContext { /* private fields */ }Expand description
An AES work queue user.
Implementations§
Source§impl AesContext
impl AesContext
Sourcepub fn new(
cipher_mode: impl Into<CipherState>,
operation: Operation,
key: impl Into<Key>,
) -> Self
pub fn new( cipher_mode: impl Into<CipherState>, operation: Operation, key: impl Into<Key>, ) -> Self
Creates a new context to encrypt or decrypt data with the given block cipher mode of operation.
Sourcepub fn process<'t>(
&'t mut self,
input: &'t [u8],
output: &'t mut [u8],
) -> Result<AesHandle<'t>, Error>
pub fn process<'t>( &'t mut self, input: &'t [u8], output: &'t mut [u8], ) -> Result<AesHandle<'t>, Error>
Starts transforming the input buffer, and writes the result into the output buffer.
- For encryption the input is the plaintext, the output is the ciphertext.
- For decryption the input is the ciphertext, the output is the plaintext.
The returned Handle must be polled until it returns true. Dropping the handle
before the operation finishes will cancel the operation.
For an example, see the documentation of AesBackend.
§Errors
Sourcepub fn process_in_place<'t>(
&'t mut self,
buffer: &'t mut [u8],
) -> Result<AesHandle<'t>, Error>
pub fn process_in_place<'t>( &'t mut self, buffer: &'t mut [u8], ) -> Result<AesHandle<'t>, Error>
Starts transforming the buffer.
The processed data is written back to the buffer.
The returned Handle must be polled until it returns true. Dropping the handle
before the operation finishes will cancel the operation.
Operates similarly to AesContext::process, but overwrites the data buffer with the
result of the transformation.
§Examples
use esp_hal::aes::{AesBackend, AesContext, Operation, cipher_modes::Ecb};
let mut aes = AesBackend::new(peripherals.AES);
// Start the backend, which pins it in place and 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, in place. The ECB mode of operation requires that
// the length of the data is a multiple of the block (16 bytes) size.
let mut buffer: [u8; 16] = *b"message\0\0\0\0\0\0\0\0\0";
let operation_handle = ecb_encrypt.process_in_place(&mut buffer)?;
operation_handle.wait_blocking();
// Instead of the plaintext message, buffer now contains the ciphertext.
assert_eq!(
buffer,
[
0xb3, 0xc8, 0xd2, 0x3b, 0xa7, 0x36, 0x5f, 0x18, 0x61, 0x70, 0x0, 0x3e, 0xd9, 0x3a,
0x31, 0x96,
]
);§Errors
Error when ECB or OFB cipher modes are used and the data length is not a multiple of the
block size (16).
Trait Implementations§
Source§impl Clone for AesContext
Available on crate feature unstable only.
impl Clone for AesContext
unstable only.Source§fn clone(&self) -> AesContext
fn clone(&self) -> AesContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more