24 Oct 2025
Key Exchange Mechanisms
key exchange mechanisms
Diffie Hellman Key exchange
Primitive roots of prime numbers
- If \(p\) is a very large prime number then a value \(\alpha\) is called the primitive root of the prime if \(\alpha \mod\ p, \alpha^2 \mod\ p, \dots \alpha{}^{(p-1)} \mod\ p\) all form the modulo set wrt \(p\).
- Alternately, for any \(b \in \{1, \dots p - 1\}\), there exists a unique \(i\) s.t. \(b \equiv \alpha^i \mod\ p\). \(i\) is called the discrete logarithm of \(b\) for base \(\alpha\) and modulus \(p\).
- There can be multiple primitive roots.
The key exchange
- We have publicly known numbers \(\alpha\) and \(p\) as noted above. Let the two users be A and B.
- A generates \(X_A\) and sends to B \(Y_A = \alpha^{^{X_A}} \mod\ p\)
- B generates \(X_B\) and sends to A \(Y_B = \alpha^{^{X_B}} \mod\ p\)
- Both raise the publicly exchanges stuff to their own private keys
- The final key \(K = \alpha^{X_AX_B} \mod\ p\)
- Susceptible to MITM if the attacker in between is present even during key exchange itself. He can simply exchange his own set of private keys with each party.
Symmetric key distribution
- Key distribution centre KDC.
- Every user \(X\) has a secret key with the KDC \(K_X\).
- Create a session key \(K_S\) for two users trying to communicate to each other.
- A -> KDC: IDA || E[Ka, (IDA || IDB || N1)]
- KDC -> A: KDC || E[Ka, (Ks || IDA || IDB || N1)] || E[Kb, (KS || IDA || IDB)]
- A -> B: IDA || E[Kb, (Ks || IDA || IDB)]
- This is susceptible to replay attacks.
- B -> A: IDB || E[Ks, N2]
- A -> B: IDA || E[Ks, f(N2)]
- Here E can be any symmetric key cryptography algorithm. ChaCha20 is a popular choice.
For the above, we can also introduce a third nonce to prevent replay.
Assymetric key distribution
- A -> B: E[PUB, (N1 || IDA)]
- B -> A: E[PUB, (f(N1)|| N2)]
- A then generates a session key KS
- A -> B: E[PUB, (f(N2) || KS || E[PRA, H(KS)])] (last part acts as a signature)
- B -> A: E[KS, N3]
- A -> B: E[KS, F(N3)]
This ensures authenticity. If you remove the signature, it does not ensure authenticity but saves steps.
Public key exchange mechanism
- Public key authority PKA.
- A -> PKA: Request || T1
- PKA -> A: E[PRAUTH, (PUB || Request || T1)]
- A -> B: E[PUB, (IDA || N1)]
- B -> PKA: Request || T2
- PKA -> B: E[PRAUTH, (PUA || Request || T2)]
- B -> A: E[PUA, (f(N1) || N2)]
- A -> B: E[PUB, f(N2)]
