public static function getRelativeHash(string $preHash, bool $asString = false)
{
$state = State::instance();
$cacheKey = $state->keyring['cache.hash_key'];
if (!$cacheKey instanceof Key) {
throw new InvalidType(\trk('errors.type.wrong_class', '\\ParagonIE\\Halite\\Key'));
}
// We use a keyed hash, with a distinct key per Airship deployment to
// make collisions unlikely,
$hash = \Sodium\crypto_generichash($preHash, $cacheKey->getRawKeyMaterial(), self::HASH_SIZE);
$relHash = [\Sodium\bin2hex($hash[0]), \Sodium\bin2hex($hash[1]), \Sodium\bin2hex(Util::subString($hash, 2))];
if ($asString) {
return \implode(DIRECTORY_SEPARATOR, $relHash);
}
return $relHash;
}