Skip to content

CCM: harden DeclarePayloadLength (follow-up to #106) - #12

Closed
omonien wants to merge 7 commits into
developmentfrom
cursor/ccm-declare-payload-length-201b
Closed

omonien wants to merge 7 commits into
developmentfrom
cursor/ccm-declare-payload-length-201b

Conversation

@omonien

@omonien omonien commented Sep 18, 2026

Copy link
Copy Markdown
Owner

Follow-up to MHumm#106.

Markus noted that TCCM.DeclarePayloadLength was inconsistent: CheckNotFinalized already raises after Done, but a call after processing has started or after a length was already declared was silently ignored.

Agreed with Markus (“Jupp!”) — this PR applies that:

  1. After Done/finalize → still raise via CheckNotFinalized.
  2. Re-declare the same length → allowed (idempotent).
  3. Re-declare a different length → EDECCipherException.
  4. Declare after Encode/Decode has started → EDECCipherException.
  5. Otherwise set FExpectedPayloadLength / FPayloadLengthDeclared as before.

EncodeStream only auto-declares when no payload length is set yet, so existing multi-chunk streams that already set AuthenticatedPayloadLength keep working.

SupportsMultiChunk stays a Boolean.

Unit tests in TestDECCipherModesCCM.pas cover the cases above (including Decode-after-start).

Target: intended merge is MHumm/DelphiEncryptionCompendium branch development (cross-fork). Versus that base the delta is 5 files / +164 −8. This GitHub App cannot open the upstream PR (createPullRequest is not allowed on MHumm); please retarget or open from omonien:cursor/ccm-declare-payload-length-201b onto MHumm development. The larger diff on this fork PR is only because omonien/development does not yet include merged MHumm#106.

Open in Web Open in Cursor 

cursoragent and others added 7 commits September 15, 2026 13:11
Follow-up to PR MHumm#102 (points 1, 3, 5, 6). Reading CalculatedAuthenticationTag
before Done now raises EDECCipherException. Protected EncodeGCM/EncodeCCM
are unified as EncodeAuthenticated (Decode counterpart too). CCM materializes
the authentication tag in Done so GCM and CCM share one lifecycle. Modes
without prescribed tag lengths document returning an empty array.

Co-authored-by: Olaf Monien <omonien@users.noreply.github.com>
Follow-up to PR MHumm#102 (points 2 and 4). CCM can process several Encode/Decode
chunks when the total payload length is known (AuthenticatedPayloadLength or
a one-shot Size / EncodeStream DataSize). B_0 still encodes l(m) as required
by RFC 3610 / NIST SP 800-38C. InitMode keeps the 128-bit block-size check
for both GCM and CCM; comments cite the original CCM spec, RFC 3610, and
SP 800-38C/38D. SupportsAuthenticatedMultiChunk reports the capability.

Co-authored-by: Olaf Monien <omonien@users.noreply.github.com>
…api-2915

AEAD lifecycle/API: tag after Done, EncodeAuthenticated, CCM via Done
…spec-2915

CCM multi-chunk streaming; keep 128-bit InitMode check (spec)
Make TCCM.DeclarePayloadLength fail hard after start or when a different
length is declared, while still allowing an idempotent re-declare of the
same length. EncodeStream only auto-declares when no length is set yet so
multi-chunk streams keep working.

Follow-up to MHumm#106.

Co-authored-by: Olaf Monien <omonien@users.noreply.github.com>
@omonien

omonien commented Sep 18, 2026

Copy link
Copy Markdown
Owner Author

Opened upstream as MHumm#107 — closing this fork listing as duplicate.

@omonien omonien closed this Sep 18, 2026
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.

3 participants