security(ntt): make Barrett reduction branchless, closing the constant-time gap#55
Merged
Merged
Conversation
…t-time gap Replaces priv_barrett's data-dependent canonicalization (if r<0 ... if r>=q ...) with a branchless version using only unsigned arithmetic and a well-defined C99 boolean comparison, contributed by u/robchroma on r/C_Programming in response to the constant-time caveat this project had documented. Exhaustively verified against a % q for all 22,164,483 valid inputs in [0, 2*q^2] before adoption, not spot-checked. Rebuilt and re-ran the full test suite (335 tests) plus AddressSanitizer/UndefinedBehaviorSanitizer, clean under both, and recompiled under -std=c99 -pedantic-errors -Wall -Wextra -Werror on gcc and clang with zero warnings. Updates docs/algorithms/ntt.md and README.md to reflect that no known data-dependent branches remain in the transform, while keeping the honest caveat that this is not a formally audited cryptographic primitive. Credits robchroma in CONTRIBUTORS.md and adds a CHANGELOG entry.
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.
Summary
Direct response to feedback on r/C_Programming (Bman1296, robchroma, AttractiveDaddy) on the constant-time caveat documented in
docs/algorithms/ntt.md. u/robchroma proposed a branchless canonicalization forpriv_barrettthat avoids the implementation-defined-behavior problem with the reference Kyber technique.Verification
a % qfor all 22,164,483 valid inputs in[0, 2*q^2], zero mismatches (not spot-checked)-std=c99 -pedantic-errors -Wall -Wextra -Werroron both gcc and clang: zero warningsDocs
Updates the constant-time warning in
docs/algorithms/ntt.mdandREADME.mdto reflect the fix, while keeping the honest caveat that this isn't a formally audited cryptographic primitive. Credits robchroma inCONTRIBUTORS.md, adds a### Securityentry toCHANGELOG.md.Not done here (separate, larger decision)
This closes the specific constant-time gap that was documented and publicly flagged. It does not constitute a security audit of the NTT module as a whole.