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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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
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]>
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.03%. Comparing base (7518c78) to head (5ddb00b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2195      +/-   ##
==========================================
- Coverage   79.04%   79.03%   -0.02%     
==========================================
  Files         612      612              
  Lines      106067   106078      +11     
  Branches    14985    14984       -1     
==========================================
- Hits        83842    83840       -2     
- Misses      21571    21586      +15     
+ Partials      654      652       -2     

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

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
11 tasks
ml_kem_512_params_init(&params);
return ml_kem_keypair_derand_ref(&params, public_key, secret_key, seed);
res = ml_kem_keypair_derand_ref(&params, public_key, secret_key, seed);
#if defined(AWSLC_FIPS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be implemented in AWS_LC_FIPS_failure?

Maybe can avoid littering the code-base with if defined(AWS_FIPS).

Copy link
Contributor Author

@hanno-becker hanno-becker Feb 14, 2025

Choose a reason for hiding this comment

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

I stuck with the precedent here. If one wants to change this, it should be a separate PR, as there are other calls to AWS_LC_FIPS_failure.

AWS_LC_FIPS_failure("ML-KEM keygen PCT failed");
}
#else
assert(res == 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why capture here? All other code-paths normally throw it up the stack.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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