Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
playfulFence committed Mar 21, 2024
1 parent 48fc3d9 commit c02c9d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
13 changes: 6 additions & 7 deletions esp-hal/src/aes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,12 @@ impl<'d> Aes<'d> {

/// Encrypts/Decrypts the given buffer based on `mode` parameter
pub fn process(&mut self, block: &mut [u8; 16], mode: Mode, key: &[u8]) {
if key.len() != 16
|| (cfg!(any(feature = "esp32", feature = "esp32s2")) && key.len() != 24)
|| key.len() != 32
{
panic!("Invalid key size");
}

assert!(
key.len() == 16
|| (cfg!(any(feature = "esp32", feature = "esp32s2")) && key.len() == 24)
|| key.len() == 32,
"Invalid key size"
);
self.write_key(key);
self.set_mode(mode as u8);
self.set_block(block);
Expand Down
8 changes: 2 additions & 6 deletions examples/src/bin/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,10 @@ fn main() -> ! {
);
let sw_decrypted = block;

assert!(eq(&sw_encrypted, &hw_encrypted));
assert!(eq(&sw_decrypted, &hw_decrypted));
assert!(&sw_encrypted as &[u8] == &hw_encrypted);
assert!(&sw_decrypted as &[u8] == &hw_decrypted);

println!("done");

loop {}
}

fn eq(slice1: &[u8], slice2: &[u8]) -> bool {
slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b)
}
8 changes: 2 additions & 6 deletions examples/src/bin/aes_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,9 @@ fn main() -> ! {
);
let sw_decrypted = block.clone();

assert!(eq(&sw_encrypted, &hw_encrypted));
assert!(eq(&sw_decrypted, &hw_decrypted));
assert!(&sw_encrypted as &[u8] == &hw_encrypted);
assert!(&sw_decrypted as &[u8] == &hw_decrypted);

println!("done");
loop {}
}

fn eq(slice1: &[u8], slice2: &[u8]) -> bool {
slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b)
}

0 comments on commit c02c9d8

Please sign in to comment.