From 6d70bb98108ab5a99b038d73d80cb8041ff1ab33 Mon Sep 17 00:00:00 2001 From: baibaratsky Date: Sat, 18 Apr 2015 02:03:04 +0300 Subject: [PATCH 1/2] Bug fixed in bcpowmod --- Signer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Signer.php b/Signer.php index 2d364b6..0b16b19 100644 --- a/Signer.php +++ b/Signer.php @@ -62,7 +62,7 @@ public function sign($data) $base = pack('v', strlen($base)) . $base; // Modular exponentiation - $dec = bcpowmod(self::reverseToDecimal($base), $this->power, $this->modulus); + $dec = bcpowmod(self::reverseToDecimal($base), $this->power, $this->modulus, 0); // Convert result to hexadecimal $hex = self::dec2hex($dec); From e0a3d7129fce2d4865ed1a14eaabc1f530d7283e Mon Sep 17 00:00:00 2001 From: baibaratsky Date: Sun, 19 Apr 2015 12:06:57 +0300 Subject: [PATCH 2/2] Fixed the problem with BCMath causing wrong results on some systems --- Signer.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Signer.php b/Signer.php index 0b16b19..3979d7b 100644 --- a/Signer.php +++ b/Signer.php @@ -64,7 +64,7 @@ public function sign($data) // Modular exponentiation $dec = bcpowmod(self::reverseToDecimal($base), $this->power, $this->modulus, 0); - // Convert result to hexadecimal + // Convert to hexadecimal $hex = self::dec2hex($dec); // Fill empty bytes with zeros @@ -199,7 +199,8 @@ private static function hex2decBC($hex) { return bcadd( (string)hexdec($last), - bcmul('16', self::hex2decBC($rest)) + bcmul('16', self::hex2decBC($rest), 0), + 0 ); } @@ -228,7 +229,7 @@ private static function dec2hex($dec) */ private static function dec2hexBC($dec) { $remainder = bcmod($dec, '16'); - $quotient = bcdiv(bcsub($dec, $remainder), '16'); + $quotient = bcdiv(bcsub($dec, $remainder, 0), '16', 0); if ($quotient == 0) { return dechex($remainder);