|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-10-02 16:50 UTC] cmb@php.net
-Assigned To:
+Assigned To: leigh
[2018-10-02 16:50 UTC] cmb@php.net
[2018-10-02 17:03 UTC] requinix@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 14 06:00:02 2025 UTC |
Description: ------------ "chacha20-poly1305" is listed in the result of openssl_get_cipher_methods(). Wikipedia says it is an AEAD. I.e., if I call openssl_encrypt and provide a reference to a variable that is supposed to get the authentication tag, I expect it to get the tag. Instead, I get this warning: PHP Warning: openssl_encrypt(): The authenticated tag cannot be provided for cipher that doesn not support AEAD in /home/aep/aead-test/index.php on line 17 There is a pure PHP implementation of chacha20-poly1305, and it does support the AEAD mode (i.e. gets a tag). It is available as "leigh/aead-chacha20-poly1305" via composer, and the test script below uses it for reference. Test script: --------------- <?php # make sure that you used Composer to get "leigh/aead-chacha20-poly1305" require __DIR__ . '/vendor/autoload.php'; $key = str_repeat('k', 32); $nonce = str_repeat('n', 12); $plaintext = '12345678'; $aad = ''; list($ciphertext, $tag) = \ChaCha20Poly1305\encrypt($key, $nonce, $aad, $plaintext); $cl = implode(unpack("H*", $ciphertext)); $tl = implode(unpack("H*", $tag)); print("Pure PHP\n"); print("Ciphertext: $cl, tag: $tl\n"); $openssl_ct = openssl_encrypt($plaintext, "chacha20-poly1305", $key, OPENSSL_RAW_DATA, $nonce, $openssl_tag, $aad); $ocl = implode(unpack("H*", $openssl_ct)); $otl = implode(unpack("H*", $openssl_tag)); print("OpenSSL\n"); print("Ciphertext: $ocl, tag: $otl\n"); Expected result: ---------------- Pure PHP Ciphertext: bfcd0d66f7e49c21, tag: e48864c53c4deb83bcee96add54ef851 OpenSSL Ciphertext: bfcd0d66f7e49c21, tag: e48864c53c4deb83bcee96add54ef851 Actual result: -------------- Pure PHP Ciphertext: bfcd0d66f7e49c21, tag: e48864c53c4deb83bcee96add54ef851 PHP Warning: openssl_encrypt(): The authenticated tag cannot be provided for cipher that doesn not support AEAD in /home/aep/aead-test/index.php on line 17 OpenSSL Ciphertext: bfcd0d66f7e49c21, tag: