From 137cda7ed6a0ed686d503aa70e4f2d8bd5f51b0b Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Thu, 27 Feb 2025 18:49:46 -0800 Subject: [PATCH 1/2] backport PR573 --- sha3/src/lib.rs | 2 +- sha3/src/macros.rs | 12 +++++++----- sha3/tests/cshake.rs | 28 +++++++--------------------- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/sha3/src/lib.rs b/sha3/src/lib.rs index b24ba73a6..3aa9d976c 100644 --- a/sha3/src/lib.rs +++ b/sha3/src/lib.rs @@ -8,7 +8,7 @@ #![forbid(unsafe_code)] #![warn(missing_docs)] -pub use digest::{self, Digest}; +pub use digest::{self, CustomizedInit, Digest}; use core::fmt; use digest::{ diff --git a/sha3/src/macros.rs b/sha3/src/macros.rs index a91d09cab..2963a4985 100644 --- a/sha3/src/macros.rs +++ b/sha3/src/macros.rs @@ -469,11 +469,6 @@ macro_rules! impl_cshake { pub type $full_name = CoreWrapper<$name>; impl $name { - /// Creates a new CSHAKE instance with the given customization. - pub fn new(customization: &[u8]) -> Self { - Self::new_with_function_name(&[], customization) - } - /// Creates a new CSHAKE instance with the given function name and customization. /// Note that the function name is intended for use by NIST and should only be set to /// values defined by NIST. You probably don't need to use this function. @@ -642,5 +637,12 @@ macro_rules! impl_cshake { #[cfg(feature = "zeroize")] impl ZeroizeOnDrop for $reader {} + + impl CustomizedInit for $name { + #[inline] + fn new_customized(customization: &[u8]) -> Self { + Self::new_with_function_name(&[], customization) + } + } }; } diff --git a/sha3/tests/cshake.rs b/sha3/tests/cshake.rs index 0ba62e2c9..33ba2576b 100644 --- a/sha3/tests/cshake.rs +++ b/sha3/tests/cshake.rs @@ -1,5 +1,5 @@ use core::fmt::Debug; -use digest::ExtendableOutput; +use digest::{CustomizedInit,ExtendableOutput}; #[cfg(feature = "reset")] use digest::ExtendableOutputReset; @@ -88,7 +88,7 @@ where } macro_rules! new_cshake_test { - ($name:ident, $test_name:expr, $hasher:ty, $hasher_core:ty, $test_func:ident $(,)?) => { + ($name:ident, $test_name:expr, $hasher:ty, $test_func:ident $(,)?) => { #[test] fn $name() { use digest::dev::blobby::Blob3Iterator; @@ -96,9 +96,9 @@ macro_rules! new_cshake_test { for (i, row) in Blob3Iterator::new(data).unwrap().enumerate() { let [customization, input, output] = row.unwrap(); - if let Some(desc) = $test_func(input, output, || { - <$hasher>::from_core(<$hasher_core>::new(customization)) - }) { + if let Some(desc) = + $test_func(input, output, || <$hasher>::new_customized(customization)) + { panic!( "\n\ Failed test №{}: {}\n\ @@ -117,7 +117,6 @@ new_cshake_test!( cshake128_reset, "cshake128", sha3::CShake128, - sha3::CShake128Core, cshake_reset_test ); #[cfg(feature = "reset")] @@ -125,21 +124,8 @@ new_cshake_test!( cshake256_reset, "cshake256", sha3::CShake256, - sha3::CShake256Core, cshake_reset_test ); -new_cshake_test!( - cshake128, - "cshake128", - sha3::CShake128, - sha3::CShake128Core, - cshake_test -); -new_cshake_test!( - cshake256, - "cshake256", - sha3::CShake256, - sha3::CShake256Core, - cshake_test -); +new_cshake_test!(cshake128, "cshake128", sha3::CShake128, cshake_test); +new_cshake_test!(cshake256, "cshake256", sha3::CShake256, cshake_test); From ee0776f1b805e2e3b75b106f9d5073ac43e64ecb Mon Sep 17 00:00:00 2001 From: Arthur Gautier Date: Wed, 26 Feb 2025 14:23:48 -0800 Subject: [PATCH 2/2] newtypes support --- Cargo.lock | 12 ++--- Cargo.toml | 4 ++ ascon-hash/src/lib.rs | 109 +++++++++++++++++++++++------------------- belt-hash/src/lib.rs | 3 +- blake2/src/lib.rs | 10 ++-- fsb/src/macros.rs | 3 +- gost94/src/lib.rs | 20 ++++---- groestl/src/lib.rs | 12 ++--- jh/src/lib.rs | 24 ++++++---- md2/src/lib.rs | 3 +- md4/src/lib.rs | 3 +- md5/src/lib.rs | 3 +- ripemd/src/lib.rs | 7 +-- sha1/src/lib.rs | 3 +- sha2/src/lib.rs | 41 +++++++++++----- sha3/src/macros.rs | 7 +-- sha3/tests/cshake.rs | 2 +- shabal/src/lib.rs | 34 +++++++++---- sm3/src/lib.rs | 3 +- streebog/src/lib.rs | 6 +-- tiger/src/lib.rs | 6 +-- whirlpool/src/lib.rs | 3 +- 22 files changed, 179 insertions(+), 139 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06f03fab6..e1cc37941 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "ascon" @@ -84,9 +84,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "const-oid" -version = "0.10.0-rc.3" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68ff6be19477a1bd5441f382916a89bc2a0b2c35db6d41e0f6e8538bf6d6463f" +checksum = "1cb3c4a0d3776f7535c32793be81d6d5fec0d48ac70955d9834e643aa249a52f" [[package]] name = "cpufeatures" @@ -100,8 +100,7 @@ dependencies = [ [[package]] name = "crypto-common" version = "0.2.0-rc.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "170d71b5b14dec99db7739f6fc7d6ec2db80b78c3acb77db48392ccc3d8a9ea0" +source = "git+https://github.com/baloo/traits.git?branch=baloo%2Fdigest%2Fnew-type#54d27021790bd9103fc31caf3f9ebe24c206b72c" dependencies = [ "hybrid-array", ] @@ -109,8 +108,7 @@ dependencies = [ [[package]] name = "digest" version = "0.11.0-pre.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c478574b20020306f98d61c8ca3322d762e1ff08117422ac6106438605ea516" +source = "git+https://github.com/baloo/traits.git?branch=baloo%2Fdigest%2Fnew-type#54d27021790bd9103fc31caf3f9ebe24c206b72c" dependencies = [ "blobby", "block-buffer", diff --git a/Cargo.toml b/Cargo.toml index f333d2a4c..671398af7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,3 +27,7 @@ members = [ [profile.dev] opt-level = 2 + +[patch.crates-io] +#digest = { path = "../traits/digest" } +digest = { git = "https://github.com/baloo/traits.git", branch = "baloo/digest/new-type" } diff --git a/ascon-hash/src/lib.rs b/ascon-hash/src/lib.rs index 5c138fe63..90200ab86 100644 --- a/ascon-hash/src/lib.rs +++ b/ascon-hash/src/lib.rs @@ -381,55 +381,68 @@ impl AlgorithmName for AsconAXofCore { } } -/// Ascon hash -/// -/// ``` -/// use ascon_hash::{AsconHash, Digest}; -/// -/// let mut hasher = AsconHash::new(); -/// hasher.update(b"some bytes"); -/// let digest = hasher.finalize(); -/// assert_eq!(&digest[..], b"\xb7\x42\xca\x75\xe5\x70\x38\x75\x70\x59\xcc\xcc\x68\x74\x71\x4f\x9d\xbd\x7f\xc5\x92\x4a\x7d\xf4\xe3\x16\x59\x4f\xd1\x42\x6c\xa8"); -/// ``` -pub type AsconHash = CoreWrapper; -/// AsconA hash -/// -/// ``` -/// use ascon_hash::{AsconAHash, Digest}; -/// -/// let mut hasher = AsconAHash::new(); -/// hasher.update(b"some bytes"); -/// let digest = hasher.finalize(); -/// assert_eq!(&digest[..], b"\x1d\x1a\xc8\x74\x4a\x4a\x05\x81\x33\x7d\x5a\xf2\x78\xc2\x55\x88\xe1\xa3\xdd\x2d\x86\x73\x07\x64\x26\x53\xdc\xa4\x45\xf5\x5c\x2a"); -/// ``` -pub type AsconAHash = CoreWrapper; -/// AsconXof -/// -/// ``` -/// use ascon_hash::{AsconXof, ExtendableOutput, Update, XofReader}; -/// -/// let mut xof = AsconXof::default(); -/// xof.update(b"some bytes"); -/// let mut reader = xof.finalize_xof(); -/// let mut dst = [0u8; 5]; -/// reader.read(&mut dst); -/// assert_eq!(&dst, b"\xc2\x19\x72\xfd\xe9"); -/// ``` -pub type AsconXof = CoreWrapper; +digest::newtype!( + r#"Ascon hash + +``` +use ascon_hash::{AsconHash, Digest}; + +let mut hasher = AsconHash::new(); +hasher.update(b"some bytes"); +let digest = hasher.finalize(); +assert_eq!(&digest[..], b"\xb7\x42\xca\x75\xe5\x70\x38\x75\x70\x59\xcc\xcc\x68\x74\x71\x4f\x9d\xbd\x7f\xc5\x92\x4a\x7d\xf4\xe3\x16\x59\x4f\xd1\x42\x6c\xa8"); +```"#, + AsconHash = CoreWrapper +); + +digest::newtype!( + r#"AsconA hash + +``` +use ascon_hash::{AsconAHash, Digest}; + +let mut hasher = AsconAHash::new(); +hasher.update(b"some bytes"); +let digest = hasher.finalize(); +assert_eq!(&digest[..], b"\x1d\x1a\xc8\x74\x4a\x4a\x05\x81\x33\x7d\x5a\xf2\x78\xc2\x55\x88\xe1\xa3\xdd\x2d\x86\x73\x07\x64\x26\x53\xdc\xa4\x45\xf5\x5c\x2a"); +```"#, + AsconAHash = CoreWrapper +); + +digest::newtype!( + r#"AsconXof + +``` +use ascon_hash::{AsconXof, ExtendableOutput, Update, XofReader}; + +let mut xof = AsconXof::default(); +xof.update(b"some bytes"); +let mut reader = xof.finalize_xof(); +let mut dst = [0u8; 5]; +reader.read(&mut dst); +assert_eq!(&dst, b"\xc2\x19\x72\xfd\xe9"); +```"#, + AsconXof = CoreWrapper +); + /// Reader for AsconXof output pub type AsconXofReader = XofReaderCoreWrapper; -/// AsconAXof -/// -/// ``` -/// use ascon_hash::{AsconAXof, ExtendableOutput, Update, XofReader}; -/// -/// let mut xof = AsconAXof::default(); -/// xof.update(b"some bytes"); -/// let mut reader = xof.finalize_xof(); -/// let mut dst = [0u8; 5]; -/// reader.read(&mut dst); -/// assert_eq!(&dst, b"\xb8\xd6\xbd\xf0\xa7"); -/// ``` -pub type AsconAXof = CoreWrapper; + +digest::newtype!( + r#"AsconAXof + +``` +use ascon_hash::{AsconAXof, ExtendableOutput, Update, XofReader}; + +let mut xof = AsconAXof::default(); +xof.update(b"some bytes"); +let mut reader = xof.finalize_xof(); +let mut dst = [0u8; 5]; +reader.read(&mut dst); +assert_eq!(&dst, b"\xb8\xd6\xbd\xf0\xa7"); +```"#, + AsconAXof = CoreWrapper +); + /// Reader for AsconAXof output pub type AsconAXofReader = XofReaderCoreWrapper; diff --git a/belt-hash/src/lib.rs b/belt-hash/src/lib.rs index 7affb4b03..3f55bcdf5 100644 --- a/belt-hash/src/lib.rs +++ b/belt-hash/src/lib.rs @@ -40,8 +40,7 @@ pub struct BeltHashCore { h: [u32; 8], } -/// BelT hasher state. -pub type BeltHash = CoreWrapper; +digest::newtype!("BelT hasher hasher", BeltHash = CoreWrapper); impl BeltHashCore { fn compress_block(&mut self, block: &Block) { diff --git a/blake2/src/lib.rs b/blake2/src/lib.rs index 9eb8c4036..b2f085dd4 100644 --- a/blake2/src/lib.rs +++ b/blake2/src/lib.rs @@ -69,12 +69,10 @@ pub type Blake2bVar = RtVariableCoreWrapper; pub type Blake2bCore = CtVariableCoreWrapper; /// BLAKE2b generic over output size. pub type Blake2b = CoreWrapper>; -/// BLAKE2b-128 hasher state. -pub type Blake2b128 = Blake2b; -/// BLAKE2b-256 hasher state. -pub type Blake2b256 = Blake2b; -/// BLAKE2b-512 hasher state. -pub type Blake2b512 = Blake2b; + +digest::newtype!("BLAKE2b-128 hasher state.", Blake2b128 = Blake2b); +digest::newtype!("BLAKE2b-256 hasher state.", Blake2b256 = Blake2b); +digest::newtype!("BLAKE2b-512 hasher state.", Blake2b512 = Blake2b); blake2_mac_impl!(Blake2bMac, Blake2bVarCore, U64, "Blake2b MAC function"); diff --git a/fsb/src/macros.rs b/fsb/src/macros.rs index 59845f79c..d2d9bb7d2 100644 --- a/fsb/src/macros.rs +++ b/fsb/src/macros.rs @@ -12,8 +12,7 @@ macro_rules! fsb_impl { state: [u8; $r / 8], } - #[doc=$full_doc] - pub type $full_state = CoreWrapper<$state>; + digest::newtype!($full_doc, $full_state = CoreWrapper<$state>); impl HashMarker for $state {} diff --git a/gost94/src/lib.rs b/gost94/src/lib.rs index a27a1b380..b023d01c8 100644 --- a/gost94/src/lib.rs +++ b/gost94/src/lib.rs @@ -34,12 +34,14 @@ impl AssociatedOid for Gost94Core { const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.804.2.1.1.1.1.2.1"); } -/// GOST94 hash function with CryptoPro parameters. -pub type Gost94CryptoPro = CoreWrapper>; -/// GOST94 hash function with S-box defined in GOST R 34.12-2015. -pub type Gost94s2015 = CoreWrapper>; -/// GOST94 hash function with test parameters. -pub type Gost94Test = CoreWrapper>; -/// GOST94 hash function with UAPKI GOST 34.311-95 parameters -/// (1.2.804.2.1.1.1.1.2.1 OID). -pub type Gost94UA = CoreWrapper>; +digest::newtype!("GOST94 hash function with CryptoPro parameters.", Gost94CryptoPro = CoreWrapper>); + +digest::newtype!("GOST94 hash function with S-box defined in GOST R 34.12-2015.", Gost94s2015 = CoreWrapper>); + +digest::newtype!("GOST94 hash function with test parameters.", Gost94Test = CoreWrapper>); + +digest::newtype!( + r#"GOST94 hash function with UAPKI GOST 34.311-95 parameters +(1.2.804.2.1.1.1.1.2.1 OID)."#, + Gost94UA = CoreWrapper> +); diff --git a/groestl/src/lib.rs b/groestl/src/lib.rs index 47d6be00b..2ee4962b5 100644 --- a/groestl/src/lib.rs +++ b/groestl/src/lib.rs @@ -44,10 +44,8 @@ pub type GroestlShortCore = CtVariableCoreWrapper = CoreWrapper>; -/// Groestl-224 hasher state. -pub type Groestl224 = CoreWrapper>; -/// Groestl-256 hasher state. -pub type Groestl256 = CoreWrapper>; +digest::newtype!("Groestl-224 hasher state.", Groestl224 = CoreWrapper>); +digest::newtype!("Groestl-256 hasher state.", Groestl256 = CoreWrapper>); impl HashMarker for GroestlShortVarCore {} @@ -175,10 +173,8 @@ pub type GroestlLongCore = CtVariableCoreWrapper = CoreWrapper>; -/// Groestl-384 hasher state. -pub type Groestl384 = CoreWrapper>; -/// Groestl-512 hasher state. -pub type Groestl512 = CoreWrapper>; +digest::newtype!("Groestl-384 hasher state.", Groestl384 = CoreWrapper>); +digest::newtype!("Groestl-512 hasher state.", Groestl512 = CoreWrapper>); impl HashMarker for GroestlLongVarCore {} diff --git a/jh/src/lib.rs b/jh/src/lib.rs index 09640aa14..be63d5c11 100644 --- a/jh/src/lib.rs +++ b/jh/src/lib.rs @@ -38,14 +38,22 @@ pub struct JhCore { block_len: u64, } -/// Jh-224 hasher state -pub type Jh224 = CoreWrapper>; -/// Jh-256 hasher state -pub type Jh256 = CoreWrapper>; -/// Jh-384 hasher state -pub type Jh384 = CoreWrapper>; -/// Jh-512 hasher state -pub type Jh512 = CoreWrapper>; +digest::newtype!( + "Jh-224 hasher state", + Jh224 = CoreWrapper> +); +digest::newtype!( + "Jh-256 hasher state", + Jh256 = CoreWrapper> +); +digest::newtype!( + "Jh-384 hasher state", + Jh384 = CoreWrapper> +); +digest::newtype!( + "Jh-512 hasher state", + Jh512 = CoreWrapper> +); impl HashMarker for JhCore {} diff --git a/md2/src/lib.rs b/md2/src/lib.rs index 26e71d5a7..472cc648a 100644 --- a/md2/src/lib.rs +++ b/md2/src/lib.rs @@ -37,8 +37,7 @@ pub struct Md2Core { checksum: Block, } -/// MD2 hasher state. -pub type Md2 = CoreWrapper; +digest::newtype!("MD2 hasher state.", Md2 = CoreWrapper); const STATE_LEN: usize = 48; diff --git a/md4/src/lib.rs b/md4/src/lib.rs index c36cbb949..3a6d8a8bc 100644 --- a/md4/src/lib.rs +++ b/md4/src/lib.rs @@ -44,8 +44,7 @@ pub struct Md4Core { state: [Wu32; STATE_LEN], } -/// MD4 hasher state -pub type Md4 = CoreWrapper; +digest::newtype!("MD4 hasher state", Md4 = CoreWrapper); const STATE_LEN: usize = 4; diff --git a/md5/src/lib.rs b/md5/src/lib.rs index e8db6240d..9792da844 100644 --- a/md5/src/lib.rs +++ b/md5/src/lib.rs @@ -37,8 +37,7 @@ pub struct Md5Core { state: [u32; STATE_LEN], } -/// MD5 hasher state. -pub type Md5 = CoreWrapper; +digest::newtype!("MD5 hasher", Md5 = CoreWrapper); const STATE_LEN: usize = 4; diff --git a/ripemd/src/lib.rs b/ripemd/src/lib.rs index feecf9ad8..0c196e7a9 100644 --- a/ripemd/src/lib.rs +++ b/ripemd/src/lib.rs @@ -46,9 +46,10 @@ macro_rules! impl_ripemd { block_len: u64, } - #[doc = $doc_name] - #[doc = " hasher."] - pub type $wrapped_name = CoreWrapper<$name>; + digest::newtype!( + concat!($doc_name, " hasher state."), + $wrapped_name = CoreWrapper<$name> + ); impl HashMarker for $name {} diff --git a/sha1/src/lib.rs b/sha1/src/lib.rs index 60bd643ae..cbea015a4 100644 --- a/sha1/src/lib.rs +++ b/sha1/src/lib.rs @@ -44,8 +44,7 @@ pub struct Sha1Core { block_len: u64, } -/// SHA-1 hasher state. -pub type Sha1 = CoreWrapper; +digest::newtype!("SHA-1 hasher", Sha1 = CoreWrapper); impl HashMarker for Sha1Core {} diff --git a/sha2/src/lib.rs b/sha2/src/lib.rs index 19cf7a26f..9cdb359b5 100644 --- a/sha2/src/lib.rs +++ b/sha2/src/lib.rs @@ -46,15 +46,32 @@ impl_oid_carrier!(OidSha224, "2.16.840.1.101.3.4.2.4"); impl_oid_carrier!(OidSha512_224, "2.16.840.1.101.3.4.2.5"); impl_oid_carrier!(OidSha512_256, "2.16.840.1.101.3.4.2.6"); -/// SHA-224 hasher. -pub type Sha224 = CoreWrapper>; -/// SHA-256 hasher. -pub type Sha256 = CoreWrapper>; -/// SHA-512/224 hasher. -pub type Sha512_224 = CoreWrapper>; -/// SHA-512/256 hasher. -pub type Sha512_256 = CoreWrapper>; -/// SHA-384 hasher. -pub type Sha384 = CoreWrapper>; -/// SHA-512 hasher. -pub type Sha512 = CoreWrapper>; +digest::newtype!( + "SHA-224 hasher", + Sha224 = CoreWrapper> +); + +digest::newtype!( + "SHA-256 hasher", + Sha256 = CoreWrapper> +); + +digest::newtype!( + "SHA-512/224 hasher", + Sha512_224 = CoreWrapper> +); + +digest::newtype!( + "SHA-512/256 hasher", + Sha512_256 = CoreWrapper> +); + +digest::newtype!( + "SHA-384 hasher", + Sha384 = CoreWrapper> +); + +digest::newtype!( + "SHA-512 hasher", + Sha512 = CoreWrapper> +); diff --git a/sha3/src/macros.rs b/sha3/src/macros.rs index 2963a4985..81fe52b8b 100644 --- a/sha3/src/macros.rs +++ b/sha3/src/macros.rs @@ -464,9 +464,10 @@ macro_rules! impl_cshake { padding: u8, } - #[doc = $alg_name] - #[doc = " hasher state."] - pub type $full_name = CoreWrapper<$name>; + digest::newtype!( + concat!($alg_name, " hasher state."), + $full_name = CoreWrapper<$name> + ); impl $name { /// Creates a new CSHAKE instance with the given function name and customization. diff --git a/sha3/tests/cshake.rs b/sha3/tests/cshake.rs index 33ba2576b..eff8a0464 100644 --- a/sha3/tests/cshake.rs +++ b/sha3/tests/cshake.rs @@ -1,7 +1,7 @@ use core::fmt::Debug; -use digest::{CustomizedInit,ExtendableOutput}; #[cfg(feature = "reset")] use digest::ExtendableOutputReset; +use digest::{CustomizedInit, ExtendableOutput}; #[cfg(feature = "reset")] pub(crate) fn cshake_reset_test(input: &[u8], output: &[u8], new: F) -> Option<&'static str> diff --git a/shabal/src/lib.rs b/shabal/src/lib.rs index e28d325e0..7f9a01b30 100644 --- a/shabal/src/lib.rs +++ b/shabal/src/lib.rs @@ -20,13 +20,27 @@ use digest::{ core_api::{CoreWrapper, CtVariableCoreWrapper}, }; -/// Shabal192 hasher. -pub type Shabal192 = CoreWrapper>; -/// Shabal224 hasher. -pub type Shabal224 = CoreWrapper>; -/// Shabal256 hasher. -pub type Shabal256 = CoreWrapper>; -/// Shabal384 hasher. -pub type Shabal384 = CoreWrapper>; -/// Shabal512 hasher. -pub type Shabal512 = CoreWrapper>; +digest::newtype!( + "Shabal192 hasher", + Shabal192 = CoreWrapper> +); + +digest::newtype!( + "Shabal224 hasher", + Shabal224 = CoreWrapper> +); + +digest::newtype!( + "Shabal256 hasher", + Shabal256 = CoreWrapper> +); + +digest::newtype!( + "Shabal384 hasher", + Shabal384 = CoreWrapper> +); + +digest::newtype!( + "Shabal512 hasher", + Shabal512 = CoreWrapper> +); diff --git a/sm3/src/lib.rs b/sm3/src/lib.rs index bd1453b42..c1ebef56a 100644 --- a/sm3/src/lib.rs +++ b/sm3/src/lib.rs @@ -37,8 +37,7 @@ pub struct Sm3Core { h: [u32; consts::H_LEN], } -/// Sm3 hasher state. -pub type Sm3 = CoreWrapper; +digest::newtype!("Sm3 hasher", Sm3 = CoreWrapper); impl HashMarker for Sm3Core {} diff --git a/streebog/src/lib.rs b/streebog/src/lib.rs index 9ead316ad..8b004a1a6 100644 --- a/streebog/src/lib.rs +++ b/streebog/src/lib.rs @@ -28,7 +28,5 @@ pub use digest::{self, Digest}; impl_oid_carrier!(Oid256, "1.2.643.7.1.1.2.2"); impl_oid_carrier!(Oid512, "1.2.643.7.1.1.2.3"); -/// Streebog256 hasher. -pub type Streebog256 = CoreWrapper>; -/// Streebog512 hasher. -pub type Streebog512 = CoreWrapper>; +digest::newtype!("Streebog256 hasher.", Streebog256 = CoreWrapper>); +digest::newtype!("Streebog512 hasher.", Streebog512 = CoreWrapper>); diff --git a/tiger/src/lib.rs b/tiger/src/lib.rs index 8173597c6..6e6d02cc8 100644 --- a/tiger/src/lib.rs +++ b/tiger/src/lib.rs @@ -43,10 +43,8 @@ pub struct TigerCore { state: State, } -/// Tiger hasher state. -pub type Tiger = CoreWrapper>; -/// Tiger2 hasher state. -pub type Tiger2 = CoreWrapper>; +digest::newtype!("Tiger hasher state.", Tiger = CoreWrapper>); +digest::newtype!("Tiger2 hasher state.", Tiger2 = CoreWrapper>); impl HashMarker for TigerCore {} diff --git a/whirlpool/src/lib.rs b/whirlpool/src/lib.rs index f70ab6f8d..2449020a5 100644 --- a/whirlpool/src/lib.rs +++ b/whirlpool/src/lib.rs @@ -40,8 +40,7 @@ pub struct WhirlpoolCore { const STATE_LEN: usize = 8; const BITLEN_LEN: usize = 4; -/// Whirlpool hasher state. -pub type Whirlpool = CoreWrapper; +digest::newtype!("Whirlpool hasher state.", Whirlpool = CoreWrapper); impl HashMarker for WhirlpoolCore {}