mirror of
https://github.com/phpseclib/phpseclib.git
synced 2025-01-12 18:01:09 +00:00
Hash: fix for masks at upper boundary of what signed ints allow
on 64-bit PHP installs (1 << 63) - 1 == (1 << 63) -1 ^ (-1 << 63) gives the correct result on 32-bit PHP installs (1 << 31) - 1 returns a float and using the result as a bitmask yields this error on sufficiently new versions of PHP: Deprecated: Implicit conversion from float -2147483649 to int loses precision Explicitly casting (1 << 31) - 1 to an int yields the correct result but, then again, so does -1 ^ (-1 << 31) and that one is consistent with how it works on 64-bit PHP installs
This commit is contained in:
parent
8307eb3b01
commit
28866e826b
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user