: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
# if (sodium_memcmp(mac, stored_mac, sizeof mac) != 0) {
# sodium_memzero(mac, sizeof mac);
$stored = ParagonIE_Sodium_Core_Util::substr($cipher, $msglen + 1, 16);
if (!ParagonIE_Sodium_Core_Util::hashEquals($mac, $stored)) {
# crypto_stream_chacha20_ietf_xor_ic(m, c, mlen, state->nonce, 2U, state->k);
$out = ParagonIE_Sodium_Core_ChaCha20::ietfStreamXorIc(
ParagonIE_Sodium_Core_Util::substr($cipher, 1, $msglen),
ParagonIE_Sodium_Core_Util::store64_le(2)
# XOR_BUF(STATE_INONCE(state), mac,
# crypto_secretstream_xchacha20poly1305_INONCEBYTES);
# sodium_increment(STATE_COUNTER(state),
# crypto_secretstream_xchacha20poly1305_COUNTERBYTES);
# if ((tag & crypto_secretstream_xchacha20poly1305_TAG_REKEY) != 0 ||
# sodium_is_zero(STATE_COUNTER(state),
# crypto_secretstream_xchacha20poly1305_COUNTERBYTES)) {
# crypto_secretstream_xchacha20poly1305_rekey(state);
// Overwrite by reference:
$state = $st->toString();
$rekey = ($tag & ParagonIE_Sodium_Compat::CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_TAG_REKEY) !== 0;
if ($rekey || $st->needsRekey()) {
self::secretstream_xchacha20poly1305_rekey($state);
return array($out, $tag);
* @throws SodiumException
public static function secretstream_xchacha20poly1305_rekey(&$state)
$st = ParagonIE_Sodium_Core_SecretStream_State::fromString($state);
# unsigned char new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES +
# crypto_secretstream_xchacha20poly1305_INONCEBYTES];
# for (i = 0U; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) {
# new_key_and_inonce[i] = state->k[i];
$new_key_and_inonce = $st->getKey();
# for (i = 0U; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) {
# new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i] =
# STATE_INONCE(state)[i];
$new_key_and_inonce .= ParagonIE_Sodium_Core_Util::substR($st->getNonce(), 0, 8);
# crypto_stream_chacha20_ietf_xor(new_key_and_inonce, new_key_and_inonce,
# sizeof new_key_and_inonce,
# state->nonce, state->k);
$st->rekey(ParagonIE_Sodium_Core_ChaCha20::ietfStreamXorIc(
ParagonIE_Sodium_Core_Util::store64_le(0)
# for (i = 0U; i < crypto_stream_chacha20_ietf_KEYBYTES; i++) {
# state->k[i] = new_key_and_inonce[i];
# for (i = 0U; i < crypto_secretstream_xchacha20poly1305_INONCEBYTES; i++) {
# STATE_INONCE(state)[i] =
# new_key_and_inonce[crypto_stream_chacha20_ietf_KEYBYTES + i];
# _crypto_secretstream_xchacha20poly1305_counter_reset(state);
$state = $st->toString();
* Detached Ed25519 signature.
* @internal Do not use this directly. Use ParagonIE_Sodium_Compat.
* @throws SodiumException
public static function sign_detached($message, $sk)
return ParagonIE_Sodium_Core_Ed25519::sign_detached($message, $sk);
* Attached Ed25519 signature. (Returns a signed message.)
* @internal Do not use this directly. Use ParagonIE_Sodium_Compat.
* @throws SodiumException
public static function sign($message, $sk)
return ParagonIE_Sodium_Core_Ed25519::sign($message, $sk);
* Opens a signed message. If valid, returns the message.
* @internal Do not use this directly. Use ParagonIE_Sodium_Compat.
* @param string $signedMessage
* @throws SodiumException
public static function sign_open($signedMessage, $pk)
return ParagonIE_Sodium_Core_Ed25519::sign_open($signedMessage, $pk);
* Verify a detached signature of a given message and public key.
* @internal Do not use this directly. Use ParagonIE_Sodium_Compat.
* @param string $signature
* @throws SodiumException
public static function sign_verify_detached($signature, $message, $pk)
return ParagonIE_Sodium_Core_Ed25519::verify_detached($signature, $message, $pk);