@@ -13,13 +13,12 @@ use ascon::State;
1313pub use digest:: { self , Digest , ExtendableOutput , Reset , Update , XofReader } ;
1414use digest:: {
1515 HashMarker , Output , OutputSizeUser ,
16- block_buffer:: Eager ,
17- consts:: { U8 , U32 } ,
18- core_api:: {
19- AlgorithmName , Block , Buffer , BufferKindUser , CoreWrapper , ExtendableOutputCore ,
20- FixedOutputCore , UpdateCore , XofReaderCore , XofReaderCoreWrapper ,
16+ block_api:: {
17+ AlgorithmName , Block , BlockSizeUser , Buffer , BufferKindUser , Eager , ExtendableOutputCore ,
18+ FixedOutputCore , UpdateCore , XofReaderCore ,
2119 } ,
22- crypto_common:: BlockSizeUser ,
20+ consts:: { U8 , U32 , U40 } ,
21+ crypto_common:: hazmat:: { DeserializeStateError , SerializableState , SerializedState } ,
2322} ;
2423
2524/// Produce mask for padding.
@@ -176,6 +175,26 @@ impl AlgorithmName for AsconCore {
176175 }
177176}
178177
178+ impl SerializableState for AsconCore {
179+ type SerializedStateSize = U40 ;
180+
181+ fn serialize ( & self ) -> SerializedState < Self > {
182+ self . state . state . as_bytes ( ) . into ( )
183+ }
184+
185+ fn deserialize (
186+ serialized_state : & SerializedState < Self > ,
187+ ) -> Result < Self , DeserializeStateError > {
188+ let state = ascon:: State :: from ( & serialized_state. 0 ) ;
189+ Ok ( Self {
190+ state : HashCore {
191+ state,
192+ phantom : PhantomData ,
193+ } ,
194+ } )
195+ }
196+ }
197+
179198/// Ascon XOF
180199#[ derive( Clone , Debug , Default ) ]
181200pub struct AsconXofCore {
@@ -241,29 +260,37 @@ impl AlgorithmName for AsconXofCore {
241260 }
242261}
243262
244- /// Ascon-Hash256
245- ///
246- /// ```
247- /// use ascon_hash::{AsconHash256, Digest};
248- ///
249- /// let mut hasher = AsconHash256::new();
250- /// hasher.update(b"some bytes");
251- /// let digest = hasher.finalize();
252- /// assert_eq!(&digest[..], b"\xe9\x09\xc2\xf6\xda\x9c\xb3\x02\x84\x23\x26\x5c\x8f\x23\xfc\x2d\x26\xbf\xc0\xf3\xdb\x70\x46\x83\xef\x16\xb7\x87\xa9\x45\xed\x68");
253- /// ```
254- pub type AsconHash256 = CoreWrapper < AsconCore > ;
255- /// Ascon-XOF128
256- ///
257- /// ```
258- /// use ascon_hash::{AsconXof128, ExtendableOutput, Update, XofReader};
259- ///
260- /// let mut xof = AsconXof128::default();
261- /// xof.update(b"some bytes");
262- /// let mut reader = xof.finalize_xof();
263- /// let mut dst = [0u8; 5];
264- /// reader.read(&mut dst);
265- /// assert_eq!(&dst, b"\x8c\x7d\xd1\x14\xa0");
266- /// ```
267- pub type AsconXof128 = CoreWrapper < AsconXofCore > ;
268- /// Reader for AsconXOF output
269- pub type AsconXof128Reader = XofReaderCoreWrapper < AsconXofReaderCore > ;
263+ impl SerializableState for AsconXofCore {
264+ type SerializedStateSize = U40 ;
265+
266+ fn serialize ( & self ) -> SerializedState < Self > {
267+ self . state . state . as_bytes ( ) . into ( )
268+ }
269+
270+ fn deserialize (
271+ serialized_state : & SerializedState < Self > ,
272+ ) -> Result < Self , DeserializeStateError > {
273+ let state = ascon:: State :: from ( & serialized_state. 0 ) ;
274+ Ok ( Self {
275+ state : HashCore {
276+ state,
277+ phantom : PhantomData ,
278+ } ,
279+ } )
280+ }
281+ }
282+
283+ digest:: buffer_fixed!(
284+ /// Ascon-Hash256
285+ pub struct AsconHash256 ( AsconCore ) ;
286+ impl : FixedHashTraits ;
287+ ) ;
288+
289+ digest:: buffer_xof!(
290+ /// Ascon-XOF128 hasher.
291+ pub struct AsconXof128 ( AsconXofCore ) ;
292+ impl : XofHasherTraits ;
293+ /// Ascon-XOF128 reader.
294+ pub struct AsconXof128Reader ( AsconXofReaderCore ) ;
295+ impl : XofReaderTraits ;
296+ ) ;
0 commit comments