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

Switch ML-DSA to use AWS-LC SHA3 #2001

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

jakemas
Copy link
Contributor

@jakemas jakemas commented Nov 19, 2024

Issues:

Resolves CryptoAlg-2726

Description of changes:

Following the inclusion of SHAKE as an extensible-output-function (XOF) in #1839, we are now able to fully support ML-DSA with SHA3/SHAKE usage within crypto/fipsmodule. As such, all references to the internal implementation of SHA3 (within crypto/dilithium/pqcrystals_dilithium_ref_common/fips202.{h|c}) have been removed.

Call-outs:

  • The structure keccak_state provided by the Dilithium reference implementation has been replaced with KECCAK1600_CTX
  • The calls to absorb/update/final have been replaced with a straight swap to AWS-LC's implementation
  • The dilithium specific function dilithium_shake128_stream_init, dilithium_shake128_squeeze, dilithium_shake256_stream_init, dilithium_shake256_squeeze of fips202.c has been replaced with versions that call SHA3 from fipsmodule.

Testing:

The testing framework is the KATs for ML-DSA, and all other ML-DSA tests completed.

#CryptoAlg-2589 design documentation provides an analysis of all fips202.c usage from ML-DSA, to verify that all functionality that used to be provided by fips202.c has been replaced by this commit, the file has been removed from the library.

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.

@jakemas jakemas requested a review from a team as a code owner November 19, 2024 19:25
@jakemas
Copy link
Contributor Author

jakemas commented Nov 19, 2024

See c4a0fdb for the changes proposed in this PR without the muddiness of #1999

@codecov-commenter
Copy link

codecov-commenter commented Nov 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.89%. Comparing base (80f984e) to head (69e15e7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2001      +/-   ##
==========================================
- Coverage   78.90%   78.89%   -0.01%     
==========================================
  Files         594      594              
  Lines      102415   102414       -1     
  Branches    14517    14517              
==========================================
- Hits        80812    80804       -8     
- Misses      20953    20960       +7     
  Partials      650      650              

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


🚨 Try these New Features:

Copy link
Contributor

@geedo0 geedo0 left a comment

Choose a reason for hiding this comment

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

Looks pretty straightforward. The only big thing missing here seems to be updates to the README.md file.


void dilithium_shake128_stream_init(keccak_state *state, const uint8_t seed[SEEDBYTES], uint16_t nonce)
/*************************************************
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll defer to the LC team on this point, but IMO the docstrings here should be in the header file and match LC's style conventions for comments. I can see that these were ported over from the fips202 source, so I can see the merit in retaining that style and content. It's also not part of LC's public interface so I feel less strong about belaboring it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call out. As I added these functions within the crypto/dilithium/pqcrystals_dilithium_ref_common/ directory, I wanted to be consistant with function conventions. I did the same within ML-KEM (see example).

shake128_finalize(state);
SHAKE_Init(ctx, SHAKE128_BLOCKSIZE);
SHA3_Update(ctx, seed, SEEDBYTES);
SHA3_Update(ctx, t, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps extract the 2 as a constant value to improve readability?

@jakemas
Copy link
Contributor Author

jakemas commented Nov 23, 2024

Looks pretty straightforward. The only big thing missing here seems to be updates to the README.md file.

README.md updated (was waiting on merge).

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.

3 participants