Skip to content

Commit eac04cb

Browse files
fixed problems after unsafe
1 parent e7f8553 commit eac04cb

4 files changed

Lines changed: 22 additions & 32 deletions

File tree

boards/nucleo_u545re_q/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ unsafe fn start() -> (
264264
AES256
265265
));
266266

267-
aes.set_client(aes_driver);
267+
AES::set_client(aes, aes_driver);
268268

269269
// Platform and Interrupts
270270
let platform = static_init!(

capsules/extra/src/test/aes256.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ impl<'a, A: AES<'a, AES256> + AESCtr> TestAES256Ctr<'a, A> {
291291
let step = self.step.get();
292292
let encrypting = is_encrypting(step);
293293
let in_place = is_in_place(step);
294-
debug!("aes_test CTR step: {:?}", step);
295294

296295
if !is_second_chunk(step) {
297296
self.aes.enable();

chips/stm32u5xx-unsafe/src/aes.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ use kernel::utilities::registers::{
1414
use kernel::utilities::StaticRef;
1515

1616
pub const AES_BASE: StaticRef<AesRegisters> =
17-
/// ### Safety
18-
///
19-
/// The address 0x520C0000 is the dedicated memory-mapped region for the AES
20-
/// peripheral on the STM32U5 series, as specified in the reference manual.
2117
unsafe { StaticRef::new(0x520C0000 as *const AesRegisters) };
2218

2319
register_structs! {
@@ -239,7 +235,26 @@ impl DMABuffers {
239235
let ptr = dma_slice.as_mut_ptr() as u32;
240236
(dma_slice, ptr)
241237
}
242-
}
243-
r)
238+
239+
/// Helper function designed to calculate the length of the buffer as a multiple of AES_BLOCK_SIZE
240+
/// and return the remaining bytes inside a 0-padded buffer. If the length of the buffer, beginning
241+
/// from start is a multiple of AES_BLOCK_SIZE, will return total_len and None
242+
pub fn extract_dma_padding(
243+
buf: &[u8],
244+
start: usize,
245+
total_len: usize,
246+
) -> (usize, Option<[u8; AES_BLOCK_SIZE]>) {
247+
// check whether the buffer needs 0-padding
248+
if total_len > 0 && !total_len.is_multiple_of(AES_BLOCK_SIZE) {
249+
// length multiple of AES_BLOCK_SIZE
250+
let len = total_len - (total_len % AES_BLOCK_SIZE);
251+
// remainder of the buffer, padded with 0s
252+
let mut pad = [0u8; AES_BLOCK_SIZE];
253+
let rem = total_len - len;
254+
pad[..rem].copy_from_slice(&buf[start + len..start + total_len]);
255+
(len, Some(pad))
256+
} else {
257+
(total_len, None)
258+
}
244259
}
245260
}

chips/stm32u5xx/src/aes/mod.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,6 @@ pub struct Aes<'a, K: AESKeySize> {
8585
pub(crate) _phantom: PhantomData<K>,
8686
}
8787

88-
impl DMABuffers {
89-
/// Helper function designed to calculate the length of the buffer as a multiple of AES_BLOCK_SIZE
90-
/// and return the remaining bytes inside a 0-padded buffer. If the length of the buffer, beginning
91-
/// from start is a multiple of AES_BLOCK_SIZE, will return total_len and None
92-
pub fn extract_dma_padding(
93-
buf: &[u8],
94-
start: usize,
95-
total_len: usize,
96-
) -> (usize, Option<[u8; AES_BLOCK_SIZE]>) {
97-
// check whether the buffer needs 0-padding
98-
if total_len > 0 && !total_len.is_multiple_of(AES_BLOCK_SIZE) {
99-
// length multiple of AES_BLOCK_SIZE
100-
let len = total_len - (total_len % AES_BLOCK_SIZE);
101-
// remainder of the buffer, padded with 0s
102-
let mut pad = [0u8; AES_BLOCK_SIZE];
103-
let rem = total_len - len;
104-
pad[..rem].copy_from_slice(&buf[start + len..start + total_len]);
105-
(len, Some(pad))
106-
} else {
107-
(total_len, None)
108-
}
109-
}
110-
}
111-
11288
impl<'a, K: AESKeySize> Aes<'a, K> {
11389
// default mode: ECB , encrypting
11490
pub const fn new(base: AesRegistersManager) -> Aes<'a, K> {

0 commit comments

Comments
 (0)