Skip to content

Commit

Permalink
tweak sha3 macros
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Nov 19, 2021
1 parent 1b76492 commit 5b201da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 76 deletions.
91 changes: 18 additions & 73 deletions sha3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
6 changes: 3 additions & 3 deletions sha3/src/macros.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5b201da

Please sign in to comment.