liveBook · Manning

Prime number theorem

As explained in Hacking Cryptography

The prime number theorem describes the asymptotic distribution of prime numbers up to a given bound.

The prime number theorem estimates how primes are distributed among large integers. Let π(N) count primes less than or equal to N. Its asymptotic relation, π(N) ~ N/ln(N), says that primes grow less frequent as N grows while remaining plentiful at cryptographic sizes. section 8.4.1

Equation 8.17
\[\begin{aligned} \begin{aligned} \pi(N) \sim \frac{N}{\ln(N)} \end{aligned} \label{equation:prime-number-theorem} \end{aligned}\]

Use the theorem’s estimate for the number of primes up to a bound N. section 8.4.1

Estimating a 512-bit prime pool

Applying the estimate to 2^512 gives π(2^512) ~ 2^503/ln(2), placing the number of available 512-bit primes roughly between 2^503 and 2^504. This immense space means shared RSA primes are not expected from an ideal uniform RNG, even at enormous scale. section 8.4.1

This distinction matters for the common-factors attack: reused RSA primes indicate hardware faults or poor entropy rather than a shortage of large primes. A weak generator that chooses from a limited pool can cause moduli to share a factor, allowing a GCD calculation to recover it and enable private-key reconstruction. section 8.4.1

How Hacking Cryptography covers it

How deep it goes
Defines π(N), states its asymptotic estimate, and applies it to a 512-bit bound without deriving the theorem.
Examples
Estimates the population of 512-bit primes and compares its scale with the observable universe’s atoms.
What it assumes
Introduces the prime-counting notation π(N) and uses logarithms and powers of two in the estimate.
What you can do after
Evaluate/understand why shared RSA primes signal defective randomness rather than insufficient prime supply.
How it connects
Connects prime number generation, RSA, random number generation, the birthday paradox, and the common-factors attack.

This explainer was generated by Manning's knowledge graph from the text of Hacking Cryptography. The section links point to the parts of the book it draws on.