mirror of
https://github.com/danog/tgseclib.git
synced 2024-11-30 04:39:02 +01:00
Merge branch '1.0' into 2.0
This commit is contained in:
commit
bd6dbd0695
@ -545,7 +545,7 @@ class BigInteger
|
||||
$bytes = chr(0);
|
||||
}
|
||||
|
||||
if (ord($bytes[0]) & 0x80) {
|
||||
if ($this->precision <= 0 && (ord($bytes[0]) & 0x80)) {
|
||||
$bytes = chr(0) . $bytes;
|
||||
}
|
||||
|
||||
@ -707,6 +707,7 @@ class BigInteger
|
||||
}
|
||||
|
||||
$temp = $this->copy();
|
||||
$temp->bitmask = false;
|
||||
$temp->is_negative = false;
|
||||
|
||||
$divisor = new static();
|
||||
@ -3569,7 +3570,14 @@ class BigInteger
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
if ($this->bitmask !== false) {
|
||||
$flip = gmp_cmp($result->value, gmp_init(0)) < 0;
|
||||
if ($flip) {
|
||||
$result->value = gmp_neg($result->value);
|
||||
}
|
||||
$result->value = gmp_and($result->value, $result->bitmask->value);
|
||||
if ($flip) {
|
||||
$result->value = gmp_neg($result->value);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
@ -431,4 +431,21 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
|
||||
$temp = $this->getInstance('-0');
|
||||
$this->assertSame($temp->toString(), '0');
|
||||
}
|
||||
|
||||
public function testNegativePrecision()
|
||||
{
|
||||
$vals = [
|
||||
'-9223372036854775808', // eg. 8000 0000 0000 0000
|
||||
'-1'
|
||||
];
|
||||
foreach ($vals as $val) {
|
||||
$x = $this->getInstance($val);
|
||||
$x->setPrecision(64); // ie. 8 bytes
|
||||
$this->assertSame($val, "$x");
|
||||
$r = $x->toBytes(true);
|
||||
$this->assertSame(8, strlen($r));
|
||||
$x2 = $this->getInstance($r, -256);
|
||||
$this->assertSame(0, $x->compare($x2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user