ParagonIE_Sodium_Crypto::generichash() public WP 1.0
Calculate a BLAKE2b hash.
{} It's a method of the class: ParagonIE_Sodium_Crypto{}
No Hooks.
Return
String
. Null. Nothing.
Usage
$result = ParagonIE_Sodium_Crypto::generichash( $message, $key, $outlen );
- $message(string) (required)
- -
$key *(string | null)* |
---|
- $outlen(int)
- -
Code of ParagonIE_Sodium_Crypto::generichash() ParagonIE Sodium Crypto::generichash WP 5.7
public static function generichash($message, $key = '', $outlen = 32)
{
// This ensures that ParagonIE_Sodium_Core_BLAKE2b::$iv is initialized
ParagonIE_Sodium_Core_BLAKE2b::pseudoConstructor();
$k = null;
if (!empty($key)) {
/** @var SplFixedArray $k */
$k = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($key);
if ($k->count() > ParagonIE_Sodium_Core_BLAKE2b::KEYBYTES) {
throw new RangeException('Invalid key size');
}
}
/** @var SplFixedArray $in */
$in = ParagonIE_Sodium_Core_BLAKE2b::stringToSplFixedArray($message);
/** @var SplFixedArray $ctx */
$ctx = ParagonIE_Sodium_Core_BLAKE2b::init($k, $outlen);
ParagonIE_Sodium_Core_BLAKE2b::update($ctx, $in, $in->count());
/** @var SplFixedArray $out */
$out = new SplFixedArray($outlen);
$out = ParagonIE_Sodium_Core_BLAKE2b::finish($ctx, $out);
/** @var array<int, int> */
$outArray = $out->toArray();
return ParagonIE_Sodium_Core_Util::intArrayToString($outArray);
}