[php-src] PR #21872: Fix GH-20851: AES-SIV / AES-GCM-SIV not handled as AEAD in openssl_encrypt
| From: | Rakdos8 | Date: | Sat, 25 Apr 2026 16:08:39 +0000 |
| Subject: | [php-src] PR #21872: Fix GH-20851: AES-SIV / AES-GCM-SIV not handled as AEAD in openssl_encrypt | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-35892@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/21872
Author: Rakdos8
Fixes #20851.
php_openssl_load_cipher_mode() only set is_aead for GCM, CCM, OCB and
ChaCha20-Poly1305. The two SIV-family AEAD modes added by OpenSSL providers were missed:
| OpenSSL mode constant | Value | Ciphers covered | Available since |
|---------------------------|-----------|------------------------------------------|-----------------|
| EVP_CIPH_SIV_MODE | 0x10004 | aes-{128,192,256}-siv (RFC
5297) | OpenSSL 3.0 |
| EVP_CIPH_GCM_SIV_MODE | 0x10005 | aes-{128,192,256}-gcm-siv
(RFC 8452) | OpenSSL 3.2 |
Symptoms with openssl_encrypt() (PHP 8.5+):
- the $tag out-parameter was assigned null instead of the 16-byte
authentication tag — for AES-GCM-SIV the tag *is* the synthetic IV, so without it
openssl_decrypt() cannot recover the plaintext at all
- the $aad parameter was passed only as raw key material, never as AEAD additional data
- openssl_decrypt() rejected any caller-supplied tag with the warning *"The tag
cannot be used because the cipher algorithm does not support AEAD"*
The cipher list (openssl_get_cipher_methods()) already correctly enumerated these
algorithms because that path uses the provider-aware EVP_CIPHER_do_all_provided, hiding
the inconsistency.
Both modes implement the standard EVP_CTRL_AEAD_*_TAG controls in their provider, so
adding them to the AEAD-mode switch and calling the existing
php_openssl_set_aead_flags() helper is sufficient. No
set_tag_length_when_encrypting / is_single_run_aead quirks are needed
(those are CCM-specific).
LibreSSL does not currently expose either mode constant, hence the #ifdef guards.
### Tests
- ext/openssl/tests/openssl_encrypt_gcm_siv.phpt — RFC 8452 known answer tests (empty
plaintext, 8-byte plaintext with and without AAD, vectors from
openssl/test/recipes/30-test_evp_data/evpciph_aes_gcm_siv.txt) plus a random round-trip
and a missing-tag failure path.
- ext/openssl/tests/openssl_decrypt_gcm_siv.phpt — RFC 8452 vector plus tampering of
tag, ciphertext, nonce and AAD; all four tampering attempts must reject.
- ext/openssl/tests/gh20851.phpt — round-trip of aes-256-siv with and
without AAD plus tampered-tag and wrong-AAD rejection, matching the original reporter's
scenario.
### Verification
Built PHP-8.5 + OpenSSL 3.5.5 on Debian Trixie with --enable-debug --with-openssl:
- the 3 new tests pass
- the full ext/openssl/ suite passes: **212 / 212** non-skipped tests, no regression
- smoke-tested round-trip on all six affected ciphers (aes-{128,192,256}-{siv,gcm-siv}