Skip to content

Commit

Permalink
Fixed the problem with BCMath causing wrong results on some systems
Browse files Browse the repository at this point in the history
  • Loading branch information
baibaratsky committed Apr 19, 2015
1 parent 6d70bb9 commit e0a3d71
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Signer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e0a3d71

Please sign in to comment.