Skip to content

Properly initialize AEAD cipher flags in OpenSSL backend#20853

Closed
jordikroon wants to merge 6 commits intophp:masterfrom
jordikroon:fix/gh20851
Closed

Properly initialize AEAD cipher flags in OpenSSL backend#20853
jordikroon wants to merge 6 commits intophp:masterfrom
jordikroon:fix/gh20851

Conversation

@jordikroon
Copy link
Copy Markdown
Contributor

@jordikroon jordikroon commented Jan 6, 2026

Fixes #20851

Add support for AEAD ciphers like AES-SIV by detecting and initializing AEAD flags during cipher mode loading.
Includes test case for AES-256-SIV encryption/decryption roundtrip.

@jordikroon jordikroon requested a review from bukka as a code owner January 6, 2026 22:38
@jordikroon jordikroon changed the title properly initialize AEAD cipher flags in OpenSSL backend Properly initialize AEAD cipher flags in OpenSSL backend Jan 6, 2026
@jordikroon jordikroon requested a review from kocsismate as a code owner January 7, 2026 19:09
@jordikroon
Copy link
Copy Markdown
Contributor Author

Please review commits 1 by 1 since I am not sure if the change from string $aad = "" to ?string $aad = "" is acceptable.
The first commit only fixes SIV Synthetic Initialization Vector where it generates its own IV. It was not respected.

The second commit allows AAD to be null since it behaves differently than when only an empty string is given. The matches other implementations like cryptography in python.

Copy link
Copy Markdown
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable. Just some minor things really.

Comment thread ext/openssl/openssl_backend_common.c Outdated
Comment thread ext/openssl/openssl_backend_common.c
Copy link
Copy Markdown
Member

@bukka bukka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good now. It would be just nice to convert the test so it's consistent with other AEAD tests.

Comment thread ext/openssl/tests/gh20851_aad_empty.phpt Outdated
@onyn
Copy link
Copy Markdown

onyn commented Jan 23, 2026

Note that openssl supports aes-gcm-siv since v3.2 which is improved version of aes-siv. Is it possible to add support for aes-gcm-siv here in advance?

@bukka
Copy link
Copy Markdown
Member

bukka commented Apr 3, 2026

The code looks good but it needs rebase...

@jordikroon
Copy link
Copy Markdown
Contributor Author

@bukka This has been rebased

@bukka bukka closed this in b5fe9a1 Apr 25, 2026
Rakdos8 added a commit to Rakdos8/php-src that referenced this pull request Apr 25, 2026
Extends the AEAD switch in php_openssl_load_cipher_mode() to also
recognize EVP_CIPH_GCM_SIV_MODE alongside the SIV/OCB cases added by
phpGH-20853. GCM-SIV (OpenSSL >= 3.2, RFC 8452) uses the standard
EVP_CTRL_AEAD_*_TAG controls and falls into the same arm. The existing
aad_supports_vector = (cipher_mode == EVP_CIPH_SIV_MODE) check keeps
that flag false for GCM-SIV, since RFC 8452 takes a single AAD input
rather than vector AAD like RFC 5297 SIV. LibreSSL does not currently
define EVP_CIPH_GCM_SIV_MODE, hence the #ifdef guard.

Tests:
  - cipher_tests.inc gains aes-256-gcm-siv vectors from RFC 8452
    Appendix C.2 (empty plaintext, 8-byte plaintext with and without
    AAD).
  - openssl_encrypt_gcm_siv.phpt and openssl_decrypt_gcm_siv.phpt
    consume those vectors, mirroring the SIV equivalents, and cover
    the missing-tag and tampering failure paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AES SIV cipher algorithms implemented incorrectly in openssl module

4 participants