Skip to content

Commit

Permalink
Remove unnecessary constants for ESP32
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed Nov 30, 2023
1 parent 9be77d8 commit 069e16d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions esp-hal-common/src/aes/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use crate::{
system::{Peripheral as PeripheralEnable, PeripheralClockControl},
};

const KEY_LEN: usize = 8;
const TEXT_LEN: usize = 4;

impl<'d> Aes<'d> {
pub(super) fn init(&mut self) {
PeripheralClockControl::enable(PeripheralEnable::Aes);
Expand All @@ -20,14 +17,16 @@ impl<'d> Aes<'d> {
}

pub(super) fn write_key(&mut self, key: &[u8]) {
debug_assert!(key.len() <= KEY_LEN * ALIGN_SIZE);
let key_len = self.aes.key_iter().count();
debug_assert!(key.len() <= key_len * ALIGN_SIZE);
debug_assert_eq!(key.len() % ALIGN_SIZE, 0);
Self::write_to_regset(key, KEY_LEN, self.aes.key(0).as_ptr());
Self::write_to_regset(key, key_len, self.aes.key(0).as_ptr());
}

pub(super) fn write_block(&mut self, block: &[u8]) {
debug_assert_eq!(block.len(), TEXT_LEN * ALIGN_SIZE);
Self::write_to_regset(block, TEXT_LEN, self.aes.text(0).as_ptr());
let text_len = self.aes.text_iter().count();
debug_assert_eq!(block.len(), text_len * ALIGN_SIZE);
Self::write_to_regset(block, text_len, self.aes.text(0).as_ptr());
}

pub(super) fn write_mode(&mut self, mode: u32) {
Expand Down Expand Up @@ -63,8 +62,9 @@ impl<'d> Aes<'d> {
}

pub(super) fn read_block(&self, block: &mut [u8]) {
debug_assert_eq!(block.len(), TEXT_LEN * ALIGN_SIZE);
Self::read_from_regset(block, TEXT_LEN, &self.aes.text(0));
let text_len = self.aes.text_iter().count();
debug_assert_eq!(block.len(), text_len * ALIGN_SIZE);
Self::read_from_regset(block, text_len, &self.aes.text(0));
}
}

Expand Down

0 comments on commit 069e16d

Please sign in to comment.