Skip to content

ML-DSA constant-time hardening for caddq, poly_chknorm, decompose#2602

Merged
dkostic merged 1 commit intoaws:mainfrom
dkostic:ml-dsa-ct-hardening
Aug 12, 2025
Merged

ML-DSA constant-time hardening for caddq, poly_chknorm, decompose#2602
dkostic merged 1 commit intoaws:mainfrom
dkostic:ml-dsa-ct-hardening

Conversation

@dkostic
Copy link
Copy Markdown
Contributor

@dkostic dkostic commented Aug 5, 2025

Issues:

N/A

Description of changes:

ML-DSA constant-time hardening for caddq, poly_chknorm, decompose

Based on pq-code-package/mldsa-native#371.

Call-outs:

Point out areas that need special attention or support during the review process. Discuss architecture or design changes.

Testing:

How is this change tested (unit tests, fuzz tests, etc.)? Are there any testing steps to be verified by the reviewer?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@dkostic dkostic requested a review from a team as a code owner August 5, 2025 20:42
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

int32_t ml_dsa_caddq(int32_t a) {
a += (a >> 31) & ML_DSA_Q;
// a = a < 0 ? a + Q : a;
a = constant_time_select_int(constant_time_msb_w(a), a + ML_DSA_Q, a);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: call to undeclared function 'constant_time_msb_w'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration]

  a = constant_time_select_int(constant_time_msb_w(a), a + ML_DSA_Q, a);
                               ^

int32_t ml_dsa_caddq(int32_t a) {
a += (a >> 31) & ML_DSA_Q;
// a = a < 0 ? a + Q : a;
a = constant_time_select_int(constant_time_msb_w(a), a + ML_DSA_Q, a);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: call to undeclared function 'constant_time_select_int'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration]

  a = constant_time_select_int(constant_time_msb_w(a), a + ML_DSA_Q, a);
      ^

a1 = (a1*11275 + (1 << 23)) >> 24;
a1 ^= ((43 - a1) >> 31) & a1;
// a1 = 43 < a1 ? 0 : a1;
a1 = constant_time_select_int(constant_time_msb_w(43 - a1), 0, a1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: call to undeclared function 'constant_time_msb_w'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration]

    a1 = constant_time_select_int(constant_time_msb_w(43 - a1), 0, a1);
                                  ^

a1 = (a1*11275 + (1 << 23)) >> 24;
a1 ^= ((43 - a1) >> 31) & a1;
// a1 = 43 < a1 ? 0 : a1;
a1 = constant_time_select_int(constant_time_msb_w(43 - a1), 0, a1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

warning: call to undeclared function 'constant_time_select_int'; ISO C99 and later do not support implicit function declarations [clang-diagnostic-implicit-function-declaration]

    a1 = constant_time_select_int(constant_time_msb_w(43 - a1), 0, a1);
         ^

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.68%. Comparing base (d966806) to head (579a7a5).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2602   +/-   ##
=======================================
  Coverage   78.68%   78.68%           
=======================================
  Files         645      645           
  Lines      110738   110744    +6     
  Branches    15656    15661    +5     
=======================================
+ Hits        87132    87144   +12     
+ Misses      22915    22910    -5     
+ Partials      691      690    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dkostic dkostic enabled auto-merge (squash) August 12, 2025 17:05
@dkostic dkostic merged commit 2a184bd into aws:main Aug 12, 2025
133 of 139 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.

5 participants