Skip to content

Add RFC 9580 version 6 and RFC 9980 post-quantum OpenPGP - #715

Open
rosen-vl wants to merge 1 commit into
bcgit:masterfrom
rosen-vl:rfc9980-implementation
Open

rosen-vl wants to merge 1 commit into
bcgit:masterfrom
rosen-vl:rfc9980-implementation

Conversation

@rosen-vl

@rosen-vl rosen-vl commented Oct 26, 2026 •

Copy link
Copy Markdown

Describe your changes

Implements #714
Implement the version 6 format of RFC 9580 and the post-quantum algorithms of RFC 9980 in the OpenPGP API, and move the handling of version 4 data closer to RFC 9580 where that keeps existing callers working. Nothing is removed from the public API; changes that would break it are recorded as TODO[api] comments.

RFC 9580, version 6:

  • Version 6 keys, signatures, one-pass signatures, PKESKs and SKESKs are parsed and generated: salted signatures, issuer fingerprints, exact packet lengths, minimal MPIs and the current packet format.
  • Version 2 SEIPD (AEAD with OCB, EAX or GCM) is encrypted and decrypted; truncated or altered AEAD data is an error.
  • X25519, X448, Ed25519 and Ed448 keys (algorithms 25 to 28).
  • Secret keys can be protected with AEAD and Argon2 or iterated S2K (PgpSecretKeyProtection).
  • PgpKeyRingGenerator makes direct-key signatures for version 6 keys and embeds back-signatures for signing subkeys.
  • PgpEncryptionPreferences chooses the cipher, AEAD mode and SEIPD version that all recipients support, from their newest valid self-signatures, and the Preferred AEAD Ciphersuites subpacket is read and written.
  • Validation follows RFC 9580: the newest valid self-signature in effect decides (user attributes included, non-revocable ones respected), a version 6 key needs a valid direct-key signature, and malformed or unknown version 6 signatures (5.2.5) never validate.

RFC 9980, post-quantum:

  • ML-KEM-768+X25519 and ML-KEM-1024+X448 composite encryption, in version 6 PKESKs and in version 3 PKESKs to version 4 keys.
  • ML-DSA-65+Ed25519 and ML-DSA-87+Ed448 composite signatures, and SLH-DSA-SHAKE-128s, -128f and -256s signatures.
  • The binding hash, digest size and AES-256 preference rules of RFC 9980 sections 5 to 7.

Changes for version 4 data and existing APIs:

  • New signatures, S2Ks and secret key protections refuse MD5, SHA-1 and RIPEMD-160, and default to hashes as large as the key needs; MD5 and MD2 signatures never validate, SHA-1 ones still do.
  • Encrypted secret keys always use the SHA-1 integrity check (usage 254), and their encrypted material must end with the key material.
  • The armor checksum follows RFC 9580 6.1: a missing or bad one is accepted unless asked for, and none is written for version 6 data. A cleartext signed message with armor headers other than a well-formed Hash header yields no signatures.
  • Malformed signature and one-pass signature packets, and unknown non-critical packets, are skipped instead of ending the parsing of a message or key ring; PgpSignatureList and PgpOnePassSignatureList count what they leave out.
  • Partial body lengths are only written for data packets, starting at 512 octets, and a partial body without its final length is read as truncated.
  • Signature subpackets: two-octet lengths up to 16319 octets are read, the hashed area is verified as it was read, the subpacket of a non-exportable signature is critical, and notation names and values are kept whole and decoded as UTF-8. Long literal file names are cut at a character boundary.
  • GetValidSeconds(masterKey) takes the expiry of a primary key from its newest verified self-signature in effect, and PgpPublicKey makes its key parameters once.
  • PgpV3SignatureGenerator and AddRevocationKey are obsolete.

New public API includes the composite and SLH-DSA key classes, PgpEncryptionPreferences, PgpSecretKeyProtection,
PreferredAeadCiphersuites, version-aware PgpKeyPair, PgpPublicKey and PgpKeyRingGenerator constructors, AEAD PgpEncryptedDataGenerator constructors, PgpSignature.VerifyCertification(byte[], PgpPublicKey), GetSalt and GetFingerprint on signatures and one-pass signatures, and the UnsupportedCount of the signature lists.

The existing OpenPGP tests are updated for the new defaults (SHA-256 instead of SHA-1, usage 254), and the placeholder AEAD tests are completed.

How has this been tested?

A new branch with tests is added. It tests well-known libraries for compatibility with the PQ PGP keys generated with this version of the code and vice-versa. The separate branch will be used for a PR to this branch, to make it easier to review the code changes.
Branch and PR with tests: rosen-vl#1

Path Purpose
docker/rsop.Dockerfile rsop 0.12.0 (rpgpie 0.12.0, rPGP 0.21.0 with post-quantum support)
docker/sq.Dockerfile Sequoia sq 1.4.1 (sequoia-openpgp 2.4.1, which has RFC 9980; OpenSSL 3.5 backend)
docker/gosop.Dockerfile gosop 1.1.0 (GopenPGP 3.4.1, ProtonMail/go-crypto 529840d2b1bd), pinned commit of the gosop-gopenpgp-v3-pqc branch
docker/openpgpjs.Dockerfile sop-openpgpjs 2.2.0 on OpenPGP.js 6.3.1 (the psk branch with post-quantum algorithms), with an rfc9980 key profile
docker/pgpainless.Dockerfile pgpainless-cli 2.0.4 (PGPainless on Bouncy Castle Java 1.84), the pinned jar from Maven Central
docker/gnupg.Dockerfile GnuPG 2.5.24 (RFC 9980 mode --allow-9980), the release tarball pinned by SHA-256, on Debian forky (libgcrypt 1.12)
docker/rnp.Dockerfile RNP (Thunderbird) at a pinned commit of main with ENABLE_PQC and ENABLE_CRYPTO_REFRESH, on Botan 3.13
bcjava/ BcJavaCheck: a small command line over the OpenPGP API of Bouncy Castle Java 1.86, and its Dockerfile

Used Claude's Opus 5.5 for the implementation and OpenAI Sol 5.6 and Astra 6 for validation and security assessment.

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have kept the patch limited to only change the parts related to the patch
  • This change requires a documentation update

See also Contributing Guidelines.