From 5b201daa7220e7df783fb1d97decfd2391f3dd1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Fri, 19 Nov 2021 19:52:20 +0300 Subject: [PATCH] tweak sha3 macros --- sha3/src/lib.rs | 91 +++++++++------------------------------------- sha3/src/macros.rs | 6 +-- 2 files changed, 21 insertions(+), 76 deletions(-) diff --git a/sha3/src/lib.rs b/sha3/src/lib.rs index 97236160d..63b312fa8 100644 --- a/sha3/src/lib.rs +++ b/sha3/src/lib.rs @@ -84,100 +84,45 @@ mod state; use crate::state::Sha3State; -const KECCAK_PAD: u8 = 0x01; -const SHA3_PAD: u8 = 0x06; -const SHAKE_PAD: u8 = 0x1f; +// Paddings +const KECCAK: u8 = 0x01; +const SHA3: u8 = 0x06; +const SHAKE: u8 = 0x1f; -sha3_impl!( - Keccak224Core, - Keccak224, - U28, - U144, - KECCAK_PAD, - "Keccak-224", -); -sha3_impl!( - Keccak256Core, - Keccak256, - U32, - U136, - KECCAK_PAD, - "Keccak-256", -); -sha3_impl!( - Keccak384Core, - Keccak384, - U48, - U104, - KECCAK_PAD, - "Keccak-384", -); -sha3_impl!( - Keccak512Core, - Keccak512, - U64, - U72, - KECCAK_PAD, - "Keccak-512", -); +impl_sha3!(Keccak224Core, Keccak224, U28, U144, KECCAK, "Keccak-224"); +impl_sha3!(Keccak256Core, Keccak256, U32, U136, KECCAK, "Keccak-256"); +impl_sha3!(Keccak384Core, Keccak384, U48, U104, KECCAK, "Keccak-384"); +impl_sha3!(Keccak512Core, Keccak512, U64, U72, KECCAK, "Keccak-512"); -sha3_impl!( +impl_sha3!( Keccak256FullCore, Keccak256Full, U200, U136, - KECCAK_PAD, + KECCAK, "SHA-3 CryptoNight variant", ); -sha3_impl!( - Sha3_224Core, - Sha3_224, - U28, - U144, - SHA3_PAD, - "SHA-3-224", -); -sha3_impl!( - Sha3_256Core, - Sha3_256, - U32, - U136, - SHA3_PAD, - "SHA-3-256", -); -sha3_impl!( - Sha3_384Core, - Sha3_384, - U48, - U104, - SHA3_PAD, - "SHA-3-384", -); -sha3_impl!( - Sha3_512Core, - Sha3_512, - U64, - U72, - SHA3_PAD, - "SHA-3-512", -); +impl_sha3!(Sha3_224Core, Sha3_224, U28, U144, SHA3, "SHA-3-224"); +impl_sha3!(Sha3_256Core, Sha3_256, U32, U136, SHA3, "SHA-3-256"); +impl_sha3!(Sha3_384Core, Sha3_384, U48, U104, SHA3, "SHA-3-384"); +impl_sha3!(Sha3_512Core, Sha3_512, U64, U72, SHA3, "SHA-3-512"); -shake_impl!( +impl_shake!( Shake128Core, Shake128, Shake128ReaderCore, Shake128Reader, U168, - SHAKE_PAD, + SHAKE, "SHAKE128", ); -shake_impl!( +impl_shake!( Shake256Core, Shake256, Shake256ReaderCore, Shake256Reader, U136, - SHAKE_PAD, + SHAKE, "SHAKE256", ); diff --git a/sha3/src/macros.rs b/sha3/src/macros.rs index d1e2728cb..1ec96367b 100644 --- a/sha3/src/macros.rs +++ b/sha3/src/macros.rs @@ -1,7 +1,7 @@ -macro_rules! sha3_impl { +macro_rules! impl_sha3 { ( $name:ident, $full_name:ident, $output_size:ident, - $rate:ident, $pad:expr, $alg_name:expr, + $rate:ident, $pad:expr, $alg_name:expr $(,)? ) => { #[doc = "Core "] #[doc = $alg_name] @@ -87,7 +87,7 @@ macro_rules! sha3_impl { }; } -macro_rules! shake_impl { +macro_rules! impl_shake { ( $name:ident, $full_name:ident, $reader:ident, $reader_full:ident, $rate:ident, $pad:expr, $alg_name:expr,