Skip to content

ml-dsa: use ctutils for constant-time selection, avoid branches#1245

Merged
tarcieri merged 10 commits intoRustCrypto:masterfrom
tob-scott-a:branchless
Mar 26, 2026
Merged

ml-dsa: use ctutils for constant-time selection, avoid branches#1245
tarcieri merged 10 commits intoRustCrypto:masterfrom
tob-scott-a:branchless

Conversation

@tob-scott-a
Copy link
Copy Markdown
Contributor

@tob-scott-a tob-scott-a commented Mar 3, 2026

Uses ctutils::CtSelect directly at call sites to replace secret-dependent branches with constant-time selection (cmov/CSEL intrinsics). No wrapper trait or macro.

Changes

  • algebra.rs: BarrettReduce::reduce, decompose, mod_plus_minus, and infinity_norm use u32::ct_select instead of if/else branches on secret values
  • hint.rs: use_hint uses u32::ct_select instead of nested branches on r0 and h
  • Cargo.toml: adds ctutils dependency

See: https://blog.trailofbits.com/2025/12/02/introducing-constant-time-support-for-llvm-to-protect-cryptographic-code/

@tarcieri
Copy link
Copy Markdown
Member

tarcieri commented Mar 8, 2026

I'd suggest just using ctutils::CtSelect directly.

Whenever stable rustc has support for the LLVM intrinsic, we can add support to ctutils.

Remove ct.rs wrapper trait/module, use ctutils::CtSelect directly
at call sites per maintainer feedback. Resolve Cargo.lock conflict
by accepting upstream.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tob-scott-a tob-scott-a changed the title ml-dsa: add ct_select macro, avoid branches in ML-DSA ml-dsa: use ctutils for constant-time selection, avoid branches Mar 24, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tarcieri tarcieri merged commit 7b0ffd0 into RustCrypto:master Mar 26, 2026
82 checks passed
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.

2 participants