aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/Cargo.toml4
-rw-r--r--embassy-stm32/src/cryp/mod.rs7
-rw-r--r--examples/stm32f7/src/bin/cryp.rs14
3 files changed, 13 insertions, 12 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index d585d2cd6..4c856141b 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -70,7 +70,7 @@ rand_core = "0.6.3"
70sdio-host = "0.5.0" 70sdio-host = "0.5.0"
71critical-section = "1.1" 71critical-section = "1.1"
72#stm32-metapac = { version = "15" } 72#stm32-metapac = { version = "15" }
73stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6097928f720646c73d6483a3245f922bd5faee2f" } 73stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-ca48d946840840c5b311c96ff17cf4f8a865f9fb" }
74vcell = "0.1.3" 74vcell = "0.1.3"
75bxcan = "0.7.0" 75bxcan = "0.7.0"
76nb = "1.0.0" 76nb = "1.0.0"
@@ -94,7 +94,7 @@ critical-section = { version = "1.1", features = ["std"] }
94proc-macro2 = "1.0.36" 94proc-macro2 = "1.0.36"
95quote = "1.0.15" 95quote = "1.0.15"
96#stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} 96#stm32-metapac = { version = "15", default-features = false, features = ["metadata"]}
97stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6097928f720646c73d6483a3245f922bd5faee2f", default-features = false, features = ["metadata"]} 97stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-ca48d946840840c5b311c96ff17cf4f8a865f9fb", default-features = false, features = ["metadata"]}
98 98
99 99
100[features] 100[features]
diff --git a/embassy-stm32/src/cryp/mod.rs b/embassy-stm32/src/cryp/mod.rs
index 9d1a62905..fef5def6a 100644
--- a/embassy-stm32/src/cryp/mod.rs
+++ b/embassy-stm32/src/cryp/mod.rs
@@ -2,12 +2,11 @@
2#[cfg(cryp_v2)] 2#[cfg(cryp_v2)]
3use core::cmp::min; 3use core::cmp::min;
4use core::marker::PhantomData; 4use core::marker::PhantomData;
5
5use embassy_hal_internal::{into_ref, PeripheralRef}; 6use embassy_hal_internal::{into_ref, PeripheralRef};
6 7
7use crate::pac;
8use crate::peripherals::CRYP;
9use crate::rcc::sealed::RccPeripheral; 8use crate::rcc::sealed::RccPeripheral;
10use crate::{interrupt, peripherals, Peripheral}; 9use crate::{interrupt, pac, peripherals, Peripheral};
11 10
12const DES_BLOCK_SIZE: usize = 8; // 64 bits 11const DES_BLOCK_SIZE: usize = 8; // 64 bits
13const AES_BLOCK_SIZE: usize = 16; // 128 bits 12const AES_BLOCK_SIZE: usize = 16; // 128 bits
@@ -827,7 +826,7 @@ pub struct Cryp<'d, T: Instance> {
827impl<'d, T: Instance> Cryp<'d, T> { 826impl<'d, T: Instance> Cryp<'d, T> {
828 /// Create a new CRYP driver. 827 /// Create a new CRYP driver.
829 pub fn new(peri: impl Peripheral<P = T> + 'd) -> Self { 828 pub fn new(peri: impl Peripheral<P = T> + 'd) -> Self {
830 CRYP::enable_and_reset(); 829 T::enable_and_reset();
831 into_ref!(peri); 830 into_ref!(peri);
832 let instance = Self { _peripheral: peri }; 831 let instance = Self { _peripheral: peri };
833 instance 832 instance
diff --git a/examples/stm32f7/src/bin/cryp.rs b/examples/stm32f7/src/bin/cryp.rs
index be41955c5..04927841a 100644
--- a/examples/stm32f7/src/bin/cryp.rs
+++ b/examples/stm32f7/src/bin/cryp.rs
@@ -1,10 +1,9 @@
1#![no_std] 1#![no_std]
2#![no_main] 2#![no_main]
3 3
4use aes_gcm::{ 4use aes_gcm::aead::heapless::Vec;
5 aead::{heapless::Vec, AeadInPlace, KeyInit}, 5use aes_gcm::aead::{AeadInPlace, KeyInit};
6 Aes128Gcm, 6use aes_gcm::Aes128Gcm;
7};
8use defmt::info; 7use defmt::info;
9use embassy_executor::Spawner; 8use embassy_executor::Spawner;
10use embassy_stm32::cryp::*; 9use embassy_stm32::cryp::*;
@@ -55,9 +54,12 @@ async fn main(_spawner: Spawner) -> ! {
55 let mut payload_vec: Vec<u8, 32> = Vec::from_slice(&payload).unwrap(); 54 let mut payload_vec: Vec<u8, 32> = Vec::from_slice(&payload).unwrap();
56 let cipher = Aes128Gcm::new(&key.into()); 55 let cipher = Aes128Gcm::new(&key.into());
57 let _ = cipher.encrypt_in_place(&iv.into(), aad.into(), &mut payload_vec); 56 let _ = cipher.encrypt_in_place(&iv.into(), aad.into(), &mut payload_vec);
58 57
59 assert_eq!(ciphertext, payload_vec[0..ciphertext.len()]); 58 assert_eq!(ciphertext, payload_vec[0..ciphertext.len()]);
60 assert_eq!(encrypt_tag, payload_vec[ciphertext.len()..ciphertext.len() + encrypt_tag.len()]); 59 assert_eq!(
60 encrypt_tag,
61 payload_vec[ciphertext.len()..ciphertext.len() + encrypt_tag.len()]
62 );
61 63
62 // Decrypt in software using AES-GCM 128-bit 64 // Decrypt in software using AES-GCM 128-bit
63 let _ = cipher.decrypt_in_place(&iv.into(), aad.into(), &mut payload_vec); 65 let _ = cipher.decrypt_in_place(&iv.into(), aad.into(), &mut payload_vec);