Skip to content

Conversation

@jakemas
Copy link
Collaborator

@jakemas jakemas commented Oct 30, 2025

Issues:

Resolves #V1982530715 and #V1982532566

Description of changes:

The reference implementation implements poly_chknorm in variables time. It argues that while the input coefficients itself are secret in some call sites, it is okay to leak which coefficient lead to rejection. It, hence, does absolute value computation in constant-time and then checks the bound using a conditional.

This approach appears safe, but somewhat unclean as it is still operating on secret data. When performing constant-time testing it also requires a number of declassifications.

This commit takes a more conservative approach and changes poly_chknorm to a constant-time implementation in the hope that the performance penalty is acceptable.

A minor change is that the API of poly_chknorm is changed to returning 0xFFFFFFFF in the case of failure to be able to re-use existing constant-time primitives.

Call-outs:

PR source adapted from: Upstream PR in pq-code-package/mldsa-native#392.

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.

Copy link
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

Comment on lines 232 to 235
/* Reference: Leaks which polynomial violates the bound via a conditional.
* We are more conservative to reduce the number of declassifications in
* constant-time testing.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/* Reference: Leaks which polynomial violates the bound via a conditional.
* We are more conservative to reduce the number of declassifications in
* constant-time testing.
*/

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed!


/* FIPS 204: Algorithm 7 line 23 - Reject if either check fails (constant-time to avoid leaking
which check failed) */
if(z_invalid | w0_invalid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the compiler can turn this into non-CT code, please use an appropriate constant_time_* function to get the branch condition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed this check, added documentation and references to https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf section 5.5

@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2025

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.60%. Comparing base (d826708) to head (d106952).

Files with missing lines Patch % Lines
crypto/fipsmodule/ml_dsa/ml_dsa_ref/poly.c 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2788      +/-   ##
==========================================
+ Coverage   78.42%   78.60%   +0.18%     
==========================================
  Files         683      683              
  Lines      116283   116287       +4     
  Branches    16404    16407       +3     
==========================================
+ Hits        91194    91409     +215     
+ Misses      24213    24002     -211     
  Partials      876      876              

☔ 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.

Comment on lines 262 to 264
/* FIPS 204: Algorithm 7 line 23 - Reject if either check fails (constant-time to avoid leaking
which check failed) */
if(z_invalid | w0_invalid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment as above. We may want to harden this as defense-in-depth, but separate checks are OK from all we know -- and what is explicitly stated in 5.5 of https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf -- so the comment should be changed.

Copy link
Contributor

@hanno-becker hanno-becker left a comment

Choose a reason for hiding this comment

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

I'm fine with defense-in-depth hardening of poly_chknorm as already done in mldsa-native, but we should change the comment so it's not suggested that the implementation would be insecure otherwise.

I have reservations towards consolidating the validity checks. As mentioned in the comments, they too are explicitly documented in the Dilithium documentation as safe to be performed separately, and merging them comes at a meaningful performance penalty (~5%); see the test PR pq-code-package/mldsa-native#572.

@jakemas jakemas marked this pull request as ready for review November 3, 2025 19:53
@jakemas jakemas requested a review from a team as a code owner November 3, 2025 19:53
@jakemas jakemas merged commit 93f9f73 into aws:main Nov 7, 2025
381 of 388 checks passed
justsmth added a commit that referenced this pull request Nov 11, 2025
### Description of changes: 
Prepare release v1.64.0.


### What's Changed
* Update max polyz value by @jakemas in
#2787
* ECR Repositories for Android and Formal Verification Images by
@skmcgrail in #2794
* Support more "openssl rsa" options by @justsmth in
#2777
* Remove python codebuild patches by @WillChilds-Klein in
#2793
* Additional options for "openssl c_client" by @justsmth in
#2791
* GitHub-based Formal Verification Image Build by @skmcgrail in
#2796
* Use C++11 atomics to update session stats by @justsmth in
#2786
* Support "openssl dhparam" by @justsmth in
#2790
* Add scrutinice pull permissions for aws-lc/amazonlinux repository by
@skmcgrail in #2799
* Use GitHub-based Verification Images by @skmcgrail in
#2798
* Remove dead code by @torben-hansen in
#2797
* Rename snapsafe to VM UBE by @torben-hansen in
#2800
* Bump MySQL version tag to 9.5.0 by @samuel40791765 in
#2768
* Migrate to macos-15-intel by @samuel40791765 in
#2802
* Use right compiler with ruby CI by @samuel40791765 in
#2801
* Migrate analytics job to be GitHub triggered by @skmcgrail in
#2779
* Support NetBSD by @justsmth in #2754
* Make poly_chknorm constant flow by @jakemas in
#2788
* Rename fork to fork UBE by @torben-hansen in
#2803
* Extend grv asan timeout for Golang to allow completion by
@torben-hansen in #2805

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.
sgmenda-aws pushed a commit to sgmenda-aws/aws-lc that referenced this pull request Nov 11, 2025
### Description of changes: 
Prepare release v1.64.0.


### What's Changed
* Update max polyz value by @jakemas in
aws#2787
* ECR Repositories for Android and Formal Verification Images by
@skmcgrail in aws#2794
* Support more "openssl rsa" options by @justsmth in
aws#2777
* Remove python codebuild patches by @WillChilds-Klein in
aws#2793
* Additional options for "openssl c_client" by @justsmth in
aws#2791
* GitHub-based Formal Verification Image Build by @skmcgrail in
aws#2796
* Use C++11 atomics to update session stats by @justsmth in
aws#2786
* Support "openssl dhparam" by @justsmth in
aws#2790
* Add scrutinice pull permissions for aws-lc/amazonlinux repository by
@skmcgrail in aws#2799
* Use GitHub-based Verification Images by @skmcgrail in
aws#2798
* Remove dead code by @torben-hansen in
aws#2797
* Rename snapsafe to VM UBE by @torben-hansen in
aws#2800
* Bump MySQL version tag to 9.5.0 by @samuel40791765 in
aws#2768
* Migrate to macos-15-intel by @samuel40791765 in
aws#2802
* Use right compiler with ruby CI by @samuel40791765 in
aws#2801
* Migrate analytics job to be GitHub triggered by @skmcgrail in
aws#2779
* Support NetBSD by @justsmth in aws#2754
* Make poly_chknorm constant flow by @jakemas in
aws#2788
* Rename fork to fork UBE by @torben-hansen in
aws#2803
* Extend grv asan timeout for Golang to allow completion by
@torben-hansen in aws#2805

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.
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