Skip to content

Commit

Permalink
Merge pull request #2 from baibaratsky/test
Browse files Browse the repository at this point in the history
BCMath problem fixed
  • Loading branch information
baibaratsky committed Apr 20, 2015
2 parents b590c54 + e0a3d71 commit 13d316b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Signer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ 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
// 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 13d316b

Please sign in to comment.