Skip to content

Commit

Permalink
Rename IS_VER2 to VER2
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov committed Jan 11, 2024
1 parent f3a4279 commit 3f785e8
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tiger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const S0: State = [

/// Core Tiger hasher state.
#[derive(Clone)]
pub struct TigerCore<const IS_VER2: bool> {
pub struct TigerCore<const VER2: bool = true> {
block_len: u64,
state: State,
}
Expand All @@ -47,21 +47,21 @@ pub type Tiger = CoreWrapper<TigerCore<false>>;
/// Tiger2 hasher state.
pub type Tiger2 = CoreWrapper<TigerCore<true>>;

impl<const IS_VER2: bool> HashMarker for TigerCore<IS_VER2> {}
impl<const VER2: bool> HashMarker for TigerCore<VER2> {}

impl<const IS_VER2: bool> BlockSizeUser for TigerCore<IS_VER2> {
impl<const VER2: bool> BlockSizeUser for TigerCore<VER2> {
type BlockSize = U64;
}

impl<const IS_VER2: bool> BufferKindUser for TigerCore<IS_VER2> {
impl<const VER2: bool> BufferKindUser for TigerCore<VER2> {
type BufferKind = Eager;
}

impl<const IS_VER2: bool> OutputSizeUser for TigerCore<IS_VER2> {
impl<const VER2: bool> OutputSizeUser for TigerCore<VER2> {
type OutputSize = U24;
}

impl<const IS_VER2: bool> UpdateCore for TigerCore<IS_VER2> {
impl<const VER2: bool> UpdateCore for TigerCore<VER2> {
#[inline]
fn update_blocks(&mut self, blocks: &[Block<Self>]) {
self.block_len += blocks.len() as u64;
Expand All @@ -71,14 +71,14 @@ impl<const IS_VER2: bool> UpdateCore for TigerCore<IS_VER2> {
}
}

impl<const IS_VER2: bool> FixedOutputCore for TigerCore<IS_VER2> {
impl<const VER2: bool> FixedOutputCore for TigerCore<VER2> {
#[inline]
fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>) {
let bs = Self::BlockSize::U64;
let pos = buffer.get_pos() as u64;
let bit_len = 8 * (pos + bs * self.block_len);

if IS_VER2 {
if VER2 {
buffer.len64_padding_le(bit_len, |b| compress(&mut self.state, b.as_ref()));
} else {
buffer.digest_pad(1, &bit_len.to_le_bytes(), |b| {
Expand All @@ -92,7 +92,7 @@ impl<const IS_VER2: bool> FixedOutputCore for TigerCore<IS_VER2> {
}
}

impl<const IS_VER2: bool> Default for TigerCore<IS_VER2> {
impl<const VER2: bool> Default for TigerCore<VER2> {
#[inline]
fn default() -> Self {
Self {
Expand All @@ -102,35 +102,35 @@ impl<const IS_VER2: bool> Default for TigerCore<IS_VER2> {
}
}

impl<const IS_VER2: bool> Reset for TigerCore<IS_VER2> {
impl<const VER2: bool> Reset for TigerCore<VER2> {
#[inline]
fn reset(&mut self) {
*self = Default::default();
}
}

impl<const IS_VER2: bool> AlgorithmName for TigerCore<IS_VER2> {
impl<const VER2: bool> AlgorithmName for TigerCore<VER2> {
#[inline]
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
if IS_VER2 {
if VER2 {
f.write_str("Tiger2")
} else {
f.write_str("Tiger")
}
}
}

impl<const IS_VER2: bool> fmt::Debug for TigerCore<IS_VER2> {
impl<const VER2: bool> fmt::Debug for TigerCore<VER2> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if IS_VER2 {
if VER2 {
f.write_str("Tiger2Core { ... }")
} else {
f.write_str("TigerCore { ... }")
}
}
}

impl<const IS_VER2: bool> Drop for TigerCore<IS_VER2> {
impl<const VER2: bool> Drop for TigerCore<VER2> {
#[inline]
fn drop(&mut self) {
#[cfg(feature = "zeroize")]
Expand All @@ -142,4 +142,4 @@ impl<const IS_VER2: bool> Drop for TigerCore<IS_VER2> {
}

#[cfg(feature = "zeroize")]
impl<const IS_VER2: bool> ZeroizeOnDrop for TigerCore<IS_VER2> {}
impl<const VER2: bool> ZeroizeOnDrop for TigerCore<VER2> {}

0 comments on commit 3f785e8

Please sign in to comment.