1
1
use core:: marker:: PhantomData ;
2
2
3
3
use aligned:: { A4 , Aligned } ;
4
- use block_buffer:: { byteorder :: { ByteOrder , BE } , BlockBuffer } ;
4
+ use block_buffer:: BlockBuffer ;
5
5
6
6
use crate :: {
7
7
peripherals:: hashcrypt:: Hashcrypt ,
8
8
traits:: {
9
- digest:: { BlockInput , FixedOutput , Input /*, Reset*/ } ,
9
+ digest:: { BlockInput , FixedOutputDirty , Update /*, Reset*/ } ,
10
10
digest:: generic_array:: { GenericArray , typenum:: { U20 , U32 , U64 } } ,
11
11
} ,
12
12
typestates:: init_state:: Enabled ,
@@ -78,36 +78,34 @@ impl<Size: OutputSize> BlockInput for Sha<'_, Size> {
78
78
type BlockSize = BlockSize ;
79
79
}
80
80
81
- impl < Size : OutputSize > FixedOutput for Sha < ' _ , Size > {
81
+ impl < Size : OutputSize > FixedOutputDirty for Sha < ' _ , Size > {
82
82
type OutputSize = Size ;
83
83
84
- fn fixed_result ( mut self ) -> GenericArray < u8 , Self :: OutputSize > {
84
+ fn finalize_into_dirty ( & mut self , out : & mut GenericArray < u8 , Self :: OutputSize > ) {
85
85
self . finish ( ) ;
86
86
// cf `hashcrypt_get_data` ~line 315 of `fsl_hashcrypt.c`
87
- let mut out = GenericArray :: < u8 , Self :: OutputSize > :: default ( ) ;
88
87
for i in 0 ..Size :: to_usize ( ) / 4 {
89
- BE :: write_u32_into ( & [ self . inner . raw . digest0 [ i] . read ( ) . bits ( ) ] , & mut out . as_mut_slice ( ) [ 4 * i.. 4 * i + 4 ] ) ;
88
+ out . as_mut_slice ( ) [ 4 * i.. 4 * i + 4 ] . copy_from_slice ( & self . inner . raw . digest0 [ i] . read ( ) . bits ( ) . to_be_bytes ( ) ) ;
90
89
}
91
- out
92
90
}
93
91
}
94
92
95
- impl < Size : OutputSize > Input for Sha < ' _ , Size > {
96
- fn input < B : AsRef < [ u8 ] > > ( & mut self , input : B ) {
97
- self . input ( input . as_ref ( ) ) ;
93
+ impl < Size : OutputSize > Update for Sha < ' _ , Size > {
94
+ fn update ( & mut self , data : impl AsRef < [ u8 ] > ) {
95
+ self . update ( data . as_ref ( ) ) ;
98
96
}
99
97
}
100
98
101
99
// the actual implementation
102
100
103
101
impl < Size : OutputSize > Sha < ' _ , Size > {
104
- fn input ( & mut self , input : & [ u8 ] ) {
102
+ fn update ( & mut self , data : & [ u8 ] ) {
105
103
// Assumes that input.len() can be converted to u64 without overflow
106
- self . len += ( input . len ( ) as u64 ) << 3 ;
104
+ self . len += ( data . len ( ) as u64 ) << 3 ;
107
105
// need to convince compiler we're using buffer and peripheral
108
106
// independently, and not doing a double &mut
109
107
let peripheral = & mut self . inner ;
110
- self . buffer . input ( input , |input | Self :: process_block ( peripheral, input ) ) ;
108
+ self . buffer . input_block ( data , |data | Self :: process_block ( peripheral, data ) ) ;
111
109
}
112
110
113
111
// relevant code is ~line 800 in fsl_hashcrypt.c
@@ -130,7 +128,7 @@ impl<Size: OutputSize> Sha<'_, Size> {
130
128
fn finish ( & mut self ) {
131
129
let peripheral = & mut self . inner ;
132
130
let l = self . len ;
133
- self . buffer . len64_padding :: < BE , _ > ( l, |block| Self :: process_block ( peripheral, block) ) ;
131
+ self . buffer . len64_padding_be ( l, |block| Self :: process_block ( peripheral, block) ) ;
134
132
while peripheral. raw . status . read ( ) . digest ( ) . is_not_ready ( ) {
135
133
continue ;
136
134
}
0 commit comments