From 4aac31bf0937f9169f75a8e173b1d9ae03158ab7 Mon Sep 17 00:00:00 2001 From: Paul Adelsbach Date: Mon, 30 Mar 2026 13:16:10 -0700 Subject: [PATCH] Cast to unsigned prior to shift to avoid UB in SLH-DSA --- wolfcrypt/src/wc_slhdsa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/wc_slhdsa.c b/wolfcrypt/src/wc_slhdsa.c index 46adf35f72..65926a4334 100644 --- a/wolfcrypt/src/wc_slhdsa.c +++ b/wolfcrypt/src/wc_slhdsa.c @@ -5768,7 +5768,7 @@ static void slhdsakey_set_ha_from_md(SlhDsaKey* key, const byte* md, /* Step 9/12: Mask off any extra high bits. */ bits = key->params->h - (key->params->h / key->params->d); if (bits < 64) { - t[1] &= (1 << (bits - 32)) - 1; + t[1] &= ((word32)1 << (bits - 32)) - 1; } /* Step 8/11: Get pointer to tree leaf index data. */ @@ -5777,7 +5777,7 @@ static void slhdsakey_set_ha_from_md(SlhDsaKey* key, const byte* md, ato32(p, l); /* Step 10/13: Mask off any extra high bits. */ bits = key->params->h / key->params->d; - *l &= (1 << bits) - 1; + *l &= ((word32)1 << bits) - 1; /* Step 11/14: Set the tree index into address. */ HA_SetTreeAddress(adrs, t);