WordPress at Your Fingertips
function is not described

ParagonIE_Sodium_Compat::crypto_stream_xchacha20() public WP 1.0

Expand a key and nonce into a keystream of pseudorandom bytes.

{} It's a method of the class: ParagonIE_Sodium_Compat{}

No Hooks.

Return

String. Pseudorandom stream that can be XORed with messages to provide encryption (but not authentication; see Poly1305 or crypto_auth() for that, which is not optional for security)

Usage

$result = ParagonIE_Sodium_Compat::crypto_stream_xchacha20( $len, $nonce, $key, $dontFallback );
$len(int) (required)
Number of bytes desired
$nonce(string) (required)
Number to be used Once; must be 24 bytes
$key(string) (required)
XChaCha20 key
$dontFallback *(true false)*

Default: false

Code of ParagonIE_Sodium_Compat::crypto_stream_xchacha20() WP 5.8.2

public static function crypto_stream_xchacha20($len, $nonce, $key, $dontFallback = false)
{
    /* Type checks: */
    ParagonIE_Sodium_Core_Util::declareScalarType($len, 'int', 1);
    ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
    ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3);

    /* Input validation: */
    if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_STREAM_XCHACHA20_NONCEBYTES) {
        throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_XCHACHA20_NONCEBYTES long.');
    }
    if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_XCHACHA20_KEYBYTES) {
        throw new SodiumException('Argument 3 must be CRYPTO_STREAM_XCHACHA20_KEYBYTES long.');
    }

    if (self::useNewSodiumAPI() && !$dontFallback) {
        return sodium_crypto_stream_xchacha20($len, $nonce, $key);
    }
    if (PHP_INT_SIZE === 4) {
        return ParagonIE_Sodium_Core32_XChaCha20::stream($len, $nonce, $key);
    }
    return ParagonIE_Sodium_Core_XChaCha20::stream($len, $nonce, $key);
}