From b25681beebb1c644c76778b52344b9db859e5fef Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 9 Dec 2017 18:16:48 -0600 Subject: [PATCH] fix float to int conversions on ARM CPU's --- phpseclib/Crypt/Blowfish.php | 13 ++++++++----- phpseclib/Crypt/Hash.php | 11 +++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/phpseclib/Crypt/Blowfish.php b/phpseclib/Crypt/Blowfish.php index 17c8e7e8..aa535f05 100644 --- a/phpseclib/Crypt/Blowfish.php +++ b/phpseclib/Crypt/Blowfish.php @@ -550,7 +550,7 @@ class Crypt_Blowfish extends Crypt_Base // on 32-bit linux systems with PHP < 5.3 float to integer conversion is bad switch (true) { case defined('PHP_INT_SIZE') && PHP_INT_SIZE == 8: - case version_compare(PHP_VERSION, '5.3.0') >= 0: + case version_compare(PHP_VERSION, '5.3.0') >= 0 && (php_uname('m') & "\xDF\xDF\xDF") != 'ARM': case (PHP_OS & "\xDF\xDF\xDF") === 'WIN': $safeint = '%s'; break; @@ -663,10 +663,13 @@ class Crypt_Blowfish extends Crypt_Base */ function safe_intval($x) { - // PHP 5.3, per http://php.net/releases/5_3_0.php, introduced "more consistent float rounding" - // PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster - if (is_int($x) || version_compare(PHP_VERSION, '5.3.0') >= 0 || (PHP_OS & "\xDF\xDF\xDF") === 'WIN') { - return $x; + switch (true) { + case is_int($x): + // PHP 5.3, per http://php.net/releases/5_3_0.php, introduced "more consistent float rounding" + case version_compare(PHP_VERSION, '5.3.0') >= 0 && (php_uname('m') & "\xDF\xDF\xDF") != 'ARM': + // PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster + case (PHP_OS & "\xDF\xDF\xDF") === 'WIN': + return $x; } return (fmod($x, 0x80000000) & 0x7FFFFFFF) | ((fmod(floor($x / 0x80000000), 2) & 1) << 31); diff --git a/phpseclib/Crypt/Hash.php b/phpseclib/Crypt/Hash.php index faa17c57..d69db2f8 100644 --- a/phpseclib/Crypt/Hash.php +++ b/phpseclib/Crypt/Hash.php @@ -832,10 +832,13 @@ class Crypt_Hash $result+= $argument < 0 ? ($argument & 0x7FFFFFFF) + 0x80000000 : $argument; } - // PHP 5.3, per http://php.net/releases/5_3_0.php, introduced "more consistent float rounding" - // PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster - if (is_int($result) || version_compare(PHP_VERSION, '5.3.0') >= 0 || (PHP_OS & "\xDF\xDF\xDF") === 'WIN') { - return fmod($result, $mod); + switch (true) { + case is_int($result): + // PHP 5.3, per http://php.net/releases/5_3_0.php, introduced "more consistent float rounding" + case version_compare(PHP_VERSION, '5.3.0') >= 0 && (php_uname('m') & "\xDF\xDF\xDF") != 'ARM': + // PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster + case (PHP_OS & "\xDF\xDF\xDF") === 'WIN': + return fmod($result, $mod); } return (fmod($result, 0x80000000) & 0x7FFFFFFF) |