public static function ParagonIE_Sodium_Crypto32::generichash in Automatic Updates 8
Same name and namespace in other branches
- 7 vendor/paragonie/sodium_compat/src/Crypto32.php \ParagonIE_Sodium_Crypto32::generichash()
Calculate a BLAKE2b hash.
@internal Do not use this directly. Use ParagonIE_Sodium_Compat.
Parameters
string $message:
string|null $key:
int $outlen:
Return value
string
Throws
RangeException
SodiumException
TypeError
4 calls to ParagonIE_Sodium_Crypto32::generichash()
- ParagonIE_Sodium_Compat::crypto_generichash in vendor/paragonie/ sodium_compat/ src/ Compat.php 
- Calculates a BLAKE2b hash, with an optional key.
- ParagonIE_Sodium_Crypto32::box_seal in vendor/paragonie/ sodium_compat/ src/ Crypto32.php 
- X25519-XSalsa20-Poly1305 with one ephemeral X25519 keypair.
- ParagonIE_Sodium_Crypto32::box_seal_open in vendor/paragonie/ sodium_compat/ src/ Crypto32.php 
- Opens a message encrypted via box_seal().
- ParagonIE_Sodium_Crypto32::keyExchange in vendor/paragonie/ sodium_compat/ src/ Crypto32.php 
- Libsodium's crypto_kx().
File
- vendor/paragonie/ sodium_compat/ src/ Crypto32.php, line 689 
Class
- ParagonIE_Sodium_Crypto32
- Class ParagonIE_Sodium_Crypto
Code
public static function generichash($message, $key = '', $outlen = 32) {
  // This ensures that ParagonIE_Sodium_Core32_BLAKE2b::$iv is initialized
  ParagonIE_Sodium_Core32_BLAKE2b::pseudoConstructor();
  $k = null;
  if (!empty($key)) {
    /** @var SplFixedArray $k */
    $k = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray($key);
    if ($k
      ->count() > ParagonIE_Sodium_Core32_BLAKE2b::KEYBYTES) {
      throw new RangeException('Invalid key size');
    }
  }
  /** @var SplFixedArray $in */
  $in = ParagonIE_Sodium_Core32_BLAKE2b::stringToSplFixedArray($message);
  /** @var SplFixedArray $ctx */
  $ctx = ParagonIE_Sodium_Core32_BLAKE2b::init($k, $outlen);
  ParagonIE_Sodium_Core32_BLAKE2b::update($ctx, $in, $in
    ->count());
  /** @var SplFixedArray $out */
  $out = new SplFixedArray($outlen);
  $out = ParagonIE_Sodium_Core32_BLAKE2b::finish($ctx, $out);
  /** @var array<int, int> */
  $outArray = $out
    ->toArray();
  return ParagonIE_Sodium_Core32_Util::intArrayToString($outArray);
}