$state->
update(str_repeat("\x00",
(0x10 -
$clen) & 0xf
));
$state->
update(ParagonIE_Sodium_Core32_Util::
store64_le($adlen));
$state->
update(ParagonIE_Sodium_Core32_Util::
store64_le($clen));
$computed_mac =
$state->
finish();
/* Compare the given MAC with the recalculated MAC: */
if (!ParagonIE_Sodium_Core32_Util::
verify_16($computed_mac,
$mac)) { throw new SodiumException('Invalid MAC'
);
} // Here, we know that the MAC is valid, so we decrypt and return the plaintext
return ParagonIE_Sodium_Core32_ChaCha20::
ietfStreamXorIc( $ciphertext,
$nonce,
$key,
ParagonIE_Sodium_Core32_Util::
store64_le(1
) );
} /**
* AEAD Encryption with ChaCha20-Poly1305, IETF mode (96-bit nonce)
*
* @internal Do not use this directly. Use ParagonIE_Sodium_Compat.
*
* @param string $message
* @param string $ad
* @param string $nonce
* @param string $key
* @return string
* @throws SodiumException
* @throws TypeError
*/