Skip to content

Commit 54844f2

Browse files
committed
use one round permutation for tests
1 parent 9373ebb commit 54844f2

2 files changed

Lines changed: 43 additions & 43 deletions

File tree

0 Bytes
Binary file not shown.

sponge-cursor/tests/mod.rs

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const CHUNK_SIZES: &[usize] = &[1, 17, 133, 139, 203, 300];
88
static SHORT_DATA: [u8; 12] = *b"hello world!";
99

1010
#[allow(clippy::cast_possible_truncation)]
11-
static DATA: [u8; DATA_LEN] = {
11+
static LONG_DATA: [u8; DATA_LEN] = {
1212
let mut buf = [0u8; DATA_LEN];
1313
let mut i = 0;
1414
while i < buf.len() {
@@ -26,50 +26,50 @@ static CONCAT_DATA: [u8; SHORT_DATA.len() + DATA_LEN] = {
2626
buf[i] = if i < SHORT_DATA.len() {
2727
SHORT_DATA[i]
2828
} else {
29-
DATA[i - SHORT_DATA.len()]
29+
LONG_DATA[i - SHORT_DATA.len()]
3030
};
3131
i += 1;
3232
}
3333
buf
3434
};
3535

36-
static STATE1: State1600 = [
37-
0x9C40D618E6055156,
38-
0x44755CBBEAEBC6F9,
39-
0xF903B381412808D8,
40-
0x0339BEC23E8A90AB,
41-
0xF32F96B8456CB8AF,
42-
0xCE6349D647F4BE3C,
43-
0x1AA37FEB280A570F,
44-
0x99233F523925282C,
45-
0x835AA18F6EEA40E5,
46-
0xAEEFA72F28932C4C,
47-
0x8A602BA780C75936,
48-
0x16E389AAA33064F0,
49-
0xB2889A3A30E2DCC3,
50-
0x052546C55F62FF34,
51-
0xD7146414F4796631,
52-
0x77EE6E84441B567A,
53-
0xE2C698D4357E57AF,
54-
0x744AE4F10636A122,
55-
0x020E03048CD9CD5E,
56-
0x43C4B8081CF9C548,
57-
0x81A3AED00DD27357,
58-
0x54159D6C3AF969DE,
59-
0xD73C4B34CAB22195,
60-
0xEDD07D1D23162C0D,
61-
0x87CBF66555849682,
36+
static STATE: State1600 = [
37+
0xB2970DE4121985B5,
38+
0x29C223B87687A340,
39+
0x4A146BF36ABB1CC8,
40+
0x3D3BCBE920587765,
41+
0x8293EBA8BC356351,
42+
0x329C7414B019521A,
43+
0x5E733DF382609717,
44+
0x20F3B803705BCC28,
45+
0xB1A1DCC9DC4FCD20,
46+
0x084A6874972249D7,
47+
0x85C9D5D5437F2081,
48+
0x84E9EDD8482329E0,
49+
0x2E6259B24480185D,
50+
0x9B9F2680A9872C6A,
51+
0xCB08DC6DF5ADBB78,
52+
0x12BBABF030B4A3DE,
53+
0x82F72D4928A50AE4,
54+
0x1D071289E249ACB5,
55+
0x701BC30DFA4E5DF5,
56+
0xBA4910413F89A74E,
57+
0x3CCD8011250F3584,
58+
0x9548960143837F4C,
59+
0xC025CF3059BE5E14,
60+
0x0863BB97DA339D82,
61+
0x207CEB1D10C336C4,
6262
];
6363

6464
static SQUEEZE_DATA: &[u8; DATA_LEN] = include_bytes!("data/squeeze.bin");
6565

6666
#[test]
6767
fn keccak_test() {
68-
Keccak::new().with_f1600(|f1600| {
68+
Keccak::new().with_p1600::<1>(|p1600| {
6969
let mut cursor = SpongeCursor::<136>::default();
7070
let mut state = State1600::default();
7171

72-
cursor.absorb_u64_le(&mut state, f1600, &SHORT_DATA);
72+
cursor.absorb_u64_le(&mut state, p1600, &SHORT_DATA);
7373
assert_eq!(state[0], 0x6F77_206F_6C6C_6568);
7474
assert_eq!(state[1], 0x0000_0000_2164_6C72);
7575
assert!(state[2..].iter().all(|v| *v == 0));
@@ -78,15 +78,15 @@ fn keccak_test() {
7878
let short_len = u8::try_from(SHORT_DATA.len()).unwrap();
7979
assert_eq!(cursor, SpongeCursor::new(short_len).unwrap());
8080

81-
let expected_pos = (SHORT_DATA.len() + DATA.len()) % 136;
81+
let expected_pos = (SHORT_DATA.len() + LONG_DATA.len()) % 136;
8282
for &chunk_size in CHUNK_SIZES {
8383
let mut state_copy = state;
8484
let mut cursor_copy = cursor.clone();
8585

86-
for chunk in DATA.chunks(chunk_size) {
87-
cursor_copy.absorb_u64_le(&mut state_copy, f1600, chunk);
86+
for chunk in LONG_DATA.chunks(chunk_size) {
87+
cursor_copy.absorb_u64_le(&mut state_copy, p1600, chunk);
8888
}
89-
assert_eq!(state_copy, STATE1);
89+
assert_eq!(state_copy, STATE);
9090
assert_eq!(cursor_copy.pos(), expected_pos);
9191
assert_eq!(usize::from(cursor_copy.raw_pos()), expected_pos);
9292
}
@@ -95,39 +95,39 @@ fn keccak_test() {
9595
let mut cursor = SpongeCursor::<136>::default();
9696
let mut state = State1600::default();
9797

98-
cursor.absorb_u64_le(&mut state, f1600, &CONCAT_DATA);
99-
assert_eq!(state, STATE1);
98+
cursor.absorb_u64_le(&mut state, p1600, &CONCAT_DATA);
99+
assert_eq!(state, STATE);
100100
assert_eq!(cursor.pos(), expected_pos);
101101
assert_eq!(usize::from(cursor.raw_pos()), expected_pos);
102102
}
103103

104-
cursor.absorb_u64_le(&mut state, f1600, &DATA);
105-
assert_eq!(state, STATE1);
104+
cursor.absorb_u64_le(&mut state, p1600, &LONG_DATA);
105+
assert_eq!(state, STATE);
106106
assert_eq!(cursor.pos(), expected_pos);
107107
assert_eq!(usize::from(cursor.raw_pos()), expected_pos);
108108

109-
f1600(&mut state);
109+
p1600(&mut state);
110110

111111
for &chunk_size in CHUNK_SIZES {
112112
let mut buf = [0u8; DATA_LEN];
113113
cursor = Default::default();
114114
let mut state_copy = state;
115115

116116
for chunk in buf.chunks_mut(chunk_size) {
117-
cursor.squeeze_read_u64_le(&mut state_copy, f1600, chunk);
117+
cursor.squeeze_read_u64_le(&mut state_copy, p1600, chunk);
118118
}
119119

120120
assert_eq!(&buf, SQUEEZE_DATA);
121121
}
122122

123-
let expected: [u8; DATA_LEN] = core::array::from_fn(|i| DATA[i] ^ SQUEEZE_DATA[i]);
123+
let expected: [u8; DATA_LEN] = core::array::from_fn(|i| LONG_DATA[i] ^ SQUEEZE_DATA[i]);
124124
for &chunk_size in CHUNK_SIZES {
125-
let mut buf = DATA;
125+
let mut buf = LONG_DATA;
126126
cursor = Default::default();
127127
let mut state_copy = state;
128128

129129
for chunk in buf.chunks_mut(chunk_size) {
130-
cursor.squeeze_xor_u64_le(&mut state_copy, f1600, chunk);
130+
cursor.squeeze_xor_u64_le(&mut state_copy, p1600, chunk);
131131
}
132132

133133
assert_eq!(buf, expected);

0 commit comments

Comments
 (0)