You are here

public static function ParagonIE_Sodium_Compat::crypto_shorthash in Automatic Updates 7

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

Calculates a SipHash-2-4 hash of a message for a given key.

@psalm-suppress MixedArgument @psalm-suppress MixedInferredReturnType @psalm-suppress MixedReturnStatement

Parameters

string $message Input message:

string $key SipHash-2-4 key:

Return value

string Hash

Throws

SodiumException

TypeError

2 calls to ParagonIE_Sodium_Compat::crypto_shorthash()
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 2520

Class

ParagonIE_Sodium_Compat

Code

public static function crypto_shorthash($message, $key) {

  /* Type checks: */
  ParagonIE_Sodium_Core_Util::declareScalarType($message, 'string', 1);
  ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 2);

  /* Input validation: */
  if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_SHORTHASH_KEYBYTES) {
    throw new SodiumException('Argument 2 must be CRYPTO_SHORTHASH_KEYBYTES long.');
  }
  if (self::useNewSodiumAPI()) {
    return sodium_crypto_shorthash($message, $key);
  }
  if (self::use_fallback('crypto_shorthash')) {
    return (string) call_user_func('\\Sodium\\crypto_shorthash', $message, $key);
  }
  if (PHP_INT_SIZE === 4) {
    return ParagonIE_Sodium_Core32_SipHash::sipHash24($message, $key);
  }
  return ParagonIE_Sodium_Core_SipHash::sipHash24($message, $key);
}