blob: 75382fa89950a0ba26133dbabb1e456d5fc0ae38 [file] [log] [blame]
#![no_std]
use libtock::hmac::{HmacDataBuffer, HmacDestBuffer, HmacKeyBuffer};
use libtock::println;
use libtock::result::TockResult;
use libtock::syscalls;
libtock_core::stack_size! {0x800}
#[libtock::main]
async fn main() -> TockResult<()> {
let mut drivers = libtock::retrieve_drivers()?;
drivers.console.create_console();
println!("Starting HMAC example");
let hmac_driver = drivers.hmac.init_driver()?;
println!("Loading in 0 key");
let mut key_buffer = HmacKeyBuffer::default();
let _key_buffer = hmac_driver.init_key_buffer(&mut key_buffer)?;
println!(" done");
println!("Creating data buffer");
let mut data_buffer = HmacDataBuffer::default();
let data: &[u8; 72] =
b"A language empowering everyone to build reliable and efficient software.";
for (i, d) in data.iter().enumerate() {
data_buffer[i] = *d;
}
let _data_buffer = hmac_driver.init_data_buffer(&mut data_buffer)?;
println!(" done");
println!("Creating dest buffer");
let mut dest_buffer = HmacDestBuffer::default();
let dest_buffer = hmac_driver.init_dest_buffer(&mut dest_buffer)?;
println!(" done");
let mut temp_buffer = [0; libtock::hmac::DEST_BUFFER_SIZE];
println!("Setting callback and running");
let mut callback = |_result, _digest| {
println!("HMAC Complete, printing digest");
dest_buffer.read_bytes(&mut temp_buffer[..]);
for buf in temp_buffer.iter().take(libtock::hmac::DEST_BUFFER_SIZE) {
println!("{:x}", *buf);
}
};
let _subscription = hmac_driver.subscribe(&mut callback)?;
hmac_driver.run()?;
loop {
unsafe { syscalls::raw::yieldk() };
}
}