From d1cadd145199040299538891ab2ccd1208f7776e Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Wed, 30 Oct 2013 08:57:15 +0200 Subject: bithelp: fix undefined behaviour with rol and ror * cipher/bithelp.h (rol, ror): Mask shift with 31. -- Signed-off-by: Jussi Kivilinna --- cipher/bithelp.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cipher/bithelp.h') diff --git a/cipher/bithelp.h b/cipher/bithelp.h index 601ecac6..418bdf5c 100644 --- a/cipher/bithelp.h +++ b/cipher/bithelp.h @@ -26,14 +26,14 @@ /**************** * Rotate the 32 bit unsigned integer X by N bits left/right */ -static inline u32 rol( u32 x, int n) +static inline u32 rol(u32 x, int n) { - return ( (x << n) | (x >> (32-n)) ); + return ( (x << (n&(32-1))) | (x >> ((32-n)&(32-1))) ); } static inline u32 ror(u32 x, int n) { - return ( (x >> n) | (x << (32-n)) ); + return ( (x >> (n&(32-1))) | (x << ((32-n)&(32-1))) ); } /* Byte swap for 32-bit and 64-bit integers. If available, use compiler -- cgit v1.2.1