From 1dffcffb803886b5546dabdce756997a4fc65c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Wed, 20 May 2026 10:16:37 -0700 Subject: [PATCH] Fix hashType comparison in SLH-DSA --- wolfcrypt/src/wc_slhdsa.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/wolfcrypt/src/wc_slhdsa.c b/wolfcrypt/src/wc_slhdsa.c index 00ff711f4b..cb97e1623a 100644 --- a/wolfcrypt/src/wc_slhdsa.c +++ b/wolfcrypt/src/wc_slhdsa.c @@ -8295,11 +8295,9 @@ int wc_SlhDsaKey_SignHash(SlhDsaKey* key, const byte* ctx, byte ctxSz, else if ((key->flags & WC_SLHDSA_FLAG_PRIVATE) == 0) { ret = MISSING_KEY; } - /* The cryptocb path below casts hashType to word32 to fit the - * wc_CryptoInfo.preHashType field. Reject negative enum values here so - * the cast can't smuggle a huge unsigned value past the callback (the - * downstream prehash validator only inspects values it knows about). */ - else if ((int)hashType < 0) { + /* First sanity check on hashType; the downstream prehash validator does + * the detailed check for the actual type. */ + else if ((word32)hashType > (word32)WC_HASH_TYPE_MAX) { ret = BAD_FUNC_ARG; } @@ -8421,11 +8419,9 @@ int wc_SlhDsaKey_VerifyHash(SlhDsaKey* key, const byte* ctx, byte ctxSz, else if ((key->flags & WC_SLHDSA_FLAG_PUBLIC) == 0) { ret = MISSING_KEY; } - /* The cryptocb path below casts hashType to word32 to fit the - * wc_CryptoInfo.preHashType field. Reject negative enum values here so - * the cast can't smuggle a huge unsigned value past the callback (the - * downstream prehash validator only inspects values it knows about). */ - else if ((int)hashType < 0) { + /* First sanity check on hashType; the downstream prehash validator does + * the detailed check for the actual type. */ + else if ((word32)hashType > (word32)WC_HASH_TYPE_MAX) { ret = BAD_FUNC_ARG; }