Skip to content

Post-quantum cryptography in Stalwart: TLS, encryption at rest and DKIM2

Yesterday, the US National Security Agency published a press release with an unusually direct title: NSA Advises Immediate Transition to Post-Quantum Cryptography to Protect National Security Systems. On the same day, the Office of the National Cyber Director, the NSA and CISA released a joint statement on recent advances in cryptographic and cybersecurity capabilities, and the NSA published an advisory with concrete steps, Immediate Actions to Push Toward Post-Quantum.

Today we are releasing Stalwart 1.2.3, which makes post-quantum key exchange the first choice for TLS connections that Stalwart opens to other servers. We recommend that every Stalwart user upgrade. This post explains what the announcement says and why it is relevant, even to readers who have never had to think about cryptography. It then covers every post-quantum feature in Stalwart, from TLS to encryption at rest and DKIM2, and how to start using each of them.

Almost every secure connection and every signed or encrypted message on the internet relies on public-key cryptography. Each party has two keys: a public key, which anyone can see, and a private key, which never leaves its owner. Two strangers can use them to agree on a secret over a network that anyone may be listening to, and a sender can sign a message in a way that anyone can check but nobody else can imitate.

This works because of a few mathematical problems that are easy to compute in one direction and, as far as anyone knows, practically impossible to reverse. RSA relies on the difficulty of splitting a very large number into its prime factors. The elliptic-curve algorithms used almost everywhere today (X25519, Ed25519, ECDSA) rely on a related problem called the discrete logarithm. Multiplying two primes takes a fraction of a second; recovering them from a large enough product would take ordinary computers far longer than anyone could wait. The security of the whole system rests on that imbalance between the easy direction and the hard one.

There are two ways that imbalance can disappear. The first is a quantum computer. Quantum computers are not faster ordinary computers; they compute in a different way, and in 1994 Peter Shor showed that a large enough one could solve both factoring and the discrete logarithm efficiently. No such machine exists yet. The second is better mathematics: someone finds a shortcut that makes the “hard” problem easier on ordinary computers. Cryptographers choose key sizes with a safety margin for exactly this reason, and history has a few examples of margins that had to be raised after new results.

The new element in yesterday’s announcement is the second kind of threat, arriving from an unexpected direction. According to the joint statement, the latest generation of frontier AI models (the statement calls them “Super Intelligence”, or SI) “has demonstrated the capability to solve some of the most complex and previously unsolved problems in the field of mathematics”, and “American SI companies have disclosed discoveries that impact the security of some cryptography currently in use.” The NSA release adds that this comes “alongside the existing concerns about quantum computing”.

Three points are worth reading carefully:

  • Nothing has been broken in public. Neither document says which algorithms are affected or how. The joint assessment is that these advances “do not present an immediate and widespread threat to that cryptography.”
  • The advice is still to act now. The NSA advises owners and vendors of national security systems “to immediately accelerate the transition to post-quantum cryptography”, and warns that “adversaries are already collecting encrypted information to decrypt once the capabilities become available.”
  • Time is the issue, not the present. That last quote describes a strategy known as “harvest now, decrypt later”. A recorded TLS session or an encrypted email does not expire. If the mathematics protecting it falls in five years, everything recorded today becomes readable in five years. Data that must stay confidential for a long time needs protection that will still hold then, which means post-quantum protection now.

The advisory turns this into an ordered list of actions. The first ones concern exactly the software a mail server runs: take an inventory of where cryptography is used; move TLS services to TLS 1.3 and enable post-quantum settings where they are available; and update software to versions that support post-quantum cryptography, then configure it to use it, without leaving “non-PQC defaults in place”.

Post-quantum algorithms are built on different mathematics, chosen because no efficient attack is known for either classical or quantum computers. The ones standardised so far by NIST, after a public competition that ran for most of a decade, are based on problems over mathematical structures called lattices:

  • ML-KEM (FIPS 203, formerly Kyber) lets two parties agree on a secret key. It replaces the key agreement part of TLS and the key encryption part of OpenPGP and S/MIME.
  • ML-DSA (FIPS 204, formerly Dilithium) produces digital signatures. It replaces RSA and Ed25519 signatures, for example in DKIM.

Lattice cryptography is younger than RSA and elliptic curves, and it has been studied for fewer years. The usual answer, and the one Stalwart follows wherever the standards allow it, is to use it in hybrid form: a post-quantum algorithm and a classical one are combined, and an attacker must break both to read the data. A hybrid is never weaker than the classical algorithm alone, and it stays secure if a weakness is ever found in either half. After an announcement that does not name which cryptography is affected, that property is worth having.

One distinction is useful to keep in mind. The NSA’s own requirements for national security systems, known as CNSA 2.0, call for the largest parameter sets (ML-KEM-1024 and ML-DSA-87) and are stricter than what is used on the public internet. The advisory is written for those systems. The direction it sets, however, applies to everyone, and the steps below follow it.

TLS protects every connection to and from a mail server: mail clients reading mail over IMAP, JMAP or the Exchange protocols, submission of new messages, the WebUI, and the delivery of mail between servers over SMTP. At the start of each connection, the two sides perform a key exchange to agree on the keys that encrypt the rest of the session. This is the step that a “harvest now, decrypt later” attacker targets: whoever can redo the key exchange from a recording can read the whole session.

Stalwart supports the hybrid key exchange group X25519MLKEM768, which combines X25519 with ML-KEM-768. It is the same group that current web browsers use, and it is already widely deployed on the web. The server offers it on every listener with TLS 1.3, and when a mail client or another server that supports it connects, it is used. The client’s preference decides the group on incoming connections, as described in Key exchange groups.

What changes in Stalwart 1.2.3 is the other direction. When Stalwart is the one opening the connection (delivering mail to a recipient’s server, relaying through a smart host, or connecting to other services over TLS), it now proposes X25519MLKEM768 first instead of last. With TLS 1.3, the first proposal comes with a ready key share, so a server that also supports the hybrid group agrees to it in the same round trip. A server that does not support it picks one of the classical groups that Stalwart also offers, and the delivery goes ahead as before. Nothing needs to be configured.

Server-to-server SMTP is where this has the largest effect on mail. It crosses the public internet, it is the connection over which most mail enters and leaves an organisation, and until now Stalwart’s own deliveries used post-quantum key exchange only when the receiving server insisted on it. With 1.2.3, every message that Stalwart delivers to a server with post-quantum support is protected against harvesting from the first hop.

Two related settings are worth reviewing in light of the advisory’s TLS 1.3 recommendation. X25519MLKEM768 is a TLS 1.3 key exchange group, so connections that fall back to TLS 1.2 use classical key exchange. On listeners where every client is known to support TLS 1.3, such as submission or IMAP in a managed environment, tlsDisableProtocols can refuse TLS 1.2 altogether. Port 25 is the exception: many sending servers on the internet still use TLS 1.2, and refusing it would push them to plain text or to failure.

Stalwart can encrypt every message it stores with the user’s own OpenPGP key or S/MIME certificate, so that a copy of the server, its disks or its backups reveals nothing. The private key never reaches the server in any form. Since v1.0.2, the encryption engine supports post-quantum keys in both standards, as described in the encryption gateway post:

  • In OpenPGP, the hybrid keys of RFC 9980: ML-KEM-768 with X25519 and ML-KEM-1024 with X448. Messages for post-quantum keys are always encrypted with AES-256.
  • In S/MIME, certificates with ML-KEM-512, ML-KEM-768 and ML-KEM-1024 keys as defined in RFC 9936, with AES-256-GCM for the content.

The same applies to the encryption gateway, which encrypts outgoing mail with each recipient’s key: when a recipient publishes a post-quantum key, the gateway uses it.

Encrypted mailboxes are the clearest case of data with a long life, and therefore the clearest target for harvesting. If your mail software can read post-quantum messages, we encourage you to replace your encryption at rest key with a post-quantum one. On the OpenPGP side, clients built on Sequoia, rPGP, OpenPGP.js or GopenPGP can read them, and recent GnuPG 2.5 releases can when their RFC 9580 features are enabled explicitly. Thunderbird and GnuPG in its default configuration cannot yet. On the S/MIME side, no mainstream mail client decrypts ML-KEM messages yet, and no public certificate authority issues ML-KEM certificates, so for now post-quantum encryption at rest is an OpenPGP feature in practice. Check every device you read mail on: the key must be readable by all of them.

A few details make the switch work as intended:

  • Generate the key in your own software, never on the server, and register its public part in the account’s public keys. After registering it, the key’s description shows its algorithms (for example OpenPGP v6: ML-KEM-1024+X448), and its postQuantum capability confirms that it contains a post-quantum encryption key.
  • Do not leave a classical key next to it. Encrypting a message to both a classical and a post-quantum key would let anyone who breaks the classical one read it, so Stalwart encrypts to the post-quantum keys only when every key in the set has one, and to the classical keys otherwise. The simplest path is to register the post-quantum key as a separate public key and select it in the account’s encryption settings, as described in Change or disable encryption.
  • Keep your old private key. Messages that are already stored remain encrypted for the key they were encrypted for; the server holds no private key, so it cannot re-encrypt them. Only new mail is protected by the new key.

The OpenPGP and S/MIME pages of the documentation list the supported keys and the exact choices the server makes for each of them.

DKIM lets a domain sign the mail it sends, so that receivers can check that a message claiming to come from the domain really does, and that it was not altered on the way. Its successor, DKIM2, also signs the SMTP envelope and builds a chain of signatures from the sender to the final recipient. Stalwart signs and verifies both.

Signatures face a different quantum threat from encryption. A recorded signature cannot be “decrypted later”; the risk is that someone who can break the algorithm can forge new signatures and send mail that verifies as if it came from your domain. That makes the transition less urgent than for encryption, but it also takes longer: every verifier on the internet has to support the new algorithm before a domain can rely on it, and that only starts once senders begin signing with it.

DKIM2 defines three signature algorithms: RSA, Ed25519 and ML-DSA-44, the smallest parameter set of ML-DSA. Stalwart implements all three, and can generate, publish and rotate ML-DSA-44 keys automatically.

A word on status: DKIM2 is still an Internet-Draft. Its details can change before it becomes an RFC, and Stalwart has followed those changes as they happened; an earlier draft, for example, combined ML-DSA-44 with Ed25519 in a composite signature, and Stalwart moved to the plain ML-DSA-44 signature when the draft did. The cryptography itself is final: ML-DSA is a published NIST standard, FIPS 204, and will not change. What may still change is how DKIM2 applies it, such as the record format or the way signatures are encoded.

We recommend starting gradually:

  1. Enable DKIM2 with a classical key. With automatic DKIM management, add Dkim2Ed25519Sha256 to the domain’s algorithms, which by default contains only Dkim1Ed25519Sha256 and Dkim1RsaSha256.
  2. Add an ML-DSA-44 key next to it by adding Dkim2MlDsa44 to the same list. Stalwart then generates, publishes and rotates a key of each listed type, and signs every message with all of them in a single DKIM2 signature. Each key’s signature is an alternative to the others: receivers that implement ML-DSA-44 verify that one, and the rest verify the Ed25519 signature.
  3. Watch the cost. An ML-DSA-44 signature is about 37 times the size of an Ed25519 one (3,228 base64 characters against 88), and it is repeated in every message. Its public key record in DNS is about 1,780 characters long, which some DNS providers do not accept, so check that the record is published.
  4. Drop the classical keys later. Because the signatures are alternatives, a forger who breaks Ed25519 can still produce a passing signature with it alone. The ML-DSA-44 key protects against quantum forgery only once the domain stops signing with RSA and Ed25519. That step makes sense once receivers implement ML-DSA-44 widely, and signing with it today is how that support gets built.

The following settings make automatic DKIM management generate DKIM keys and DKIM2 keys with both Ed25519 and ML-DSA-44:

{
"dkimManagement": {
"@type": "Automatic",
"algorithms": {
"Dkim1Ed25519Sha256": true,
"Dkim1RsaSha256": true,
"Dkim2Ed25519Sha256": true,
"Dkim2MlDsa44": true
}
}
}

Keys can also be created by hand: OpenSSL 3.5 and later generate ML-DSA-44 keys, and Choosing an algorithm in the DKIM2 documentation compares the three algorithms in detail.

All the post-quantum features in Stalwart are part of the open source Community edition:

AreaPost-quantum algorithmWhat to do
TLS, incoming connectionsX25519MLKEM768 hybrid key exchangeNothing; used with every client that supports it
TLS, outgoing connectionsX25519MLKEM768, now preferredUpgrade to 1.2.3
Encryption at rest and gateway, OpenPGPML-KEM-768 + X25519, ML-KEM-1024 + X448Register a post-quantum key if your mail clients can read it
Encryption at rest and gateway, S/MIMEML-KEM-512, ML-KEM-768, ML-KEM-1024Ready on the server; waiting for mail clients and certificate authorities
DKIM2 signaturesML-DSA-44Add an ML-DSA-44 key next to the classical ones

None of this is a reason to panic. The joint statement is explicit that there is no immediate and widespread threat, and nothing in it suggests that mail encrypted or signed today can be read or forged today. But the direction is clear, and the transition takes years for the internet as a whole. The parts that depend on a mail server are available now.

Stalwart 1.2.3 is available now. Upgrading is a matter of replacing the binary or pulling the new container image, as described in the upgrade instructions. The changelog lists every change in this release.