diff options
| author | Caleb Garrett <[email protected]> | 2024-02-23 16:05:18 -0500 |
|---|---|---|
| committer | Caleb Garrett <[email protected]> | 2024-02-25 20:59:07 -0500 |
| commit | 967b4927b002dbcdcfbe968bf9c15014fc1de2a0 (patch) | |
| tree | 9bec3b3a10c99085bec4166a26191e4f92ad9209 | |
| parent | bf4cbd75779b230e9e33a9d2a849f67335a68cf9 (diff) | |
Correct tag generation.
| -rw-r--r-- | embassy-stm32/src/cryp/mod.rs | 8 | ||||
| -rw-r--r-- | examples/stm32f7/src/bin/cryp.rs | 9 |
2 files changed, 10 insertions, 7 deletions
diff --git a/embassy-stm32/src/cryp/mod.rs b/embassy-stm32/src/cryp/mod.rs index 965e4a35d..038923870 100644 --- a/embassy-stm32/src/cryp/mod.rs +++ b/embassy-stm32/src/cryp/mod.rs | |||
| @@ -1166,10 +1166,10 @@ impl<'d, T: Instance> Cryp<'d, T> { | |||
| 1166 | T::regs().cr().modify(|w| w.set_gcm_ccmph(3)); | 1166 | T::regs().cr().modify(|w| w.set_gcm_ccmph(3)); |
| 1167 | T::regs().cr().modify(|w| w.set_crypen(true)); | 1167 | T::regs().cr().modify(|w| w.set_crypen(true)); |
| 1168 | 1168 | ||
| 1169 | let headerlen1: u32 = (ctx.header_len >> 32) as u32; | 1169 | let headerlen1: u32 = ((ctx.header_len * 8) >> 32) as u32; |
| 1170 | let headerlen2: u32 = ctx.header_len as u32; | 1170 | let headerlen2: u32 = (ctx.header_len * 8) as u32; |
| 1171 | let payloadlen1: u32 = (ctx.payload_len >> 32) as u32; | 1171 | let payloadlen1: u32 = ((ctx.payload_len * 8) >> 32) as u32; |
| 1172 | let payloadlen2: u32 = ctx.payload_len as u32; | 1172 | let payloadlen2: u32 = (ctx.payload_len * 8) as u32; |
| 1173 | 1173 | ||
| 1174 | T::regs().din().write_value(headerlen1.swap_bytes()); | 1174 | T::regs().din().write_value(headerlen1.swap_bytes()); |
| 1175 | T::regs().din().write_value(headerlen2.swap_bytes()); | 1175 | T::regs().din().write_value(headerlen2.swap_bytes()); |
diff --git a/examples/stm32f7/src/bin/cryp.rs b/examples/stm32f7/src/bin/cryp.rs index c1b80ddc3..be41955c5 100644 --- a/examples/stm32f7/src/bin/cryp.rs +++ b/examples/stm32f7/src/bin/cryp.rs | |||
| @@ -51,13 +51,16 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 51 | 51 | ||
| 52 | let sw_start_time = Instant::now(); | 52 | let sw_start_time = Instant::now(); |
| 53 | 53 | ||
| 54 | //Encrypt in software using AES-GCM 128-bit | 54 | // Encrypt in software using AES-GCM 128-bit |
| 55 | let mut payload_vec: Vec<u8, 32> = Vec::from_slice(&payload).unwrap(); | 55 | let mut payload_vec: Vec<u8, 32> = Vec::from_slice(&payload).unwrap(); |
| 56 | let cipher = Aes128Gcm::new(&key.into()); | 56 | let cipher = Aes128Gcm::new(&key.into()); |
| 57 | let _ = cipher.encrypt_in_place(&iv.into(), aad.into(), &mut payload_vec); | 57 | let _ = cipher.encrypt_in_place(&iv.into(), aad.into(), &mut payload_vec); |
| 58 | |||
| 59 | assert_eq!(ciphertext, payload_vec[0..ciphertext.len()]); | ||
| 60 | assert_eq!(encrypt_tag, payload_vec[ciphertext.len()..ciphertext.len() + encrypt_tag.len()]); | ||
| 58 | 61 | ||
| 59 | //Decrypt in software using AES-GCM 128-bit | 62 | // Decrypt in software using AES-GCM 128-bit |
| 60 | let _ = cipher.encrypt_in_place(&iv.into(), aad.into(), &mut payload_vec); | 63 | let _ = cipher.decrypt_in_place(&iv.into(), aad.into(), &mut payload_vec); |
| 61 | 64 | ||
| 62 | let sw_end_time = Instant::now(); | 65 | let sw_end_time = Instant::now(); |
| 63 | let sw_execution_time = sw_end_time - sw_start_time; | 66 | let sw_execution_time = sw_end_time - sw_start_time; |
