32
32
//! ```rust, no_run
33
33
#![ doc = crate :: before_snippet!( ) ]
34
34
//! # use esp_hal::sha::Sha;
35
- //! # use esp_hal::sha::ShaMode ;
35
+ //! # use esp_hal::sha::Sha256 ;
36
36
//! # use core::option::Option::None;
37
37
//! # use nb::block;
38
38
//! let source_data = "HELLO, ESPRESSIF!".as_bytes();
39
39
//! let mut remaining = source_data;
40
- //! let mut hasher = Sha ::new(peripherals.SHA, ShaMode::SHA256 );
40
+ //! let mut hasher = Sha256 ::new(peripherals.SHA);
41
41
//! // Short hashes can be created by decreasing the output buffer to the
42
42
//! // desired length
43
43
//! let mut output = [0u8; 32];
@@ -124,7 +124,8 @@ pub trait Sha<'d, DM: crate::Mode>: core::ops::DerefMut<Target = Context<DM>> {
124
124
125
125
fn digest_length ( & self ) -> usize ;
126
126
127
- /// ESP32 requires that a control register to be written to calculate the final SHA hash.
127
+ /// ESP32 requires that a control register to be written to calculate the
128
+ /// final SHA hash.
128
129
#[ cfg( esp32) ]
129
130
fn load_reg ( & self ) ;
130
131
@@ -347,8 +348,8 @@ pub trait Sha<'d, DM: crate::Mode>: core::ops::DerefMut<Target = Context<DM>> {
347
348
}
348
349
}
349
350
350
- /// This macro implements the Sha<'a, DM> trait for a specified Sha algorithm and a set of
351
- /// parameters
351
+ /// This macro implements the Sha<'a, DM> trait for a specified Sha algorithm
352
+ /// and a set of parameters
352
353
macro_rules! impl_sha {
353
354
( $name: ident, $mode_bits: tt, $digest_length: tt, $chunk_length: tt) => {
354
355
pub struct $name<' d, DM : crate :: Mode >( PeripheralRef <' d, SHA >, Context <DM >) ;
@@ -404,7 +405,9 @@ macro_rules! impl_sha {
404
405
// ESP32 uses different registers for its operation
405
406
#[ cfg( esp32) ]
406
407
fn load_reg( & self ) {
407
- unsafe { self . 0 . sha1_load( ) . write( |w| w. bits( 1 ) ) } ;
408
+ paste:: paste! {
409
+ unsafe { self . 0. [ < $name: lower _load >] ( ) . write( |w| w. bits( 1 ) ) } ;
410
+ }
408
411
}
409
412
410
413
#[ cfg( esp32) ]
@@ -416,24 +419,27 @@ macro_rules! impl_sha {
416
419
417
420
#[ cfg( esp32) ]
418
421
fn process_buffer( & mut self ) {
419
- if self . first_run {
420
- self . 0 . sha1_start( ) . write( |w| unsafe { w. bits( 1 ) } ) ;
421
- self . first_run = false ;
422
- } else {
423
- self . 0 . sha1_continue( ) . write( |w| unsafe { w. bits( 1 ) } ) ;
422
+ paste:: paste! {
423
+ if self . first_run {
424
+ self . 0. [ < $name: lower _start >] ( ) . write( |w| unsafe { w. bits( 1 ) } ) ;
425
+ self . first_run = false ;
426
+ } else {
427
+ self . 0. [ < $name: lower _continue >] ( ) . write( |w| unsafe { w. bits( 1 ) } ) ;
428
+ }
424
429
}
425
430
}
426
431
}
427
432
428
433
/// implement digest traits if digest feature is present.
429
- /// Note: digest has a blanket trait implementation for [digest::Digest] for any element
430
- /// that implements FixedOutput + Default + Update + HashMarker
434
+ /// Note: digest has a blanket trait implementation for [digest::Digest] for any
435
+ /// element that implements FixedOutput + Default + Update + HashMarker
431
436
#[ cfg( feature = "digest" ) ]
432
437
impl <' d, DM : crate :: Mode > digest:: HashMarker for $name<' d, DM > { }
433
438
434
439
#[ cfg( feature = "digest" ) ]
435
440
impl <' a, DM : crate :: Mode > digest:: OutputSizeUser for $name<' a, DM > {
436
- // We use paste to append `U` to the digest size to match a const defined in digest
441
+ // We use paste to append `U` to the digest size to match a const defined in
442
+ // digest
437
443
paste:: paste! {
438
444
type OutputSize = digest:: consts:: [ < U $digest_length >] ;
439
445
}
0 commit comments