Cryptography Safe primes are also important in cryptography because of their use in
discrete logarithm-based techniques like
Diffie–Hellman key exchange. If is a safe prime, the multiplicative
group of integers
modulo has a
subgroup of large prime
order. It is usually this prime-order subgroup that is desirable, and the reason for using safe primes is so that the modulus is as small as possible relative to
p. A prime number
p = 2
q + 1 is called a
safe prime if
q is prime. Thus,
p = 2
q + 1 is a safe prime if and only if
q is a Sophie Germain prime, so finding safe primes and finding Sophie Germain primes are equivalent in computational difficulty. The notion of a safe prime can be strengthened to a strong prime, for which both
p − 1 and
p + 1 have large prime factors. Safe and strong primes were useful as the factors of secret keys in the
RSA cryptosystem, because they prevent the system being broken by some
factorization algorithms such as
Pollard's p − 1 algorithm. However, with the current factorization technology, the advantage of using safe and strong primes appears to be negligible. Similar issues apply in other cryptosystems as well, including
Diffie–Hellman key exchange and similar systems that depend on the security of the
discrete logarithm problem rather than on integer factorization. For this reason, key generation protocols for these methods often rely on efficient algorithms for generating strong primes, which in turn rely on the conjecture that these primes have a sufficiently high density. In
Sophie Germain Counter Mode, it was proposed to use the arithmetic in the
finite field of order equal to the safe prime 2128 + 12451, to counter weaknesses in
Galois/Counter Mode using the binary finite field GF(2128). However, SGCM has been shown to be vulnerable to many of the same cryptographic attacks as GCM.
Primality testing In the first version of the
AKS primality test paper, a conjecture about Sophie Germain primes is used to lower the worst-case complexity from to . A later version of the paper is shown to have time complexity which can also be lowered to using the conjecture. Later variants of AKS have been proven to have complexity of without any conjectures or use of Sophie Germain primes.
Pseudorandom number generation Safe primes obeying certain congruences can be used to generate
pseudo-random numbers of use in
Monte Carlo simulation. Similarly, Sophie Germain primes may be used in the generation of
pseudo-random numbers. The decimal expansion of 1/
q will produce a
stream of
q − 1 pseudo-random digits, if
q is the safe prime of a Sophie Germain prime
p, with
p congruent to 3, 9, or 11 modulo 20. Thus "suitable" prime numbers
q are 7, 23, 47, 59, 167, 179, etc. () (corresponding to
p = 3, 11, 23, 29, 83, 89, etc.) (). The result is a stream of
length q − 1 digits (including leading zeros). So, for example, using
q = 23 generates the pseudo-random digits 0, 4, 3, 4, 7, 8, 2, 6, 0, 8, 6, 9, 5, 6, 5, 2, 1, 7, 3, 9, 1, 3. Note that these digits are not appropriate for cryptographic purposes, as the value of each can be derived from its predecessor in the digit-stream. ==In popular culture==