public static function ParagonIE_Sodium_Compat::crypto_stream in Automatic Updates 8
Same name and namespace in other branches
- 7 vendor/paragonie/sodium_compat/src/Compat.php \ParagonIE_Sodium_Compat::crypto_stream()
Expand a key and nonce into a keystream of pseudorandom bytes.
@psalm-suppress MixedArgument
Parameters
int $len Number of bytes desired:
string $nonce Number to be used Once; must be 24 bytes:
string $key XSalsa20 key:
Return value
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)
Throws
SodiumException
TypeError
2 calls to ParagonIE_Sodium_Compat::crypto_stream()
- php72compat.php in vendor/
paragonie/ sodium_compat/ lib/ php72compat.php - sodium_compat.php in vendor/
paragonie/ sodium_compat/ lib/ sodium_compat.php
File
- vendor/
paragonie/ sodium_compat/ src/ Compat.php, line 2967
Class
Code
public static function crypto_stream($len, $nonce, $key) {
/* 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_NONCEBYTES) {
throw new SodiumException('Argument 2 must be CRYPTO_SECRETBOX_NONCEBYTES long.');
}
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_STREAM_KEYBYTES) {
throw new SodiumException('Argument 3 must be CRYPTO_STREAM_KEYBYTES long.');
}
if (self::useNewSodiumAPI()) {
return sodium_crypto_stream($len, $nonce, $key);
}
if (self::use_fallback('crypto_stream')) {
return (string) call_user_func('\\Sodium\\crypto_stream', $len, $nonce, $key);
}
if (PHP_INT_SIZE === 4) {
return ParagonIE_Sodium_Core32_XSalsa20::xsalsa20($len, $nonce, $key);
}
return ParagonIE_Sodium_Core_XSalsa20::xsalsa20($len, $nonce, $key);
}