Repository navigation
aes: add dupctx for AES-GCM and AES-CCM - #518
Open
ColtonWilley wants to merge 2 commits into
Open
ColtonWilley wants to merge 2 commits into
ColtonWilley wants to merge 2 commits into
Conversation
EVP_CIPHER_CTX_copy failed for GCM/CCM, breaking pyca/cryptography's AESGCM, which copies a keyed context per operation. The copy re-keys its own Aes from the saved key; streaming GCM refuses a copy mid-operation, and final starts the stream if no update followed the IV.
Copy keyed base contexts as pyca/cryptography does: the copies must match the default provider, decrypt, and leave the base reusable. GCM also finalises an empty message straight after the IV.
There was a problem hiding this comment.
🔵 Needs a closer look
Cryptographic buffer ownership and active-stream copy boundaries remain untested and require human review.
1 open issue
What changed in this PR
Adds AES-GCM/CCM context duplication to support EVP_CIPHER_CTX_copy, including pyca/cryptography’s per-operation copies of keyed contexts.
Changes:
- Re-keys duplicated contexts and deep-copies cached buffers, while rejecting active streaming GCM copies.
- Initializes streaming GCM during finalization when no update follows the IV, and clears sensitive context memory on release.
- Adds copy regression tests across AES key sizes, including empty-message GCM operations.
| File | Description |
|---|---|
| test/unit.h | Declares the AEAD context-copy test. |
| test/unit.c | Registers the new regression test. |
| test/test_aestag.c | Tests keyed-context copies against OpenSSL results. |
| src/wp_aes_aead.c | Implements duplication, key retention, cleanup, and GCM finalization changes. |
Review effort: Balanced
Comment on lines
+2574
to
+2575
| base[0] = aead_base(cipher[1], 1, ccm, key); | ||
| base[1] = aead_base(cipher[1], 0, ccm, key); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

AES-GCM/CCM had no dupctx, so
EVP_CIPHER_CTX_copyfailed and pyca/cryptography's AESGCM, which copies a keyed context per operation, failed on every call. The copy re-keys its own Aes from a saved key and deep-copies cached AAD/input; streaming GCM refuses a copy once data has been processed. GCM final now starts the stream when no update followed the IV.