Key exchange

ECDH-P-256

Elliptic-curve Diffie-Hellman key agreement on NIST curves, Curve25519 and Curve448

standard Safe API Specified in a FIPS standard

About ECDH-P-256

ECDH-P-256 is one of 5 ECDH (including X25519 and X448) variants in the NextSSL registry, a key exchange. It uses a 65-byte public key, a 32-byte secret key, a 32-byte shared secret and a 32-byte seed. Its registry entry cites SEC 1 and NIST SP 800-56A Rev. 3. It is also known as ecdh-secp256r1. NextSSL lists it in the standard tier and exposes it through the safe API.

Overview

Elliptic Curve Diffie-Hellman lets two parties derive a shared secret from each other's public keys over an insecure channel. It is the classical key agreement used in TLS, SSH, Signal and most modern protocols, and today is usually paired with ML-KEM in hybrid post-quantum key exchange.

Each party holds a secret scalar and publishes the corresponding curve point. Multiplying the peer's public point by one's own scalar yields the same point on both sides, because scalar multiplication commutes. An eavesdropper who sees only the public points would need to solve the elliptic curve Diffie-Hellman problem. The raw shared secret should always be passed through a KDF such as HKDF before use as a key.

Two styles are present. ecdh-p256, ecdh-p384 and ecdh-p521 operate on the NIST prime curves following SP 800-56A and SEC 1, and require validating that received points lie on the curve to avoid invalid-curve attacks. X25519 and X448, specified in RFC 7748, use Montgomery curves and the Montgomery ladder; they accept any 32- or 56-byte string as a public key and clamp private scalars, which removes most validation pitfalls.

X25519 targets about 128-bit classical security and X448 about 224-bit. X25519 is the most widely used key exchange in TLS 1.3 and is the classical half of the X25519MLKEM768 hybrid. P-256 and P-384 remain common where FIPS validation is required, and X448 is used where a higher classical security margin is wanted. The raw output is the x-coordinate (the u-coordinate for X25519 and X448), not a uniformly random key.

History

1985–2018
  1. ECDH published

  2. Specified in RFC 7748

  3. Specified in NIST SP 800-56A Rev. 3

How it works

  1. Each party generates a secret scalar a or b and publishes A = aG or B = bG.
  2. Each side validates the peer's public key (point-on-curve checks for NIST curves).
  3. Both compute the shared point aB = bA and extract its x-coordinate.
  4. The shared value is fed into a KDF together with protocol context to derive keys.

Security notes

Broken by a large quantum computer, so recorded traffic is exposed to harvest-now, decrypt-later attacks; combine with ML-KEM in a hybrid for long-term confidentiality. On NIST curves, skipping public-key validation enables invalid-curve attacks, and the all-zero X25519 output from low-order points should be rejected where contributory behaviour matters.

Typical uses

Key exchange in TLS 1.3, SSH, QUIC and VPNsThe classical half of hybrid post-quantum key exchangeKEM inside HPKE and ECIES-style encryptionMessaging protocols such as X3DH

Sizes

FieldBytesMeaning
pk65Public key
sk32Secret key
ss32Shared secret
seed32 – 32Seed

Use it

from nextssl_demo import NextSSL

ns = NextSSL()              # safe API: safe and standard tiers
pk_a, sk_a = ns.call("kex_keygen", "ecdh-p256", None, outs=2)
ss = ns.call("kex_agree", "ecdh-p256", None, sk_a, peer_pk)[0]

Calls follow the NextSSL C ABI and its language bindings. Buffer sizes are validated against the sizes above.

Other ECDH (including X25519 and X448) variants

4

Frequently asked questions

What is ECDH-P-256?

ECDH-P-256 is a key exchange in the ECDH (including X25519 and X448) family. Elliptic Curve Diffie-Hellman lets two parties derive a shared secret from each other's public keys over an insecure channel. It is also known as ecdh-secp256r1.

What are the ECDH-P-256 sizes?

In NextSSL, ECDH-P-256 uses: public key 65 bytes, shared secret 32 bytes.

Who designed ECDH-P-256 and when?

ECDH-P-256 belongs to the ECDH (including X25519 and X448) family, first published in 1985 by Whitfield Diffie, Martin Hellman (Diffie-Hellman); Neal Koblitz, Victor Miller (elliptic-curve cryptography); Daniel J. Bernstein (X25519); Mike Hamburg (Curve448). Its origin: NIST SP 800-56A Rev. 3, RFC 7748, SEC 1.

Which standards define ECDH-P-256?

ECDH-P-256 is referenced by SEC 1, NIST SP 800-56A Rev. 3. It is specified in a FIPS standard.

Is ECDH-P-256 safe to use?

ECDH-P-256 is in the standard tier. Standardised and sound. Reachable from the safe API. It can be called from the safe API.

What other ECDH (including X25519 and X448) variants are there?

NextSSL also registers ecdh-p384, ecdh-p521, x25519, x448 in the ECDH (including X25519 and X448) family.