Skip to content

Add instrumented constant-time verification (dudect + ctgrind/Valgrind) - #164

Merged
Xor-el merged 4 commits into
masterfrom
feature/ct-checks
Jul 27, 2026
Merged

Add instrumented constant-time verification (dudect + ctgrind/Valgrind)#164
Xor-el merged 4 commits into
masterfrom
feature/ct-checks

Conversation

@Xor-el

@Xor-el Xor-el commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds a measured constant-time gate under CryptoLib.ConstantTime/, pairing constant-time subjects with known-leaky controls. The gate passes only when every control fires and every subject stays clean — all under CRYPTOLIB_FORCE_SCALAR.

Two independent verification legs

Leg Tool Leak type caught
dudect (CTLeakDetect) Fix-vs-random timing, Welch's t-test (|t| > 4.5) Control-flow / iteration-count (mean-separating)
ctgrind / Valgrind (CTValgrind) Secret marked undefined via ct_poison.c Data-dependent memory access / branch (deterministic)

dudect subjects and controls

  • X25519 ladder (subject only)
  • P-256 [d]Q: FixedWindow CT vs wNAF control
  • sect283k1 [d]Q: F2m Montgomery CT vs WTauNAF control
  • AES-128 block: bit-sliced (subject only; T-table leak covered by Valgrind)
  • GHASH: ImplMul64 (subject only; 4k-table leak covered by Valgrind)
  • mod-inv (core): safegcd core vs variable-time core
  • mod-inv (wrapper): full TBigIntegerUtilities.ModOddInverse(n, k) vs variable-time wrapper — ECDSA nonce inverse measured end-to-end

Valgrind subjects and controls

  • Subjects (must be clean): x25519, aes-bitsliced, ghash-basic
  • Controls (must fire): aes-ttable, ghash-4k

New components

  • ClpDudect.pas, ClpCtClock.pas, ClpCtSubjects.pas — shared subject registry and dudect engine
  • ct_poison.c — Valgrind taint shim
  • CTLeakDetect / CTValgrind Lazarus console programs
  • CryptoLib.ConstantTime/README.md — coverage matrix, local run instructions, setup notes

CI integration

  • Add .github/workflows/ci/valgrind-ct.sh — builds CTValgrind against prebuilt scalar packages and runs the taint gate
  • Wire into linux-x64-scalar and linux-arm64-scalar jobs (after standard build)
  • Add MAKE_RUN_CT_VALGRIND toggle (default true; set false to skip)

Xor-el added 4 commits July 27, 2026 09:50
Measured-CT gate: paired constant-time subjects and known-leaky controls, the
gate being "controls fire AND subjects clean". dudect (CTLeakDetect) covers the
wNAF/tau-NAF/variable-time-inverse control-flow leaks; ctgrind/Valgrind
(CTValgrind + ct_poison.c) covers the T-table AES / 4k GHASH memory-access
leaks. All under CRYPTOLIB_FORCE_SCALAR. Valgrind leg wired into the
linux-x64-scalar CI job (ci/valgrind-ct.sh, MAKE_RUN_CT_VALGRIND toggle).
Measured-CT gate under CryptoLib.ConstantTime/: constant-time subjects paired
with known-leaky controls, the gate being "controls fire AND subjects clean",
all under CRYPTOLIB_FORCE_SCALAR. dudect (CTLeakDetect) covers the wNAF /
tau-NAF / variable-time-inverse control-flow leaks; ctgrind/Valgrind
(CTValgrind + ct_poison.c) covers the T-table AES / 4k GHASH memory-access
leaks. Valgrind leg wired as a CI gate in the linux-x64-scalar and
linux-arm64-scalar jobs (native x86_64 + AArch64); MAKE_RUN_CT_VALGRIND toggle.
Add a `mod-inv (wrapper)` row measuring the exact signer call
TBigIntegerUtilities.ModOddInverse(n, k) — the full TBigInteger wrapper, not
just the safegcd core — with k in [1, n-1], fixed class n-1, allocation-
symmetric prep, and only the call timed. Subject clean on both x86_64 cells,
variable-time control fires: the nonce inverse is measured-CT end-to-end.
Updates the README coverage matrix (aarch64 dudect open; macOS not pursued).
@Xor-el
Xor-el merged commit 2d47544 into master Jul 27, 2026
28 checks passed
@Xor-el
Xor-el deleted the feature/ct-checks branch July 27, 2026 12:06
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