Skip to content

Lecture 6 - Key Exchange and Public-Key Cryptography

Lecture 6 - Key Exchange and Public-Key Cryptography

eecs-388

Diffie-Hellman Key Exchange

  • Alice and Bob can have a public conversation to derive a secret shared key

Procedure

  1. use public (often from standards) parameters:
    • p: a large prime (e.g. 2048-bits)
    • g: a primitive root modulo p (usually small)
  2. Alice generates a random secret value 0<a<p0 < a < p Bob generates random secret value 0<b<p0 < b < p Alice computes A:=gamod  pA := g^a \mod p and shares it with Bob Bob computes B:=gbmod  pB := g^b \mod p and shares it with Alice
  3. Alice computes s:=Bamod  ps := B^a \mod p Bob computes s:=Abmod  ps := A^b \mod p Alice and Bob each obtain the same value: Bamod  p=gbamod  p=gabmod  p=Abmod  pB^a \mod p = g^{ba} \mod p = g^{ab} \mod p = A^b \mod p Mallory is not able to derive in polynomial time either aa or bb

Security of Diffie-Hellman

  • passive eavesdropping fails
    • Eve knows p,g,gamod  p,gbmod  pp,g,g^a \mod p, g^b \mod p
    • Eve wants to compute s:=gabmod  ps := g^{ab} \mod p
    • best known approach: find aa or bb, then compute ss
    • finding xx given gxmod  pg^x \mod p is an instance of the discrete logarithm problem, which is believed to be intractable for 2048-bit pp
  • active MITM attack succeeds
    • Alice does DH with Mallory, ends up with u:=gab′mod  pu := g^{ab'} \mod p
    • Bob does DH with Mallory, ends up with v:=ga′bmod  pv := g^{a'b} \mod p
    • Alice and Bob think they’re talking to each other, but really they’ve computed a separate secret key shared with Mallory
  • DH dives you a shared secret, but you don’t know who it’s shared with

Issues About Keys

Defending DH from MITMs Approaches:

  1. trust-on-first-use - hope there’s no attacker the first time, but detect if keys change later (SSH)
  2. have users communicate out-of-band - ask people to meet or call each other to verify they have the same kk (Signal)
  3. rely on proximity to limit MITMs - attacker must be nearby, or in contact (IoT devices)
  4. use digital signatures - what HTTPS websites do Important Goal: forward secrecy
  • we usually want to communicate repeatedly
  • pitfall - adversary could record all the ciphertexts, then later steal our key
  • solution - for each session, use DH to generate a temp session key; use separate long-term key to authenticate it
  • benefits - compromising long-term key would allow future impersonation but not retrospective decryption (assuming attacker can’t break DH)

RSA - Public-Key Cryptography

  • since antiquity, encryption key = decryption key “symmetric key crypto”
  • breakthrough - keys can be distinct

“Textbook” RSA

key generation (in secret):

  1. generate large random primes pp and qq (say, 2048 bits each)
  2. compute “modulus” N:=pqN := pq (say, 4096 bits)
  3. pick small “encryption exponent” ee (say, 65537) must be relatively prime to (p−1)(q−1)(p-1)(q-1)
  4. compute “decryption exponent” dd such that ed≡1mod  (p−1)(q−1)ed \equiv 1 \mod (p-1)(q-1)
  • yields RSA key pair: - public key - (e,N)(e,N) - private key - d,N)d,N)
  • public key encryption:
    • encrypt - c:=memod  Nc := m^e \mod N
    • decrypt - m:=cdmod  Nm := c^d \mod N
  • digital signatures:
    • sign - s:=mdmod  Ns := m^d \mod N
    • verify: m=semod  Nm = s^e \mod N

Facts about RSA

  • RSA can be used for confidentiality and/or integrity+authenticity
  • confidentiality - public-key encryption
    • Alice encrypts mm using Bob’s public key to get cc
    • Bob decrypts cc using Bob’s private key to get mm
  • integrity/sender authenticity - digital signatures
    • Alice signs mm using Alice’s private key to get ss
    • Bob verifies m,sm,s using Alice’s public key
  • both properties - use both, with two key pairs
    • Alice encrypts mm using Bob’s public key to get cc, then Alice signs cc using Alice’s private key to get ss
    • Bob verifies c,sc,s using Alice’s public key, then Bob decrypts cc using Bob’s private key to get mm

Security

  • best known way to compute dd from ee is factoring NN into pp and qq
  • best known algorithm - number field sieve
  • believed intractable for 4096-bit NN

Drawbacks

  • 1000x slower than AES

  • messages must be shorter than NN
  • keys must be relatively large

Alternative - Elliptic-Curve Cryptography (ECC)

  • elliptic curves are a mathematical alternative for constructing key exchange, signing, encryption
  • pros: attacks (hoped) harder, so key can be shorter
  • ex: ECDH, ECDSA, Ed25519

Subtle Attacks on Textbook RSA

Sep 17, 2026