Join our Newsletter — 33% off our NHI Course
Home› Guides› Key Exchange and Diffie-Hellman Guide: ECDHE, Forward Secrecy…
Guide Non-Human Identity (NHI)

Key Exchange and Diffie-Hellman Guide: ECDHE, Forward Secrecy and Hybrid ML-KEM Explained

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 27 October 2026 11 min read
On this page

Every encrypted connection between services starts with two machines agreeing a secret key over a network that an adversary may be watching, and a weak or misconfigured key exchange undermines everything built on top of it. Key exchange is the step in TLS, SSH, IPsec and messaging protocols where that shared secret is created. Diffie-Hellman and its elliptic curve form (ECDH) have done this job for decades, and post-quantum key encapsulation (ML-KEM) is now being combined with them. This guide explains how key exchange works, why ephemeral exchange gives forward secrecy, what goes wrong in practice and how hybrid post-quantum groups fit in. It is written for engineers and architects who run machine-to-machine encryption, and it complements the Post-Quantum Migration for NHIs Guide.

Key takeaways

  • Key exchange creates the session key; authentication proves who you agreed it with. Diffie-Hellman alone does not stop an adversary in the middle; certificates, host keys or pre-shared keys do.
  • Ephemeral exchange gives forward secrecy. With ECDHE a stolen server private key does not decrypt past recorded sessions, which is why RFC 9325 says static RSA and static DH suites should not be negotiated.
  • Use named, standard groups. X25519, P-256 and the RFC 7919 FFDHE groups avoid the weak and custom parameters behind past attacks.
  • Hybrid post-quantum exchange is now standardised for TLS 1.3. RFC 10024 (August 2026) defines X25519MLKEM768 and two NIST-curve hybrids built on FIPS 203 ML-KEM.
  • Machine identities depend on this step. Workload mTLS, SSH automation and API traffic all inherit the strength of the negotiated group, so key exchange belongs in the cryptographic inventory.

What it is

A key exchange (or key establishment) scheme lets two parties derive the same secret value without ever sending it. NIST SP 800-56A Rev. 3 specifies the pair-wise schemes based on discrete logarithms: Diffie-Hellman and MQV, over finite fields (FFC) and elliptic curves (ECC). The derived secret is fed into a key derivation function to produce symmetric keys, which then protect data with an AEAD cipher. See the Authenticated Encryption and Block Cipher Modes Guide for that second stage.

There are three families in common use:

  • Finite field Diffie-Hellman (DH, DHE): each side picks a private exponent, publishes g raised to that exponent modulo a large prime p, and raises the other side's value to its own exponent. Security rests on the discrete logarithm problem in that group.
  • Elliptic curve Diffie-Hellman (ECDH, ECDHE): the same idea on an elliptic curve group, with much smaller keys for similar strength. X25519 uses 32-byte keys and targets about 128-bit security (RFC 7748 describes it as slightly under that level); X448 uses 56-byte keys and targets about 224 bits.
  • Key encapsulation mechanisms (KEMs): one side publishes an encapsulation key, the other generates a random secret and sends it encrypted as a ciphertext. FIPS 203 (Final, 13 August 2024) specifies ML-KEM in three parameter sets, ML-KEM-512, ML-KEM-768 and ML-KEM-1024, whose security rests on the Module Learning with Errors problem and is believed to resist quantum adversaries. NIST SP 800-227 (Final, September 2025) gives recommendations for using KEMs.

Static, ephemeral and key transport compared

ApproachExampleForward secrecyStatus in modern TLSMain risk
RSA key transportTLS_RSA_* suites in TLS 1.2NoRFC 9325: should not be negotiated; absent from TLS 1.3Server key compromise decrypts all recorded traffic
Static DH or ECDHTLS_DH_*, TLS_ECDH_* suitesNoRFC 9325: should not be negotiatedLong-lived secret reused across sessions
Ephemeral finite field DHTLS_DHE_* in TLS 1.2; ffdhe groups in TLS 1.3YesRFC 9325: TLS_DHE_* should not be negotiated in TLS 1.2; 2048-bit minimumCustom or small groups, cost of large moduli
Ephemeral elliptic curve DHECDHE with X25519 or P-256YesPreferred in RFC 9325; default in TLS 1.3Quantum attack on recorded traffic in future
Hybrid ECDHE plus ML-KEMX25519MLKEM768 (RFC 10024)YesProposed Standard for TLS 1.3, codepoint 0x11ECLarger handshakes; middlebox and library support

How it works

Inside a TLS 1.3 handshake

  1. ClientHello: the client lists supported groups (for example X25519MLKEM768, X25519, secp256r1) and sends a key share for one or more of them.
  2. ServerHello: the server picks a group and returns its own share. Both sides compute the shared secret; for a hybrid group they compute both the ML-KEM and ECDH secrets and concatenate them (64 bytes for X25519MLKEM768 under RFC 10024).
  3. Key schedule: the secret is fed through HKDF to derive handshake and traffic keys. From here everything is encrypted.
  4. Authentication: the server, and in mTLS the client, signs the handshake transcript with its certificate key. This is what binds the exchanged secret to an identity and defeats an adversary in the middle (MITRE ATT&CK T1557).

SSH follows the same pattern: an ephemeral exchange such as curve25519 produces session keys, and the server's host key signature authenticates it. See the SSH Protocol and Certificate Authority Guide.

Group sizes and wire costs

GroupSourceClient shareServer shareNotes
X25519RFC 774832 bytes32 bytesFast, simple, constant-time designs available
secp256r1 (P-256)NIST curve65 bytes uncompressed65 bytesWidely required in regulated and FIPS settings
ffdhe2048 to ffdhe8192RFC 7919, codepoints 256 to 260256 to 1,024 bytesSameSafe primes with generator 2; estimated about 103 to 192-bit strength
X25519MLKEM768RFC 10024, 0x11EC (Recommended)1,216 bytes1,120 bytesML-KEM-768 encapsulation key plus X25519 share
SecP256r1MLKEM768RFC 10024, 0x11EB1,249 bytes1,153 bytesUses P-256 for environments that require NIST curves
SecP384r1MLKEM1024RFC 10024, 0x11ED1,665 bytes1,665 bytesHigher security category, larger handshake

Hybrid client shares above about 1,200 bytes can push the ClientHello across more than one TCP packet, which has exposed middleboxes and servers that assumed it would fit in one. Test through load balancers, proxies and inspection devices before enabling hybrids broadly. The live Hybrid Post-Quantum TLS Key Exchange Guide covers rollout in detail.

Validating what the peer sends

  • Finite field: RFC 7919 requires each side to check that the peer's public value Y satisfies 1 < Y < p minus 1 and abort otherwise, and says clients accepting custom groups must reject moduli under 768 bits and should reject those under 1,024 bits.
  • X25519 and X448: RFC 7748 notes that small-order inputs can force an all-zero shared secret; implementations may check for this and abort, and protocol designers must not assume both parties contributed to the secret.
  • Side channels: RFC 7748 asks for constant-time implementation, with no memory access or branches that depend on key bits.

Why it matters

Key exchange failures are silent. A connection with a weak group still shows a padlock, still passes health checks and still carries production traffic. Three properties are at stake:

  • Forward secrecy: with ephemeral keys, compromise of a long-term private key (a TLS certificate key or SSH host key) lets an attacker impersonate the service from that point, but not decrypt sessions recorded earlier. RSA key transport and static DH lose this property.
  • Harvest now, decrypt later: traffic recorded today with classical ECDHE could be decrypted by a future quantum computer. Data with a long confidentiality life (health, financial, government, long-lived credentials sent over the wire) is the reason hybrid ML-KEM groups exist now, before signatures need to change.
  • Machine identity trust: service meshes, workload identity systems and API gateways establish thousands of sessions per second between non-human identities. Their key exchange settings are usually inherited from a library or platform default, so one weak default spreads everywhere. See the mTLS Guide.

Choosing and rolling out

  1. Inventory negotiated groups on every endpoint (public, internal, service mesh, SSH) with a scanner or handshake logs, and record them in the Cryptographic Inventory and CBOM Guide format.
  2. Remove non-forward-secret options: disable TLS_RSA_*, static DH and static ECDH suites, and TLS_DHE_* in TLS 1.2, in line with RFC 9325.
  3. Set a classical baseline: X25519 and P-256 for ECDHE; ffdhe2048 or larger only where finite field DH is required.
  4. Pilot hybrids on a canary ring of clients and services with X25519MLKEM768 first in the preference list and X25519 as fallback. Measure handshake failures and latency.
  5. Widen in rings (internal service mesh, then partner APIs, then public edge), keeping the classical fallback until telemetry shows negligible failures.
  6. Roll back by reordering the group preference list to classical first; no certificate or key change is needed, which makes this an unusually safe migration step.

Small organisations mostly inherit this from their CDN, cloud load balancer and operating system updates; the job is to confirm the setting and avoid pinning old libraries. Large organisations need policy (approved groups per tier), central TLS libraries and per-environment exceptions for appliances that cannot yet support hybrids. Regulated environments should check which groups their validated modules support; see the FIPS 140-3 and Cryptographic Module Validation Guide.

Detection and measurement

  • Log the negotiated group and protocol version on load balancers, proxies and service mesh sidecars.
  • Alert on any session using non-forward-secret key exchange or a downgrade from the configured preference (ATT&CK T1600 Weaken Encryption covers adversaries forcing weaker cryptography).
  • Metrics: percentage of sessions with forward secrecy (target 100%); percentage of internal and external sessions using a hybrid PQ group; number of endpoints still offering static RSA or DH suites; handshake failure rate after enabling hybrids; count of appliances on the exception list and their planned upgrade dates.

Framework mapping

FrameworkReferenceRelevance
NIST SP 800-53 Rev. 5SC-12 Cryptographic Key Establishment and ManagementApproved key establishment schemes and groups
NIST SP 800-53 Rev. 5SC-13 Cryptographic ProtectionAlgorithm choice, including ML-KEM
NIST SP 800-53 Rev. 5SC-8 Transmission Confidentiality and IntegrityProtected channels between services
NIST CSF 2.0PR.DS-02Data in transit protected
NIST standardsSP 800-56A Rev. 3, FIPS 203, SP 800-227Scheme specifications and KEM guidance
MITRE ATT&CKT1557, T1600, T1040Interception, forced weakening and sniffing that key exchange must withstand

Common misconceptions

  • "Diffie-Hellman stops man-in-the-middle attacks." Unauthenticated DH lets an attacker run two exchanges, one with each side. Only authentication of the transcript prevents it.
  • "A bigger certificate key makes the session stronger." Session confidentiality depends on the negotiated group, not the certificate key size. A 4,096-bit RSA certificate with a weak DH group is still weak.
  • "Post-quantum means replacing certificates first." Key exchange is the urgent part because recorded traffic can be decrypted later; signature migration can follow. See the ML-DSA and SLH-DSA Post-Quantum Signatures Guide.
  • "ML-KEM is just Diffie-Hellman with new maths." It is a KEM: one side encapsulates a secret to the other's key. Protocols that relied on DH properties, such as both parties contributing, need redesign rather than a drop-in swap.
  • "Hybrid is a temporary hack." Hybrids keep classical security if a new scheme is later weakened, which is why RFC 10024 marks X25519MLKEM768 as Recommended for TLS 1.3.
  • "Custom DH parameters are safer because they are unique." RFC 7919 exists because clients cannot cheaply verify arbitrary groups; standard safe-prime groups are the safer choice.

Practitioner checklist

  • Inventory negotiated key exchange groups across public, internal, mesh and SSH endpoints.
  • Disable RSA key transport, static DH and static ECDH suites everywhere.
  • Standardise on X25519 and P-256, with ffdhe2048 or larger only where needed.
  • Validate peer public values as RFC 7919 and RFC 7748 describe, using maintained libraries.
  • Pilot X25519MLKEM768 with classical fallback and test through every middlebox.
  • Log negotiated groups and alert on non-forward-secret or downgraded sessions.
  • Prioritise hybrid exchange for traffic carrying long-lived secrets and machine credentials.
  • Track appliance exceptions with owners and upgrade dates.

Standards and references

Related NHI Mgmt Group resources: Post-Quantum Migration for NHIs Guide · Hybrid Post-Quantum TLS Key Exchange Guide · mTLS Guide · Cryptographic Key Management Guide

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 27 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org