: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$b1 = (($b1 | $x0) >> 1);
$b2 = (($b2 | $x1) >> 1);
$b3 = (($b3 | $x2) >> 1);
$return->limbs[0] = $ret0;
$return->limbs[1] = $ret1;
$return->limbs[2] = $ret2;
$return->limbs[3] = $ret3;
* OR this 64-bit integer with another.
* @param ParagonIE_Sodium_Core32_Int64 $b
* @return ParagonIE_Sodium_Core32_Int64
public function orInt64(ParagonIE_Sodium_Core32_Int64 $b)
$return = new ParagonIE_Sodium_Core32_Int64();
$return->unsignedInt = $this->unsignedInt;
(int) ($this->limbs[0] | $b->limbs[0]),
(int) ($this->limbs[1] | $b->limbs[1]),
(int) ($this->limbs[2] | $b->limbs[2]),
(int) ($this->limbs[3] | $b->limbs[3])
* @return ParagonIE_Sodium_Core32_Int64
* @throws SodiumException
* @psalm-suppress MixedArrayAccess
public function rotateLeft($c = 0)
ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
$return = new ParagonIE_Sodium_Core32_Int64();
$return->unsignedInt = $this->unsignedInt;
// NOP, but we want a copy.
$return->limbs = $this->limbs;
/** @var array<int, int> $limbs */
$limbs =& $return->limbs;
/** @var array<int, int> $myLimbs */
$myLimbs =& $this->limbs;
/** @var int $idx_shift */
$idx_shift = ($c >> 4) & 3;
/** @var int $sub_shift */
for ($i = 3; $i >= 0; --$i) {
$j = ($i + $idx_shift) & 3;
$k = ($i + $idx_shift + 1) & 3;
((int) ($myLimbs[$j]) << $sub_shift)
((int) ($myLimbs[$k]) >> (16 - $sub_shift))
* @return ParagonIE_Sodium_Core32_Int64
* @throws SodiumException
* @psalm-suppress MixedArrayAccess
public function rotateRight($c = 0)
ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
/** @var ParagonIE_Sodium_Core32_Int64 $return */
$return = new ParagonIE_Sodium_Core32_Int64();
$return->unsignedInt = $this->unsignedInt;
// NOP, but we want a copy.
$return->limbs = $this->limbs;
/** @var array<int, int> $limbs */
$limbs =& $return->limbs;
/** @var array<int, int> $myLimbs */
$myLimbs =& $this->limbs;
/** @var int $idx_shift */
$idx_shift = ($c >> 4) & 3;
/** @var int $sub_shift */
for ($i = 3; $i >= 0; --$i) {
$j = ($i - $idx_shift) & 3;
$k = ($i - $idx_shift - 1) & 3;
((int) ($myLimbs[$j]) >> (int) ($sub_shift))
((int) ($myLimbs[$k]) << (16 - (int) ($sub_shift)))
* @return ParagonIE_Sodium_Core32_Int64
* @throws SodiumException
public function shiftLeft($c = 0)
ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
$return = new ParagonIE_Sodium_Core32_Int64();
$return->unsignedInt = $this->unsignedInt;
$this->limbs[2], $this->limbs[3], 0, 0
$this->limbs[1], $this->limbs[2], $this->limbs[3], 0
return $return->shiftLeft($c & 15);
$return->limbs = $this->limbs;
return $this->shiftRight(-$c);
for ($i = 3; $i >= 0; --$i) {
$tmp = ($this->limbs[$i] << $c) | ($carry & 0xffff);
$return->limbs[$i] = (int) ($tmp & 0xffff);
* @return ParagonIE_Sodium_Core32_Int64
* @throws SodiumException
public function shiftRight($c = 0)
ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
$return = new ParagonIE_Sodium_Core32_Int64();
$return->unsignedInt = $this->unsignedInt;
$negative = -(($this->limbs[0] >> 15) & 1);
(int) ($negative & 0xffff),
(int) ($negative & 0xffff),
(int) ($negative & 0xffff),
(int) ($negative & 0xffff),
(int) ($negative & 0xffff),
(int) ($negative & 0xffff),
return $return->shiftRight($c & 15);
$return->limbs = $this->limbs;
return $this->shiftLeft(-$c);
/** @var int $carryRight */
$carryRight = ($negative & 0xffff);
$mask = (int) (((1 << ($c + 1)) - 1) & 0xffff);
for ($i = 0; $i < 4; ++$i) {
$return->limbs[$i] = (int) (
(($this->limbs[$i] >> $c) | ($carryRight << (16 - $c))) & 0xffff
$carryRight = (int) ($this->limbs[$i] & $mask);
* Subtract a normal integer from an int64 object.
* @return ParagonIE_Sodium_Core32_Int64
* @throws SodiumException
public function subInt($int)
ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
$return = new ParagonIE_Sodium_Core32_Int64();
$return->unsignedInt = $this->unsignedInt;
for ($i = 3; $i >= 0; --$i) {
$tmp = $this->limbs[$i] - (($int >> 16) & 0xffff) + $carry;
$return->limbs[$i] = (int) ($tmp & 0xffff);
* The difference between two Int64 objects.
* @param ParagonIE_Sodium_Core32_Int64 $b
* @return ParagonIE_Sodium_Core32_Int64
public function subInt64(ParagonIE_Sodium_Core32_Int64 $b)
$return = new ParagonIE_Sodium_Core32_Int64();
$return->unsignedInt = $this->unsignedInt;
for ($i = 3; $i >= 0; --$i) {
$tmp = $this->limbs[$i] - $b->limbs[$i] + $carry;
$return->limbs[$i] = (int) ($tmp & 0xffff);
* XOR this 64-bit integer with another.
* @param ParagonIE_Sodium_Core32_Int64 $b
* @return ParagonIE_Sodium_Core32_Int64
public function xorInt64(ParagonIE_Sodium_Core32_Int64 $b)
$return = new ParagonIE_Sodium_Core32_Int64();
$return->unsignedInt = $this->unsignedInt;
(int) ($this->limbs[0] ^ $b->limbs[0]),
(int) ($this->limbs[1] ^ $b->limbs[1]),
(int) ($this->limbs[2] ^ $b->limbs[2]),
(int) ($this->limbs[3] ^ $b->limbs[3])
* @throws SodiumException
public static function fromInts($low, $high)
ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
ParagonIE_Sodium_Core32_Util::declareScalarType($high, 'int', 2);
return new ParagonIE_Sodium_Core32_Int64(
(int) (($high >> 16) & 0xffff),
(int) (($low >> 16) & 0xffff),
* @throws SodiumException
public static function fromInt($low)
ParagonIE_Sodium_Core32_Util::declareScalarType($low, 'int', 1);
return new ParagonIE_Sodium_Core32_Int64(
(int) (($low >> 16) & 0xffff),
(($this->limbs[2] & 0xffff) << 16)
($this->limbs[3] & 0xffff)
* @throws SodiumException
public static function fromString($string)
ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
$string = (string) $string;
if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
throw new RangeException(
'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
$return = new ParagonIE_Sodium_Core32_Int64();
$return->limbs[0] = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff) << 8);
$return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff);
$return->limbs[1] = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff) << 8);
$return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff);
$return->limbs[2] = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[4]) & 0xff) << 8);
$return->limbs[2] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[5]) & 0xff);
$return->limbs[3] = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[6]) & 0xff) << 8);
$return->limbs[3] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[7]) & 0xff);
* @throws SodiumException
public static function fromReverseString($string)
ParagonIE_Sodium_Core32_Util::declareScalarType($string, 'string', 1);
$string = (string) $string;
if (ParagonIE_Sodium_Core32_Util::strlen($string) !== 8) {
throw new RangeException(
'String must be 8 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
$return = new ParagonIE_Sodium_Core32_Int64();
$return->limbs[0] = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[7]) & 0xff) << 8);
$return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[6]) & 0xff);
$return->limbs[1] = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[5]) & 0xff) << 8);
$return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[4]) & 0xff);
$return->limbs[2] = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff) << 8);
$return->limbs[2] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff);
$return->limbs[3] = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff) << 8);
$return->limbs[3] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff);
* @return array<int, int>
public function toArray()
(int) ((($this->limbs[0] & 0xffff) << 16) | ($this->limbs[1] & 0xffff)),
(int) ((($this->limbs[2] & 0xffff) << 16) | ($this->limbs[3] & 0xffff))
* @return ParagonIE_Sodium_Core32_Int32
public function toInt32()
$return = new ParagonIE_Sodium_Core32_Int32();
$return->limbs[0] = (int) ($this->limbs[2]);
$return->limbs[1] = (int) ($this->limbs[3]);
$return->unsignedInt = $this->unsignedInt;
$return->overflow = (int) (ParagonIE_Sodium_Core32_Util::abs($this->limbs[1], 16) & 0xffff);
* @return ParagonIE_Sodium_Core32_Int64
public function toInt64()