Skip to content

Commit d45a90c

Browse files
ebiggersherbertx
authored andcommitted
crypto: sm3 - fix undefined shift by >= width of value
sm3_compress() calls rol32() with shift >= 32, which causes undefined behavior. This is easily detected by enabling CONFIG_UBSAN. Explicitly AND with 31 to make the behavior well defined. Fixes: 4f0fc16 ("crypto: sm3 - add OSCCA SM3 secure hash") Cc: <stable@vger.kernel.org> # v4.15+ Cc: Gilad Ben-Yossef <gilad@benyossef.com> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 1bea445 commit d45a90c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

crypto/sm3_generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void sm3_compress(u32 *w, u32 *wt, u32 *m)
100100

101101
for (i = 0; i <= 63; i++) {
102102

103-
ss1 = rol32((rol32(a, 12) + e + rol32(t(i), i)), 7);
103+
ss1 = rol32((rol32(a, 12) + e + rol32(t(i), i & 31)), 7);
104104

105105
ss2 = ss1 ^ rol32(a, 12);
106106

0 commit comments

Comments
 (0)