Skip to content

aes: add dupctx for AES-GCM and AES-CCM - #518

Open
ColtonWilley wants to merge 2 commits into
wolfSSL:masterfrom
ColtonWilley:fix/aead-dupctx
Open

ColtonWilley wants to merge 2 commits into
wolfSSL:masterfrom
ColtonWilley:fix/aead-dupctx

Conversation

@ColtonWilley

Copy link
Copy Markdown
Contributor

AES-GCM/CCM had no dupctx, so EVP_CIPHER_CTX_copy failed 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.

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.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 23:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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 thread test/test_aestag.c
Comment on lines +2574 to +2575
base[0] = aead_base(cipher[1], 1, ccm, key);
base[1] = aead_base(cipher[1], 0, ccm, key);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants