Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ML-KEM: Move FIPS-abort upon PCT failure to top-level ML-KEM API #2195

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

hanno-becker
Copy link
Contributor

@hanno-becker hanno-becker commented Feb 13, 2025

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.

Discussed with: @andrewhop


If AWSLC_FIPS is set, ML-KEM includes a PCT check after key generation, in compliance with the FIPS-203 IG
https://csrc.nist.gov/csrc/media/Projects/cryptographic-module-validation-program/documents/fips%20140-3/FIPS%20140-3%20IG.pdf If the PCT fails, AWS_LC_FIPS_failure is called to abort operation.

This PR hoists the call to AWS_LC_FIPS_failure one level up, into the toplevel ML-KEM API of crypto/fipsmodule/ml_kem/ml_kem.h: When the PCT fails, the lower-level key generation API that invokes the PCT returns -1, which is caught by the top-level ML-KEM API and converted into a call to AWS_LC_FIPS_failure. There is no other failure condition during key generation.

When the PCT fails in the randomized key generation API, the coins are still cleansed before propagating the PCT error. It could be considered whether the PK and SK should be cleansed in this case, too, but this commit does not change behvaiour in this regard.

The change facilitates replacing the ML-KEM reference implementation, specifically mlkem-native (see #2176), since only the return-value behaviour needs to be maintained, but an alternative implementation need not be aware of the abort macro AWS_LC_FIPS_failure.

@hanno-becker hanno-becker marked this pull request as ready for review February 13, 2025 12:05
@hanno-becker hanno-becker requested a review from a team as a code owner February 13, 2025 12:05
@hanno-becker hanno-becker changed the title ML-KEM: Move FIPS-abort upon PCT failure to top-level API ML-KEM: Move FIPS-abort upon PCT failure to top-level ML-KEM API Feb 13, 2025
@codecov-commenter
Copy link

codecov-commenter commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.03%. Comparing base (154f998) to head (667c142).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2195      +/-   ##
==========================================
- Coverage   79.05%   79.03%   -0.02%     
==========================================
  Files         612      612              
  Lines      106159   106167       +8     
  Branches    15002    15004       +2     
==========================================
- Hits        83923    83913      -10     
- Misses      21582    21600      +18     
  Partials      654      654              

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

andrewhop
andrewhop previously approved these changes Feb 13, 2025
Copy link
Contributor

@jakemas jakemas left a comment

Choose a reason for hiding this comment

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

Looks good to me

@hanno-becker hanno-becker mentioned this pull request Feb 14, 2025
1 task
If AWSLC_FIPS is set, ML-KEM includes a PCT check after key generation,
in compliance with the FIPS-203 IG
https://csrc.nist.gov/csrc/media/Projects/cryptographic-module-validation-program/documents/fips%20140-3/FIPS%20140-3%20IG.pdf
If the PCT fails, AWS_LC_FIPS_failure is called to abort operation.

This commit hoists the call to AWS_LC_FIPS_failure one level up,
into the toplevel ML-KEM API of crypto/fipsmodule/ml_kem/ml_kem.h:
When the PCT fails, the lower-level key generation API that invokes
the PCT returns -1, which is caught by the top-level ML-KEM API
and converted into a call to AWS_LC_FIPS_failure. There is no other
failure condition during key generation.

When the PCT fails in the randomized key generation API, the coins are
still cleansed before propagating the PCT error. It could be considered
whether the PK and SK should be cleansed in this case, too, but this
commit does not change behvaiour in this regard.

The change facilitates replacing the ML-KEM reference implementation,
since only the return-value behaviour needs to be maintained, but an
alternative implementation need not be aware of the abort macro
AWS_LC_FIPS_failure.

Signed-off-by: Hanno Becker <[email protected]>
@hanno-becker
Copy link
Contributor Author

@andrewhop @jakemas I rebased and addressed @torben-hansen's request to remove the assert(res == 0). Can you please re-review?

@torben-hansen torben-hansen merged commit 90b2336 into aws:main Feb 18, 2025
114 of 119 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.

6 participants