Repository navigation
Description
Context
RFC 9964 registers ML-DSA (FIPS 204, the module-lattice signature scheme) for JOSE: the alg values ML-DSA-44, ML-DSA-65 and ML-DSA-87 (§8.1.4), the AKP key type (§8.1.5) and its pub / priv parameters (§8.1.6). It is the first post-quantum signature in the JOSE registries, and the library has nothing for it: JWK knows oct, RSA, EC and OKP, the thumbprint hard-codes the RFC 7638 members of those four, and no SignatureAlgorithm answers for the three names.
The COSE side of the same RFC has just been implemented in web-auth/cose-lib (web-auth/cose-lib#223, issue web-auth/cose-lib#214), and the crypto backend question is settled there — OpenSSL, through ext-openssl, which is already a hard requirement:
- OpenSSL ≥ 3.5 ships ML-DSA in its default provider:
openssl_pkey_get_private()loads an ML-DSA PrivateKeyInfo,openssl_sign($data, $sig, $key, 0)produces the 2420 / 3309 / 4627-byte signature,openssl_verify(…, 0)returns1. Any digest other than "none" is refused by the provider ("invalid digest"), which is what RFC 9964 §5 requires: pure ML-DSA, emptyctx, no HashML-DSA (§7.2 says why it is excluded). - A seed-only PrivateKeyInfo (RFC 9881
seed [0] OCTET STRING, 32 bytes, tag0x80) loads, and OpenSSL derives the public key from it —openssl_pkey_get_details()['key']is the SubjectPublicKeyInfo PEM,typeis-1and no raw material is returned. That is exactly the AKPprivof §4: "the priv parameter MUST be the seed and MUST have a length of 32 bytes". NoKeyGen_internalto implement. - The SPKI is a 22-byte fixed header (OID
2.16.840.1.101.3.4.3.17/.18/.19, no parameters) followed by the rawpub.
Two platform gates, both settled at runtime: OpenSSL ≥ 3.5 — OPENSSL_VERSION_TEXT is the compile-time header and reports 3.0.13 on a machine whose loaded library is 3.5.5, so the probe has to load an ML-DSA key once per process (the 52-byte all-zero-seed PrivateKeyInfo of RFC 9964 Appendix A does it) — and PHP ≥ 8.4 for the digest-less openssl_sign() (PHP 8.3 returns false with digest 0, verified). The library requires PHP ≥ 8.2, so the algorithms are unavailable on 8.2 and 8.3 whatever the OpenSSL, and on any PHP running on OpenSSL < 3.5.
Everything below is additive. The reference for the design decisions, the checks and the vectors is the cose-lib PR; the JOSE encoding differs only by the base64url of pub and priv and by the thumbprint format.
Scope
Algorithms — Jose\Component\Signature\Algorithm
MLDSA44,MLDSA65,MLDSA87implementingSignatureAlgorithm,name()returning the registeredML-DSA-44/ML-DSA-65/ML-DSA-87,allowedKeyTypes()returning['AKP']. One shared base with the OpenSSL plumbing: build the SPKI / seed PrivateKeyInfo in DER (spomky-labs/pki-framework, already a dependency),openssl_sign/openssl_verifywith digest0.verify()returnsfalsefor a signature whose length is not 2420 / 3309 / 4627, before OpenSSL is called; a malformed or tampered signature is afalse, never an exception, in line with the rest of the signature algorithms.sign()refuses a public key (nopriv), like EdDSA refuses an OKP key withoutd.- Platform gate:
isSupported()(PHP ≥ 8.4 and the runtime probe, result kept for the process); the constructor throws aMissingDependencyExceptionnaming the missing piece — the PHP version or the OpenSSL library — the wayEdDSAthrows withoutext-sodium. Check how the bundle behaves with a taggedjose.algorithmservice whose constructor throws (theEdDSAprecedent applies) and keep the container compiling on a platform without ML-DSA. - Key checks before OpenSSL sees the key (§7.3):
algpresent and equal to the algorithm's name — §3 makesalgREQUIRED on every AKP key, the type says nothing about the algorithm —pubof the size of the parameter set (1312 / 1952 / 2592),privof exactly 32 bytes (the expanded private key of FIPS 204 — 2560 / 4032 / 4896 bytes — is deliberately not a representation §4 allows: reject it). When the key carries bothpubandpriv, derivepubfrom the seed through OpenSSL and compare withhash_equals(); reject on mismatch (§7.4: "the consequences of using mismatched parameters can range from operations failing to private key compromise").
Keys — Jose\Component\Core\JWK, Jose\Component\KeyManagement
JWK::thumbprint()gains the AKP case of §6: the required members arealg,ktyandpub(lexicographic order, RFC 7638 §3.3) — notealg, which no other key type includes and which the currentarray_intersect_key(…, ['kty', 'n', 'e', 'crv', 'x', 'y', 'k'])would silently drop, producing a wrong thumbprint rather than an error. An AKP key withoutalghas no thumbprint: throw. Thekidof every JWK of RFC 9964 Appendix A.1 is that thumbprint, so the three are the test vectors.JWK::toPublic()stripspriv(today it stripsp,d,q,dp,dq,qionly, so the seed would leak throughtoPublic()).JWKFactory::createMLDSAKey(string $alg, array $values = [])(and the instancemldsa()), generating fromrandom_bytes(32)and derivingpubthrough OpenSSL,algset from the parameter; a way to rebuild a key from a stored seed (values['priv']given,pubderived), which is how §4 wants private keys stored.KeyConverter/JWKFactory::createFromKey(),createFromKeyFile(): an ML-DSA PEM — the seed PrivateKeyInfo of RFC 9881 or a SubjectPublicKeyInfo — loads into an AKP JWK carrying thealgthe OID names;openssl_pkey_get_details()givestype => -1and no material, so the DER has to be parsed (pki-framework).createFromCertificate()for a certificate holding an ML-DSA key:openssl_x509_read()works on OpenSSL 3.5, but check what spomky-labs/pki-framework does with a certificate signed with ML-DSA — cose-lib found that 1.6 throws "Unsupported signature algorithm 2.16.840.1.101.3.4.3.17"; ifKeyConvertergoes through it, document the limitation rather than work around it.- Key analyzer: an
MLDSAKeyAnalyzer(or one per parameter set, likeES256KeyAnalyzer…) reporting a missingalg, sizes that do not match it, aprivthat is not the seed; theuse/key_opsanalyzers apply as they are. - Console:
key:generate:mldsaalongsidekey:generate:okp(OkpKeyGeneratorCommand), taking the parameter set;key:thumbprintworks through theJWKchange.
Bundle
Resources/config/Algorithms/signature_mldsa.phpregistering the three services under the aliasesML-DSA-44,ML-DSA-65,ML-DSA-87, so thatjose.jws_builder/jws_verifierconfiguration names them like any other algorithm.AlgorithmAnalyzer/ the algorithm checkers know the three names.
Docs
- The algorithm table, the key type table (
AKP,pub,priv,algrequired), the thumbprint note, the platform requirement (PHP 8.4 + OpenSSL 3.5 at runtime,isSupported()), and the seed-only private key form, in the documentation site and in the changelog.
Out of scope
- HashML-DSA (§7.2 excludes it) and a non-empty
ctx(§5: "MUST be the empty string"; PHP cannot pass one to OpenSSL anyway). - The expanded private key form as
priv(§4). - ML-KEM / HPKE for JWE, SLH-DSA (no registration).
Acceptance criteria
- Sign / verify round-trip for the three parameter sets through
JWSBuilder/JWSVerifier, compact, flattened and general serialization. - The three JWS of RFC 9964 Appendix A.1 verify with the JWK the RFC prints; the seed of each (all zeros) expands to the
pubthe RFC prints; thekidof each JWK isJWK::thumbprint('sha256'). The appendix is machine-readable once the line wrapping is undone —tests/fixtures/rfc9964/extract.pyin cose-lib does it, andappendix-a.jsoncan be vendored as is (raw_to_be_signedis the JWS signing input). - The NIST ACVP
ML-DSA-keyGen-FIPS204seed →pkcases and the pure-mode, empty-context cases ofML-DSA-sigGen-FIPS204verify (thesigVerfile of the same release has no empty-context pure case; cose-lib'stests/fixtures/nist-acvp/ml-dsa/holds the extracted subset and its provenance). - A key with
priv≠ 32 bytes,pubof the wrong length, a missingalg, analgof another parameter set, or apubnot matching the seed is rejected before any OpenSSL call; a 2419-byte or tampered signature isfalse. - On PHP < 8.4 or OpenSSL < 3.5,
MLDSA44::isSupported()isfalse, the constructor throws, the bundle still compiles and the rest of the suite is unaffected. CI runs both sides of the gate: the matrix already has PHP 8.2/8.3 (PHP gate) and 8.4/8.5; the OpenSSL side needs a PHP 8.4 on an OpenSSL 3.0 — cose-lib usesubuntu-24.04+shivammathur/setup-php(OpenSSL 3.0.13) with an environment variable making the test assert which side it expects, so that a runner drifting to OpenSSL 3.5 fails instead of silently losing the coverage.
References
- RFC 9964 §3 (AKP), §4 (seed), §5 (algorithms, sizes), §6 (thumbprints), §7.2–7.4 (security), §8.1.4–8.1.6 (JOSE registrations), Appendix A.1 (vectors)
- RFC 9881 (ML-DSA in X.509: OIDs, the seed choice of the private key)
- FIPS 204 Table 2 (sizes), Algorithm 2 (ML-DSA.Sign), Algorithm 6 (KeyGen_internal)
- feat(algorithms): ML-DSA-44/65/87 and the AKP key type via OpenSSL 3.5 (RFC 9964) (#214) web-auth/cose-lib#223 — the COSE implementation:
MLDSAbase class (gate, probe, checks),AkpKey(sizes, PEM forms), fixtures and their extractors
Activity
feat(core): JWK Thumbprint URI (RFC 9278)
feat(signature): ML-DSA-44/65/87 and the AKP key type via OpenSSL 3.5…