Skip to content

Fix mldsa constant time issues#1386

Open
lukaszobernig wants to merge 2 commits into
RustCrypto:masterfrom
lukaszobernig:fix_mldsa_constant_time
Open

Fix mldsa constant time issues#1386
lukaszobernig wants to merge 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.
@lukaszobernig lukaszobernig force-pushed the fix_mldsa_constant_time branch from 6d25679 to 73325cc Compare June 17, 2026 14:41
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