Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions ascon-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use core::marker::PhantomData;
use ascon::State;
pub use digest::{self, Digest, ExtendableOutput, Reset, Update, XofReader};
use digest::{
HashMarker, Output, OutputSizeUser,
CollisionResistance, HashMarker, Output, OutputSizeUser,
block_api::{
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, Eager, ExtendableOutputCore,
FixedOutputCore, UpdateCore, XofReaderCore,
},
consts::{U8, U32, U40},
consts::{U8, U16, U32, U40},
crypto_common::hazmat::{DeserializeStateError, SerializableState, SerializedState},
};

Expand Down Expand Up @@ -294,3 +294,8 @@ digest::buffer_xof!(
pub struct AsconXof128Reader(AsconXofReaderCore);
impl: XofReaderTraits;
);

impl CollisionResistance for AsconXof128 {
// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-232.ipd.pdf#table.caption.25
type CollisionResistance = U16;
}
9 changes: 7 additions & 2 deletions k12/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ pub mod block_api;

use core::fmt;
use digest::{
ExtendableOutput, HashMarker, Reset, Update, XofReader,
CollisionResistance, ExtendableOutput, HashMarker, Reset, Update, XofReader,
block_api::{AlgorithmName, BlockSizeUser, ExtendableOutputCore, UpdateCore, XofReaderCore},
block_buffer::{BlockBuffer, Eager, ReadBuffer},
consts::{U128, U168},
consts::{U16, U128, U168},
};

/// `KangarooTwelve` hasher.
Expand Down Expand Up @@ -82,6 +82,11 @@ impl ExtendableOutput for KangarooTwelve<'_> {
}
}

impl CollisionResistance for KangarooTwelve<'_> {
// https://www.ietf.org/archive/id/draft-irtf-cfrg-kangarootwelve-17.html#section-7-7
type CollisionResistance = U16;
}

#[cfg(feature = "zeroize")]
impl digest::zeroize::ZeroizeOnDrop for KangarooTwelve<'_> {}

Expand Down
14 changes: 12 additions & 2 deletions sha3/src/cshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use crate::{
};
use core::fmt;
use digest::{
CustomizedInit, HashMarker, Reset,
CollisionResistance, CustomizedInit, HashMarker, Reset,
block_api::{
AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, Eager, ExtendableOutputCore,
UpdateCore,
},
consts::{U136, U168, U400},
consts::{U16, U32, U136, U168, U400},
crypto_common::hazmat::{DeserializeStateError, SerializableState, SerializedState},
typenum::Unsigned,
};
Expand Down Expand Up @@ -212,3 +212,13 @@ macro_rules! impl_cshake {

impl_cshake!(CShake128Core, CShake128, CShake128Reader, U168, "cSHAKE128");
impl_cshake!(CShake256Core, CShake256, CShake256Reader, U136, "cSHAKE256");

impl CollisionResistance for CShake128 {
// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf#[{"num":68,"gen":0},{"name":"XYZ"},108,440,null]
type CollisionResistance = U16;
}

impl CollisionResistance for CShake256 {
// https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf#[{"num":68,"gen":0},{"name":"XYZ"},108,440,null]
type CollisionResistance = U32;
}
14 changes: 12 additions & 2 deletions sha3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![forbid(unsafe_code)]
#![warn(missing_docs, missing_debug_implementations)]

pub use digest::{self, CustomizedInit, Digest};
pub use digest::{self, CollisionResistance, CustomizedInit, Digest};

/// Block-level types
pub mod block_api;
Expand All @@ -19,7 +19,7 @@ pub use cshake::{CShake128, CShake128Reader, CShake256, CShake256Reader};
pub use turbo_shake::{TurboShake128, TurboShake128Reader, TurboShake256, TurboShake256Reader};

use block_api::{Sha3HasherCore, Sha3ReaderCore};
use digest::consts::{U0, U28, U32, U48, U64, U72, U104, U136, U144, U168, U200};
use digest::consts::{U0, U16, U28, U32, U48, U64, U72, U104, U136, U144, U168, U200};

// Paddings
const KECCAK_PAD: u8 = 0x01;
Expand Down Expand Up @@ -98,3 +98,13 @@ digest::buffer_fixed!(
pub struct Keccak512(Sha3HasherCore<U72, U64, KECCAK_PAD>);
impl: FixedHashTraits;
);

impl CollisionResistance for Shake128 {
// https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf#page=31
type CollisionResistance = U16;
}

impl CollisionResistance for Shake256 {
// https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf#page=31
type CollisionResistance = U32;
}
14 changes: 12 additions & 2 deletions sha3/src/turbo_shake.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use crate::{Sha3HasherCore, Sha3ReaderCore};
use core::fmt;
use digest::{
ExtendableOutput, ExtendableOutputReset, HashMarker, Update, XofReader,
CollisionResistance, ExtendableOutput, ExtendableOutputReset, HashMarker, Update, XofReader,
block_api::{
AlgorithmName, BlockSizeUser, ExtendableOutputCore, Reset, UpdateCore, XofReaderCore,
},
block_buffer::{EagerBuffer, ReadBuffer},
consts::{U0, U136, U168},
consts::{U0, U16, U32, U136, U168},
};

const TURBO_SHAKE_ROUND_COUNT: usize = 12;
Expand Down Expand Up @@ -121,3 +121,13 @@ macro_rules! impl_turbo_shake {

impl_turbo_shake!(TurboShake128, TurboShake128Reader, U168, "TurboSHAKE128");
impl_turbo_shake!(TurboShake256, TurboShake256Reader, U136, "TurboSHAKE256");

impl<const DS: u8> CollisionResistance for TurboShake128<DS> {
// https://www.ietf.org/archive/id/draft-irtf-cfrg-kangarootwelve-17.html#section-7-7
type CollisionResistance = U16;
}

impl<const DS: u8> CollisionResistance for TurboShake256<DS> {
// https://www.ietf.org/archive/id/draft-irtf-cfrg-kangarootwelve-17.html#section-7-8
type CollisionResistance = U32;
}
Loading