Expand description
Advanced Encryption Standard (AES) support.
Overview
The AES module provides an interface to interact with the AES peripheral, provides encryption and decryption capabilities for ESP chips using the AES algorithm. We currently support the following AES encryption modes:
- AES-128
- AES-192
- AES-256
Example
Initialization
let mut aes = Aes::new(peripherals.AES, &mut system.peripheral_clock_control);
Creating key and block Buffer
let keytext = "SUp4SeCp@sSw0rd".as_bytes();
let plaintext = "message".as_bytes();
// create an array with aes128 key size
let mut keybuf = [0_u8; 16];
keybuf[..keytext.len()].copy_from_slice(keytext);
// create an array with aes block size
let mut block_buf = [0_u8; 16];
block_buf[..plaintext.len()].copy_from_slice(plaintext);
Encrypting and Decrypting (using hardware)
let key = Key::<Aes128>::from(&keybuf);
let mut cipher = Cipher::new(&mut aes, &key);
let mut block = block_buf.clone();
cipher.encrypt_block(&mut block);
let hw_encrypted = block.clone();
cipher.decrypt_block(&mut block);
let hw_decrypted = block;
Encrypting and Decrypting (using software)
let key = GenericArray::from(keybuf);
let mut block = GenericArray::from(block_buf);
let cipher = Aes128SW::new(&key);
cipher.encrypt_block(&mut block);
let sw_encrypted = block.clone();
cipher.decrypt_block(&mut block);
let sw_decrypted = block;
Implementation State
- DMA mode is currently not supported ⚠️
Structs
- AES peripheral container
- Marker type for AES-128
- Marker type for AES-192
- Marker type for AES-256
- Block cipher
- Aes cipher key
Enums
- State matrix endianness