Fix undefined behaviour in shifts.
authorEmilia Kasper <emilia@openssl.org>
Sat, 14 Mar 2015 04:10:13 +0000 (21:10 -0700)
committerEmilia Kasper <emilia@openssl.org>
Sat, 14 Mar 2015 04:14:56 +0000 (21:14 -0700)
commita2fcab9978a0905c4286051993da63329fda8a19
tree1ba8152acb8171fde5e8c0b14be933b1efd8329f
parent1a098164354e8e14e0237993cca7a0bffe820ed6
Fix undefined behaviour in shifts.

Td4 and Te4 are arrays of u8. A u8 << int promotes the u8 to an int first then shifts.
If the mathematical result of a shift (as modelled by lhs * 2^{rhs}) is not representable
in an integer, behaviour is undefined. In other words, you can't shift into the sign bit
of a signed integer. Fix this by casting to u32 whenever we're shifting left by 24.

(For consistency, cast other shifts, too.)

Caught by -fsanitize=shift

Submitted by Nick Lewycky (Google)

Reviewed-by: Andy Polyakov <appro@openssl.org>
(cherry picked from commit 8b37e5c14f0eddb10c7f91ef91004622d90ef361)
crypto/aes/aes_core.c
crypto/aes/aes_x86core.c