Skip to content

Reject legacy Dilithium keys instead of signing them as ML-DSA - #1813

Merged
andreasrosdalw merged 1 commit into
LibrePDF:masterfrom
andreasrosdal:reject-dilithium-as-ml-dsa
Dec 3, 2026
Merged

andreasrosdalw merged 1 commit into
LibrePDF:masterfrom
andreasrosdal:reject-dilithium-as-ml-dsa

Conversation

@andreasrosdal

@andreasrosdal andreasrosdal commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Description of the new Feature/Bugfix

PdfPKCS7 treated the legacy CRYSTALS-Dilithium names Dilithium2, Dilithium3 and Dilithium5 as aliases of ML-DSA-44, ML-DSA-65 and ML-DSA-87. Dilithium is a different algorithm with its own OIDs, so a Dilithium signature could be written into a SignerInfo under an ML-DSA OID.

isMlDsaName now accepts only ML-DSA names, and the parameter-set mapping knows only the ML-DSA names. A Dilithium key passed to the constructor, or a Dilithium name passed to setExternalDigest, is now rejected as an unknown key algorithm. OpenPDF does not support signing with legacy Dilithium.

Why reject Dilithium instead of supporting it

  • ML-DSA replaced it. CRYSTALS-Dilithium was the round 3 submission to the NIST competition. NIST standardised a changed version of it as ML-DSA in FIPS 204 (August 2024). The two do not interoperate: a Dilithium signature does not verify as ML-DSA, and an ML-DSA signature does not verify as Dilithium.
  • No standard covers Dilithium in CMS. RFC 9882 defines ML-DSA in CMS. Nothing equivalent exists for Dilithium, only experimental OIDs from the research period, so OpenPDF would have to write signatures in a format that no standard defines.
  • Validators would not accept it. PDF signature validators such as Adobe Acrobat and the EU DSS are adding ML-DSA, not Dilithium. A PDF signed with Dilithium would show an invalid or unknown signature.
  • Providers are dropping it. The JDK implements only ML-DSA. Bouncy Castle keeps Dilithium for compatibility and points users to ML-DSA.
  • PDF signatures are meant to last. A signed PDF is often kept for decades, and a pre-standard algorithm is the wrong thing to put in a long-lived document.
  • It would add risk to the signing code. Supporting it would mean extra code paths and tests in security-sensitive code, for an algorithm whose users should move to ML-DSA anyway.

Rejecting Dilithium with a clear error is the safe choice. Verifying PDFs that were signed with Dilithium during the experimental years could be added on request, and only for verification, never for signing.

Related Issue: Fixes #1812

Unit-Tests for the new Feature/Bugfix

  • Unit-Tests added to reproduce the bug
  • Unit-Tests added to the added feature

Added to PdfPKCS7MlDsaTest:

  • rejectsDilithiumKeys: Dilithium2, Dilithium3, Dilithium5 and DILITHIUM3 keys are rejected.
  • rejectsExternalDilithiumSignatures: setExternalDigest with a Dilithium name throws, even when the certificate holds an ML-DSA key.
  • externalSignatureNamedWithItsParameterSet: external signatures named ML-DSA-44, ML-DSA-65 and ML-DSA-87 are encoded with the matching OID and verify.

Compatibilities Issues

Behaviour change: code that signed with a key named Dilithium*, or called setExternalDigest with such a name, now gets an exception instead of a signature labelled as ML-DSA. No method signatures change. The 4.0.0 changelog has an entry under Upgrade Notes. The ML-DSA support is only on master, so 3.0-java21 is not affected.

Your real name

Andreas Røsdal

Testing details

./mvnw -pl openpdf-core test -Dtest=PdfPKCS7MlDsaTest (needs Java 25). Checkstyle passes locally. I could not run the tests locally because there is no JDK 25 on this machine, so this relies on CI.

PdfPKCS7 mapped Dilithium2, Dilithium3 and Dilithium5 to the ML-DSA-44,
ML-DSA-65 and ML-DSA-87 OIDs. CRYSTALS-Dilithium is a different algorithm,
so its signatures were labelled as ML-DSA. Dilithium names are now
rejected as unknown key algorithms, for internal and external signing.

Fixes LibrePDF#1812

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 8 complexity · 4 duplication

Metric Results
Complexity 8
Duplication 4

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@sonarqubecloud

sonarqubecloud Bot commented Dec 3, 2026

Copy link
Copy Markdown

@andreasrosdalw
andreasrosdalw merged commit 484cad9 into LibrePDF:master Dec 3, 2026
15 checks passed
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.

Legacy Dilithium signatures are emitted under ML-DSA OIDs

2 participants