To exchange a shared key over an insecure channel we will use Diffie-Hellman. TLS relies heavily on Diffie-Hellman and it’s overall an important key exchange in cybersecurity.

Here is the algorithm simplified:

image.png

Discrete Logarithm

Is a logarithm combine with modulo.

image.png

If we use a huge prime number instead of 7 this because extremely hard to compute.

image.png

public | private | title (name of the current step)

Procedure

  1. Key Exchange Process: Alice and Bob both agree on a huge prime number “p” and a generator g, which is the primitive root of p.

Primitive Root: Where the residuals are all not zero for every exponent from 1 to p.

image.png

  1. Private Key Selection: Alice chooses a private key “a” and Bob chooses a private key “b”, both between 1 and p. Both number are 2048 bits long, so there is no change you could randomly guess it.
  2. Public Key Calculation: Alice and Bob both calculate their public keys that they will share with each other over the insecure channel. They create a public version, since it is mathematically infeasible to get the private key back out. It’s called the discrete logarithm problem.

$$ Alice-PublicKey: g^a mod  p $$

$$ Bob-Public Key: g^b mod p $$

  1. Public Key Exchange: They exchange their respective public keys.
  2. Shared Secret Calculation: Alice adds her secret to the calculation, which results in the same number as Bob who adds his secret to it as well. This is because of basic algebraic rules. Because no one knows b or a, their shared secret is kept secret.

$$ Alice - SharedSecret: (g^b)^a mod p $$

$$ Bob - Shared Secret: (g^a)^b mod p $$