MCPcopy Create free account
hub / github.com/RustCrypto/utils / keccak_test

Function keccak_test

sponge-cursor/tests/mod.rs:67–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65
66#[test]
67fn keccak_test() {
68 Keccak::new().with_p1600::<1>(|p1600| {
69 let mut cursor = SpongeCursor::<136>::default();
70 let mut state = State1600::default();
71
72 cursor.absorb_u64_le(&mut state, p1600, &SHORT_DATA);
73 assert_eq!(state[0], 0x6F77_206F_6C6C_6568);
74 assert_eq!(state[1], 0x0000_0000_2164_6C72);
75 assert!(state[2..].iter().all(|v| *v == 0));
76 assert_eq!(cursor.pos(), SHORT_DATA.len());
77 assert_eq!(usize::from(cursor.raw_pos()), SHORT_DATA.len());
78 let short_len = u8::try_from(SHORT_DATA.len()).unwrap();
79 assert_eq!(cursor, SpongeCursor::new(short_len).unwrap());
80
81 let expected_pos = (SHORT_DATA.len() + LONG_DATA.len()) % 136;
82 for &chunk_size in CHUNK_SIZES {
83 let mut state_copy = state;
84 let mut cursor_copy = cursor.clone();
85
86 for chunk in LONG_DATA.chunks(chunk_size) {
87 cursor_copy.absorb_u64_le(&mut state_copy, p1600, chunk);
88 }
89 assert_eq!(state_copy, STATE);
90 assert_eq!(cursor_copy.pos(), expected_pos);
91 assert_eq!(usize::from(cursor_copy.raw_pos()), expected_pos);
92 }
93
94 {
95 let mut cursor = SpongeCursor::<136>::default();
96 let mut state = State1600::default();
97
98 cursor.absorb_u64_le(&mut state, p1600, &CONCAT_DATA);
99 assert_eq!(state, STATE);
100 assert_eq!(cursor.pos(), expected_pos);
101 assert_eq!(usize::from(cursor.raw_pos()), expected_pos);
102 }
103
104 cursor.absorb_u64_le(&mut state, p1600, &LONG_DATA);
105 assert_eq!(state, STATE);
106 assert_eq!(cursor.pos(), expected_pos);
107 assert_eq!(usize::from(cursor.raw_pos()), expected_pos);
108
109 p1600(&mut state);
110
111 for &chunk_size in CHUNK_SIZES {
112 let mut buf = [0u8; DATA_LEN];
113 cursor = Default::default();
114 let mut state_copy = state;
115
116 for chunk in buf.chunks_mut(chunk_size) {
117 cursor.squeeze_read_u64_le(&mut state_copy, p1600, chunk);
118 }
119
120 assert_eq!(&buf, SQUEEZE_DATA);
121 }
122
123 let expected: [u8; DATA_LEN] = core::array::from_fn(|i| LONG_DATA[i] ^ SQUEEZE_DATA[i]);
124 for &chunk_size in CHUNK_SIZES {

Callers

nothing calls this directly

Calls 7

defaultFunction · 0.85
absorb_u64_leMethod · 0.80
lenMethod · 0.80
squeeze_read_u64_leMethod · 0.80
squeeze_xor_u64_leMethod · 0.80
unwrapMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected