Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Hybrid Key Exchange: Adding Post-Quantum Protection

· 6 min read · Home Tech

In this article
  1. Why Hybrid Key Exchange Matters
  2. How Hybrid Key Exchange Works
  3. Choosing the Right Post-Quantum Algorithm
  4. Common Problems and Misconceptions
  5. Practical Implementation Steps
  6. Costs and Performance Considerations
  7. Alternatives to Hybrid Key Exchange
  8. Frequently Asked Questions

Hybrid key exchange safely adds post-quantum protection by combining a traditional algorithm (like ECDHE) with a quantum-resistant one (like ML-KEM), so the session key is only secure if both are broken. This ensures forward secrecy and protects against 'harvest now, decrypt later' attacks, even if one algorithm is later found to be weak.

Why Hybrid Key Exchange Matters

Classic key exchange algorithms—such as Diffie-Hellman (DH) and Elliptic Curve Diffie-Hellman (ECDHE)—rely on the difficulty of problems like discrete logarithms or elliptic curve discrete logarithms. A sufficiently powerful quantum computer, using Shor's algorithm, could solve these problems in polynomial time, breaking the encryption that protects today's internet traffic. This is not a theoretical concern for the distant future: attackers are already recording encrypted traffic, waiting for the day they can decrypt it. This is known as the 'harvest now, decrypt later' threat. Hybrid key exchange addresses this by layering a post-quantum algorithm on top of a classic one, ensuring that even if the quantum computer arrives, the recorded traffic remains secure.

How Hybrid Key Exchange Works

In a hybrid key exchange, both parties run two independent key exchanges: one classic (e.g., X25519) and one post-quantum (e.g., ML-KEM, formerly known as Kyber). The resulting shared secrets are then combined to produce a single session key. The combination must be done in a way that is secure even if one of the two algorithms is completely broken. The most common approach is to concatenate the two shared secrets and then hash the result, for example using SHA-256 or SHA-384. This is called a 'combiner'. The security property is simple: if at least one of the two inputs is secret, the output is secret. This is achieved because the hash function is a one-way function, and the attacker cannot recover the combined secret without knowing both inputs.

Choosing the Right Post-Quantum Algorithm

The National Institute of Standards and Technology (NIST) has standardized several post-quantum algorithms. The most relevant for key exchange is ML-KEM (Module-Lattice Key Encapsulation Mechanism), based on the CRYSTALS-Kyber submission. It is designed for general encryption and key establishment. For hybrid key exchange, you would typically pair ML-KEM with a classic algorithm like X25519 or ECDHE P-256. Other NIST-selected algorithms, like ML-DSA (Dilithium) for digital signatures, are not used for key exchange but are important for authentication. When choosing a post-quantum algorithm, consider:

  • Security strength: ML-KEM offers three parameter sets (512, 768, 1024), providing security levels comparable to AES-128, AES-192, and AES-256, respectively.
  • Performance: ML-KEM is relatively fast, but key sizes and ciphertexts are larger than classic ECDHE. For example, ML-KEM-768 has a public key of 1184 bytes and a ciphertext of 1088 bytes, compared to 32 bytes for X25519.
  • Implementation maturity: Look for implementations that have undergone external review and are available in well-known libraries like OpenSSL, BoringSSL, or liboqs.

Common Problems and Misconceptions

One common misconception is that you can simply replace the classic algorithm with a post-quantum one. This is risky because post-quantum algorithms are newer and may have undiscovered vulnerabilities. Hybrid key exchange mitigates this by not putting all eggs in one basket. Another problem is the 'downgrade attack' risk: if an attacker can force the connection to use only the classic algorithm, they can strip away the post-quantum protection. To prevent this, the protocol must clearly indicate that hybrid is in use and fail closed if the post-quantum part is not supported. Also, be aware of the 'combiner' pitfalls: simply XORing the two secrets is not secure if one is weak, because an attacker could manipulate the other. The hash-based combiner is the safe choice.

Practical Implementation Steps

To add hybrid post-quantum protection to your key exchange, follow these steps:

  1. Choose your algorithms: Select a classic algorithm (e.g., X25519) and a post-quantum algorithm (e.g., ML-KEM-768). Ensure both are supported by your cryptographic library.
  2. Generate keys: For each side, generate a key pair for each algorithm independently. For ML-KEM, this means generating an encapsulation key and a decapsulation key.
  3. Exchange public keys: Send both public keys (or encapsulation keys) to the peer. The order and encoding must be agreed upon to avoid ambiguity.
  4. Compute shared secrets: Each side computes the classic shared secret (e.g., ECDHE) and the post-quantum shared secret (e.g., ML-KEM encapsulation).
  5. Combine the secrets: Concatenate the two shared secrets in a fixed order (e.g., classic || post-quantum) and hash them with a strong hash function (e.g., SHA-384). Use the output as the session key.
  6. Authenticate the exchange: Use a digital signature (e.g., ML-DSA or Ed25519) to authenticate the public keys, preventing man-in-the-middle attacks.
  7. Test thoroughly: Run interoperability tests with other implementations and perform negative tests to ensure that failure of one algorithm does not compromise the session.

Costs and Performance Considerations

The main cost of hybrid key exchange is increased bandwidth and computation. The post-quantum key and ciphertext sizes are larger, which adds to the handshake size. For example, a hybrid TLS handshake using X25519 and ML-KEM-768 might add about 2 KB to the handshake. Computation is also slightly higher, but on modern hardware, the impact is minimal—ML-KEM is very fast, especially with optimized implementations. The security benefit far outweighs these costs for most applications, especially those that handle sensitive data with long-term value.

Alternatives to Hybrid Key Exchange

Some might consider using only a post-quantum algorithm, but this is not recommended for most use cases due to the maturity of the algorithms. Another alternative is to use a 'quantum-resistant' key exchange that is not hybrid, but this is risky. There is also the option of using a pre-shared key (PSK) in addition to the key exchange, which provides some quantum resistance, but it is not a complete solution. The hybrid approach is the industry consensus because it provides a smooth migration path: if the post-quantum algorithm is later broken, the classic algorithm still protects the session, and vice versa.

Frequently Asked Questions

What does 'harvest now, decrypt later' mean?

This refers to the practice of attackers collecting encrypted data today and storing it, with the intention of decrypting it in the future when quantum computers become available. Hybrid key exchange protects against this by ensuring that even if the classic algorithm is broken later, the post-quantum algorithm still protects the data.

Is ML-KEM the same as Kyber?

ML-KEM is the NIST-standardized version of the CRYSTALS-Kyber algorithm. The name was changed to avoid trademark issues. The underlying mathematics is the same, but ML-KEM includes specific parameter and implementation details defined in the NIST standard.

Can I use hybrid key exchange with TLS 1.3?

Yes, TLS 1.3 supports hybrid key exchange by allowing the use of custom groups. Several implementations, such as OpenSSL and BoringSSL, have added support for hybrid key exchange using X25519 and ML-KEM. The IETF has also published drafts for hybrid key exchange in TLS.

How do I know if my hybrid key exchange is secure?

You should rely on well-vetted libraries and follow the recommendations of standards bodies like NIST and the IETF. Also, ensure that your combiner uses a strong hash function and that the key exchange is authenticated. Avoid rolling your own crypto.

What is the difference between key exchange and key encapsulation?

Key exchange (like ECDHE) allows two parties to derive a shared secret from their public keys. Key encapsulation (like ML-KEM) is a public-key encryption scheme where one party generates a shared secret and encrypts it to the other party's public key. Both can be used for key establishment, but KEMs are more natural for post-quantum algorithms.