diff options
author | Daniel Schadt <kingdread@gmx.de> | 2025-09-04 22:04:48 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2025-09-04 22:04:48 +0200 |
commit | bf5a408e852c79f3373da59c7675c13e53434ff6 (patch) | |
tree | 246ef4943b3e89425fdbfbbfb69d3dc91d20a5f9 /src/lib.rs | |
parent | 4b83bfcad25c8d8e36fe210a76faa5797f9c5aaf (diff) | |
download | zears-bf5a408e852c79f3373da59c7675c13e53434ff6.tar.gz zears-bf5a408e852c79f3373da59c7675c13e53434ff6.tar.bz2 zears-bf5a408e852c79f3373da59c7675c13e53434ff6.zip |
inline pad_to_blocks
I like the way with chunks_exact more, as we get the remainder for free
and we don't have to do the chunk.len() dance
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 26 |
1 files changed, 9 insertions, 17 deletions
@@ -688,16 +688,6 @@ fn cipher_aez_core<A: AsRef<[u8]>, T: IntoIterator<Item = A>>( blocks.set_m_y(c_y); } -fn pad_to_blocks(value: &[u8]) -> impl Iterator<Item = Block> { - value.chunks(16).map(|chunk| { - if chunk.len() == 16 { - Block::from_slice(chunk) - } else { - Block::from_slice(chunk).pad(chunk.len() * 8) - } - }) -} - fn aez_hash<A: AsRef<[u8]>, T: IntoIterator<Item = A>>(aez: &Aez, tweaks: T) -> Block { let mut hash = Block::null(); for (i, tweak) in tweaks.into_iter().enumerate() { @@ -716,15 +706,17 @@ fn aez_hash<A: AsRef<[u8]>, T: IntoIterator<Item = A>>(aez: &Aez, tweaks: T) -> hash = hash ^ ej.eval(Block::from_slice(chunk)); } } else { - let blocks = pad_to_blocks(tweak); - for (l, chunk) in blocks.enumerate() { + let blocks = tweak.chunks_exact(16); + let remainder = blocks.remainder(); + + for chunk in blocks { ej.advance(); - if l == tweak.len() / 16 { - hash = hash ^ e(j.try_into().unwrap(), 0, aez, chunk); - } else { - hash = hash ^ ej.eval(chunk); - } + hash = hash ^ ej.eval(Block::from_slice(chunk)); } + + ej.advance(); + let chunk = Block::from_slice(remainder).pad_bytes(remainder.len() as u8); + hash = hash ^ e(j.try_into().unwrap(), 0, aez, chunk); } } hash |