ParagonIE_Sodium_Compat::crypto_generichash_init() public WP 1.0
Initialize a BLAKE2b hashing context, for use in a streaming interface.
{} It's a method of the class: ParagonIE_Sodium_Compat{}
No Hooks.
Return
String
. A BLAKE2 hashing context, encoded as a string (To be 100% compatible with ext/libsodium)
Usage
$result = ParagonIE_Sodium_Compat::crypto_generichash_init( $key, $length );
- $key(string|null)
- If specified must be a string between 16 and 64 bytes
- $length(int)
- The size of the desired hash output
Code of ParagonIE_Sodium_Compat::crypto_generichash_init() ParagonIE Sodium Compat::crypto generichash init WP 5.7
public static function crypto_generichash_init($key = '', $length = self::CRYPTO_GENERICHASH_BYTES)
{
/* Type checks: */
if (is_null($key)) {
$key = '';
}
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 1);
ParagonIE_Sodium_Core_Util::declareScalarType($length, 'int', 2);
/* Input validation: */
if (!empty($key)) {
if (ParagonIE_Sodium_Core_Util::strlen($key) < self::CRYPTO_GENERICHASH_KEYBYTES_MIN) {
throw new SodiumException('Unsupported key size. Must be at least CRYPTO_GENERICHASH_KEYBYTES_MIN bytes long.');
}
if (ParagonIE_Sodium_Core_Util::strlen($key) > self::CRYPTO_GENERICHASH_KEYBYTES_MAX) {
throw new SodiumException('Unsupported key size. Must be at most CRYPTO_GENERICHASH_KEYBYTES_MAX bytes long.');
}
}
if (self::useNewSodiumAPI()) {
return sodium_crypto_generichash_init($key, $length);
}
if (self::use_fallback('crypto_generichash_init')) {
return (string) call_user_func('\\Sodium\\crypto_generichash_init', $key, $length);
}
if (PHP_INT_SIZE === 4) {
return ParagonIE_Sodium_Crypto32::generichash_init($key, $length);
}
return ParagonIE_Sodium_Crypto::generichash_init($key, $length);
}