: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @return ParagonIE_Sodium_Core32_Int32
* @throws SodiumException
* @psalm-suppress MixedArrayAccess
public function rotateRight($c = 0)
ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
$return = new ParagonIE_Sodium_Core32_Int32();
$return->unsignedInt = $this->unsignedInt;
// NOP, but we want a copy.
$return->limbs = $this->limbs;
/** @var int $idx_shift */
$idx_shift = ($c >> 4) & 1;
/** @var int $sub_shift */
/** @var array<int, int> $limbs */
$limbs =& $return->limbs;
/** @var array<int, int> $myLimbs */
$myLimbs =& $this->limbs;
for ($i = 1; $i >= 0; --$i) {
$j = ($i - $idx_shift) & 1;
$k = ($i - $idx_shift - 1) & 1;
((int) ($myLimbs[$j]) >> (int) ($sub_shift))
((int) ($myLimbs[$k]) << (16 - (int) ($sub_shift)))
public function setUnsignedInt($bool = false)
$this->unsignedInt = !empty($bool);
* @return ParagonIE_Sodium_Core32_Int32
* @throws SodiumException
public function shiftLeft($c = 0)
ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
$return = new ParagonIE_Sodium_Core32_Int32();
$return->unsignedInt = $this->unsignedInt;
$return->limbs = $this->limbs;
return $this->shiftRight(-$c);
$tmp = $this->limbs[1] << $c;
$return->limbs[1] = (int)($tmp & 0xffff);
$tmp = ($this->limbs[0] << $c) | ($carry & 0xffff);
$return->limbs[0] = (int) ($tmp & 0xffff);
* @return ParagonIE_Sodium_Core32_Int32
* @throws SodiumException
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedOperand
public function shiftRight($c = 0)
ParagonIE_Sodium_Core32_Util::declareScalarType($c, 'int', 1);
$return = new ParagonIE_Sodium_Core32_Int32();
$return->unsignedInt = $this->unsignedInt;
(int) ($this->overflow & 0xffff),
$return->overflow = $this->overflow >> 16;
return $return->shiftRight($c & 15);
$return->limbs = $this->limbs;
return $this->shiftLeft(-$c);
// $return->limbs[0] = (int) (($this->limbs[0] >> $c) & 0xffff);
$carryLeft = (int) ($this->overflow & ((1 << ($c + 1)) - 1));
$return->limbs[0] = (int) ((($this->limbs[0] >> $c) | ($carryLeft << (16 - $c))) & 0xffff);
$carryRight = (int) ($this->limbs[0] & ((1 << ($c + 1)) - 1));
$return->limbs[1] = (int) ((($this->limbs[1] >> $c) | ($carryRight << (16 - $c))) & 0xffff);
$return->overflow >>= $c;
* Subtract a normal integer from an int32 object.
* @return ParagonIE_Sodium_Core32_Int32
* @throws SodiumException
public function subInt($int)
ParagonIE_Sodium_Core32_Util::declareScalarType($int, 'int', 1);
$return = new ParagonIE_Sodium_Core32_Int32();
$return->unsignedInt = $this->unsignedInt;
$tmp = $this->limbs[1] - ($int & 0xffff);
$return->limbs[1] = (int) ($tmp & 0xffff);
$tmp = $this->limbs[0] - (($int >> 16) & 0xffff) + $carry;
$return->limbs[0] = (int) ($tmp & 0xffff);
* Subtract two int32 objects from each other
* @param ParagonIE_Sodium_Core32_Int32 $b
* @return ParagonIE_Sodium_Core32_Int32
public function subInt32(ParagonIE_Sodium_Core32_Int32 $b)
$return = new ParagonIE_Sodium_Core32_Int32();
$return->unsignedInt = $this->unsignedInt;
$tmp = $this->limbs[1] - ($b->limbs[1] & 0xffff);
$return->limbs[1] = (int) ($tmp & 0xffff);
$tmp = $this->limbs[0] - ($b->limbs[0] & 0xffff) + $carry;
$return->limbs[0] = (int) ($tmp & 0xffff);
* XOR this 32-bit integer with another.
* @param ParagonIE_Sodium_Core32_Int32 $b
* @return ParagonIE_Sodium_Core32_Int32
public function xorInt32(ParagonIE_Sodium_Core32_Int32 $b)
$return = new ParagonIE_Sodium_Core32_Int32();
$return->unsignedInt = $this->unsignedInt;
(int) ($this->limbs[0] ^ $b->limbs[0]),
(int) ($this->limbs[1] ^ $b->limbs[1])
* @throws SodiumException
public static function fromInt($signed)
ParagonIE_Sodium_Core32_Util::declareScalarType($signed, 'int', 1);;
return new ParagonIE_Sodium_Core32_Int32(
(int) (($signed >> 16) & 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) !== 4) {
throw new RangeException(
'String must be 4 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
$return = new ParagonIE_Sodium_Core32_Int32();
$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);
* @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) !== 4) {
throw new RangeException(
'String must be 4 bytes; ' . ParagonIE_Sodium_Core32_Util::strlen($string) . ' given.'
$return = new ParagonIE_Sodium_Core32_Int32();
$return->limbs[0] = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[3]) & 0xff) << 8);
$return->limbs[0] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[2]) & 0xff);
$return->limbs[1] = (int) ((ParagonIE_Sodium_Core32_Util::chrToInt($string[1]) & 0xff) << 8);
$return->limbs[1] |= (ParagonIE_Sodium_Core32_Util::chrToInt($string[0]) & 0xff);
* @return array<int, int>
public function toArray()
return array((int) ($this->limbs[0] << 16 | $this->limbs[1]));
public function toString()
ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff) .
ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff);
(($this->limbs[0] & 0xffff) << 16)
($this->limbs[1] & 0xffff)
* @return ParagonIE_Sodium_Core32_Int32
public function toInt32()
$return = new ParagonIE_Sodium_Core32_Int32();
$return->limbs[0] = (int) ($this->limbs[0] & 0xffff);
$return->limbs[1] = (int) ($this->limbs[1] & 0xffff);
$return->unsignedInt = $this->unsignedInt;
$return->overflow = (int) ($this->overflow & 0x7fffffff);
* @return ParagonIE_Sodium_Core32_Int64
public function toInt64()
$return = new ParagonIE_Sodium_Core32_Int64();
$return->unsignedInt = $this->unsignedInt;
if ($this->unsignedInt) {
$return->limbs[0] += (($this->overflow >> 16) & 0xffff);
$return->limbs[1] += (($this->overflow) & 0xffff);
$neg = -(($this->limbs[0] >> 15) & 1);
$return->limbs[0] = (int)($neg & 0xffff);
$return->limbs[1] = (int)($neg & 0xffff);
$return->limbs[2] = (int) ($this->limbs[0] & 0xffff);
$return->limbs[3] = (int) ($this->limbs[1] & 0xffff);
public function toReverseString()
return ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[1] & 0xff) .
ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[1] >> 8) & 0xff) .
ParagonIE_Sodium_Core32_Util::intToChr($this->limbs[0] & 0xff) .
ParagonIE_Sodium_Core32_Util::intToChr(($this->limbs[0] >> 8) & 0xff);
public function __toString()
return $this->toString();
} catch (TypeError $ex) {
// PHP engine can't handle exceptions from __toString()