ParagonIE_Sodium_Compat::crypto_generichash() public WP 1.0
Calculates a BLAKE2b hash, with an optional key.
{} It's a method of the class: ParagonIE_Sodium_Compat{}
No Hooks.
Return
String
. Raw binary
Usage
$result = ParagonIE_Sodium_Compat::crypto_generichash( $message, $key, $length );
- $message(string) (required)
- The message to be hashed
- $key(string|null)
- If specified, must be a string between 16 and 64 bytes long
- $length(int)
- Output length in bytes; must be between 16 and 64 (default = 32)
Code of ParagonIE_Sodium_Compat::crypto_generichash() ParagonIE Sodium Compat::crypto generichash WP 5.7
public static function crypto_generichash($message, $key = '', $length = self::CRYPTO_GENERICHASH_BYTES)
{
/* Type checks: */
ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 1);
if (is_null($key)) {
$key = '';
}
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 2);
ParagonIE_Sodium_Core_Util::declareScalarType($length, 'int', 3);
/* 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 (string) sodium_crypto_generichash($message, $key, $length);
}
if (self::use_fallback('crypto_generichash')) {
return (string) call_user_func('\\Sodium\\crypto_generichash', $message, $key, $length);
}
if (PHP_INT_SIZE === 4) {
return ParagonIE_Sodium_Crypto32::generichash($message, $key, $length);
}
return ParagonIE_Sodium_Crypto::generichash($message, $key, $length);
}