|
16 | 16 | </p> |
17 | 17 | <br> |
18 | 18 |
|
19 | | -🔑 JSON Web Token signing and verification (HMAC, RSA, PSS, ECDSA, EdDSA) using SwiftCrypto. |
| 19 | +🔑 JSON Web Token signing and verification (HMAC, ECDSA, EdDSA, MLDSA, RSA, PSS) using SwiftCrypto. |
20 | 20 |
|
21 | 21 | ### Supported Platforms |
22 | 22 |
|
@@ -58,21 +58,23 @@ JWTKit provides APIs for signing and verifying JSON Web Tokens, as specified by |
58 | 58 | The following algorithms, as defined in [RFC 7518 § 3](https://www.rfc-editor.org/rfc/rfc7518.html#section-3) and [RFC 8037 § 3](https://www.rfc-editor.org/rfc/rfc8037.html#section-3), are supported for both signing and verification: |
59 | 59 |
|
60 | 60 | | JWS | Algorithm | Description | |
61 | | -| :-------------: | :-------------: | :----- | |
62 | | -| HS256 | HMAC256 | HMAC with SHA-256 | |
63 | | -| HS384 | HMAC384 | HMAC with SHA-384 | |
64 | | -| HS512 | HMAC512 | HMAC with SHA-512 | |
65 | | -| RS256 | RSA256 | RSASSA-PKCS1-v1_5 with SHA-256 | |
66 | | -| RS384 | RSA384 | RSASSA-PKCS1-v1_5 with SHA-384 | |
67 | | -| RS512 | RSA512 | RSASSA-PKCS1-v1_5 with SHA-512 | |
68 | | -| PS256 | RSA256PSS | RSASSA-PSS with SHA-256 | |
69 | | -| PS384 | RSA384PSS | RSASSA-PSS with SHA-384 | |
70 | | -| PS512 | RSA512PSS | RSASSA-PSS with SHA-512 | |
71 | | -| ES256 | ECDSA256 | ECDSA with curve P-256 and SHA-256 | |
72 | | -| ES384 | ECDSA384 | ECDSA with curve P-384 and SHA-384 | |
73 | | -| ES512 | ECDSA512 | ECDSA with curve P-521 and SHA-512 | |
74 | | -| EdDSA | EdDSA | EdDSA with Ed25519 | |
75 | | -| none | None | No digital signature or MAC | |
| 61 | +| :---: | :---: | --- | |
| 62 | +| `HS256` | `HMAC256` | HMAC with SHA‑256 | |
| 63 | +| `HS384` | `HMAC384` | HMAC with SHA‑384 | |
| 64 | +| `HS512` | `HMAC512` | HMAC with SHA‑512 | |
| 65 | +| `RS256` | `RSA256` | RSASSA‑PKCS1‑v1_5 + SHA‑256 | |
| 66 | +| `RS384` | `RSA384` | RSASSA‑PKCS1‑v1_5 + SHA‑384 | |
| 67 | +| `RS512` | `RSA512` | RSASSA‑PKCS1‑v1_5 + SHA‑512 | |
| 68 | +| `PS256` | `RSA256PSS` | RSASSA‑PSS + SHA‑256 | |
| 69 | +| `PS384` | `RSA384PSS` | RSASSA‑PSS + SHA‑384 | |
| 70 | +| `PS512` | `RSA512PSS` | RSASSA‑PSS + SHA‑512 | |
| 71 | +| `ES256` | `ECDSA256` | P‑256 + SHA‑256 | |
| 72 | +| `ES384` | `ECDSA384` | P‑384 + SHA‑384 | |
| 73 | +| `ES512` | `ECDSA512` | P‑521 + SHA‑512 | |
| 74 | +| `EdDSA` | `EdDSA` | Ed25519 | |
| 75 | +| `ML-DSA-65` | `MLDSA65` | MLDSA with parameter set 65 | |
| 76 | +| `ML-DSA-87` | `MLDSA87` | MLDSA with parameter set 87 | |
| 77 | +| `none` | `None`| No signature / MAC | |
76 | 78 |
|
77 | 79 | ## Vapor |
78 | 80 |
|
@@ -271,6 +273,30 @@ await keys.add(eddsa: publicKey) |
271 | 273 | await keys.add(eddsa: privateKey) |
272 | 274 | ``` |
273 | 275 |
|
| 276 | +## MLDSA |
| 277 | + |
| 278 | +Hidden behind the `@_spi(PostQuantum)` flag, JWTKit supports MLDSA (Module-Lattice-Based Digital Signature Algorithm), a post-quantum signature scheme based on the CRYSTALS-DILITHIUM algorithm. It is currently behind an SPI flag because, while the MLDSA signature scheme is [standardized by NIST](https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.204.pdf), its [usage in JWT](https://www.ietf.org/archive/id/draft-ietf-cose-dilithium-04.html) is still in draft state, and, while unlikely, may change before being finalized. Therefore JWTKit reserves the ability to make breaking changes to this API until the usage of MLDSA in JWT is finalized. |
| 279 | + |
| 280 | +> [!NOTE]\ |
| 281 | +> MLDSA requires macOS 26+. |
| 282 | +
|
| 283 | +Currently, to use MLDSA, you must import JWTKit with the `@_spi(PostQuantum)` flag enabled: |
| 284 | + |
| 285 | +```swift |
| 286 | +@_spi(PostQuantum) import JWTKit |
| 287 | +``` |
| 288 | + |
| 289 | +Then you can choose whether to use MLDSA65 or MLDSA87. Use them as follows: |
| 290 | + |
| 291 | +```swift |
| 292 | +// Initialize an MLDSA key with its seed |
| 293 | +let seedRepresentation = Data("...".utf8) |
| 294 | +let privateKey = try MLDSA87PrivateKey(seedRepresentation: seedRepresentation) |
| 295 | + |
| 296 | +// Add private key to the key collection |
| 297 | +await keys.add(mldsa: privateKey) |
| 298 | +``` |
| 299 | + |
274 | 300 | ## RSA |
275 | 301 |
|
276 | 302 | RSA is an asymmetric algorithm. It uses a public key to verify tokens and a private key to sign them. |
|
0 commit comments