Disclosure: Some links on this site are affiliate links. If you purchase through them, we earn a small commission at no extra cost to you. Learn more

Symmetric vs. Asymmetric Encryption: The Key Exchange Problem

TL;DR

Symmetric ciphers (AES) use one key kk for both encryption and decryption, C=Ek(P)C = E_k(P), and run near hardware speed — but two parties must already share kk over a secure channel before any traffic can flow, and an nn-party network needs (n2)\binom{n}{2} pairwise keys. Asymmetric cryptography solves distribution by splitting the key: RSA generates a modulus N=p×qN = p \times q from two large primes and derives a public exponent ee and private exponent dd with ed1(modφ(N))ed \equiv 1 \pmod{\varphi(N)}; Diffie-Hellman lets two parties compute a shared secret gabmodpg^{ab} \bmod p over a public channel without ever transmitting it. Both rest on problems (factoring, discrete log) that are classically hard but fall to Shor's algorithm. TLS uses asymmetric primitives only to bootstrap a symmetric session key, then hands bulk data to AES — asymmetric operations are too slow for high-throughput encryption.

Symmetric Encryption: AES and the Key Distribution Problem

AES is a substitution-permutation network operating on 128-bit blocks under a single shared key kk:

Equation
C=Ek(P),P=Dk(C)C = E_k(P), \qquad P = D_k(C)

Encryption and decryption use the same key, and each round is a fixed sequence of byte substitution, row shifting, column mixing, and key XOR — no exponentiation, no modular arithmetic over large integers. This is why AES throughput on hardware with AES-NI reaches gigabytes per second, several orders of magnitude faster than any public-key operation of comparable security margin.

The cost is distribution. Before C=Ek(P)C = E_k(P) means anything, both parties must possess kk, and kk must reach the second party without being observed. For a network of nn participants who all need pairwise secure channels, the number of distinct keys required is

Equation
(n2)=n(n1)2\binom{n}{2} = \frac{n(n-1)}{2}

which is quadratic in nn and does not scale to the open internet: there is no pre-existing secure channel between a browser and a server it has never contacted. AES gives no mechanism for establishing kk in the first place — that problem requires a different mathematical structure entirely.

Asymmetric Encryption: RSA

RSA replaces a single shared secret with a key pair, generated as follows.

  1. Choose two large primes pp, qq and compute the modulus:
Equation
N=p×qN = p \times q
  1. Compute Euler's totient of NN:
Equation
φ(N)=(p1)(q1)\varphi(N) = (p - 1)(q - 1)
  1. Choose a public exponent ee coprime to φ(N)\varphi(N) (commonly e=65537e = 65537), then compute the private exponent as its modular inverse:
Equation
de1(modφ(N))d \equiv e^{-1} \pmod{\varphi(N)}

The public key is (N,e)(N, e); the private key is (N,d)(N, d). Encryption and decryption are modular exponentiation:

Equation
C=MemodN,M=CdmodNC = M^e \bmod N, \qquad M = C^d \bmod N

Correctness follows from Euler's theorem given ed1(modφ(N))ed \equiv 1 \pmod{\varphi(N)}. Security follows from the opposite direction: recovering dd from (N,e)(N, e) requires φ(N)\varphi(N), and computing φ(N)\varphi(N) without p,qp, q is believed to require factoring NN — classically sub-exponential, and the exact problem Shor's algorithm solves in polynomial time on a quantum computer.

Diffie-Hellman Key Exchange

Diffie-Hellman does not encrypt a key for transport — it lets two parties derive an identical secret from public values, without either value ever crossing the wire.

Public parameters: a large prime pp and a generator gg of the multiplicative group Zp\mathbb{Z}_p^*.

Equation
Alice: a$Zp,A=gamodp\text{Alice: } a \xleftarrow{\$} \mathbb{Z}_p,\quad A = g^a \bmod p
Equation
Bob: b$Zp,B=gbmodp\text{Bob: } b \xleftarrow{\$} \mathbb{Z}_p,\quad B = g^b \bmod p

Alice and Bob exchange AA and BB over the open channel, then each computes the same value independently:

Equation
s=Bamodp=(gb)amodp=gabmodp=(ga)bmodp=Abmodps = B^a \bmod p = (g^b)^a \bmod p = g^{ab} \bmod p = (g^a)^b \bmod p = A^b \bmod p

An eavesdropper who observes p,g,A,Bp, g, A, B but not aa or bb must solve the discrete logarithm problem — recover aa from A=gamodpA = g^a \bmod p — to reconstruct ss. No efficient classical algorithm does this for well-chosen parameters.

Elliptic Curve Diffie-Hellman (ECDHE) replaces Zp\mathbb{Z}_p^* with the group of points on an elliptic curve over a finite field, and modular exponentiation with scalar point multiplication:

Equation
A=aG,B=bG,s=aB=bA=(ab)GA = a \cdot G, \qquad B = b \cdot G, \qquad s = a \cdot B = b \cdot A = (ab) \cdot G

where GG is a fixed base point. The hard problem — the elliptic curve discrete logarithm problem — has no known sub-exponential classical attack, so ECC reaches RSA-2048-equivalent security with a ~256-bit key, which is why TLS 1.3 defaults to ECDHE over classical Diffie-Hellman or RSA key transport.

Why the Modern Web Needs Both

Neither primitive is sufficient alone. Asymmetric operations — modular exponentiation over 2048-bit integers, or scalar multiplication over elliptic curve groups — cost microseconds to milliseconds per operation and do not scale to encrypting a video stream or a large file. Symmetric ciphers scale to that throughput but have no answer to the distribution problem described above.

TLS 1.3 resolves this with hybrid encryption: an ECDHE exchange runs once per connection to derive a shared secret, which is fed through a key derivation function to produce a symmetric session key. Every subsequent record on that connection is encrypted with AES (typically AES-GCM), not with the asymmetric primitive. RSA or ECDSA signatures separately authenticate the handshake, binding the exchange to a certificate so the shared secret cannot be intercepted by a man-in-the-middle. The asymmetric layer solves distribution and identity; the symmetric layer does the encryption work at line rate. Removing either half breaks the protocol — this is also why the migration to post-quantum cryptography touches the asymmetric layer (KEMs replacing RSA/ECDHE) while leaving AES itself largely untouched.