[PATCH] crypto: rsassa-pkcs1: use constant-time comparison for digest and signature verification

From: David C.C.M. Gall

Date: Fri Jul 10 2026 - 13:30:41 EST


Replace memcmp() with crypto_memneq() for cryptographic digest and
signature comparisons to prevent timing side-channel attacks.

crypto/rsassa-pkcs1.c: RSA signature digest verification used memcmp
which can leak valid prefix length via timing analysis, user data
could reach the leaky comparison via the digest argument to verify.

Assisted-by: gregkh_clanker_t1000
Signed-off-by: David C.C.M. Gall <david.ccm.gall@xxxxxxxxxxxxxx>
---
crypto/rsassa-pkcs1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/rsassa-pkcs1.c b/crypto/rsassa-pkcs1.c
index 94fa5e9600e7..a612a9eef2dd 100644
--- a/crypto/rsassa-pkcs1.c
+++ b/crypto/rsassa-pkcs1.c
@@ -291,7 +291,7 @@ static int rsassa_pkcs1_verify(struct crypto_sig *tfm,
/* RFC 8017 sec 8.2.2 step 4 - comparison of digest with out_buf */
if (dlen != dst_len - pos)
return -EKEYREJECTED;
- if (memcmp(digest, out_buf + pos, dlen) != 0)
+ if (crypto_memneq(digest, out_buf + pos, dlen))
return -EKEYREJECTED;

return 0;
--
2.43.0