diff --git a/phpseclib/Crypt/Hash.php b/phpseclib/Crypt/Hash.php index 2d01807b..4825c70d 100644 --- a/phpseclib/Crypt/Hash.php +++ b/phpseclib/Crypt/Hash.php @@ -1322,9 +1322,10 @@ class Hash list($lo, $hi) = $x; } + $mask = -1 ^ (-1 << $shift); return [ - ($hi << $shift) | (($lo >> (32 - $shift)) & (1 << $shift) - 1), - ($lo << $shift) | (($hi >> (32 - $shift)) & (1 << $shift) - 1) + ($hi << $shift) | (($lo >> (32 - $shift)) & $mask), + ($lo << $shift) | (($hi >> (32 - $shift)) & $mask) ]; } @@ -1481,7 +1482,8 @@ class Hash */ private static function rotateLeft64($x, $shift) { - return ($x << $shift) | (($x >> (64 - $shift)) & ((1 << $shift) - 1)); + $mask = -1 ^ (-1 << $shift); + return ($x << $shift) | (($x >> (64 - $shift)) & $mask); } /**