You are here

public static function ParagonIE_Sodium_Crypto::generichash in Automatic Updates 7

Same name and namespace in other branches
  1. 8 vendor/paragonie/sodium_compat/src/Crypto.php \ParagonIE_Sodium_Crypto::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

3 calls to ParagonIE_Sodium_Crypto::generichash()
ParagonIE_Sodium_Compat::crypto_generichash in vendor/paragonie/sodium_compat/src/Compat.php
Calculates a BLAKE2b hash, with an optional key.
ParagonIE_Sodium_Crypto::box_seal in vendor/paragonie/sodium_compat/src/Crypto.php
X25519-XSalsa20-Poly1305 with one ephemeral X25519 keypair.
ParagonIE_Sodium_Crypto::box_seal_open in vendor/paragonie/sodium_compat/src/Crypto.php
Opens a message encrypted via box_seal().

File

vendor/paragonie/sodium_compat/src/Crypto.php, line 690

Class

ParagonIE_Sodium_Crypto
Class ParagonIE_Sodium_Crypto

Code

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