: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$ctx[3][$i + $left] = $p[$i + $offset];
* @internal You should not use this directly from another application
* @param SplFixedArray $ctx
* @param SplFixedArray $out
* @throws SodiumException
* @psalm-suppress MixedArgument
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedArrayAccess
* @psalm-suppress MixedArrayAssignment
* @psalm-suppress MixedArrayOffset
* @psalm-suppress MixedOperand
public static function finish(SplFixedArray $ctx, SplFixedArray $out)
self::pseudoConstructor();
self::increment_counter($ctx, 128);
self::compress($ctx, $ctx[3]);
throw new SodiumException('Failed to assert that buflen <= 128 bytes');
for ($i = $ctx[4]; $i--;) {
$ctx[3][$i] = $ctx[3][$i + 128];
self::increment_counter($ctx, $ctx[4]);
$ctx[2][0] = self::new64(0xffffffff, 0xffffffff);
for ($i = 256 - $ctx[4]; $i--;) {
self::compress($ctx, $ctx[3]);
$i = (int) (($out->getSize() - 1) / 8);
self::store64($out, $i << 3, $ctx[0][$i]);
* @internal You should not use this directly from another application
* @param SplFixedArray|null $key
* @param SplFixedArray|null $salt
* @param SplFixedArray|null $personal
* @throws SodiumException
* @psalm-suppress MixedArgument
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedArrayAccess
* @psalm-suppress MixedArrayAssignment
* @psalm-suppress MixedArrayOffset
public static function init(
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, int|string> $arr
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 MixedAssignment
* @psalm-suppress MixedArrayAccess
* @psalm-suppress MixedArrayAssignment
* @psalm-suppress MixedArrayOffset
* @psalm-suppress MixedMethodCall
public static function contextToString(SplFixedArray $ctx)
/** @var array<int, array<int, int>> $ctxA */
$ctxA = $ctx[0]->toArray();
for ($i = 0; $i < 8; ++$i) {
$str .= self::store32_le($ctxA[$i][1]);
$str .= self::store32_le($ctxA[$i][0]);
for ($i = 1; $i < 3; ++$i) {
$ctxA = $ctx[$i]->toArray();
$str .= self::store32_le($ctxA[0][1]);
$str .= self::store32_le($ctxA[0][0]);
$str .= self::store32_le($ctxA[1][1]);
$str .= self::store32_le($ctxA[1][0]);
$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 MixedArrayAssignment
public static function stringToContext($string)
for ($i = 0; $i < 8; ++$i) {
$ctx[0][$i] = SplFixedArray::fromArray(
self::substr($string, (($i << 3) + 4), 4)
self::substr($string, (($i << 3) + 0), 4)
for ($i = 1; $i < 3; ++$i) {
$ctx[$i][1] = SplFixedArray::fromArray(
self::load_4(self::substr($string, 76 + (($i - 1) << 4), 4)),
self::load_4(self::substr($string, 72 + (($i - 1) << 4), 4))
$ctx[$i][0] = SplFixedArray::fromArray(
self::load_4(self::substr($string, 68 + (($i - 1) << 4), 4)),
self::load_4(self::substr($string, 64 + (($i - 1) << 4), 4))
$ctx[3] = self::stringToSplFixedArray(self::substr($string, 96, 256));
for ($i = 0; $i < 8; ++$i) {
$int |= self::chrToInt($string[352 + $i]) << ($i << 3);