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

Add internal APIs for ML-DSA #1999

Merged
merged 12 commits into from
Nov 22, 2024
Merged

Add internal APIs for ML-DSA #1999

merged 12 commits into from
Nov 22, 2024

Conversation

jakemas
Copy link
Contributor

@jakemas jakemas commented Nov 18, 2024

Issues:

Resolves #CryptoAlg-2723

Description of changes:

This PR adds the internal functions from FIPS 204: Module-Lattice-Based Digital Signature Standard. We base this implementation on the upstream reference implementation of ML-DSA pq-crystals/dilithium@444cdcc. However, the upstream commit only includes implementation of ML-DSA.Sign_internal and ML-DSA.Verify_internal, so we also include ML-DSA.KeyGen_internal to complete the implementation.

Changes:

Call-outs:

We can remove the testing mechanism for the KATs pq_custom_randombytes as we now support KATs that use the internal functions that provide randomness via an input seed.

Testing:

The KATs have been migrated to use the internal functions.

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 18, 2024 20:07
@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.93%. Comparing base (ab8953b) to head (019e09d).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1999      +/-   ##
==========================================
+ Coverage   78.89%   78.93%   +0.04%     
==========================================
  Files         595      594       -1     
  Lines      102451   102432      -19     
  Branches    14527    14524       -3     
==========================================
+ Hits        80827    80853      +26     
+ Misses      20976    20930      -46     
- Partials      648      649       +1     

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


🚨 Try these New Features:

crypto/dilithium/ml_dsa.h Show resolved Hide resolved
crypto/dilithium/pqcrystals_dilithium_ref_common/README.md Outdated Show resolved Hide resolved
crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c Outdated Show resolved Hide resolved
crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c Outdated Show resolved Hide resolved
crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c Outdated Show resolved Hide resolved
crypto/dilithium/p_pqdsa_test.cc Show resolved Hide resolved
crypto/dilithium/p_pqdsa_test.cc Outdated Show resolved Hide resolved
crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c Outdated Show resolved Hide resolved
crypto/dilithium/ml_dsa.c Show resolved Hide resolved
crypto/dilithium/p_pqdsa_test.cc Outdated Show resolved Hide resolved
crypto/dilithium/pqcrystals_dilithium_ref_common/sign.h Outdated Show resolved Hide resolved
crypto/dilithium/kat/mldsa65.txt Outdated Show resolved Hide resolved
andrewhop
andrewhop previously approved these changes Nov 20, 2024
crypto/dilithium/p_pqdsa_test.cc Show resolved Hide resolved
crypto/dilithium/p_pqdsa_test.cc Outdated Show resolved Hide resolved
crypto/dilithium/ml_dsa.h Show resolved Hide resolved
crypto/dilithium/kat/mldsa65.txt Outdated Show resolved Hide resolved
crypto/dilithium/p_pqdsa_test.cc Show resolved Hide resolved
crypto/dilithium/p_pqdsa_test.cc Outdated Show resolved Hide resolved
crypto/dilithium/p_pqdsa_test.cc Show resolved Hide resolved
crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c Outdated Show resolved Hide resolved
/* Compute mu = CRH(tr, 0, ctxlen, ctx, msg) */
mu[0] = 0;
mu[1] = ctxlen;
/* Compute mu = CRH(tr, pre, msg) */
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add references to lines in FIPS 204, Algorithm 7 please (for verify_internal and keygen_internal as well)? For example, I believe this comment refers to line 6 that says: 𝜇 ← H(BytesToBits(𝑡𝑟)||𝑀 ′, 64) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'm staging a PR that adds a LOT of documentation and call out to each of the algorithms in FIPS 204 and their implementation here.

However, I want to get the larger code integrations complete before I start touching every single file in the dilithium repo to add comments. This will prevent me from re-base/conflicts pain down the line.

I'll add specific call outs to the lines in sign/verify in that forthcoming PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

sure, but the point of documentation is to make the review easier, once we merge the code it's not as useful :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh I understand now, added these callouts to lines in the spec in 8c3d53e. I plan on adding a lot more documentation like this.

crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c Outdated Show resolved Hide resolved
goto rej;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/* FIPS 204: line 26 Compute signer's hint */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

crypto/dilithium/pqcrystals_dilithium_ref_common/sign.c Outdated Show resolved Hide resolved
dkostic
dkostic previously approved these changes Nov 21, 2024
@dkostic dkostic enabled auto-merge (squash) November 21, 2024 23:42
@dkostic dkostic merged commit c48572a into aws:main Nov 22, 2024
115 of 117 checks passed
nebeid pushed a commit that referenced this pull request Dec 3, 2024
This change adds ML-DSA-44 and ML-DSA-87 to AWS-LC. As we already have support for ML-DSA-65 through the PQDSA signature API (see #1963) and already support internal functions and KATs that use these internal APIs (see #1999), this change consists of:

- The addition of the 6 `pqdsa` APIs for ML-DSA-44 and ML-DSA-87:
`ml_dsa_{44/87}_keypair`, `ml_dsa_{44/87}_keypair_internal`,
`ml_dsa_{44/87}_sign`, `ml_dsa_{44/87}_sign_internal`,
`ml_dsa_{44/87}_verify`, and`ml_dsa_{44/87}_verify_internal`
- The function methods: `sig_ml_dsa_44_method` and
`sig_ml_dsa_87_method`
- The algorithm data structs: `sig_ml_dsa_44` and `sig_ml_dsa_87`

Integrating ML-DSA-44/87 into X.509 will be in a follow-up commit.

Benchmarking results:
```
Did 33000 MLDSA44 keygen operations in 1000554us (32981.7 ops/sec)
Did 8541 MLDSA44 signing operations in 1061153us (8048.8 ops/sec)
Did 32000 MLDSA44 verify operations in 1016751us (31472.8 ops/sec)
Did 17000 MLDSA65 keygen operations in 1021812us (16637.1 ops/sec)
Did 6000 MLDSA65 signing operations in 1148331us (5225.0 ops/sec)
Did 20000 MLDSA65 verify operations in 1019696us (19613.7 ops/sec)
Did 12000 MLDSA87 keygen operations in 1011438us (11864.3 ops/sec)
Did 4344 MLDSA87 signing operations in 1043422us (4163.2 ops/sec)
Did 12000 MLDSA87 verify operations in 1027267us (11681.5 ops/sec)
```

Testing:
`ML-DSA-44/87` are added to the test harness.
This requires the inclusion of test harness raw public keys
`mldsa{44/87}kPublicKey` and encoded public keys
`mldsa{44/87}kPublicKeySPKI`.

The lengths of the encodings are well defined by
https://datatracker.ietf.org/doc/draft-ietf-lamps-dilithium-certificates/
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