Skip to content

Commit

Permalink
Use Key enum for DMA mode
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
playfulFence committed Apr 16, 2024
1 parent 1472b0d commit 7f69deb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions esp-hal/src/aes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
//! hw_encrypted,
//! Mode::Encryption128,
//! CipherMode::Ecb,
//! &keybuf,
//! keybuf.into(),
//! )
//! .unwrap();
//! transfer.wait().unwrap();
Expand Down Expand Up @@ -307,7 +307,7 @@ pub mod dma {
use embedded_dma::{ReadBuffer, WriteBuffer};

use crate::{
aes::Mode,
aes::{Key, Mode},
dma::{
AesPeripheral,
Channel,
Expand Down Expand Up @@ -441,10 +441,10 @@ pub mod dma {
{
/// Writes the encryption key to the AES hardware, checking that its
/// length matches expected constraints.
pub fn write_key(&mut self, key: &[u8]) {
debug_assert!(key.len() <= 8 * ALIGN_SIZE);
debug_assert_eq!(key.len() % ALIGN_SIZE, 0);
self.aes.write_key(key);
pub fn write_key(&mut self, key: Key) {
debug_assert!(key.as_slice().len() <= 8 * ALIGN_SIZE);
debug_assert_eq!(key.as_slice().len() % ALIGN_SIZE, 0);
self.aes.write_key(key.as_slice());
}

/// Writes a block of data to the AES hardware, ensuring the block's
Expand All @@ -465,7 +465,7 @@ pub mod dma {
read_buffer: &'t mut RXBUF,
mode: Mode,
cipher_mode: CipherMode,
key: &[u8],
key: Key,
) -> Result<AesDmaTransferRxTx<'t, 'd, C>, crate::dma::DmaError>
where
TXBUF: ReadBuffer<Word = u8>,
Expand Down Expand Up @@ -496,7 +496,7 @@ pub mod dma {
read_buffer_len: usize,
mode: Mode,
cipher_mode: CipherMode,
key: &[u8],
key: Key,
) -> Result<(), crate::dma::DmaError> {
// AES has to be restarted after each calculation
self.reset_aes();
Expand Down
4 changes: 2 additions & 2 deletions examples/src/bin/aes_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn main() -> ! {
&mut output,
Mode::Encryption128,
CipherMode::Ecb,
&keytext,
keytext.into(),
)
.unwrap();
transfer.wait().unwrap();
Expand All @@ -72,7 +72,7 @@ fn main() -> ! {
&mut output,
Mode::Decryption128,
CipherMode::Ecb,
&keytext,
keytext.into(),
)
.unwrap();
transfer.wait().unwrap();
Expand Down
8 changes: 4 additions & 4 deletions hil-test/tests/aes_dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod tests {
&mut output,
Mode::Encryption128,
CipherMode::Ecb,
&keybuf,
keybuf.into(),
)
.unwrap();
transfer.wait().unwrap();
Expand Down Expand Up @@ -111,7 +111,7 @@ mod tests {
&mut output,
Mode::Decryption128,
CipherMode::Ecb,
&keybuf,
keybuf.into(),
)
.unwrap();
transfer.wait().unwrap();
Expand Down Expand Up @@ -157,7 +157,7 @@ mod tests {
&mut output,
Mode::Encryption256,
CipherMode::Ecb,
&keybuf,
keybuf.into(),
)
.unwrap();
transfer.wait().unwrap();
Expand Down Expand Up @@ -202,7 +202,7 @@ mod tests {
&mut output,
Mode::Decryption256,
CipherMode::Ecb,
&keybuf,
keybuf.into(),
)
.unwrap();
transfer.wait().unwrap();
Expand Down

0 comments on commit 7f69deb

Please sign in to comment.