From db5aa6cff7f497dbb2ba7422260eea343bd5b248 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Wed, 7 Oct 2026 12:38:15 +0200 Subject: [PATCH] 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. --- lib/std/crypto/keccak_p.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/std/crypto/keccak_p.zig b/lib/std/crypto/keccak_p.zig index b707833e2d7a5a56cc8c38cd989ff6bee5a9b0a1..9164ba48bab7b6776ac8a4ab7f79d28b492c8120 100644 --- a/lib/std/crypto/keccak_p.zig +++ b/lib/std/crypto/keccak_p.zig @@ -177,8 +177,9 @@ pub fn KeccakF(comptime f: u11) type { /// Apply a (possibly) reduced-round permutation to the state. pub fn permuteR(self: *Self, comptime rounds: u5) void { + comptime assert(rounds <= max_rounds); // Keccak only supports up to 24 rounds var i = RC.len - rounds; - while (i < RC.len - RC.len % 3) : (i += 3) { + while (i < RC.len - rounds % 3) : (i += 3) { self.round(RC[i]); self.round(RC[i + 1]); self.round(RC[i + 2]); -- 2.54.0