Skip to content

Add AES-GCM-SIV AEAD support (RFC 8452) - #21874

Open
Rakdos8 wants to merge 1 commit into
php:masterfrom
Rakdos8:fix/openssl-aes-gcm-siv-aead-tag
Open

Rakdos8 wants to merge 1 commit into
php:masterfrom
Rakdos8:fix/openssl-aes-gcm-siv-aead-tag

Conversation

@Rakdos8

@Rakdos8 Rakdos8 commented Apr 25, 2026

Copy link
Copy Markdown

Follow-up to #20853 (now merged). Adds the missing GCM-SIV piece so the full set of AES SIV-family ciphers exposed by OpenSSL providers is treated as AEAD by openssl_encrypt() / openssl_decrypt().

cc @bukka @jordikroon — per Bukka's note on the previous (closed) PR, this is rebased on master and only contains the GCM-SIV delta.

@olegbaturin

Copy link
Copy Markdown

#22188

@Rakdos8
Rakdos8 force-pushed the fix/openssl-aes-gcm-siv-aead-tag branch from 489417a to 9a09a71 Compare October 31, 2026 13:49

@bukka bukka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I check this one and GCM-SIV cannot actually use variable length IV so it's always 12 bytes which means that it could result in OOB read so this will need to be addressed and fixed len IV used for GCM-SIV

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) uses the standard EVP_CTRL_AEAD_*_TAG
controls and takes a single AAD input, so aad_supports_vector stays false.
LibreSSL does not define EVP_CIPH_GCM_SIV_MODE, hence the #ifdef guard.

GCM-SIV only takes a 96-bit nonce, but OpenSSL accepts any
EVP_CTRL_AEAD_SET_IVLEN for it and reads 12 bytes from the IV buffer, so a
shorter IV was an out-of-bounds read. php_openssl_validate_iv() now rejects
any GCM-SIV IV that is not exactly 12 bytes instead of taking the
variable-length AEAD path.

Tests use RFC 8452 Appendix C.2 vectors and cover the tag, tampering and
IV length failure paths.
@Rakdos8
Rakdos8 force-pushed the fix/openssl-aes-gcm-siv-aead-tag branch from 9a09a71 to 88a741d Compare November 17, 2026 12:32
@Rakdos8

Rakdos8 commented Nov 17, 2026

Copy link
Copy Markdown
Author

I check this one and GCM-SIV cannot actually use variable length IV so it's always 12 bytes which means that it could result in OOB read so this will need to be addressed and fixed len IV used for GCM-SIV

Thanks, confirmed. Released OpenSSL versions (checked up to 3.5.7 / 3.6.2) accept any EVP_CTRL_AEAD_SET_IVLEN for GCM-SIV and then always read 12 bytes from the IVbuffer, so a short IV is an OOB read (reproduced under valgrind with a 1-byte IV). OpenSSL only fixed it recently in openssl/openssl@b8997895c2.

GCM-SIV now uses a fixed 12-byte IV: php_openssl_validate_iv() rejects any other length with a warning instead of taking the variable-length AEAD path. Tests cover empty, short and long IVs on encrypt and decrypt.

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.

3 participants