diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-10-30 08:57:15 +0200 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2013-10-30 08:57:15 +0200 |
commit | d1cadd145199040299538891ab2ccd1208f7776e (patch) | |
tree | 0515b9cc6063cefbeb4e1a0f813287f751f6e549 /cipher/bithelp.h | |
parent | ba6bffafd17bea11985afc500022d66da261d59a (diff) | |
download | libgcrypt-d1cadd145199040299538891ab2ccd1208f7776e.tar.gz |
bithelp: fix undefined behaviour with rol and ror
* cipher/bithelp.h (rol, ror): Mask shift with 31.
--
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'cipher/bithelp.h')
-rw-r--r-- | cipher/bithelp.h | 6 |
1 files changed, 3 insertions, 3 deletions
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 |