Skip to content

Conversation

@jordikroon
Copy link
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 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
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
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 on lines +1807 to +1809
/* Only pass AAD to OpenSSL if caller provided it.
This makes NULL mean zero AAD items, while "" with len 0 means one empty AAD item. */
if (mode->is_aead && aad != NULL && !EVP_CipherUpdate(cipher_ctx, NULL, &i, (const unsigned char *)aad, (int)aad_len)) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this for SIV or is this for all modes. I thought that empty string won't make difference but I guess it might.

In general allowing null should be fine for master so it's not really a problem. Just want to know the reasoning as I haven't checked this propertly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only SIV produces different outputs for aad = null and add = "". Other modes produce the same output.
From my understanding this is because in SIV mode aad could be a vector list. Thus null here means an empty vector list. And I don't believe we need to support multiple vectors as aad. Because then we would need to change $aad to string|array.

Copy link
Member

@bukka bukka Jan 12, 2026

Choose a reason for hiding this comment

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

ah ok. It would be good to check if skipping actually works for ccm, gcm and ocb (using null argument). It might make sense to potentially limit it just to SIV and treat null as "" for other modes.

Copy link
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.

@@ -0,0 +1,47 @@
--TEST--
Copy link
Member

Choose a reason for hiding this comment

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

Could you actually change it to a single test for encryption and decryption that will look like https://github.com/jordikroon/php-src/blob/ca12f45a76f3242953e7e27a9b64e509e9f518e2/ext/openssl/tests/openssl_decrypt_gcm.phpt
and
https://github.com/jordikroon/php-src/blob/ca12f45a76f3242953e7e27a9b64e509e9f518e2/ext/openssl/tests/openssl_encrypt_gcm.phpt

Please name it in a similar way and use the standard test vectors. It will also match the ccm and ocb tests...

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

2 participants