diff options
| author | Caleb Garrett <[email protected]> | 2024-03-12 12:01:14 -0400 |
|---|---|---|
| committer | Caleb Garrett <[email protected]> | 2024-03-12 12:01:14 -0400 |
| commit | 61050a16d5f02a7db718c6e39c811e6e434b032b (patch) | |
| tree | 4a4ade0865a373b84f5725f827304c75412c37e8 /examples/stm32f7/src | |
| parent | 6e9e8eeb5f6458833b28a08e7480b2630107d79c (diff) | |
Add CRYP DMA support. Updated example.
Diffstat (limited to 'examples/stm32f7/src')
| -rw-r--r-- | examples/stm32f7/src/bin/cryp.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/examples/stm32f7/src/bin/cryp.rs b/examples/stm32f7/src/bin/cryp.rs index 79b74e569..a5418765b 100644 --- a/examples/stm32f7/src/bin/cryp.rs +++ b/examples/stm32f7/src/bin/cryp.rs | |||
| @@ -6,7 +6,6 @@ use aes_gcm::aead::{AeadInPlace, KeyInit}; | |||
| 6 | use aes_gcm::Aes128Gcm; | 6 | use aes_gcm::Aes128Gcm; |
| 7 | use defmt::info; | 7 | use defmt::info; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_stm32::dma::NoDma; | ||
| 10 | use embassy_stm32::{ | 9 | use embassy_stm32::{ |
| 11 | bind_interrupts, | 10 | bind_interrupts, |
| 12 | cryp::{self, *}, | 11 | cryp::{self, *}, |
| @@ -27,7 +26,7 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 27 | let payload: &[u8] = b"hello world"; | 26 | let payload: &[u8] = b"hello world"; |
| 28 | let aad: &[u8] = b"additional data"; | 27 | let aad: &[u8] = b"additional data"; |
| 29 | 28 | ||
| 30 | let hw_cryp = Cryp::new(p.CRYP, NoDma, NoDma, Irqs); | 29 | let mut hw_cryp = Cryp::new(p.CRYP, p.DMA2_CH6, p.DMA2_CH5, Irqs); |
| 31 | let key: [u8; 16] = [0; 16]; | 30 | let key: [u8; 16] = [0; 16]; |
| 32 | let mut ciphertext: [u8; 11] = [0; 11]; | 31 | let mut ciphertext: [u8; 11] = [0; 11]; |
| 33 | let mut plaintext: [u8; 11] = [0; 11]; | 32 | let mut plaintext: [u8; 11] = [0; 11]; |
| @@ -37,16 +36,16 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 37 | 36 | ||
| 38 | // Encrypt in hardware using AES-GCM 128-bit | 37 | // Encrypt in hardware using AES-GCM 128-bit |
| 39 | let aes_gcm = AesGcm::new(&key, &iv); | 38 | let aes_gcm = AesGcm::new(&key, &iv); |
| 40 | let mut gcm_encrypt = hw_cryp.start(&aes_gcm, Direction::Encrypt); | 39 | let mut gcm_encrypt = hw_cryp.start(&aes_gcm, Direction::Encrypt).await; |
| 41 | hw_cryp.aad_blocking(&mut gcm_encrypt, aad, true); | 40 | hw_cryp.aad(&mut gcm_encrypt, aad, true).await; |
| 42 | hw_cryp.payload_blocking(&mut gcm_encrypt, payload, &mut ciphertext, true); | 41 | hw_cryp.payload(&mut gcm_encrypt, payload, &mut ciphertext, true).await; |
| 43 | let encrypt_tag = hw_cryp.finish_blocking(gcm_encrypt); | 42 | let encrypt_tag = hw_cryp.finish(gcm_encrypt).await; |
| 44 | 43 | ||
| 45 | // Decrypt in hardware using AES-GCM 128-bit | 44 | // Decrypt in hardware using AES-GCM 128-bit |
| 46 | let mut gcm_decrypt = hw_cryp.start(&aes_gcm, Direction::Decrypt); | 45 | let mut gcm_decrypt = hw_cryp.start(&aes_gcm, Direction::Decrypt).await; |
| 47 | hw_cryp.aad_blocking(&mut gcm_decrypt, aad, true); | 46 | hw_cryp.aad(&mut gcm_decrypt, aad, true).await; |
| 48 | hw_cryp.payload_blocking(&mut gcm_decrypt, &ciphertext, &mut plaintext, true); | 47 | hw_cryp.payload(&mut gcm_decrypt, &ciphertext, &mut plaintext, true).await; |
| 49 | let decrypt_tag = hw_cryp.finish_blocking(gcm_decrypt); | 48 | let decrypt_tag = hw_cryp.finish(gcm_decrypt).await; |
| 50 | 49 | ||
| 51 | let hw_end_time = Instant::now(); | 50 | let hw_end_time = Instant::now(); |
| 52 | let hw_execution_time = hw_end_time - hw_start_time; | 51 | let hw_execution_time = hw_end_time - hw_start_time; |
