@@ -5,7 +5,7 @@ use crate::{
55use core:: fmt;
66use digest:: {
77 CustomizedInit , HashMarker , Reset ,
8- consts:: { U136 , U168 } ,
8+ consts:: { U136 , U168 , U400 } ,
99 core_api:: {
1010 AlgorithmName , Block , BlockSizeUser , Buffer , BufferKindUser , Eager , ExtendableOutputCore ,
1111 UpdateCore ,
@@ -151,36 +151,50 @@ macro_rules! impl_cshake {
151151 impl digest:: zeroize:: ZeroizeOnDrop for $name { }
152152
153153 impl SerializableState for $name {
154- // TODO: implement properly with U400
155- type SerializedStateSize = digest:: consts:: U0 ;
154+ type SerializedStateSize = U400 ;
156155
157156 fn serialize( & self ) -> SerializedState <Self > {
158- todo!( )
157+ let mut serialized_state = SerializedState :: <Self >:: default ( ) ;
158+ let mut chunks = serialized_state. chunks_exact_mut( 8 ) ;
159+
160+ for ( val, chunk) in self . state. iter( ) . zip( & mut chunks) {
161+ chunk. copy_from_slice( & val. to_le_bytes( ) ) ;
162+ }
163+ for ( val, chunk) in self . initial_state. iter( ) . zip( & mut chunks) {
164+ chunk. copy_from_slice( & val. to_le_bytes( ) ) ;
165+ }
166+
167+ serialized_state
159168 }
160169
161170 fn deserialize(
162- _serialized_state : & SerializedState <Self >,
171+ serialized_state : & SerializedState <Self >,
163172 ) -> Result <Self , DeserializeStateError > {
164- todo!( )
173+ let ( state_src, initial_state_src) = serialized_state. split_at( 200 ) ;
174+ let state = core:: array:: from_fn( |i| {
175+ let chunk = state_src[ 8 * i..] [ ..8 ] . try_into( ) . unwrap( ) ;
176+ u64 :: from_le_bytes( chunk)
177+ } ) ;
178+ let initial_state = core:: array:: from_fn( |i| {
179+ let chunk = initial_state_src[ 8 * i..] [ ..8 ] . try_into( ) . unwrap( ) ;
180+ u64 :: from_le_bytes( chunk)
181+ } ) ;
182+ Ok ( Self { state, initial_state } )
165183 }
166184 }
167185
168186 digest:: newtype_xof_hash!(
169187 #[ doc = $alg_name]
170188 #[ doc = " hasher." ]
171189 pub struct $full_name( $name) ;
190+ // TODO: Use `XofHasherTraits CustomizedInit` after serialization for buffers is fixed
191+ impl : Debug AlgorithmName Clone Default BlockSizeUser CoreProxy HashMarker Update Reset ExtendableOutputReset CustomizedInit ;
172192 #[ doc = $alg_name]
173193 #[ doc = " XOF reader." ]
174194 pub struct $reader_name( Sha3ReaderCore <$rate>) ;
195+ impl : XofReaderTraits ;
175196 ) ;
176197
177- impl CustomizedInit for $full_name {
178- #[ inline]
179- fn new_customized( customization: & [ u8 ] ) -> Self {
180- Self :: new_with_function_name( & [ ] , customization)
181- }
182- }
183-
184198 impl $full_name {
185199 /// Creates a new cSHAKE instance with the given function name and customization.
186200 ///
0 commit comments