Skip to content

Commit

Permalink
crypto: sm3 - fix undefined shift by >= width of value
Browse files Browse the repository at this point in the history
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: <[email protected]> # v4.15+
Cc: Gilad Ben-Yossef <[email protected]>
Signed-off-by: Eric Biggers <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
ebiggers authored and herbertx committed Jan 10, 2019
1 parent 1bea445 commit d45a90c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crypto/sm3_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void sm3_compress(u32 *w, u32 *wt, u32 *m)

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

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

ss2 = ss1 ^ rol32(a, 12);

Expand Down

0 comments on commit d45a90c

Please sign in to comment.