Skip to content

Add MLDSA{65,87} support #229

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Add MLDSA{65,87} support #229

wants to merge 5 commits into from

Conversation

ptoffy
Copy link
Member

@ptoffy ptoffy commented Jun 12, 2025

Since swift-crypto now supports ML-DSA{65,87}, this adds support for ML-DSA based JWTs. While ML-DSA is now a formalised standard (RFC 204), its usage in JOSE is still in draft state, which means its specification could change.
Because of this, we're hiding the new APIs behind @_spi(PostQuantum) annotations, separating them from the public API and allowing therefore breaking changes, at least until the specification will be finalised.
To use them, simply

@_spi(PostQuantum) import JWTKit

but know that the APIs could be subject to change outside of major versions of JWTKit.

This PR is currently refers to the main branch of swift-crypto since no release has yet been tagged with the new post-quantum algorithms. This will change as soon as a decision is made whether to release the new APIs as a minor release before the new 2026 Crypto major release, or to wait and have them in the main Crypto module. (Discussion happening here)

@ptoffy ptoffy requested review from 0xTim and gwynne as code owners June 12, 2025 15:54
Copy link

codecov bot commented Jun 12, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 83.61%. Comparing base (7bd6ecb) to head (9915232).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
Sources/_QuantumJWTKit/MLDSA/MLDSASigner.swift 79.16% 5 Missing ⚠️
Sources/_QuantumJWTKit/MLDSA/MLDSA.swift 60.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #229      +/-   ##
==========================================
- Coverage   83.79%   83.61%   -0.18%     
==========================================
  Files          56       60       +4     
  Lines        1493     1532      +39     
==========================================
+ Hits         1251     1281      +30     
- Misses        242      251       +9     
Files with missing lines Coverage Δ
Sources/JWTKit/JWTKeyCollection.swift 93.54% <100.00%> (-0.14%) ⬇️
Sources/JWTKit/JWTSigner.swift 100.00% <ø> (ø)
.../_QuantumJWTKit/MLDSA/JWTKeyCollection+MLDSA.swift 100.00% <100.00%> (ø)
Sources/_QuantumJWTKit/MLDSA/MLDSAType.swift 100.00% <100.00%> (ø)
Sources/_QuantumJWTKit/MLDSA/MLDSA.swift 60.00% <60.00%> (ø)
Sources/_QuantumJWTKit/MLDSA/MLDSASigner.swift 79.16% <79.16%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptoffy ptoffy marked this pull request as draft June 12, 2025 16:00
Package.swift Outdated
@@ -27,11 +27,26 @@ let package = Package(
.product(name: "Logging", package: "swift-log"),
]
),
.target(
name: "_QuantumJWTKit",
Copy link
Contributor

Choose a reason for hiding this comment

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

_PQJWTKit (post-quantum == PQ) sounds cooler to me which is also in line with acronyms like "PQC" (post-quantum cryptography). Though Quantum is also fine with me since it's more clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah I didn't think about that! I had considered _PostQuantumJWTKit but it seems a bit long. Although yes, I think just your version is a bit less clear

@fpseverino
Copy link
Member

fpseverino commented Jun 12, 2025

Why don't we hide these algorithms behind a @_spi(PostQuantum), instead of a separate target? I guess it will also be easier to move them to the stable API down the line

@ptoffy
Copy link
Member Author

ptoffy commented Jun 12, 2025

@fpseverino yes that was in fact the plan in the beginning. And nothing has changed, I just forgot 🙈 done!

@ptoffy ptoffy changed the title Add MLDSA{65,87} support inside new _QuantumJWTKit module Add MLDSA{65,87} support Jun 12, 2025
@0xTim
Copy link
Member

0xTim commented Jun 16, 2025

Are we expecting these APIs to ever change? Or should we use a package trait instead of SPI?

@ptoffy
Copy link
Member Author

ptoffy commented Jun 16, 2025

The RFC isn't final yet so even though unlikely the spec and therefore the APIs might still change

@fpseverino
Copy link
Member

We should now depend on the wwdc-25 branch of swift-crypto, which has the latest API for ML-DSA

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