: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if (class_exists('ParagonIE_Sodium_Core_SipHash', false)) {
* Class ParagonIE_SodiumCompat_Core_SipHash
* Only uses 32-bit arithmetic, while the original SipHash used 64-bit integers
class ParagonIE_Sodium_Core_SipHash extends ParagonIE_Sodium_Core_Util
* @internal You should not use this directly from another application
public static function sipRound(array $v)
list($v[0], $v[1]) = self::add(
list($v[2], $v[3]) = self::rotl_64((int) $v[2], (int) $v[3], 13);
$v[2] = (int) $v[2] ^ (int) $v[0];
$v[3] = (int) $v[3] ^ (int) $v[1];
list($v[0], $v[1]) = self::rotl_64((int) $v[0], (int) $v[1], 32);
list($v[4], $v[5]) = self::add(
array((int) $v[4], (int) $v[5]),
array((int) $v[6], (int) $v[7])
list($v[6], $v[7]) = self::rotl_64((int) $v[6], (int) $v[7], 16);
$v[6] = (int) $v[6] ^ (int) $v[4];
$v[7] = (int) $v[7] ^ (int) $v[5];
list($v[0], $v[1]) = self::add(
array((int) $v[0], (int) $v[1]),
array((int) $v[6], (int) $v[7])
list($v[6], $v[7]) = self::rotl_64((int) $v[6], (int) $v[7], 21);
$v[6] = (int) $v[6] ^ (int) $v[0];
$v[7] = (int) $v[7] ^ (int) $v[1];
list($v[4], $v[5]) = self::add(
array((int) $v[4], (int) $v[5]),
array((int) $v[2], (int) $v[3])
list($v[2], $v[3]) = self::rotl_64((int) $v[2], (int) $v[3], 17);
$v[2] = (int) $v[2] ^ (int) $v[4];
$v[3] = (int) $v[3] ^ (int) $v[5];
list($v[4], $v[5]) = self::rotl_64((int) $v[4], (int) $v[5], 32);
* Add two 32 bit integers representing a 64-bit integer.
* @internal You should not use this directly from another application
* @return array<int, mixed>
public static function add(array $a, array $b)
$c = $x1 >> 32; // Carry if ($a + $b) > 0xffffffff
$x0 = $a[0] + $b[0] + $c;
* @internal You should not use this directly from another application
* @return array<int, mixed>
public static function rotl_64($int0, $int1, $c)
return array($int1, $int0);
return array($int0, $int1);
* Implements Siphash-2-4 using only 32-bit numbers.
* When we split an int into two, the higher bits go to the lower index.
* e.g. 0xDEADBEEFAB10C92D becomes [
* @internal You should not use this directly from another application
* @throws SodiumException
public static function sipHash24($in, $key)
$inlen = self::strlen($in);
# /* "somepseudorandomlygeneratedbytes" */
# u64 v0 = 0x736f6d6570736575ULL;
# u64 v1 = 0x646f72616e646f6dULL;
# u64 v2 = 0x6c7967656e657261ULL;
# u64 v3 = 0x7465646279746573ULL;
# u64 k0 = LOAD64_LE( k );
# u64 k1 = LOAD64_LE( k + 8 );
self::load_4(self::substr($key, 4, 4)),
self::load_4(self::substr($key, 0, 4)),
self::load_4(self::substr($key, 12, 4)),
self::load_4(self::substr($key, 8, 4))
# b = ( ( u64 )inlen ) << 56;
// See docblock for why the 0th index gets the higher bits.
# for ( ; in != end; in += 8 )
self::load_4(self::substr($in, 4, 4)),
self::load_4(self::substr($in, 0, 4))
$in = self::substr($in, 8);
# case 7: b |= ( ( u64 )in[ 6] ) << 48;
# case 6: b |= ( ( u64 )in[ 5] ) << 40;
# case 5: b |= ( ( u64 )in[ 4] ) << 32;
# case 4: b |= ( ( u64 )in[ 3] ) << 24;
# case 3: b |= ( ( u64 )in[ 2] ) << 16;
# case 2: b |= ( ( u64 )in[ 1] ) << 8;
# case 1: b |= ( ( u64 )in[ 0] ); break;
$b[0] |= self::chrToInt($in[6]) << 16;
$b[0] |= self::chrToInt($in[5]) << 8;
$b[0] |= self::chrToInt($in[4]);
$b[1] |= self::chrToInt($in[3]) << 24;
$b[1] |= self::chrToInt($in[2]) << 16;
$b[1] |= self::chrToInt($in[1]) << 8;
$b[1] |= self::chrToInt($in[0]);
// See docblock for why the 0th index gets the higher bits.
// Flip the lower 8 bits of v2 which is ($v[4], $v[5]) in our implementation
return self::store32_le($v[1] ^ $v[3] ^ $v[5] ^ $v[7]) .
self::store32_le($v[0] ^ $v[2] ^ $v[4] ^ $v[6]);