8000 Add return checks on SHA3 functions in ML-KEM by manastasova · Pull Request #1859 · aws/aws-lc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add return checks on SHA3 functions in ML-KEM #1859

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

Merged
merged 6 commits into from
Sep 20, 2024
Merged

Conversation

manastasova
Copy link
Contributor

Issues:

Resolves #P155314914

Description of changes:

Add checks on the return values of {SHA3,SHAKE}_{Init,Update,Final} and SHAKE256 when consumed by ML-KEM.

Call-outs:

Coverity Defect is generated when SHA3_Update return code is not checked. Checks on the return values are added to all FIPS202 function calls.

Testing:

./crypto/crypto_test

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.

@manastasova manastasova requested a review from a team as a code owner September 17, 2024 21:35
@codecov-commenter
Copy link
codecov-commenter commented Sep 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.45%. Comparing base (9c8bd6d) to head (b3f75f4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1859      +/-   ##
==========================================
- Coverage   78.46%   78.45%   -0.01%     
==========================================
  Files         585      585              
  Lines       99458    99458              
  Branches    14238    14236       -2     
==========================================
- Hits        78036    78033       -3     
- Misses      20786    20788       +2     
- Partials      636      637       +1     

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

Comment on lines 28 to 33
if (SHAKE_Init(ctx, SHAKE128_BLOCKSIZE) == 0) {
return;
}
if (SHA3_Update(ctx, extseed, sizeof(extseed)) == 0) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

While this is checking the return code now, is this safe to do? If SHAKE_Init fails can ML-KEM continue? Options I see:

  1. Make SHAKE_Init void (if it can be void and never fails)
  2. Make kyber_shake128_absorb non-void and bubble up the failure
  3. If SHAKE_init fails abort

My concern is if kyber_shake128_absorb silently fails and continues AWS-LC will be in an inconsistent state and generate an invalid result but callers will think AWS-LC succeeded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my understanding, SHA3_Update is the one creating the issue.

  1. We could make it void, however, it's success/failure is based on the execution of SHA3_Absorb, which returns the number of bytes still to be processed. Called from SHA3_Update, SHA3_Absorb is called to process the leftover data in the buffer (if any from previous calls to SHA3_Update). If the data is enough to fill at least an entire block, SHA3_Absorb will be called first on a single block. In case the block is not completely processed, the return value of SHA3_Absorb is indicating an error. This case, indeed, should never happen (even if Keccak is not executed correctly, it is a void function, so the incorrect data will be stored independently, indicating the success of SHA3_Absorb, thus, of SHA3_Update). So, we could make SHA3_Update a void function, however, we should not check the returns that are called from it either, and we cannot make SHA3_Absorb void.
  2. In the ML-KEM there are no checks for the xof success.
  3. We could abort, however, would that not impact the flow when two parties are executing the kem?

From my understanding, the tests on SHA3, SHAKE are checking the correctness of SHA3/SHAKE functionality. Since we only use the SHA3/SHAKE tested functions, we could assume they are executing correctly if SHA3/SHAKE tests pass.

@andrewhop andrewhop merged commit f89c9be into aws:main Sep 20, 2024
109 of 110 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.

4 participants
0