mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-09-30 13:50:38 +00:00
Peripheral ref/sha (#312)
* Add SHA to list of peripherals to be created * Refactor SHA peripheral to use PeripheralRef * Update SHA examples to get them building again
This commit is contained in:
parent
7817e270c2
commit
220f812625
@ -55,6 +55,7 @@ mod peripherals {
|
||||
I2C0,
|
||||
I2C1,
|
||||
RNG,
|
||||
SHA,
|
||||
SPI0,
|
||||
SPI1,
|
||||
SPI2,
|
||||
|
@ -36,6 +36,7 @@ mod peripherals {
|
||||
crate::create_peripherals! {
|
||||
I2C0,
|
||||
RNG,
|
||||
SHA,
|
||||
SPI0,
|
||||
SPI1,
|
||||
SPI2,
|
||||
|
@ -47,6 +47,7 @@ mod peripherals {
|
||||
crate::create_peripherals! {
|
||||
I2C0,
|
||||
RNG,
|
||||
SHA,
|
||||
SPI0,
|
||||
SPI1,
|
||||
SPI2,
|
||||
|
@ -53,6 +53,7 @@ mod peripherals {
|
||||
I2C0,
|
||||
I2C1,
|
||||
RNG,
|
||||
SHA,
|
||||
SPI0,
|
||||
SPI1,
|
||||
SPI2,
|
||||
|
@ -64,6 +64,7 @@ mod peripherals {
|
||||
I2C0,
|
||||
I2C1,
|
||||
RNG,
|
||||
SHA,
|
||||
SPI0,
|
||||
SPI1,
|
||||
SPI2,
|
||||
|
@ -1,6 +1,9 @@
|
||||
use core::convert::Infallible;
|
||||
|
||||
use crate::pac::SHA;
|
||||
use crate::{
|
||||
peripheral::{Peripheral, PeripheralRef},
|
||||
peripherals::SHA,
|
||||
};
|
||||
|
||||
// All the hash algorithms introduced in FIPS PUB 180-4 Spec.
|
||||
// – SHA-1
|
||||
@ -157,9 +160,8 @@ impl AlignmentHelper {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Sha {
|
||||
sha: SHA,
|
||||
pub struct Sha<'d> {
|
||||
sha: PeripheralRef<'d, SHA>,
|
||||
mode: ShaMode,
|
||||
alignment_helper: AlignmentHelper,
|
||||
cursor: usize,
|
||||
@ -224,8 +226,10 @@ fn mode_as_bits(mode: ShaMode) -> u8 {
|
||||
|
||||
// This implementation might fail after u32::MAX/8 bytes, to increase please see
|
||||
// ::finish() length/self.cursor usage
|
||||
impl Sha {
|
||||
pub fn new(sha: SHA, mode: ShaMode) -> Self {
|
||||
impl<'d> Sha<'d> {
|
||||
pub fn new(sha: impl Peripheral<P = SHA> + 'd, mode: ShaMode) -> Self {
|
||||
crate::into_ref!(sha);
|
||||
|
||||
// Setup SHA Mode
|
||||
#[cfg(not(esp32))]
|
||||
sha.mode
|
||||
@ -508,8 +512,4 @@ impl Sha {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn free(self) -> SHA {
|
||||
self.sha
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,6 @@ fn main() -> ! {
|
||||
let hw_time = post_calc - pre_calc;
|
||||
println!("Took {} cycles", hw_time);
|
||||
println!("SHA512 Hash output {:02x?}", output);
|
||||
let _usha = hasher.free();
|
||||
|
||||
let pre_calc = xtensa_lx::timer::get_cycle_count();
|
||||
let mut hasher = Sha512::new();
|
||||
|
@ -65,7 +65,6 @@ fn main() -> ! {
|
||||
// let hw_time = post_calc - pre_calc;
|
||||
// println!("Took {} cycles", hw_time);
|
||||
println!("SHA256 Hash output {:02x?}", output);
|
||||
let _usha = hasher.free();
|
||||
|
||||
// let pre_calc = xtensa_lx::timer::get_cycle_count();
|
||||
let mut hasher = Sha256::new();
|
||||
|
@ -65,7 +65,6 @@ fn main() -> ! {
|
||||
// let hw_time = post_calc - pre_calc;
|
||||
// println!("Took {} cycles", hw_time);
|
||||
println!("SHA256 Hash output {:02x?}", output);
|
||||
let _usha = hasher.free();
|
||||
|
||||
// let pre_calc = xtensa_lx::timer::get_cycle_count();
|
||||
let mut hasher = Sha256::new();
|
||||
|
@ -65,7 +65,6 @@ fn main() -> ! {
|
||||
let hw_time = post_calc - pre_calc;
|
||||
println!("Took {} cycles", hw_time);
|
||||
println!("SHA512 Hash output {:02x?}", output);
|
||||
let _usha = hasher.free();
|
||||
|
||||
let pre_calc = xtensa_lx::timer::get_cycle_count();
|
||||
let mut hasher = Sha512::new();
|
||||
|
@ -65,7 +65,6 @@ fn main() -> ! {
|
||||
let hw_time = post_calc - pre_calc;
|
||||
println!("Took {} cycles", hw_time);
|
||||
println!("SHA512 Hash output {:02x?}", output);
|
||||
let _usha = hasher.free();
|
||||
|
||||
let pre_calc = xtensa_lx::timer::get_cycle_count();
|
||||
let mut hasher = Sha512::new();
|
||||
|
Loading…
x
Reference in New Issue
Block a user