feat: try aes and find out the HW does not offer it
This commit is contained in:
parent
058f01fd13
commit
6fb993300e
1 changed files with 46 additions and 0 deletions
46
examples/aes_ecb.rs
Executable file
46
examples/aes_ecb.rs
Executable file
|
@ -0,0 +1,46 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use defmt::{debug, info};
|
||||
use hal::pwr::PWR;
|
||||
use hal::rtc::{Datelike, NaiveDateTime, Rtc, Timelike};
|
||||
use panic_probe as _;
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use hal::{pac, prelude::*, rcc::Config};
|
||||
|
||||
const AES_PT: [u8; 16] = [
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
|
||||
];
|
||||
const AES_KEY: [u32; 4] = [0x1991, 0x1991, 0xAAAAAAAA, 0xBBBBBBBB];
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let dp = pac::Peripherals::take().unwrap();
|
||||
let cp = cortex_m::Peripherals::take().unwrap();
|
||||
|
||||
let mut rcc = dp.RCC.freeze(Config::hsi16());
|
||||
let mut delay = cp.SYST.delay(rcc.clocks);
|
||||
|
||||
compile_error!("The chip does not have an AES unit >:{");
|
||||
let aes = hal::aes::AES::new(dp.AES, &mut rcc);
|
||||
let mut ecb_stream = aes.enable(<dyn hal::aes::Mode>::ecb_encrypt(), AES_KEY);
|
||||
let mut encbuf: [[u8; 16]; 4] = [[0; 16]; 4];
|
||||
|
||||
let mut i = 0;
|
||||
debug!("Entering Loop");
|
||||
#[allow(clippy::never_loop)]
|
||||
loop {
|
||||
debug!("reading from aes stream");
|
||||
encbuf[i % 4] = ecb_stream.process(&AES_PT).unwrap();
|
||||
|
||||
info!("encbuf[{:02}]: {:02x}", i, encbuf);
|
||||
|
||||
if i > 100 {
|
||||
delay.delay_ms(200_u16);
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue