Skip to content

ml-dsa: fix constant time issues#1386

Merged
tarcieri merged 2 commits into
RustCrypto:masterfrom
lukaszobernig:fix_mldsa_constant_time
Jun 24, 2026
Merged

ml-dsa: fix constant time issues#1386
tarcieri merged 2 commits into
RustCrypto:masterfrom
lukaszobernig:fix_mldsa_constant_time

Conversation

@lukaszobernig

Copy link
Copy Markdown
Contributor

I saw that these two spots still used non-constant time code, let's replace this with branchless implementations instead.

  • We only call coeff_from_half_byte during key generation, which means it is a lot harder for an attacker to collect enough execution traces. But since we generally use private key seeds, it's usually not just a one-shot for a fixed input and there is a chance to collect more traces. So it's definitely worth fixing in my opinion.

  • The change to Vector::infinity_norm is not absolutely required, since by https://pq-crystals.org/dilithium/data/dilithium-specification-round3.pdf, section 5.5, it is OK to leak which coefficient violates the bound as long as we do not leak the coefficient itself or its sign. The change to Polynomial::infinity_norm although is important since it fixes that potential leak of information about the individual coefficients. Let me know if you would want to keep Vector::infinity_norm as is, this would probably save a tiny amount of instruction cycles.

Algorithm 15 (CoeffFromHalfByte) is called during ExpandS in key generation to sample the secret signing key vectors s1 and s2 from rho'.

Rejection sampling inherently leaks accept/reject decisions, but data-dependent branches within the accepted range leak secret coefficient values via branch timing and predictor state. Using ctutils ensures coefficient reduction and sign selection are branch-free.
Polynomial::infinity_norm and Vector::infinity_norm are called during the signing loop to check rejection bounds on secret-derived vectors.

Replacing Iterator::max() with a constant-time fold reduction via ctutils eliminates data-dependent comparison branches.

@tarcieri tarcieri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tarcieri tarcieri changed the title Fix mldsa constant time issues ml-dsa: fix constant time issues Jun 24, 2026
@tarcieri tarcieri merged commit 31b7540 into RustCrypto:master Jun 24, 2026
10 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