Skip to content

feat(sdk): DSPX-4495 remove 64GiB TDF limit, use counter-based payload IVs (DSP… - #393

Open
sujankota wants to merge 1 commit into
mainfrom
feat/tdf3-size-64gb-limit
Open

feat(sdk): DSPX-4495 remove 64GiB TDF limit, use counter-based payload IVs (DSP…#393
sujankota wants to merge 1 commit into
mainfrom
feat/tdf3-size-64gb-limit

Conversation

@sujankota

@sujankota sujankota commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Removes MAX_TDF_INPUT_SIZE (68719476736) and the size check in createTDF. That constant was GCM's per-invocation plaintext limit (2^39-256 bits) misapplied to the whole TDF input; each segment is its own invocation and is capped at 4MiB by Config.MAX_SEGMENT_SIZE, so the bound was never relevant. SDK.DataSizeNotSupported is retained as public API but is no longer thrown.

Replaces the random per-segment AES-GCM nonce with a deterministic unsigned 96-bit big-endian counter (TDF.IvCounter). NIST SP 800-38D prefers the deterministic construction; the RBG-based one it replaces carries a birthday bound that a counter does not have.

Metadata is encrypted with the per-split symKey while the payload uses the XOR of all split keys, so with a single key split the two are the same key. IV 0 is therefore reserved for the metadata and payload segments start at IV 1.

The counter enforces the SP 800-38D 8.3 cap of 2^32 invocations per key and refuses to wrap, so an IV can never be issued twice. Neither limit is reachable in practice - at the 16KiB minimum segment size the cap is 64TiB of input - but the invariant now holds by construction rather than by assumption.

Every segment is still prefixed with its 12-byte IV, so the wire format is unchanged and existing TDFs continue to decrypt.

Summary by CodeRabbit

  • New Features

    • TDF creation no longer enforces a fixed input-size limit.
    • Encryption now uses deterministic, sequential IVs for metadata and payload segments.
    • Added safeguards to prevent IV reuse and enforce the AES-GCM invocation budget.
  • Documentation

    • Clarified that the data-size exception is retained only for legacy compatibility.

…X-4495)

Removes MAX_TDF_INPUT_SIZE (68719476736) and the size check in createTDF.
That constant was GCM's per-invocation plaintext limit (2^39-256 bits)
misapplied to the whole TDF input; each segment is its own invocation and is
capped at 4MiB by Config.MAX_SEGMENT_SIZE, so the bound was never relevant.
SDK.DataSizeNotSupported is retained as public API but is no longer thrown.

Replaces the random per-segment AES-GCM nonce with a deterministic unsigned
96-bit big-endian counter (TDF.IvCounter). NIST SP 800-38D prefers the
deterministic construction; the RBG-based one it replaces carries a birthday
bound that a counter does not have.

Metadata is encrypted with the per-split symKey while the payload uses the XOR
of all split keys, so with a single key split the two are the same key. IV 0 is
therefore reserved for the metadata and payload segments start at IV 1.

The counter enforces the SP 800-38D 8.3 cap of 2^32 invocations per key and
refuses to wrap, so an IV can never be issued twice. Neither limit is reachable
in practice - at the 16KiB minimum segment size the cap is 64TiB of input - but
the invariant now holds by construction rather than by assumption.

Every segment is still prefixed with its 12-byte IV, so the wire format is
unchanged and existing TDFs continue to decrypt.

Signed-off-by: sujan kota <sujankota@gmail.com>
@sujankota
sujankota requested review from a team as code owners August 27, 2026 21:35
@coderabbitai

coderabbitai Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f02e0a8b-d2eb-48bc-b6ff-4a937c79a88d

📥 Commits

Reviewing files that changed from the base of the PR and between 57d070b and a39b99c.

📒 Files selected for processing (3)
  • sdk/src/main/java/io/opentdf/platform/sdk/SDK.java
  • sdk/src/main/java/io/opentdf/platform/sdk/TDF.java
  • sdk/src/test/java/io/opentdf/platform/sdk/TDFTest.java

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Changes

TDF encryption contract

Layer / File(s) Summary
Remove TDF input-size enforcement
sdk/src/main/java/io/opentdf/platform/sdk/SDK.java, sdk/src/main/java/io/opentdf/platform/sdk/TDF.java, sdk/src/test/java/io/opentdf/platform/sdk/TDFTest.java
The TDF API no longer exposes or enforces the previous input-size limit. The compatibility exception documentation and tests were updated.
Add bounded IV counter
sdk/src/main/java/io/opentdf/platform/sdk/TDF.java, sdk/src/test/java/io/opentdf/platform/sdk/TDFTest.java
IvCounter generates 96-bit big-endian IVs. Metadata uses IV 0. Payload segments start at IV 1. Counter wraparound and the AES-GCM invocation budget raise SDKException.
Wire explicit IV encryption
sdk/src/main/java/io/opentdf/platform/sdk/TDF.java, sdk/src/test/java/io/opentdf/platform/sdk/TDFTest.java
Metadata and payload encryption pass explicit counter-derived IVs to AES-GCM. Tests verify metadata IV 0 and unique, sequential payload IVs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: 🔵 Low · up to a39b9

The SDK now supports inputs beyond 64 GiB, but callers that pass untrusted or non-terminating streams must enforce their own byte, duration, cancellation, and output limits to avoid unbounded encryption work, output growth, and memory use. This is a bounded owner-awareness follow-up rather than a demonstrated merge blocker.

Sequence Diagram(s)

sequenceDiagram
  participant TDF
  participant IvCounter
  participant AesGcm
  participant TDFOutput
  TDF->>IvCounter: metadataIv()
  TDF->>AesGcm: encrypt(IV 0, metadata)
  AesGcm-->>TDF: encrypted metadata
  TDF->>IvCounter: forPayload()
  loop Each payload segment
    TDF->>IvCounter: next()
    IvCounter-->>TDF: next sequential IV
    TDF->>AesGcm: encrypt(payload IV, segment)
    AesGcm-->>TDF: encrypted segment
    TDF->>TDFOutput: write IV and ciphertext
  end
Loading

Suggested reviewers: biscoe916

Poem

A rabbit counts IVs, one, two, three,
Metadata rests at zero peacefully.
Payloads march in ordered flight,
No counter wraps into the night,
AES-GCM keeps its sequence right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the two main changes: removal of the 64 GiB TDF limit and adoption of counter-based payload IVs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/tdf3-size-64gb-limit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

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.

1 participant