Skip to content

CCM multi-chunk streaming; keep 128-bit InitMode check (spec) - #106

Merged
MHumm merged 2 commits into
MHumm:developmentfrom
omonien:cursor/feat-ccm-multichunk-spec-2915
Sep 17, 2026
Merged

MHumm merged 2 commits into
MHumm:developmentfrom
omonien:cursor/feat-ccm-multichunk-spec-2915

Conversation

@omonien

@omonien omonien commented Sep 15, 2026

Copy link
Copy Markdown

Follow-up to #102 (points 2 and 4). Stacked on the lifecycle/API PR — please merge that first.

# Request This PR
2 CCM multi-chunk (or capability metadata) Real multi-chunk with declared total length; SupportsAuthenticatedMultiChunk True for GCM and CCM
4 InitMode 128-bit vs original CCM / RFC Check kept — original CCM, RFC 3610 §1, NIST SP 800-38C all require 128-bit blocks

CCM is not online AEAD: B_0 encodes l(m), so total payload length must be known (AuthenticatedPayloadLength, one-shot Size, or EncodeStream.DataSize).

Tests: RFC 3610 Packet 1 uneven chunks, EncodeStream internal chunks, capability flag.

Out of scope: ChaCha/Poly1305 (#90); loosening 128-bit for non-AES ciphers.

cursoragent and others added 2 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>
@MHumm

MHumm commented Sep 17, 2026

Copy link
Copy Markdown
Owner

Ok, habe mit diesem gestartet. Frage: SupportsMultiChunk sieht auf den ersten Blick ganz neet aus, aber ist abzusehen, dass es in Zukunft weitere nennenswerte Eigenschaften für solche Authenticated Modes geben wird? Falls ja fände ich ein Set evtl. besser, so wie in Context:TChipherContext.CipherType wie in DECCipherBase TDECCipher. Ich kann das für's Erste aber so übernehmen.

@MHumm

MHumm commented Sep 17, 2026

Copy link
Copy Markdown
Owner

Das finde ich leicht inkonsistent:
'''
procedure TCCM.DeclarePayloadLength(const AByteLength: UInt64);
begin
CheckNotFinalized;

if FStarted or FPayloadLengthDeclared then
Exit;

FExpectedPayloadLength := AByteLength;
FPayloadLengthDeclared := True;
end;
'''

Warum?
Weil CheckNotFinalized eine Exception wirft, den Aufruf in dem Zustand also als ganz böse deklariert, einen Aufruf nach Beginn der Verarbeitung oder wenn man schon eine Länge deklariert hat, ist nur ein Grund den Aufruf zu ignorieren.

Wenn man das aber auf Exception werfen umbauen sollte, dann könnte man im Fall von FPayLoadLengthDeclared prüfen, ob AByteLength = FExpectedPayloadLength ist ond dann keine Exception werfen. Außer man will die Anwender zum CPU-Zyklen sparen erziehen... ;-)

@MHumm
MHumm merged commit 321bf2a into MHumm:development Sep 17, 2026
@omonien

omonien commented Sep 18, 2026

Copy link
Copy Markdown
Author

Hi Markus,

danke fürs Mergen und die Hinweise!

Zu SupportsMultiChunk: Für den Moment würde ich den Boolean so lassen. Wenn später weitere nennenswerte Eigenschaften für Authenticated Modes dazukommen, können wir das gerne zu einem Set of Capabilities ausbauen (analog zu CipherType) — das wäre dann ein klarer Follow-up.

Zu DeclarePayloadLength: Da hast du recht, das ist inkonsistent. Ich würde auf Exception umstellen, außer wenn die Länge bereits deklariert ist und AByteLength gleich FExpectedPayloadLength ist — dann einfach durchlassen. Nach Start bzw. bei abweichender Länge dann Exception.

Soll ich das als kleinen Follow-up-PR nachziehen?

Viele Grüße
Olaf

@MHumm

MHumm commented Sep 18, 2026 via email

Copy link
Copy Markdown
Owner

@omonien

omonien commented Sep 18, 2026

Copy link
Copy Markdown
Author

Hallo Markus,

der kleine Follow-up zu DeclarePayloadLength ist offen: #107

Viele Grüße
Olaf

MHumm pushed a commit that referenced this pull request Sep 18, 2026
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 #106.

Co-authored-by: Olaf Monien <omonien@users.noreply.github.com>
MHumm added a commit that referenced this pull request Sep 18, 2026
…h-201b

CCM: harden DeclarePayloadLength (follow-up to #106)
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