authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-07 12:38:15+02:00
committergravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-10-15 10:09:06+02:00
logdb5aa6cff7f497dbb2ba7422260eea343bd5b248
treeb434bf6a90f5ef0cb7a146f674cf0e714ee71923
parentba450411c0e4086819d0790cc3ae4371823a323e

crypto.keccak_p: allow arbitrary round numbers (still <= 24)

Round numbers that were not a multiple of 3 caused an OOB. Nothing in the standard library uses a number of round that is not 12 or 24, and these are the only values used in current specifications. But we should be future proof and we already provide an API that's expected to work with any number of rounds, so honor that.

1 files changed, 2 insertions(+), 1 deletions(-)

lib/std/crypto/keccak_p.zig+2-1
...@@ -177,8 +177,9 @@ pub fn KeccakF(comptime f: u11) type {...@@ -177,8 +177,9 @@ pub fn KeccakF(comptime f: u11) type {
177177
178 /// Apply a (possibly) reduced-round permutation to the state.178 /// Apply a (possibly) reduced-round permutation to the state.
179 pub fn permuteR(self: *Self, comptime rounds: u5) void {179 pub fn permuteR(self: *Self, comptime rounds: u5) void {
180 comptime assert(rounds <= max_rounds); // Keccak only supports up to 24 rounds
180 var i = RC.len - rounds;181 var i = RC.len - rounds;
181 while (i < RC.len - RC.len % 3) : (i += 3) {182 while (i < RC.len - rounds % 3) : (i += 3) {
182 self.round(RC[i]);183 self.round(RC[i]);
183 self.round(RC[i + 1]);184 self.round(RC[i + 1]);
184 self.round(RC[i + 2]);185 self.round(RC[i + 2]);