Skip to content

Commit 133778b

Browse files
committed
migrate k12
1 parent aa2f94e commit 133778b

9 files changed

Lines changed: 115 additions & 134 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

k12/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ categories = ["cryptography", "no-std"]
1313
description = "Implementation of the KangarooTwelve family of extendable-output functions"
1414

1515
[dependencies]
16-
digest = "0.11"
16+
digest = { version = "0.11", default-features = false }
1717
keccak = { version = "0.2", features = ["parallel"] }
18+
sponge-cursor = "0.1"
1819

1920
[dev-dependencies]
20-
digest = { version = "0.11", features = ["alloc", "dev"] }
21+
digest = { version = "0.11", default-features = false, features = ["alloc", "dev"] }
2122
hex-literal = "1"
2223

2324
[features]

k12/src/custom/borrow.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use core::fmt;
22
use digest::{
33
CollisionResistance, ExtendableOutput, ExtendableOutputReset, HashMarker, Reset, Update,
4-
block_buffer::BlockSizes,
4+
array::ArraySize,
55
common::{AlgorithmName, BlockSizeUser},
66
consts::{U16, U32, U136, U168},
77
};
@@ -10,12 +10,12 @@ use crate::{Kt, KtReader, utils::length_encode};
1010

1111
/// Customized KangarooTwelve hasher generic over rate with borrrowed customization string.
1212
#[derive(Clone)]
13-
pub struct CustomRefKt<'a, Rate: BlockSizes> {
13+
pub struct CustomRefKt<'a, Rate: ArraySize> {
1414
customization: &'a [u8],
1515
inner: Kt<Rate>,
1616
}
1717

18-
impl<'a, Rate: BlockSizes> CustomRefKt<'a, Rate> {
18+
impl<'a, Rate: ArraySize> CustomRefKt<'a, Rate> {
1919
/// Create new customized KangarooTwelve hasher with borrrowed customization string.
2020
///
2121
/// Note that this is an inherent method and `CustomRefKt` does not implement
@@ -29,56 +29,56 @@ impl<'a, Rate: BlockSizes> CustomRefKt<'a, Rate> {
2929
}
3030
}
3131

32-
impl<Rate: BlockSizes> Default for CustomRefKt<'static, Rate> {
32+
impl<Rate: ArraySize> Default for CustomRefKt<'static, Rate> {
3333
#[inline]
3434
fn default() -> Self {
3535
Self::new_customized(&[])
3636
}
3737
}
3838

39-
impl<Rate: BlockSizes> fmt::Debug for CustomRefKt<'_, Rate> {
39+
impl<Rate: ArraySize> fmt::Debug for CustomRefKt<'_, Rate> {
4040
#[inline]
4141
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
4242
write!(f, "CustomKt{} {{ ... }}", 4 * (200 - Rate::USIZE))
4343
}
4444
}
4545

46-
impl<Rate: BlockSizes> AlgorithmName for CustomRefKt<'_, Rate> {
46+
impl<Rate: ArraySize> AlgorithmName for CustomRefKt<'_, Rate> {
4747
#[inline]
4848
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
4949
Kt::<Rate>::write_alg_name(f)
5050
}
5151
}
5252

53-
impl<Rate: BlockSizes> HashMarker for CustomRefKt<'_, Rate> {}
53+
impl<Rate: ArraySize> HashMarker for CustomRefKt<'_, Rate> {}
5454

55-
impl<Rate: BlockSizes> BlockSizeUser for CustomRefKt<'_, Rate> {
55+
impl<Rate: ArraySize> BlockSizeUser for CustomRefKt<'_, Rate> {
5656
type BlockSize = Rate;
5757
}
5858

59-
impl<Rate: BlockSizes> Update for CustomRefKt<'_, Rate> {
59+
impl<Rate: ArraySize> Update for CustomRefKt<'_, Rate> {
6060
#[inline]
6161
fn update(&mut self, data: &[u8]) {
6262
self.inner.update(data);
6363
}
6464
}
6565

66-
impl<Rate: BlockSizes> Reset for CustomRefKt<'_, Rate> {
66+
impl<Rate: ArraySize> Reset for CustomRefKt<'_, Rate> {
6767
#[inline]
6868
fn reset(&mut self) {
6969
self.inner.reset();
7070
}
7171
}
7272

73-
impl<Rate: BlockSizes> CustomRefKt<'_, Rate> {
73+
impl<Rate: ArraySize> CustomRefKt<'_, Rate> {
7474
fn absorb_customization(&mut self) {
7575
self.inner.update(self.customization);
7676
let len = u64::try_from(self.customization.len()).expect("length always fits into `u64`");
7777
length_encode(len, |enc_len| self.inner.update(enc_len));
7878
}
7979
}
8080

81-
impl<Rate: BlockSizes> ExtendableOutput for CustomRefKt<'_, Rate> {
81+
impl<Rate: ArraySize> ExtendableOutput for CustomRefKt<'_, Rate> {
8282
type Reader = KtReader<Rate>;
8383

8484
#[inline]
@@ -88,7 +88,7 @@ impl<Rate: BlockSizes> ExtendableOutput for CustomRefKt<'_, Rate> {
8888
}
8989
}
9090

91-
impl<Rate: BlockSizes> ExtendableOutputReset for CustomRefKt<'_, Rate> {
91+
impl<Rate: ArraySize> ExtendableOutputReset for CustomRefKt<'_, Rate> {
9292
#[inline]
9393
fn finalize_xof_reset(&mut self) -> Self::Reader {
9494
self.absorb_customization();
@@ -100,7 +100,7 @@ impl<Rate: BlockSizes> ExtendableOutputReset for CustomRefKt<'_, Rate> {
100100

101101
// `inner` is zeroized by `Drop` and `customization` can not be zeroized
102102
#[cfg(feature = "zeroize")]
103-
impl<Rate: BlockSizes> digest::zeroize::ZeroizeOnDrop for CustomRefKt<'_, Rate> {}
103+
impl<Rate: ArraySize> digest::zeroize::ZeroizeOnDrop for CustomRefKt<'_, Rate> {}
104104

105105
/// Customized KT128 hasher with borrowed customization string.
106106
pub type CustomRefKt128<'a> = CustomRefKt<'a, U168>;

k12/src/custom/owned.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::fmt;
55
use digest::{
66
CollisionResistance, CustomizedInit, ExtendableOutput, ExtendableOutputReset, HashMarker,
77
Reset, Update,
8-
block_buffer::BlockSizes,
8+
array::ArraySize,
99
common::{AlgorithmName, BlockSizeUser},
1010
consts::{U16, U32, U136, U168},
1111
};
@@ -14,12 +14,12 @@ use crate::{Kt, KtReader, utils::length_encode};
1414

1515
/// Customized KangarooTwelve hasher generic over rate with owned customization string.
1616
#[derive(Clone)]
17-
pub struct CustomKt<Rate: BlockSizes> {
17+
pub struct CustomKt<Rate: ArraySize> {
1818
customization: Vec<u8>,
1919
inner: Kt<Rate>,
2020
}
2121

22-
impl<Rate: BlockSizes> CustomizedInit for CustomKt<Rate> {
22+
impl<Rate: ArraySize> CustomizedInit for CustomKt<Rate> {
2323
#[inline]
2424
fn new_customized(customization: &[u8]) -> Self {
2525
let len = u64::try_from(customization.len()).expect("length should always fit into `u64`");
@@ -37,48 +37,48 @@ impl<Rate: BlockSizes> CustomizedInit for CustomKt<Rate> {
3737
}
3838
}
3939

40-
impl<Rate: BlockSizes> Default for CustomKt<Rate> {
40+
impl<Rate: ArraySize> Default for CustomKt<Rate> {
4141
#[inline]
4242
fn default() -> Self {
4343
Self::new_customized(&[])
4444
}
4545
}
4646

47-
impl<Rate: BlockSizes> fmt::Debug for CustomKt<Rate> {
47+
impl<Rate: ArraySize> fmt::Debug for CustomKt<Rate> {
4848
#[inline]
4949
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
5050
write!(f, "CustomKt{} {{ ... }}", 4 * (200 - Rate::USIZE))
5151
}
5252
}
5353

54-
impl<Rate: BlockSizes> AlgorithmName for CustomKt<Rate> {
54+
impl<Rate: ArraySize> AlgorithmName for CustomKt<Rate> {
5555
#[inline]
5656
fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result {
5757
Kt::<Rate>::write_alg_name(f)
5858
}
5959
}
6060

61-
impl<Rate: BlockSizes> HashMarker for CustomKt<Rate> {}
61+
impl<Rate: ArraySize> HashMarker for CustomKt<Rate> {}
6262

63-
impl<Rate: BlockSizes> BlockSizeUser for CustomKt<Rate> {
63+
impl<Rate: ArraySize> BlockSizeUser for CustomKt<Rate> {
6464
type BlockSize = Rate;
6565
}
6666

67-
impl<Rate: BlockSizes> Update for CustomKt<Rate> {
67+
impl<Rate: ArraySize> Update for CustomKt<Rate> {
6868
#[inline]
6969
fn update(&mut self, data: &[u8]) {
7070
self.inner.update(data);
7171
}
7272
}
7373

74-
impl<Rate: BlockSizes> Reset for CustomKt<Rate> {
74+
impl<Rate: ArraySize> Reset for CustomKt<Rate> {
7575
#[inline]
7676
fn reset(&mut self) {
7777
self.inner.reset();
7878
}
7979
}
8080

81-
impl<Rate: BlockSizes> ExtendableOutput for CustomKt<Rate> {
81+
impl<Rate: ArraySize> ExtendableOutput for CustomKt<Rate> {
8282
type Reader = KtReader<Rate>;
8383

8484
#[inline]
@@ -88,7 +88,7 @@ impl<Rate: BlockSizes> ExtendableOutput for CustomKt<Rate> {
8888
}
8989
}
9090

91-
impl<Rate: BlockSizes> ExtendableOutputReset for CustomKt<Rate> {
91+
impl<Rate: ArraySize> ExtendableOutputReset for CustomKt<Rate> {
9292
#[inline]
9393
fn finalize_xof_reset(&mut self) -> Self::Reader {
9494
self.inner.update(&self.customization);
@@ -98,7 +98,7 @@ impl<Rate: BlockSizes> ExtendableOutputReset for CustomKt<Rate> {
9898
}
9999
}
100100

101-
impl<Rate: BlockSizes> Drop for CustomKt<Rate> {
101+
impl<Rate: ArraySize> Drop for CustomKt<Rate> {
102102
#[inline]
103103
fn drop(&mut self) {
104104
#[cfg(feature = "zeroize")]
@@ -111,7 +111,7 @@ impl<Rate: BlockSizes> Drop for CustomKt<Rate> {
111111
}
112112

113113
#[cfg(feature = "zeroize")]
114-
impl<Rate: BlockSizes> digest::zeroize::ZeroizeOnDrop for CustomKt<Rate> {}
114+
impl<Rate: ArraySize> digest::zeroize::ZeroizeOnDrop for CustomKt<Rate> {}
115115

116116
/// Customized KT128 hasher with owned customization string.
117117
pub type CustomKt128 = CustomKt<U168>;

0 commit comments

Comments
 (0)