Skip to content

Commit 1dffcff

Browse files
committed
Fix hashType comparison in SLH-DSA
1 parent dc56e87 commit 1dffcff

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

wolfcrypt/src/wc_slhdsa.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8295,11 +8295,9 @@ int wc_SlhDsaKey_SignHash(SlhDsaKey* key, const byte* ctx, byte ctxSz,
82958295
else if ((key->flags & WC_SLHDSA_FLAG_PRIVATE) == 0) {
82968296
ret = MISSING_KEY;
82978297
}
8298-
/* The cryptocb path below casts hashType to word32 to fit the
8299-
* wc_CryptoInfo.preHashType field. Reject negative enum values here so
8300-
* the cast can't smuggle a huge unsigned value past the callback (the
8301-
* downstream prehash validator only inspects values it knows about). */
8302-
else if ((int)hashType < 0) {
8298+
/* First sanity check on hashType; the downstream prehash validator does
8299+
* the detailed check for the actual type. */
8300+
else if ((word32)hashType > (word32)WC_HASH_TYPE_MAX) {
83038301
ret = BAD_FUNC_ARG;
83048302
}
83058303

@@ -8421,11 +8419,9 @@ int wc_SlhDsaKey_VerifyHash(SlhDsaKey* key, const byte* ctx, byte ctxSz,
84218419
else if ((key->flags & WC_SLHDSA_FLAG_PUBLIC) == 0) {
84228420
ret = MISSING_KEY;
84238421
}
8424-
/* The cryptocb path below casts hashType to word32 to fit the
8425-
* wc_CryptoInfo.preHashType field. Reject negative enum values here so
8426-
* the cast can't smuggle a huge unsigned value past the callback (the
8427-
* downstream prehash validator only inspects values it knows about). */
8428-
else if ((int)hashType < 0) {
8422+
/* First sanity check on hashType; the downstream prehash validator does
8423+
* the detailed check for the actual type. */
8424+
else if ((word32)hashType > (word32)WC_HASH_TYPE_MAX) {
84298425
ret = BAD_FUNC_ARG;
84308426
}
84318427

0 commit comments

Comments
 (0)