You are here

public static function ParagonIE_Sodium_Compat::crypto_generichash_init in Automatic Updates 8

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

Initialize a BLAKE2b hashing context, for use in a streaming interface.

@psalm-suppress MixedArgument

Parameters

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

int $length The size of the desired hash output:

Return value

string A BLAKE2 hashing context, encoded as a string (To be 100% compatible with ext/libsodium)

Throws

SodiumException

TypeError

5 calls to ParagonIE_Sodium_Compat::crypto_generichash_init()
ParagonIE_Sodium_Compat::crypto_kx_client_session_keys in vendor/paragonie/sodium_compat/src/Compat.php
ParagonIE_Sodium_Compat::crypto_kx_server_session_keys in vendor/paragonie/sodium_compat/src/Compat.php
ParagonIE_Sodium_File::generichash in vendor/paragonie/sodium_compat/src/File.php
Calculate the BLAKE2b hash of a file.
php72compat.php in vendor/paragonie/sodium_compat/lib/php72compat.php
sodium_compat.php in vendor/paragonie/sodium_compat/lib/sodium_compat.php

File

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

Class

ParagonIE_Sodium_Compat

Code

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