ParagonIE\Halite\Symmetric\Crypto::verifyMAC PHP Method

verifyMAC() protected static method

Verify a Message Authentication Code (MAC) of a message, with a shared key.
protected static verifyMAC ( string $mac, string $message, string $authKey, SymmetricConfig $config ) : boolean
$mac string Message Authentication Code
$message string The message to verify
$authKey string Authentication key (symmetric)
$config SymmetricConfig Configuration object
return boolean
    protected static function verifyMAC(string $mac, string $message, string $authKey, SymmetricConfig $config) : bool
    {
        if (CryptoUtil::safeStrlen($mac) !== $config->MAC_SIZE) {
            throw new InvalidSignature('Argument 1: Message Authentication Code is not the correct length; is it encoded?');
        }
        if ($config->MAC_ALGO === 'BLAKE2b') {
            $calc = \Sodium\crypto_generichash($message, $authKey, $config->MAC_SIZE);
            $res = \hash_equals($mac, $calc);
            \Sodium\memzero($calc);
            return $res;
        }
        throw new InvalidMessage('Invalid Halite version');
    }