A safe prime is a prime p shaped as p = 2q + 1, where q is also prime. In Diffie-Hellman, this structure limits the multiplicative group modulo p to two subgroups: one of size 2 and one of size q. section 5.4
Safe primes matter because they reduce the attack surface in Diffie-Hellman:
- The group order is p − 1 = 2q, so its subgroup orders can only be 2 or q. section 5.4
- Having few small subgroups prevents small subgroup attacks, where invalid public keys gradually leak bits of a private key. section 5.4
- When Diffie-Hellman is unavoidable, prefer standardized groups instead of relaxed protocols or custom groups. section 5.4
The −1 subgroup
An attacker can send −1, the generator of the subgroup of size 2, as a public key. The resulting shared secret is then −1 or 1, creating the small-subgroup behavior exploited by the attack. section 5.4
Figure 5.15 A small subgroup attack impacts DH groups that have many subgroups. By choosing generators of small subgroups as public keys, an attacker can leak bits of someone’s private key little by little.
Visualizes how malicious public keys from small subgroups can leak private-key bits during Diffie-Hellman. section 5.4
