Skip to main content

keccak_rhdl/
permutation.rs

1//! Complete `Keccak-f[1600]` permutation kernels.
2
3use rhdl::prelude::*;
4
5use crate::{
6    KeccakState, ROUND_COUNT,
7    round::{
8        keccak_round_00, keccak_round_01, keccak_round_02, keccak_round_03, keccak_round_04,
9        keccak_round_05, keccak_round_06, keccak_round_07, keccak_round_08, keccak_round_09,
10        keccak_round_10, keccak_round_11, keccak_round_12, keccak_round_13, keccak_round_14,
11        keccak_round_15, keccak_round_16, keccak_round_17, keccak_round_18, keccak_round_19,
12        keccak_round_20, keccak_round_21, keccak_round_22, keccak_round_23,
13    },
14    software_keccak_round,
15};
16
17/// Apply all 24 `Keccak-f[1600]` rounds as one combinational RHDL kernel.
18///
19/// This is intentionally explicit rather than a runtime-indexed loop: the
20/// compiler sees each round number as a literal five-bit value.  The resulting
21/// logic is deep and primarily exists for correctness testing and RTL export.
22#[kernel]
23pub fn keccak_f1600(mut state: KeccakState) -> KeccakState {
24    state = keccak_round_00(state);
25    state = keccak_round_01(state);
26    state = keccak_round_02(state);
27    state = keccak_round_03(state);
28    state = keccak_round_04(state);
29    state = keccak_round_05(state);
30    state = keccak_round_06(state);
31    state = keccak_round_07(state);
32    state = keccak_round_08(state);
33    state = keccak_round_09(state);
34    state = keccak_round_10(state);
35    state = keccak_round_11(state);
36    state = keccak_round_12(state);
37    state = keccak_round_13(state);
38    state = keccak_round_14(state);
39    state = keccak_round_15(state);
40    state = keccak_round_16(state);
41    state = keccak_round_17(state);
42    state = keccak_round_18(state);
43    state = keccak_round_19(state);
44    state = keccak_round_20(state);
45    state = keccak_round_21(state);
46    state = keccak_round_22(state);
47    keccak_round_23(state)
48}
49
50/// Independent native-Rust `Keccak-f[1600]` permutation.
51#[must_use]
52pub fn software_keccak_f1600(mut state: [u64; 25]) -> [u64; 25] {
53    for round in 0..ROUND_COUNT {
54        state = software_keccak_round(state, round);
55    }
56    state
57}