You are here

public static function ParagonIE_Sodium_Compat::crypto_generichash in Automatic Updates 7

Same name and namespace in other branches
  1. 8 vendor/paragonie/sodium_compat/src/Compat.php \ParagonIE_Sodium_Compat::crypto_generichash()

Calculates a BLAKE2b hash, with an optional key.

@psalm-suppress MixedArgument

Parameters

string $message The message to be hashed:

string|null $key If specified, must be a string between 16: and 64 bytes long

int $length Output length in bytes; must be between 16: and 64 (default = 32)

Return value

string Raw binary

Throws

SodiumException

TypeError

6 calls to ParagonIE_Sodium_Compat::crypto_generichash()
ParagonIE_Sodium_Compat::crypto_kx_seed_keypair in vendor/paragonie/sodium_compat/src/Compat.php
ParagonIE_Sodium_Crypto::keyExchange in vendor/paragonie/sodium_compat/src/Crypto.php
Libsodium's crypto_kx().
ParagonIE_Sodium_File::box_seal in vendor/paragonie/sodium_compat/src/File.php
Seal a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box_seal(), but produces the same result.
ParagonIE_Sodium_File::box_seal_open in vendor/paragonie/sodium_compat/src/File.php
Open a sealed file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box_seal_open(), but produces the same result.
php72compat.php in vendor/paragonie/sodium_compat/lib/php72compat.php

... See full list

File

vendor/paragonie/sodium_compat/src/Compat.php, line 1396

Class

ParagonIE_Sodium_Compat

Code

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);
}