diff options
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/cryp/mod.rs | 7 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/cryp.rs | 14 |
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" | |||
| 70 | sdio-host = "0.5.0" | 70 | sdio-host = "0.5.0" |
| 71 | critical-section = "1.1" | 71 | critical-section = "1.1" |
| 72 | #stm32-metapac = { version = "15" } | 72 | #stm32-metapac = { version = "15" } |
| 73 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6097928f720646c73d6483a3245f922bd5faee2f" } | 73 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-ca48d946840840c5b311c96ff17cf4f8a865f9fb" } |
| 74 | vcell = "0.1.3" | 74 | vcell = "0.1.3" |
| 75 | bxcan = "0.7.0" | 75 | bxcan = "0.7.0" |
| 76 | nb = "1.0.0" | 76 | nb = "1.0.0" |
| @@ -94,7 +94,7 @@ critical-section = { version = "1.1", features = ["std"] } | |||
| 94 | proc-macro2 = "1.0.36" | 94 | proc-macro2 = "1.0.36" |
| 95 | quote = "1.0.15" | 95 | quote = "1.0.15" |
| 96 | #stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} | 96 | #stm32-metapac = { version = "15", default-features = false, features = ["metadata"]} |
| 97 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6097928f720646c73d6483a3245f922bd5faee2f", default-features = false, features = ["metadata"]} | 97 | stm32-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)] |
| 3 | use core::cmp::min; | 3 | use core::cmp::min; |
| 4 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 5 | |||
| 5 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 6 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 6 | 7 | ||
| 7 | use crate::pac; | ||
| 8 | use crate::peripherals::CRYP; | ||
| 9 | use crate::rcc::sealed::RccPeripheral; | 8 | use crate::rcc::sealed::RccPeripheral; |
| 10 | use crate::{interrupt, peripherals, Peripheral}; | 9 | use crate::{interrupt, pac, peripherals, Peripheral}; |
| 11 | 10 | ||
| 12 | const DES_BLOCK_SIZE: usize = 8; // 64 bits | 11 | const DES_BLOCK_SIZE: usize = 8; // 64 bits |
| 13 | const AES_BLOCK_SIZE: usize = 16; // 128 bits | 12 | const AES_BLOCK_SIZE: usize = 16; // 128 bits |
| @@ -827,7 +826,7 @@ pub struct Cryp<'d, T: Instance> { | |||
| 827 | impl<'d, T: Instance> Cryp<'d, T> { | 826 | impl<'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 | ||
| 4 | use aes_gcm::{ | 4 | use aes_gcm::aead::heapless::Vec; |
| 5 | aead::{heapless::Vec, AeadInPlace, KeyInit}, | 5 | use aes_gcm::aead::{AeadInPlace, KeyInit}; |
| 6 | Aes128Gcm, | 6 | use aes_gcm::Aes128Gcm; |
| 7 | }; | ||
| 8 | use defmt::info; | 7 | use defmt::info; |
| 9 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::cryp::*; | 9 | use 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); |
