ECDH Key Exchange

The Same Idea, Different Math

ECDH is Diffie-Hellman, but using elliptic curves instead of modular exponentiation.

The goal is the same: create a shared secret over a public channel.


The Setup

Alice and Bob agree on:

  • An elliptic curve
  • A generator point GG

These are public. Everyone knows them.


The Protocol

Alice’s side:

  1. Pick a secret number aa (her private key)
  2. Compute A=aGA = aG (her public key)
  3. Send AA to Bob

Bob’s side:

  1. Pick a secret number bb (his private key)
  2. Compute B=bGB = bG (his public key)
  3. Send BB to Alice

Creating the Shared Secret

Alice computes:

a×B=a×(bG)=abGa \times B = a \times (bG) = abG

Bob computes:

b×A=b×(aG)=abGb \times A = b \times (aG) = abG

Both get the same point abGabG.


Why It Works

Scalar multiplication is commutative:

a(bG)=b(aG)=(ab)Ga(bG) = b(aG) = (ab)G

The order doesn’t matter. Both paths lead to the same point.