# ML-KEM vs RSA and ECDH: sizes, speed, what changes

URL: https://postquantumplan.com/en/blog/ml-kem-vs-rsa-ecdh
Published: 2026-12-03

> ML-KEM compared with RSA and ECDH: key and ciphertext sizes, measured speed, the different API shape, and what developers must change when they migrate.

ML-KEM is a key-encapsulation mechanism standardized by NIST as FIPS 203. Compared with RSA key transport and ECDH, it is as fast or faster, but its public keys and ciphertexts are far bigger than elliptic-curve ones (about 1.2 KB each at ML-KEM-768, against 32 bytes for X25519), and it has a different shape: you encapsulate to a public key and get a secret plus a ciphertext, rather than exchange public values. Unlike RSA and ECDH, a quantum computer is not known to break it. The size is what changes protocols; the API shape is what changes application code.

## The numbers

Sizes for ML-KEM were measured with OpenSSL 4.0.3 and match the FIPS 203 parameter tables. X25519 and RSA sizes are the standard values for those algorithms.

| | Public key | Ciphertext / key share | Shared secret | Quantum-safe |
|---|---|---|---|---|
| X25519 (ECDH) | 32 B | 32 B | 32 B | No |
| ECDH P-256 | 65 B | 65 B | 32 B | No |
| RSA-2048 (key transport) | 256 B modulus | 256 B | chosen by sender | No |
| ML-KEM-512 | 800 B | 768 B | 32 B | Yes, as far as is known |
| ML-KEM-768 | 1,184 B | 1,088 B | 32 B | Yes, as far as is known |
| ML-KEM-1024 | 1,568 B | 1,568 B | 32 B | Yes, as far as is known |
| X25519MLKEM768 (TLS hybrid) | 1,216 B client share | 1,120 B server share | combined | Yes, if either half holds |

The hybrid sizes are the sum of the two components: 32 plus 1,184 for the client key share, 32 plus 1,088 for the server's. That is the roughly 1.2 KB of extra handshake data people quote.

### Speed

A rough benchmark with Node 24.22.1 on an Apple arm64 laptop, single-threaded, in microseconds per operation (tested, indicative only):

| Operation | Time |
|---|---|
| ML-KEM-768 key generation | about 19 us |
| ML-KEM-768 encapsulate | about 20 us |
| ML-KEM-768 decapsulate | about 17 us |
| X25519 key generation | about 14 us |
| X25519 shared secret | about 16 us |
| RSA-2048 OAEP encrypt | about 10 us |
| RSA-2048 OAEP decrypt | about 318 us |
| RSA-2048 key generation | about 30,000 us |

Three readings. ML-KEM operations are in the same range as X25519, and ML-KEM key generation is cheap, unlike RSA's. RSA public-key operations are quick but its private-key operation is much slower than ML-KEM decapsulation. And the CPU cost is not what you will notice. Bytes on the wire are. Your numbers will differ by platform and library; measure with your own.

You can generate keys and compare timings in your browser with the [KEM playground](https://postquantumplan.com/en/lab/kem-playground).

## The API shape

RSA transport and Diffie-Hellman look different from a KEM.

**RSA key transport:** the sender picks a random key and encrypts it to the recipient's public key.

**Diffie-Hellman or ECDH:** both sides generate key pairs, exchange public values, and each computes the shared secret.

**KEM:** the recipient publishes a public key. The sender runs encapsulate on it and gets two outputs, a shared secret and a ciphertext. The recipient runs decapsulate on the ciphertext and gets the same secret.

In Node 24 (tested):

```js
import crypto from 'node:crypto';

// recipient
const { publicKey, privateKey } = crypto.generateKeyPairSync('ml-kem-768');

// sender
const { ciphertext, sharedKey } = crypto.encapsulate(publicKey);
const key = crypto.hkdfSync('sha256', sharedKey, Buffer.alloc(0), 'ctx-v1', 32);
// ...encrypt with AES-256-GCM using `key`, send ciphertext + the encrypted payload

// recipient
const sharedKey2 = crypto.decapsulate(privateKey, ciphertext);
```

Always derive the working key through a KDF such as HKDF, with a context string, instead of using the shared secret directly.

## What changes for developers

1. **Message sizes.** Anywhere a 32-byte key share or a 256-byte RSA blob was assumed (fixed-size fields, database columns, protocol buffers, cookies), a KEM ciphertext of 1,088 bytes will not fit. Search for hard-coded lengths.
2. **Direction.** In ECDH both parties contribute a key pair per session. A KEM is one-directional: the sender needs only the recipient's public key. This suits "encrypt a data key to a recipient", but an authenticated, mutual exchange needs a protocol on top.
3. **No authentication.** A KEM does not authenticate the sender. Like RSA transport and plain ECDH, it leaves authentication to signatures or pre-shared keys elsewhere in the protocol.
4. **Failure behaviour.** In ML-KEM, decapsulating a tampered ciphertext does not return an error; it returns a different, pseudorandom secret ("implicit rejection"). A mismatch then shows up later as failed decryption. You can watch this by flipping a bit in a ciphertext in the KEM playground.
5. **Algorithm identifier.** Store an algorithm identifier with every ciphertext so you can migrate again. Do this even if you think you will never need to.
6. **Use hybrids unless you have a reason not to.** NIST approves ML-KEM on its own, but the independent [CIRG assessment](https://cirg.org/statements/1/) recommends hybrids combining schemes with different mathematical foundations. In protocols, that is `X25519MLKEM768`. In application code, use a vetted hybrid or HPKE library rather than inventing a combiner.
7. **Pick the parameter set deliberately.** CIRG recommends the highest security level an application supports. ML-KEM-768 is the common default in TLS; ML-KEM-1024 costs roughly 400 to 500 more bytes of public key and ciphertext.

## What does not change

AES-256-GCM for bulk encryption, HKDF for key derivation and TLS as the transport stay as they are. The KEM replaces only the part that agreed on a key.

## Is ML-KEM safe?

As far as is publicly known, yes at its standard parameters. In December 2026 Anthropic published a quantum algorithm for certain module-lattice problems, which include the one underlying ML-KEM. The independent review group concluded its practical impact is currently small; the attack needs a large-scale quantum computer and "galactic" resources at the NIST parameters, and the asymptotic gain does not directly apply because ML-KEM fixes the ring degree ([CIRG](https://cirg.org/statements/1/), [Cloudflare](https://blog.cloudflare.com/pq-is-still-safe/)). RSA and ECDH, by contrast, are broken by Shor's algorithm on a large enough machine. See [the NIST standards chapter](https://postquantumplan.com/en/learn/nist-pqc-standards) for context.

## Next steps

Run the [KEM playground](https://postquantumplan.com/en/lab/kem-playground) to see these sizes and the hybrid secret yourself, and read [the migration plan](https://postquantumplan.com/en/learn/migration-plan) for where to apply them first. If you would like a design review for an encryption flow that currently uses RSA or ECDH, you can contact a specialist via [/en/contact](https://postquantumplan.com/en/contact).
