You are here

public static function ParagonIE_Sodium_Compat::crypto_generichash_init_salt_personal 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_init_salt_personal()

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:

string $salt Salt (up to 16 bytes):

string $personal Personalization string (up to 16 bytes):

Return value

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

Throws

SodiumException

TypeError

1 call to ParagonIE_Sodium_Compat::crypto_generichash_init_salt_personal()
ParagonIE_Sodium_Compat::crypto_kdf_derive_from_key in vendor/paragonie/sodium_compat/src/Compat.php

File

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

Class

ParagonIE_Sodium_Compat

Code

public static function crypto_generichash_init_salt_personal($key = '', $length = self::CRYPTO_GENERICHASH_BYTES, $salt = '', $personal = '') {

  /* Type checks: */
  if (is_null($key)) {
    $key = '';
  }
  ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 1);
  ParagonIE_Sodium_Core_Util::declareScalarType($length, 'int', 2);
  ParagonIE_Sodium_Core_Util::declareScalarType($salt, 'string', 3);
  ParagonIE_Sodium_Core_Util::declareScalarType($personal, 'string', 4);
  $salt = str_pad($salt, 16, "\0", STR_PAD_RIGHT);
  $personal = str_pad($personal, 16, "\0", STR_PAD_RIGHT);

  /* 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 (PHP_INT_SIZE === 4) {
    return ParagonIE_Sodium_Crypto32::generichash_init_salt_personal($key, $length, $salt, $personal);
  }
  return ParagonIE_Sodium_Crypto::generichash_init_salt_personal($key, $length, $salt, $personal);
}