Skip to content

feat(signature): ML-DSA-44/65/87 and the AKP key type via OpenSSL 3.5 (RFC 9964) #723

Closed

Description

@Spomky

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) returns 1. Any digest other than "none" is refused by the provider ("invalid digest"), which is what RFC 9964 §5 requires: pure ML-DSA, empty ctx, no HashML-DSA (§7.2 says why it is excluded).
  • A seed-only PrivateKeyInfo (RFC 9881 seed [0] OCTET STRING, 32 bytes, tag 0x80) loads, and OpenSSL derives the public key from it — openssl_pkey_get_details()['key'] is the SubjectPublicKeyInfo PEM, type is -1 and no raw material is returned. That is exactly the AKP priv of §4: "the priv parameter MUST be the seed and MUST have a length of 32 bytes". No KeyGen_internal to 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 raw pub.

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, MLDSA87 implementing SignatureAlgorithm, name() returning the registered ML-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_verify with digest 0.
  • verify() returns false for a signature whose length is not 2420 / 3309 / 4627, before OpenSSL is called; a malformed or tampered signature is a false, never an exception, in line with the rest of the signature algorithms.
  • sign() refuses a public key (no priv), like EdDSA refuses an OKP key without d.
  • Platform gate: isSupported() (PHP ≥ 8.4 and the runtime probe, result kept for the process); the constructor throws a MissingDependencyException naming the missing piece — the PHP version or the OpenSSL library — the way EdDSA throws without ext-sodium. Check how the bundle behaves with a tagged jose.algorithm service whose constructor throws (the EdDSA precedent applies) and keep the container compiling on a platform without ML-DSA.
  • Key checks before OpenSSL sees the key (§7.3): alg present and equal to the algorithm's name — §3 makes alg REQUIRED on every AKP key, the type says nothing about the algorithm — pub of the size of the parameter set (1312 / 1952 / 2592), priv of 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 both pub and priv, derive pub from the seed through OpenSSL and compare with hash_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 are alg, kty and pub (lexicographic order, RFC 7638 §3.3) — note alg, which no other key type includes and which the current array_intersect_key(…, ['kty', 'n', 'e', 'crv', 'x', 'y', 'k']) would silently drop, producing a wrong thumbprint rather than an error. An AKP key without alg has no thumbprint: throw. The kid of every JWK of RFC 9964 Appendix A.1 is that thumbprint, so the three are the test vectors.
  • JWK::toPublic() strips priv (today it strips p, d, q, dp, dq, qi only, so the seed would leak through toPublic()).
  • JWKFactory::createMLDSAKey(string $alg, array $values = []) (and the instance mldsa()), generating from random_bytes(32) and deriving pub through OpenSSL, alg set from the parameter; a way to rebuild a key from a stored seed (values['priv'] given, pub derived), 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 the alg the OID names; openssl_pkey_get_details() gives type => -1 and 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"; if KeyConverter goes through it, document the limitation rather than work around it.
  • Key analyzer: an MLDSAKeyAnalyzer (or one per parameter set, like ES256KeyAnalyzer…) reporting a missing alg, sizes that do not match it, a priv that is not the seed; the use / key_ops analyzers apply as they are.
  • Console: key:generate:mldsa alongside key:generate:okp (OkpKeyGeneratorCommand), taking the parameter set; key:thumbprint works through the JWK change.

Bundle

  • Resources/config/Algorithms/signature_mldsa.php registering the three services under the aliases ML-DSA-44, ML-DSA-65, ML-DSA-87, so that jose.jws_builder / jws_verifier configuration 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, alg required), 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 pub the RFC prints; the kid of each JWK is JWK::thumbprint('sha256'). The appendix is machine-readable once the line wrapping is undone — tests/fixtures/rfc9964/extract.py in cose-lib does it, and appendix-a.json can be vendored as is (raw_to_be_signed is the JWS signing input).
  • The NIST ACVP ML-DSA-keyGen-FIPS204 seed → pk cases and the pure-mode, empty-context cases of ML-DSA-sigGen-FIPS204 verify (the sigVer file of the same release has no empty-context pure case; cose-lib's tests/fixtures/nist-acvp/ml-dsa/ holds the extracted subset and its provenance).
  • A key with priv ≠ 32 bytes, pub of the wrong length, a missing alg, an alg of another parameter set, or a pub not matching the seed is rejected before any OpenSSL call; a 2419-byte or tampered signature is false.
  • On PHP < 8.4 or OpenSSL < 3.5, MLDSA44::isSupported() is false, 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 uses ubuntu-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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Compliancefeature

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions