-
Notifications
You must be signed in to change notification settings - Fork 121
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
base: main
Are you sure you want to change the base?
Conversation
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]>
625ae84
to
5ddb00b
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
There was a problem hiding this 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
ml_kem_512_params_init(¶ms); | ||
return ml_kem_keypair_derand_ref(¶ms, public_key, secret_key, seed); | ||
res = ml_kem_keypair_derand_ref(¶ms, public_key, secret_key, seed); | ||
#if defined(AWSLC_FIPS) |
There was a problem hiding this comment.
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)
.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This keeps the previous behavior from https://github.com/aws/aws-lc/pull/2195/files#diff-af6c334a9ca9f10f18987e623c41f74351fd662f0e01019d54a0716cdb710904L86. I'm OK either way.
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.