>From 92128f12a18372eefe01f8ee8c795305657715c7 Mon Sep 17 00:00:00 2001
Message-ID: <92128f12a18372eefe01f8ee8c795305657715c7.1789017384.git.gniibe@fsij.org>
From: NIIBE Yutaka <gniibe@fsij.org>
Date: Thu, 10 Sep 2026 14:14:24 +0900
Subject: [PATCH] cipher:keccak: Fix padding in cSHAKE.
To: gcrypt-devel@gnupg.org
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.47.3"

This is a multi-part message in MIME format.
--------------2.47.3
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


* cipher/keccak.c (cshake_input_s): Fix PADLEN calculation.

--

Reported-by: Jonathan Plata
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
---
 cipher/keccak.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


--------------2.47.3
Content-Type: text/x-patch; name="0001-cipher-keccak-Fix-padding-in-cSHAKE.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-cipher-keccak-Fix-padding-in-cSHAKE.patch"

diff --git a/cipher/keccak.c b/cipher/keccak.c
index a0ba1fbb..5687e876 100644
--- a/cipher/keccak.c
+++ b/cipher/keccak.c
@@ -1694,7 +1694,8 @@ cshake_input_s (KECCAK_CONTEXT *ctx, const void *s, unsigned int s_len,
   keccak_write (ctx, s, s_len);
 
   len_written += buf[0] + 1 + s_len;
-  padlen = ctx->blocksize - (len_written % ctx->blocksize);
+  padlen = ctx->blocksize - 1
+    - (len_written + ctx->blocksize - 1) % ctx->blocksize;
   memset (buf, 0, padlen);
   keccak_write (ctx, buf, padlen);
 }

--------------2.47.3--


