Repository navigation
feat(sdk): return ErrAESGCMExhausted when IV collision risk exceeds 2^-32 (DSPX-4492) - #4203
Merged
Merged
Conversation
…^-32 (DSPX-4492) TDF writers now refuse to encrypt more than 2^32-1 payload segments under one DEK. With random 96-bit IVs the collision probability is about k^2/2^97, and NIST SP 800-38D section 8 caps it at 2^-32. Attempts are counted, and the check runs before the segment is encrypted, on every CreateTDF path and the chunked/experimental writers. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 55 minutes. View limit detailsLimit details: You’ve used the included review currently available. Review configuration: ⚙️ Run configuration
📒 Files selected for processing (9)
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. Comment |
Contributor
Benchmark results, click to expandBulk Benchmark Results
TDF3 Benchmark Results
|
Contributor
|
Contributor
dmihalcik-virtru
marked this pull request as ready for review
October 8, 2026 20:28
pflynn-virtru
approved these changes
Oct 9, 2026
dmihalcik-virtru
enabled auto-merge
October 9, 2026 15:04
dmihalcik-virtru
disabled auto-merge
October 9, 2026 15:10
dmihalcik-virtru
added a commit
that referenced
this pull request
Oct 14, 2026
…nter Align the Go SDK with option 2b of the AES-GCM IV ADR (virtru-corp/adr#373): - ocrypto: MaxSeals is 2^32-1 on both the deterministic and the random-IV (FIPS) path, the cap #4203 already enforced on random IVs. At the cap the random path sits at P ~ 2^-33, inside SP 800-38D's 2^-32. - sdk: drop the derived default segment size; it is 2 MiB (max 4 MiB) again in every mode, and maxPayloadSegments is the archive's MaxInt32 again. - sdk: drop the writer's own encryption counter. The DEK sealer's counter is the only budget, and ocrypto.ErrSealerExhausted is reported wrapped as ErrAESGCMExhausted. Tests reach the cap through an injected sealer instead of a lowered writer cap. - adr: record the decision and the rejected 2^26 cap. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
dmihalcik-virtru
added a commit
that referenced
this pull request
Oct 15, 2026
…nter Align the Go SDK with option 2b of the AES-GCM IV ADR (virtru-corp/adr#373): - ocrypto: MaxSeals is 2^32-1 on both the deterministic and the random-IV (FIPS) path, the cap #4203 already enforced on random IVs. At the cap the random path sits at P ~ 2^-33, inside SP 800-38D's 2^-32. - sdk: drop the derived default segment size; it is 2 MiB (max 4 MiB) again in every mode, and maxPayloadSegments is the archive's MaxInt32 again. - sdk: drop the writer's own encryption counter. The DEK sealer's counter is the only budget, and ocrypto.ErrSealerExhausted is reported wrapped as ErrAESGCMExhausted. Tests reach the cap through an injected sealer instead of a lowered writer cap. - adr: record the decision and the rejected 2^26 cap. Signed-off-by: Dave Mihalcik <dmihalcik@virtru.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
sdk.ErrAESGCMExhausted, aliased asexperimental/tdf.ErrAESGCMExhausted. A TDF writer returns it, wrapped with%w, when encrypting another segment would push the AES-GCM IV collision probability under the DEK above 2^-32.maxAESGCMSegmentsPerDEK = 2^32 - 1.chunkedWriter.WriteSegment, which every write path goes through:CreateTDFwith a known length,CreateTDFwith an unknown-length stream (no cap there before this change; see DSPX-4905),NewChunkedWriter, and the experimentaltdf.Writer. It runs under the writer lock, before the segment is encrypted, and it counts attempts. A failed encryption has still drawn an IV, so a retry does not get it back.crypto/rand96-bit IVs throughocrypto.AesGcmin every mode. Deterministic §8.2.1 IVs and FIPS mode will be stacked on top of this PR later (see feat(sdk): derive AES-GCM segment IVs from a message id and part number #4118 / feat(sdk): stateful per-key AES-GCM IV counter (alternative to #4118) #4121).Crypto-risk callout: if two GCM IVs collide under one DEK, the XOR of the two plaintexts and the GHASH key are exposed, which allows forgery under that key. This PR adds a hard stop only. It does not change the wire format, and readers are unaffected. In practice the cap is out of reach: at the 2 MiB default segment size it is about 8 PiB, and at the 16 KiB minimum it is about 64 TiB.
Note: the existing declared-size check (
errTooManySegments,math.MaxInt32segments, archive int addressing) is stricter than this cap and stays as it is. That means known-length inputs still fail early with that error. The new cap is what bounds unknown-length streams and the chunked writers.Checklist
Testing Instructions
The tests lower the cap through unexported test seams (
withChunkedMaxEncryptions,withMaxSegmentEncryptions), so they reach the error without encrypting 2^32 segments. They cover the following:CreateTDFreturnsErrAESGCMExhaustedfor both known-length and unknown-length input.Part of DSPX-4492.