fix: branchless modular arithmetic to close NTT timing side-channel#1210
Closed
BAder82t wants to merge 1 commit into
Closed
fix: branchless modular arithmetic to close NTT timing side-channel#1210BAder82t wants to merge 1 commit into
BAder82t wants to merge 1 commit into
Conversation
Closes openfheorg#1198. MultipartyDecryptFusion calls INTT on secret-correlated polynomial b = cv[0] + s*cv[1] + noise. Secret-dependent conditional branches in the butterfly (e.g. if (loVal < omegaFactor) loVal += mod) are timing oracles attackable via adaptive-chosen-ciphertext. New utils/constanttime.h adds SubIfGE, ModSubFast, AddIfNeg using the branchless mask idiom (no asm barriers, vectorisation preserved). Ten functions in ubintnat.h patched. All nine butterfly sites in transformnat-impl.h made branchless; #ifdef __GNUC__ compiler-dispatch splits and if (omegaFactor != zero) shortcut removed. NTT test added for zero-coefficient input path. Benchmarks vs original (clang -O3, Apple M-series): ModAddFast scalar: -3% | NTT n=4096: +4% | NTT n=16384: +5% (PR openfheorg#1177 asm-barrier approach regressed NTT by 49-52%) Known pre-existing limitations documented in constanttime.h: WASM: MultD carry-detect branches remain data-dependent. Non-power-of-2 rings: Bluestein INTT path not covered.
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
Closes #1198.
MultipartyDecryptFusioncalls INTT on secret-correlated polynomialb = cv[0] + s·cv[1] + noiseif (loVal < omegaFactor) loVal += modulus) leak key bits via timing__asm__ volatilebarriers but caused 1.5–1.9× NTT regressionThis PR uses the branchless mask idiom instead — no barriers, vectorisation preserved.
Changes
utils/constanttime.h—SubIfGE,ModSubFast,AddIfNegCT primitivesubintnat.h— 10 functions patched:ModAddFast/Eq,ModSubFast/Eq,ModMulFastConst/Eq,ModMulFast/Eqtransformnat-impl.h— all 9 butterfly sites made branchless;#ifdef __GNUC__splits removedUnitTestNTT.cpp— test added for zero-coefficient input pathBenchmarks (Apple M-series, clang -O3)
2051/2051 tests pass.
Known limitations (pre-existing)
MultDcarry-detect branches remain data-dependent; documented inconstanttime.h