Skip to content

feat(aead): re-introduce ContextTag on the revised Cipher/Decipher traits#190

Open
coderdan wants to merge 3 commits into
mainfrom
claude/vitaminc-aead-issue-178-vCypS
Open

feat(aead): re-introduce ContextTag on the revised Cipher/Decipher traits#190
coderdan wants to merge 3 commits into
mainfrom
claude/vitaminc-aead-issue-178-vCypS

Conversation

@coderdan
Copy link
Copy Markdown
Contributor

@coderdan coderdan commented Jun 5, 2026

PR #148 redesigned the Cipher/Encrypt/Decipher/Decrypt traits and dropped the
old ContextTag, which referenced the pre-redesign API. Re-introduce it as an
encrypt-side wrapper so the type system, not the call site, guarantees a value's
context tag is always bound as AAD — the one piece of behaviour raw tuple AAD
cannot enforce.

In the revised API, AAD is threaded through Encrypt at seal time but injected
into the Decipher by the concrete cipher at open time, so ContextTag implements
Encrypt and folds (extra_aad, tag) into the AAD, while ContextTag::aad /
aad_with rebuild the matching AAD for the cipher's decrypt entry point. refine
nests tags into a PAE-encoded tuple for hierarchical context.

The Encrypt impl bounds the tag on IntoAad<'static> (owned tags and &'static
str) and re-borrows the encoded Aad for the call lifetime via covariance,
sidestepping the HRTB that an Encrypt-level lifetime used to carry.

Covered by mock-cipher unit tests in vitaminc-aead and an end-to-end AES-256-GCM
roundtrip suite in vitaminc-encrypt (wrong/omitted/refined context all fail).

claude and others added 3 commits June 5, 2026 06:45
…aits

PR #148 redesigned the Cipher/Encrypt/Decipher/Decrypt traits and dropped the
old ContextTag, which referenced the pre-redesign API. Re-introduce it as an
encrypt-side wrapper so the type system, not the call site, guarantees a value's
context tag is always bound as AAD — the one piece of behaviour raw tuple AAD
cannot enforce.

In the revised API, AAD is threaded through Encrypt at seal time but injected
into the Decipher by the concrete cipher at open time, so ContextTag implements
Encrypt and folds (extra_aad, tag) into the AAD, while ContextTag::aad /
aad_with rebuild the matching AAD for the cipher's decrypt entry point. refine
nests tags into a PAE-encoded tuple for hierarchical context.

The Encrypt impl bounds the tag on IntoAad<'static> (owned tags and &'static
str) and re-borrows the encoded Aad for the call lifetime via covariance,
sidestepping the HRTB that an Encrypt-level lifetime used to carry.

Covered by mock-cipher unit tests in vitaminc-aead and an end-to-end AES-256-GCM
roundtrip suite in vitaminc-encrypt (wrong/omitted/refined context all fail).
…h_aad

Put extra_aad before tag so the decrypt-side helper mirrors
encrypt_with_aad(cipher, extra_aad) and the bound (extra_aad, tag)
tuple, reducing the chance of a silent same-typed argument swap.
Returned bytes are unchanged. Addresses #190 review.
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