: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
self::pseudoConstructor();
throw new SodiumException('Invalid key size');
throw new SodiumException('Invalid output size');
$p = new SplFixedArray(64);
// Zero our param buffer...
$p[0] = $outlen; // digest_length
$p[1] = $klen; // key_length
if ($salt instanceof SplFixedArray) {
// salt: [32] through [47]
for ($i = 0; $i < 16; ++$i) {
$p[32 + $i] = (int) $salt[$i];
if ($personal instanceof SplFixedArray) {
// personal: [48] through [63]
for ($i = 0; $i < 16; ++$i) {
$p[48 + $i] = (int) $personal[$i];
$ctx[0][0] = self::xor64(
if ($salt instanceof SplFixedArray || $personal instanceof SplFixedArray) {
// We need to do what blake2b_init_param() does:
for ($i = 1; $i < 8; ++$i) {
$ctx[0][$i] = self::xor64(
self::load64($p, $i << 3)
if ($klen > 0 && $key instanceof SplFixedArray) {
$block = new SplFixedArray(128);
for ($i = $klen; $i--;) {
self::update($ctx, $block, 128);
* Convert a string into an SplFixedArray of integers
* @internal You should not use this directly from another application
* @psalm-suppress MixedArgumentTypeCoercion
public static function stringToSplFixedArray($str = '')
$values = unpack('C*', $str);
return SplFixedArray::fromArray(array_values($values));
* Convert an SplFixedArray of integers into a string
* @internal You should not use this directly from another application
* @param SplFixedArray $a
public static function SplFixedArrayToString(SplFixedArray $a)
* @var array<int, string|int>
array_unshift($arr, str_repeat('C', $c));
return (string) (call_user_func_array('pack', $arr));
* @internal You should not use this directly from another application
* @param SplFixedArray $ctx
* @psalm-suppress MixedArgument
* @psalm-suppress MixedArrayAccess
* @psalm-suppress MixedArrayAssignment
* @psalm-suppress MixedMethodCall
public static function contextToString(SplFixedArray $ctx)
/** @var array<int, ParagonIE_Sodium_Core32_Int64> $ctxA */
$ctxA = $ctx[0]->toArray();
for ($i = 0; $i < 8; ++$i) {
if (!($ctxA[$i] instanceof ParagonIE_Sodium_Core32_Int64)) {
throw new TypeError('Not an instance of Int64');
/** @var ParagonIE_Sodium_Core32_Int64 $ctxAi */
$str .= $ctxAi->toReverseString();
for ($i = 1; $i < 3; ++$i) {
/** @var array<int, ParagonIE_Sodium_Core32_Int64> $ctxA */
$ctxA = $ctx[$i]->toArray();
/** @var ParagonIE_Sodium_Core32_Int64 $ctxA1 */
/** @var ParagonIE_Sodium_Core32_Int64 $ctxA2 */
$str .= $ctxA1->toReverseString();
$str .= $ctxA2->toReverseString();
$str .= self::SplFixedArrayToString($ctx[3]);
$str .= implode('', array(
self::intToChr($ctx4 & 0xff),
self::intToChr(($ctx4 >> 8) & 0xff),
self::intToChr(($ctx4 >> 16) & 0xff),
self::intToChr(($ctx4 >> 24) & 0xff),
self::intToChr(($ctx4 >> 32) & 0xff),
self::intToChr(($ctx4 >> 40) & 0xff),
self::intToChr(($ctx4 >> 48) & 0xff),
self::intToChr(($ctx4 >> 56) & 0xff)
return $str . self::intToChr($ctx[5]) . str_repeat("\x00", 23);
* Creates an SplFixedArray containing other SplFixedArray elements, from
* a string (compatible with \Sodium\crypto_generichash_{init, update, final})
* @internal You should not use this directly from another application
* @throws SodiumException
* @psalm-suppress MixedArrayAccess
* @psalm-suppress MixedArrayAssignment
public static function stringToContext($string)
for ($i = 0; $i < 8; ++$i) {
$ctx[0][$i] = ParagonIE_Sodium_Core32_Int64::fromReverseString(
self::substr($string, (($i << 3) + 0), 8)
for ($i = 1; $i < 3; ++$i) {
$ctx[$i][1] = ParagonIE_Sodium_Core32_Int64::fromReverseString(
self::substr($string, 72 + (($i - 1) << 4), 8)
$ctx[$i][0] = ParagonIE_Sodium_Core32_Int64::fromReverseString(
self::substr($string, 64 + (($i - 1) << 4), 8)
$ctx[3] = self::stringToSplFixedArray(self::substr($string, 96, 256));
for ($i = 0; $i < 8; ++$i) {
$int |= self::chrToInt($string[352 + $i]) << ($i << 3);