<commit_before>--TEST--
Check for libsodium AEAD
--SKIPIF--
<?php
if (!extension_loaded("libsodium")) print "skip extension not loaded";
if (!defined('Sodium\CRYPTO_AEAD_AES256GCM_NPUBBYTES')) print "skip libsodium without AESGCM";
?>
--FILE--
<?php
$msg = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));
$nonce = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES);
$key = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES);
$ad = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));

$ciphertext = \Sodium\crypto_aead_chacha20poly1305_encrypt($msg, $ad, $nonce, $key);
$msg2 = \Sodium\crypto_aead_chacha20poly1305_decrypt($ciphertext, $ad, $nonce, $key);
var_dump($ciphertext !== $msg);
var_dump($msg === $msg2);
var_dump(\Sodium\crypto_aead_chacha20poly1305_decrypt($ciphertext, 'x' . $ad, $nonce, $key));

$msg = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));
$nonce = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES);
$key = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES);
$ad = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));

$ciphertext = \Sodium\crypto_aead_chacha20poly1305_ietf_encrypt($msg, $ad, $nonce, $key);
$msg2 = \Sodium\crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, $ad, $nonce, $key);
var_dump($ciphertext !== $msg);
var_dump($msg === $msg2);
var_dump(\Sodium\crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, 'x' . $ad, $nonce, $key));

$msg = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));
$nonce = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_AES256GCM_NPUBBYTES);
$key = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_AES256GCM_KEYBYTES);
$ad = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));

if (\Sodium\crypto_aead_aes256gcm_is_available()) {
    $ciphertext = \Sodium\crypto_aead_aes256gcm_encrypt($msg, $ad, $nonce, $key);
    $msg2 = \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $ad, $nonce, $key);
    var_dump($ciphertext !== $msg);<commit_msg>Bypass the chacha20poly1305-ietf test on libsodium < 1.0.4<commit_after>--TEST--
Check for libsodium AEAD
--SKIPIF--
<?php
if (!extension_loaded("libsodium")) print "skip extension not loaded";
if (!defined('Sodium\CRYPTO_AEAD_AES256GCM_NPUBBYTES')) print "skip libsodium without AESGCM";
?>
--FILE--
<?php
$msg = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));
$nonce = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES);
$key = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES);
$ad = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));

$ciphertext = \Sodium\crypto_aead_chacha20poly1305_encrypt($msg, $ad, $nonce, $key);
$msg2 = \Sodium\crypto_aead_chacha20poly1305_decrypt($ciphertext, $ad, $nonce, $key);
var_dump($ciphertext !== $msg);
var_dump($msg === $msg2);
var_dump(\Sodium\crypto_aead_chacha20poly1305_decrypt($ciphertext, 'x' . $ad, $nonce, $key));

$msg = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));
$nonce = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_CHACHA20POLY1305_IETF_NPUBBYTES);
$key = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_CHACHA20POLY1305_IETF_KEYBYTES);
$ad = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));

if (\Sodium\library_version_major() > 7 ||
    (\Sodium\library_version_major() == 7 &&
     \Sodium\library_version_minor() >= 6)) {
    $ciphertext = \Sodium\crypto_aead_chacha20poly1305_ietf_encrypt($msg, $ad, $nonce, $key);
    $msg2 = \Sodium\crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, $ad, $nonce, $key);
    var_dump($ciphertext !== $msg);
    var_dump($msg === $msg2);
    var_dump(\Sodium\crypto_aead_chacha20poly1305_ietf_decrypt($ciphertext, 'x' . $ad, $nonce, $key));
} else {
    var_dump(true);
    var_dump(true);
    var_dump(false);
}

$msg = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));
$nonce = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_AES256GCM_NPUBBYTES);
$key = \Sodium\randombytes_buf(\Sodium\CRYPTO_AEAD_AES256GCM_KEYBYTES);
$ad = \Sodium\randombytes_buf(\Sodium\randombytes_uniform(1000));

if (\Sodium\crypto_aead_aes256gcm_is_available()) {
    $ciphertext = \Sodium\crypto_aead_aes256gcm_encrypt($msg, $ad, $nonce, $key);
    $msg2 = \Sodium\crypto_aead_aes256gcm_decrypt($ciphertext, $ad, $nonce, $key);
    var_dump($ciphertext !== $msg);
{'fraction_non_alphanumeric': 0.1586505584682015, 'fraction_numerical': 0.05151584226122635, 'mean_word_length': 7.374045801526718, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3182677', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1774, 'n_words': 214}