aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/cryp
diff options
context:
space:
mode:
authorCaleb Garrett <[email protected]>2024-02-20 14:27:37 -0500
committerCaleb Garrett <[email protected]>2024-02-25 20:59:07 -0500
commit1e21b758f795b5cc8a2331aacbc2a9a39bb7a7fb (patch)
treee42f9be317fd935ea5e97558e2bdf8fcd7c73f68 /embassy-stm32/src/cryp
parent690b2118c6fdad88bf1e595b6a0c0afdb0583d28 (diff)
Corrected GCM tag generation.
Diffstat (limited to 'embassy-stm32/src/cryp')
-rw-r--r--embassy-stm32/src/cryp/mod.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/embassy-stm32/src/cryp/mod.rs b/embassy-stm32/src/cryp/mod.rs
index fe248def1..81446e39e 100644
--- a/embassy-stm32/src/cryp/mod.rs
+++ b/embassy-stm32/src/cryp/mod.rs
@@ -45,7 +45,7 @@ pub trait Cipher<'c> {
45 &self, 45 &self,
46 _p: &pac::cryp::Cryp, 46 _p: &pac::cryp::Cryp,
47 _dir: Direction, 47 _dir: Direction,
48 _int_data: &[u8; AES_BLOCK_SIZE], 48 _int_data: &mut [u8; AES_BLOCK_SIZE],
49 _temp1: [u32; 4], 49 _temp1: [u32; 4],
50 _padding_mask: [u8; 16], 50 _padding_mask: [u8; 16],
51 ) { 51 ) {
@@ -236,16 +236,18 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGcm<'c, KEY_SIZE> {
236 &self, 236 &self,
237 p: &pac::cryp::Cryp, 237 p: &pac::cryp::Cryp,
238 dir: Direction, 238 dir: Direction,
239 int_data: &[u8; AES_BLOCK_SIZE], 239 int_data: &mut [u8; AES_BLOCK_SIZE],
240 _temp1: [u32; 4], 240 _temp1: [u32; 4],
241 _padding_mask: [u8; 16], 241 padding_mask: [u8; AES_BLOCK_SIZE],
242 ) { 242 ) {
243 if dir == Direction::Encrypt { 243 if dir == Direction::Encrypt {
244 //Handle special GCM partial block process. 244 //Handle special GCM partial block process.
245 p.cr().modify(|w| w.set_crypen(false)); 245 p.cr().modify(|w| w.set_crypen(false));
246 p.cr().write(|w| w.set_algomode3(true)); 246 p.cr().modify(|w| w.set_algomode3(true));
247 p.cr().write(|w| w.set_algomode0(0)); 247 p.cr().modify(|w| w.set_algomode0(0));
248 p.init(1).ivrr().write_value(2); 248 for i in 0..AES_BLOCK_SIZE {
249 int_data[i] = int_data[i] & padding_mask[i];
250 }
249 p.cr().modify(|w| w.set_crypen(true)); 251 p.cr().modify(|w| w.set_crypen(true));
250 p.cr().modify(|w| w.set_gcm_ccmph(3)); 252 p.cr().modify(|w| w.set_gcm_ccmph(3));
251 let mut index = 0; 253 let mut index = 0;
@@ -323,7 +325,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesGmac<'c, KEY_SIZE> {
323 &self, 325 &self,
324 p: &pac::cryp::Cryp, 326 p: &pac::cryp::Cryp,
325 dir: Direction, 327 dir: Direction,
326 int_data: &[u8; AES_BLOCK_SIZE], 328 int_data: &mut [u8; AES_BLOCK_SIZE],
327 _temp1: [u32; 4], 329 _temp1: [u32; 4],
328 _padding_mask: [u8; 16], 330 _padding_mask: [u8; 16],
329 ) { 331 ) {
@@ -493,7 +495,7 @@ impl<'c, const KEY_SIZE: usize> Cipher<'c> for AesCcm<'c, KEY_SIZE> {
493 &self, 495 &self,
494 p: &pac::cryp::Cryp, 496 p: &pac::cryp::Cryp,
495 dir: Direction, 497 dir: Direction,
496 int_data: &[u8; AES_BLOCK_SIZE], 498 int_data: &mut [u8; AES_BLOCK_SIZE],
497 temp1: [u32; 4], 499 temp1: [u32; 4],
498 padding_mask: [u8; 16], 500 padding_mask: [u8; 16],
499 ) { 501 ) {
@@ -872,7 +874,7 @@ impl<'d, T: Instance> Cryp<'d, T> {
872 let mut mask: [u8; 16] = [0; 16]; 874 let mut mask: [u8; 16] = [0; 16];
873 mask[..last_block_remainder].fill(0xFF); 875 mask[..last_block_remainder].fill(0xFF);
874 ctx.cipher 876 ctx.cipher
875 .post_final_block(&T::regs(), ctx.dir, &intermediate_data, temp1, mask); 877 .post_final_block(&T::regs(), ctx.dir, &mut intermediate_data, temp1, mask);
876 } 878 }
877 879
878 ctx.payload_len += input.len() as u64; 880 ctx.payload_len += input.len() as u64;