aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/cryp
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-05-01 02:21:06 +0200
committerDario Nieuwenhuis <[email protected]>2024-05-01 02:24:45 +0200
commitfb67fe0a6c155191534955f1230dccaea0e11a94 (patch)
treeac01b69047aeee08983a5149409080d137f19cb1 /embassy-stm32/src/cryp
parentecc910b76dbfa2064f42e6917a7b5654a89b81ed (diff)
stm32: add support for STM32H7[RS] "bootflash line", add HIL tests.
Diffstat (limited to 'embassy-stm32/src/cryp')
-rw-r--r--embassy-stm32/src/cryp/mod.rs133
1 files changed, 68 insertions, 65 deletions
diff --git a/embassy-stm32/src/cryp/mod.rs b/embassy-stm32/src/cryp/mod.rs
index 18b5ec918..f19c94fda 100644
--- a/embassy-stm32/src/cryp/mod.rs
+++ b/embassy-stm32/src/cryp/mod.rs
@@ -1,5 +1,5 @@
1//! Crypto Accelerator (CRYP) 1//! Crypto Accelerator (CRYP)
2#[cfg(any(cryp_v2, cryp_v3))] 2#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
3use core::cmp::min; 3use core::cmp::min;
4use core::marker::PhantomData; 4use core::marker::PhantomData;
5use core::ptr; 5use core::ptr;
@@ -7,7 +7,7 @@ use core::ptr;
7use embassy_hal_internal::{into_ref, PeripheralRef}; 7use embassy_hal_internal::{into_ref, PeripheralRef};
8use embassy_sync::waitqueue::AtomicWaker; 8use embassy_sync::waitqueue::AtomicWaker;
9 9
10use crate::dma::{NoDma, Priority, Transfer, TransferOptions}; 10use crate::dma::{NoDma, Transfer, TransferOptions};
11use crate::interrupt::typelevel::Interrupt; 11use crate::interrupt::typelevel::Interrupt;
12use crate::{interrupt, pac, peripherals, Peripheral}; 12use crate::{interrupt, pac, peripherals, Peripheral};
13 13
@@ -147,7 +147,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for TdesEcb<'c, KEY_SIZE> {
147 { 147 {
148 p.cr().modify(|w| w.set_algomode(0)); 148 p.cr().modify(|w| w.set_algomode(0));
149 } 149 }
150 #[cfg(any(cryp_v2, cryp_v3))] 150 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
151 { 151 {
152 p.cr().modify(|w| w.set_algomode0(0)); 152 p.cr().modify(|w| w.set_algomode0(0));
153 p.cr().modify(|w| w.set_algomode3(false)); 153 p.cr().modify(|w| w.set_algomode3(false));
@@ -189,7 +189,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for TdesCbc<'c, KEY_SIZE> {
189 { 189 {
190 p.cr().modify(|w| w.set_algomode(1)); 190 p.cr().modify(|w| w.set_algomode(1));
191 } 191 }
192 #[cfg(any(cryp_v2, cryp_v3))] 192 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
193 { 193 {
194 p.cr().modify(|w| w.set_algomode0(1)); 194 p.cr().modify(|w| w.set_algomode0(1));
195 p.cr().modify(|w| w.set_algomode3(false)); 195 p.cr().modify(|w| w.set_algomode3(false));
@@ -231,7 +231,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for DesEcb<'c, KEY_SIZE> {
231 { 231 {
232 p.cr().modify(|w| w.set_algomode(2)); 232 p.cr().modify(|w| w.set_algomode(2));
233 } 233 }
234 #[cfg(any(cryp_v2, cryp_v3))] 234 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
235 { 235 {
236 p.cr().modify(|w| w.set_algomode0(2)); 236 p.cr().modify(|w| w.set_algomode0(2));
237 p.cr().modify(|w| w.set_algomode3(false)); 237 p.cr().modify(|w| w.set_algomode3(false));
@@ -272,7 +272,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for DesCbc<'c, KEY_SIZE> {
272 { 272 {
273 p.cr().modify(|w| w.set_algomode(3)); 273 p.cr().modify(|w| w.set_algomode(3));
274 } 274 }
275 #[cfg(any(cryp_v2, cryp_v3))] 275 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
276 { 276 {
277 p.cr().modify(|w| w.set_algomode0(3)); 277 p.cr().modify(|w| w.set_algomode0(3));
278 p.cr().modify(|w| w.set_algomode3(false)); 278 p.cr().modify(|w| w.set_algomode3(false));
@@ -313,7 +313,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesEcb<'c, KEY_SIZE> {
313 { 313 {
314 p.cr().modify(|w| w.set_algomode(7)); 314 p.cr().modify(|w| w.set_algomode(7));
315 } 315 }
316 #[cfg(any(cryp_v2, cryp_v3))] 316 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
317 { 317 {
318 p.cr().modify(|w| w.set_algomode0(7)); 318 p.cr().modify(|w| w.set_algomode0(7));
319 p.cr().modify(|w| w.set_algomode3(false)); 319 p.cr().modify(|w| w.set_algomode3(false));
@@ -327,7 +327,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesEcb<'c, KEY_SIZE> {
327 { 327 {
328 p.cr().modify(|w| w.set_algomode(2)); 328 p.cr().modify(|w| w.set_algomode(2));
329 } 329 }
330 #[cfg(any(cryp_v2, cryp_v3))] 330 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
331 { 331 {
332 p.cr().modify(|w| w.set_algomode0(2)); 332 p.cr().modify(|w| w.set_algomode0(2));
333 p.cr().modify(|w| w.set_algomode3(false)); 333 p.cr().modify(|w| w.set_algomode3(false));
@@ -370,7 +370,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesCbc<'c, KEY_SIZE> {
370 { 370 {
371 p.cr().modify(|w| w.set_algomode(7)); 371 p.cr().modify(|w| w.set_algomode(7));
372 } 372 }
373 #[cfg(any(cryp_v2, cryp_v3))] 373 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
374 { 374 {
375 p.cr().modify(|w| w.set_algomode0(7)); 375 p.cr().modify(|w| w.set_algomode0(7));
376 p.cr().modify(|w| w.set_algomode3(false)); 376 p.cr().modify(|w| w.set_algomode3(false));
@@ -384,7 +384,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesCbc<'c, KEY_SIZE> {
384 { 384 {
385 p.cr().modify(|w| w.set_algomode(5)); 385 p.cr().modify(|w| w.set_algomode(5));
386 } 386 }
387 #[cfg(any(cryp_v2, cryp_v3))] 387 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
388 { 388 {
389 p.cr().modify(|w| w.set_algomode0(5)); 389 p.cr().modify(|w| w.set_algomode0(5));
390 p.cr().modify(|w| w.set_algomode3(false)); 390 p.cr().modify(|w| w.set_algomode3(false));
@@ -426,7 +426,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesCtr<'c, KEY_SIZE> {
426 { 426 {
427 p.cr().modify(|w| w.set_algomode(6)); 427 p.cr().modify(|w| w.set_algomode(6));
428 } 428 }
429 #[cfg(any(cryp_v2, cryp_v3))] 429 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
430 { 430 {
431 p.cr().modify(|w| w.set_algomode0(6)); 431 p.cr().modify(|w| w.set_algomode0(6));
432 p.cr().modify(|w| w.set_algomode3(false)); 432 p.cr().modify(|w| w.set_algomode3(false));
@@ -439,14 +439,14 @@ impl<'c> CipherSized for AesCtr<'c, { 192 / 8 }> {}
439impl<'c> CipherSized for AesCtr<'c, { 256 / 8 }> {} 439impl<'c> CipherSized for AesCtr<'c, { 256 / 8 }> {}
440impl<'c, const KEY_SIZE: usize> IVSized for AesCtr<'c, KEY_SIZE> {} 440impl<'c, const KEY_SIZE: usize> IVSized for AesCtr<'c, KEY_SIZE> {}
441 441
442#[cfg(any(cryp_v2, cryp_v3))] 442#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
443///AES-GCM Cipher Mode 443///AES-GCM Cipher Mode
444pub struct AesGcm<'c, const KEY_SIZE: usize> { 444pub struct AesGcm<'c, const KEY_SIZE: usize> {
445 iv: [u8; 16], 445 iv: [u8; 16],
446 key: &'c [u8; KEY_SIZE], 446 key: &'c [u8; KEY_SIZE],
447} 447}
448 448
449#[cfg(any(cryp_v2, cryp_v3))] 449#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
450impl<'c, const KEY_SIZE: usize> AesGcm<'c, KEY_SIZE> { 450impl<'c, const KEY_SIZE: usize> AesGcm<'c, KEY_SIZE> {
451 /// Constucts a new AES-GCM cipher for a cryptographic operation. 451 /// Constucts a new AES-GCM cipher for a cryptographic operation.
452 pub fn new(key: &'c [u8; KEY_SIZE], iv: &'c [u8; 12]) -> Self { 452 pub fn new(key: &'c [u8; KEY_SIZE], iv: &'c [u8; 12]) -> Self {
@@ -457,7 +457,7 @@ impl<'c, const KEY_SIZE: usize> AesGcm<'c, KEY_SIZE> {
457 } 457 }
458} 458}
459 459
460#[cfg(any(cryp_v2, cryp_v3))] 460#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
461impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGcm<'c, KEY_SIZE> { 461impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGcm<'c, KEY_SIZE> {
462 const BLOCK_SIZE: usize = AES_BLOCK_SIZE; 462 const BLOCK_SIZE: usize = AES_BLOCK_SIZE;
463 463
@@ -504,7 +504,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGcm<'c, KEY_SIZE> {
504 [0; 4] 504 [0; 4]
505 } 505 }
506 506
507 #[cfg(cryp_v3)] 507 #[cfg(any(cryp_v3, cryp_v4))]
508 fn pre_final(&self, p: &pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] { 508 fn pre_final(&self, p: &pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] {
509 //Handle special GCM partial block process. 509 //Handle special GCM partial block process.
510 p.cr().modify(|w| w.set_npblb(padding_len as u8)); 510 p.cr().modify(|w| w.set_npblb(padding_len as u8));
@@ -573,25 +573,25 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGcm<'c, KEY_SIZE> {
573 } 573 }
574} 574}
575 575
576#[cfg(any(cryp_v2, cryp_v3))] 576#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
577impl<'c> CipherSized for AesGcm<'c, { 128 / 8 }> {} 577impl<'c> CipherSized for AesGcm<'c, { 128 / 8 }> {}
578#[cfg(any(cryp_v2, cryp_v3))] 578#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
579impl<'c> CipherSized for AesGcm<'c, { 192 / 8 }> {} 579impl<'c> CipherSized for AesGcm<'c, { 192 / 8 }> {}
580#[cfg(any(cryp_v2, cryp_v3))] 580#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
581impl<'c> CipherSized for AesGcm<'c, { 256 / 8 }> {} 581impl<'c> CipherSized for AesGcm<'c, { 256 / 8 }> {}
582#[cfg(any(cryp_v2, cryp_v3))] 582#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
583impl<'c, const KEY_SIZE: usize> CipherAuthenticated<16> for AesGcm<'c, KEY_SIZE> {} 583impl<'c, const KEY_SIZE: usize> CipherAuthenticated<16> for AesGcm<'c, KEY_SIZE> {}
584#[cfg(any(cryp_v2, cryp_v3))] 584#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
585impl<'c, const KEY_SIZE: usize> IVSized for AesGcm<'c, KEY_SIZE> {} 585impl<'c, const KEY_SIZE: usize> IVSized for AesGcm<'c, KEY_SIZE> {}
586 586
587#[cfg(any(cryp_v2, cryp_v3))] 587#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
588/// AES-GMAC Cipher Mode 588/// AES-GMAC Cipher Mode
589pub struct AesGmac<'c, const KEY_SIZE: usize> { 589pub struct AesGmac<'c, const KEY_SIZE: usize> {
590 iv: [u8; 16], 590 iv: [u8; 16],
591 key: &'c [u8; KEY_SIZE], 591 key: &'c [u8; KEY_SIZE],
592} 592}
593 593
594#[cfg(any(cryp_v2, cryp_v3))] 594#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
595impl<'c, const KEY_SIZE: usize> AesGmac<'c, KEY_SIZE> { 595impl<'c, const KEY_SIZE: usize> AesGmac<'c, KEY_SIZE> {
596 /// Constructs a new AES-GMAC cipher for a cryptographic operation. 596 /// Constructs a new AES-GMAC cipher for a cryptographic operation.
597 pub fn new(key: &'c [u8; KEY_SIZE], iv: &'c [u8; 12]) -> Self { 597 pub fn new(key: &'c [u8; KEY_SIZE], iv: &'c [u8; 12]) -> Self {
@@ -602,7 +602,7 @@ impl<'c, const KEY_SIZE: usize> AesGmac<'c, KEY_SIZE> {
602 } 602 }
603} 603}
604 604
605#[cfg(any(cryp_v2, cryp_v3))] 605#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
606impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGmac<'c, KEY_SIZE> { 606impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGmac<'c, KEY_SIZE> {
607 const BLOCK_SIZE: usize = AES_BLOCK_SIZE; 607 const BLOCK_SIZE: usize = AES_BLOCK_SIZE;
608 608
@@ -649,7 +649,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGmac<'c, KEY_SIZE> {
649 [0; 4] 649 [0; 4]
650 } 650 }
651 651
652 #[cfg(cryp_v3)] 652 #[cfg(any(cryp_v3, cryp_v4))]
653 fn pre_final(&self, p: &pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] { 653 fn pre_final(&self, p: &pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] {
654 //Handle special GCM partial block process. 654 //Handle special GCM partial block process.
655 p.cr().modify(|w| w.set_npblb(padding_len as u8)); 655 p.cr().modify(|w| w.set_npblb(padding_len as u8));
@@ -716,18 +716,18 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGmac<'c, KEY_SIZE> {
716 } 716 }
717} 717}
718 718
719#[cfg(any(cryp_v2, cryp_v3))] 719#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
720impl<'c> CipherSized for AesGmac<'c, { 128 / 8 }> {} 720impl<'c> CipherSized for AesGmac<'c, { 128 / 8 }> {}
721#[cfg(any(cryp_v2, cryp_v3))] 721#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
722impl<'c> CipherSized for AesGmac<'c, { 192 / 8 }> {} 722impl<'c> CipherSized for AesGmac<'c, { 192 / 8 }> {}
723#[cfg(any(cryp_v2, cryp_v3))] 723#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
724impl<'c> CipherSized for AesGmac<'c, { 256 / 8 }> {} 724impl<'c> CipherSized for AesGmac<'c, { 256 / 8 }> {}
725#[cfg(any(cryp_v2, cryp_v3))] 725#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
726impl<'c, const KEY_SIZE: usize> CipherAuthenticated<16> for AesGmac<'c, KEY_SIZE> {} 726impl<'c, const KEY_SIZE: usize> CipherAuthenticated<16> for AesGmac<'c, KEY_SIZE> {}
727#[cfg(any(cryp_v2, cryp_v3))] 727#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
728impl<'c, const KEY_SIZE: usize> IVSized for AesGmac<'c, KEY_SIZE> {} 728impl<'c, const KEY_SIZE: usize> IVSized for AesGmac<'c, KEY_SIZE> {}
729 729
730#[cfg(any(cryp_v2, cryp_v3))] 730#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
731/// AES-CCM Cipher Mode 731/// AES-CCM Cipher Mode
732pub struct AesCcm<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> { 732pub struct AesCcm<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> {
733 key: &'c [u8; KEY_SIZE], 733 key: &'c [u8; KEY_SIZE],
@@ -737,7 +737,7 @@ pub struct AesCcm<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZ
737 ctr: [u8; 16], 737 ctr: [u8; 16],
738} 738}
739 739
740#[cfg(any(cryp_v2, cryp_v3))] 740#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
741impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> AesCcm<'c, KEY_SIZE, TAG_SIZE, IV_SIZE> { 741impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> AesCcm<'c, KEY_SIZE, TAG_SIZE, IV_SIZE> {
742 /// Constructs a new AES-CCM cipher for a cryptographic operation. 742 /// Constructs a new AES-CCM cipher for a cryptographic operation.
743 pub fn new(key: &'c [u8; KEY_SIZE], iv: &'c [u8; IV_SIZE], aad_len: usize, payload_len: usize) -> Self { 743 pub fn new(key: &'c [u8; KEY_SIZE], iv: &'c [u8; IV_SIZE], aad_len: usize, payload_len: usize) -> Self {
@@ -801,7 +801,7 @@ impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Aes
801 } 801 }
802} 802}
803 803
804#[cfg(any(cryp_v2, cryp_v3))] 804#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
805impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Cipher<'c> 805impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Cipher<'c>
806 for AesCcm<'c, KEY_SIZE, TAG_SIZE, IV_SIZE> 806 for AesCcm<'c, KEY_SIZE, TAG_SIZE, IV_SIZE>
807{ 807{
@@ -865,7 +865,7 @@ impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Cip
865 return temp1; 865 return temp1;
866 } 866 }
867 867
868 #[cfg(cryp_v3)] 868 #[cfg(any(cryp_v3, cryp_v4))]
869 fn pre_final(&self, p: &pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] { 869 fn pre_final(&self, p: &pac::cryp::Cryp, _dir: Direction, padding_len: usize) -> [u32; 4] {
870 //Handle special GCM partial block process. 870 //Handle special GCM partial block process.
871 p.cr().modify(|w| w.set_npblb(padding_len as u8)); 871 p.cr().modify(|w| w.set_npblb(padding_len as u8));
@@ -950,39 +950,39 @@ impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize, const IV_SIZE: usize> Cip
950 } 950 }
951} 951}
952 952
953#[cfg(any(cryp_v2, cryp_v3))] 953#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
954impl<'c, const TAG_SIZE: usize, const IV_SIZE: usize> CipherSized for AesCcm<'c, { 128 / 8 }, TAG_SIZE, IV_SIZE> {} 954impl<'c, const TAG_SIZE: usize, const IV_SIZE: usize> CipherSized for AesCcm<'c, { 128 / 8 }, TAG_SIZE, IV_SIZE> {}
955#[cfg(any(cryp_v2, cryp_v3))] 955#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
956impl<'c, const TAG_SIZE: usize, const IV_SIZE: usize> CipherSized for AesCcm<'c, { 192 / 8 }, TAG_SIZE, IV_SIZE> {} 956impl<'c, const TAG_SIZE: usize, const IV_SIZE: usize> CipherSized for AesCcm<'c, { 192 / 8 }, TAG_SIZE, IV_SIZE> {}
957#[cfg(any(cryp_v2, cryp_v3))] 957#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
958impl<'c, const TAG_SIZE: usize, const IV_SIZE: usize> CipherSized for AesCcm<'c, { 256 / 8 }, TAG_SIZE, IV_SIZE> {} 958impl<'c, const TAG_SIZE: usize, const IV_SIZE: usize> CipherSized for AesCcm<'c, { 256 / 8 }, TAG_SIZE, IV_SIZE> {}
959#[cfg(any(cryp_v2, cryp_v3))] 959#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
960impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<4> for AesCcm<'c, KEY_SIZE, 4, IV_SIZE> {} 960impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<4> for AesCcm<'c, KEY_SIZE, 4, IV_SIZE> {}
961#[cfg(any(cryp_v2, cryp_v3))] 961#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
962impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<6> for AesCcm<'c, KEY_SIZE, 6, IV_SIZE> {} 962impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<6> for AesCcm<'c, KEY_SIZE, 6, IV_SIZE> {}
963#[cfg(any(cryp_v2, cryp_v3))] 963#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
964impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<8> for AesCcm<'c, KEY_SIZE, 8, IV_SIZE> {} 964impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<8> for AesCcm<'c, KEY_SIZE, 8, IV_SIZE> {}
965#[cfg(any(cryp_v2, cryp_v3))] 965#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
966impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<10> for AesCcm<'c, KEY_SIZE, 10, IV_SIZE> {} 966impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<10> for AesCcm<'c, KEY_SIZE, 10, IV_SIZE> {}
967#[cfg(any(cryp_v2, cryp_v3))] 967#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
968impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<12> for AesCcm<'c, KEY_SIZE, 12, IV_SIZE> {} 968impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<12> for AesCcm<'c, KEY_SIZE, 12, IV_SIZE> {}
969#[cfg(any(cryp_v2, cryp_v3))] 969#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
970impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<14> for AesCcm<'c, KEY_SIZE, 14, IV_SIZE> {} 970impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<14> for AesCcm<'c, KEY_SIZE, 14, IV_SIZE> {}
971#[cfg(any(cryp_v2, cryp_v3))] 971#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
972impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<16> for AesCcm<'c, KEY_SIZE, 16, IV_SIZE> {} 972impl<'c, const KEY_SIZE: usize, const IV_SIZE: usize> CipherAuthenticated<16> for AesCcm<'c, KEY_SIZE, 16, IV_SIZE> {}
973#[cfg(any(cryp_v2, cryp_v3))] 973#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
974impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 7> {} 974impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 7> {}
975#[cfg(any(cryp_v2, cryp_v3))] 975#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
976impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 8> {} 976impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 8> {}
977#[cfg(any(cryp_v2, cryp_v3))] 977#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
978impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 9> {} 978impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 9> {}
979#[cfg(any(cryp_v2, cryp_v3))] 979#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
980impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 10> {} 980impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 10> {}
981#[cfg(any(cryp_v2, cryp_v3))] 981#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
982impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 11> {} 982impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 11> {}
983#[cfg(any(cryp_v2, cryp_v3))] 983#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
984impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 12> {} 984impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 12> {}
985#[cfg(any(cryp_v2, cryp_v3))] 985#[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
986impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 13> {} 986impl<'c, const KEY_SIZE: usize, const TAG_SIZE: usize> IVSized for AesCcm<'c, KEY_SIZE, TAG_SIZE, 13> {}
987 987
988#[allow(dead_code)] 988#[allow(dead_code)]
@@ -1205,7 +1205,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1205 ctx 1205 ctx
1206 } 1206 }
1207 1207
1208 #[cfg(any(cryp_v2, cryp_v3))] 1208 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
1209 /// Controls the header phase of cipher processing. 1209 /// Controls the header phase of cipher processing.
1210 /// This function is only valid for authenticated ciphers including GCM, CCM, and GMAC. 1210 /// This function is only valid for authenticated ciphers including GCM, CCM, and GMAC.
1211 /// All additional associated data (AAD) must be supplied to this function prior to starting the payload phase with `payload_blocking`. 1211 /// All additional associated data (AAD) must be supplied to this function prior to starting the payload phase with `payload_blocking`.
@@ -1302,7 +1302,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1302 self.store_context(ctx); 1302 self.store_context(ctx);
1303 } 1303 }
1304 1304
1305 #[cfg(any(cryp_v2, cryp_v3))] 1305 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
1306 /// Controls the header phase of cipher processing. 1306 /// Controls the header phase of cipher processing.
1307 /// This function is only valid for authenticated ciphers including GCM, CCM, and GMAC. 1307 /// This function is only valid for authenticated ciphers including GCM, CCM, and GMAC.
1308 /// All additional associated data (AAD) must be supplied to this function prior to starting the payload phase with `payload`. 1308 /// All additional associated data (AAD) must be supplied to this function prior to starting the payload phase with `payload`.
@@ -1420,7 +1420,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1420 if !ctx.aad_complete && ctx.header_len > 0 { 1420 if !ctx.aad_complete && ctx.header_len > 0 {
1421 panic!("Additional associated data must be processed first!"); 1421 panic!("Additional associated data must be processed first!");
1422 } else if !ctx.aad_complete { 1422 } else if !ctx.aad_complete {
1423 #[cfg(any(cryp_v2, cryp_v3))] 1423 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
1424 { 1424 {
1425 ctx.aad_complete = true; 1425 ctx.aad_complete = true;
1426 T::regs().cr().modify(|w| w.set_crypen(false)); 1426 T::regs().cr().modify(|w| w.set_crypen(false));
@@ -1512,7 +1512,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1512 if !ctx.aad_complete && ctx.header_len > 0 { 1512 if !ctx.aad_complete && ctx.header_len > 0 {
1513 panic!("Additional associated data must be processed first!"); 1513 panic!("Additional associated data must be processed first!");
1514 } else if !ctx.aad_complete { 1514 } else if !ctx.aad_complete {
1515 #[cfg(any(cryp_v2, cryp_v3))] 1515 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
1516 { 1516 {
1517 ctx.aad_complete = true; 1517 ctx.aad_complete = true;
1518 T::regs().cr().modify(|w| w.set_crypen(false)); 1518 T::regs().cr().modify(|w| w.set_crypen(false));
@@ -1585,7 +1585,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1585 self.store_context(ctx); 1585 self.store_context(ctx);
1586 } 1586 }
1587 1587
1588 #[cfg(any(cryp_v2, cryp_v3))] 1588 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
1589 /// Generates an authentication tag for authenticated ciphers including GCM, CCM, and GMAC. 1589 /// Generates an authentication tag for authenticated ciphers including GCM, CCM, and GMAC.
1590 /// Called after the all data has been encrypted/decrypted by `payload`. 1590 /// Called after the all data has been encrypted/decrypted by `payload`.
1591 pub fn finish_blocking< 1591 pub fn finish_blocking<
@@ -1614,7 +1614,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1614 payloadlen1.swap_bytes(), 1614 payloadlen1.swap_bytes(),
1615 payloadlen2.swap_bytes(), 1615 payloadlen2.swap_bytes(),
1616 ]; 1616 ];
1617 #[cfg(cryp_v3)] 1617 #[cfg(any(cryp_v3, cryp_v4))]
1618 let footer: [u32; 4] = [headerlen1, headerlen2, payloadlen1, payloadlen2]; 1618 let footer: [u32; 4] = [headerlen1, headerlen2, payloadlen1, payloadlen2];
1619 1619
1620 self.write_words_blocking(C::BLOCK_SIZE, &footer); 1620 self.write_words_blocking(C::BLOCK_SIZE, &footer);
@@ -1631,7 +1631,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1631 tag 1631 tag
1632 } 1632 }
1633 1633
1634 #[cfg(any(cryp_v2, cryp_v3))] 1634 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
1635 // Generates an authentication tag for authenticated ciphers including GCM, CCM, and GMAC. 1635 // Generates an authentication tag for authenticated ciphers including GCM, CCM, and GMAC.
1636 /// Called after the all data has been encrypted/decrypted by `payload`. 1636 /// Called after the all data has been encrypted/decrypted by `payload`.
1637 pub async fn finish< 1637 pub async fn finish<
@@ -1664,7 +1664,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1664 payloadlen1.swap_bytes(), 1664 payloadlen1.swap_bytes(),
1665 payloadlen2.swap_bytes(), 1665 payloadlen2.swap_bytes(),
1666 ]; 1666 ];
1667 #[cfg(cryp_v3)] 1667 #[cfg(any(cryp_v3, cryp_v4))]
1668 let footer: [u32; 4] = [headerlen1, headerlen2, payloadlen1, payloadlen2]; 1668 let footer: [u32; 4] = [headerlen1, headerlen2, payloadlen1, payloadlen2];
1669 1669
1670 let write = Self::write_words(&mut self.indma, C::BLOCK_SIZE, &footer); 1670 let write = Self::write_words(&mut self.indma, C::BLOCK_SIZE, &footer);
@@ -1735,7 +1735,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1735 ctx.iv[2] = T::regs().init(1).ivlr().read(); 1735 ctx.iv[2] = T::regs().init(1).ivlr().read();
1736 ctx.iv[3] = T::regs().init(1).ivrr().read(); 1736 ctx.iv[3] = T::regs().init(1).ivrr().read();
1737 1737
1738 #[cfg(any(cryp_v2, cryp_v3))] 1738 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
1739 for i in 0..8 { 1739 for i in 0..8 {
1740 ctx.csgcmccm[i] = T::regs().csgcmccmr(i).read(); 1740 ctx.csgcmccm[i] = T::regs().csgcmccmr(i).read();
1741 ctx.csgcm[i] = T::regs().csgcmr(i).read(); 1741 ctx.csgcm[i] = T::regs().csgcmr(i).read();
@@ -1750,7 +1750,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1750 T::regs().init(1).ivlr().write_value(ctx.iv[2]); 1750 T::regs().init(1).ivlr().write_value(ctx.iv[2]);
1751 T::regs().init(1).ivrr().write_value(ctx.iv[3]); 1751 T::regs().init(1).ivrr().write_value(ctx.iv[3]);
1752 1752
1753 #[cfg(any(cryp_v2, cryp_v3))] 1753 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
1754 for i in 0..8 { 1754 for i in 0..8 {
1755 T::regs().csgcmccmr(i).write_value(ctx.csgcmccm[i]); 1755 T::regs().csgcmccmr(i).write_value(ctx.csgcmccm[i]);
1756 T::regs().csgcmr(i).write_value(ctx.csgcm[i]); 1756 T::regs().csgcmr(i).write_value(ctx.csgcm[i]);
@@ -1797,7 +1797,8 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1797 let num_words = blocks.len() / 4; 1797 let num_words = blocks.len() / 4;
1798 let src_ptr = ptr::slice_from_raw_parts(blocks.as_ptr().cast(), num_words); 1798 let src_ptr = ptr::slice_from_raw_parts(blocks.as_ptr().cast(), num_words);
1799 let options = TransferOptions { 1799 let options = TransferOptions {
1800 priority: Priority::High, 1800 #[cfg(not(gpdma))]
1801 priority: crate::dma::Priority::High,
1801 ..Default::default() 1802 ..Default::default()
1802 }; 1803 };
1803 let dma_transfer = unsafe { Transfer::new_write_raw(dma, dma_request, src_ptr, dst_ptr, options) }; 1804 let dma_transfer = unsafe { Transfer::new_write_raw(dma, dma_request, src_ptr, dst_ptr, options) };
@@ -1806,7 +1807,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1806 dma_transfer.await; 1807 dma_transfer.await;
1807 } 1808 }
1808 1809
1809 #[cfg(any(cryp_v2, cryp_v3))] 1810 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
1810 fn write_words_blocking(&self, block_size: usize, blocks: &[u32]) { 1811 fn write_words_blocking(&self, block_size: usize, blocks: &[u32]) {
1811 assert_eq!((blocks.len() * 4) % block_size, 0); 1812 assert_eq!((blocks.len() * 4) % block_size, 0);
1812 let mut byte_counter: usize = 0; 1813 let mut byte_counter: usize = 0;
@@ -1820,7 +1821,7 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1820 } 1821 }
1821 } 1822 }
1822 1823
1823 #[cfg(any(cryp_v2, cryp_v3))] 1824 #[cfg(any(cryp_v2, cryp_v3, cryp_v4))]
1824 async fn write_words(dma: &mut PeripheralRef<'_, DmaIn>, block_size: usize, blocks: &[u32]) 1825 async fn write_words(dma: &mut PeripheralRef<'_, DmaIn>, block_size: usize, blocks: &[u32])
1825 where 1826 where
1826 DmaIn: crate::cryp::DmaIn<T>, 1827 DmaIn: crate::cryp::DmaIn<T>,
@@ -1836,7 +1837,8 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1836 let num_words = blocks.len(); 1837 let num_words = blocks.len();
1837 let src_ptr = ptr::slice_from_raw_parts(blocks.as_ptr().cast(), num_words); 1838 let src_ptr = ptr::slice_from_raw_parts(blocks.as_ptr().cast(), num_words);
1838 let options = TransferOptions { 1839 let options = TransferOptions {
1839 priority: Priority::High, 1840 #[cfg(not(gpdma))]
1841 priority: crate::dma::Priority::High,
1840 ..Default::default() 1842 ..Default::default()
1841 }; 1843 };
1842 let dma_transfer = unsafe { Transfer::new_write_raw(dma, dma_request, src_ptr, dst_ptr, options) }; 1844 let dma_transfer = unsafe { Transfer::new_write_raw(dma, dma_request, src_ptr, dst_ptr, options) };
@@ -1875,7 +1877,8 @@ impl<'d, T: Instance, DmaIn, DmaOut> Cryp<'d, T, DmaIn, DmaOut> {
1875 let num_words = blocks.len() / 4; 1877 let num_words = blocks.len() / 4;
1876 let dst_ptr = ptr::slice_from_raw_parts_mut(blocks.as_mut_ptr().cast(), num_words); 1878 let dst_ptr = ptr::slice_from_raw_parts_mut(blocks.as_mut_ptr().cast(), num_words);
1877 let options = TransferOptions { 1879 let options = TransferOptions {
1878 priority: Priority::VeryHigh, 1880 #[cfg(not(gpdma))]
1881 priority: crate::dma::Priority::VeryHigh,
1879 ..Default::default() 1882 ..Default::default()
1880 }; 1883 };
1881 let dma_transfer = unsafe { Transfer::new_read_raw(dma, dma_request, src_ptr, dst_ptr, options) }; 1884 let dma_transfer = unsafe { Transfer::new_read_raw(dma, dma_request, src_ptr, dst_ptr, options) };