# RSA - Finding all possible encryption exponents

Consider the standard RSA-algorithm: We have chosen two primes $$p$$ and $$q$$ such that $$n:=p \cdot q$$ and computed $$\varphi(n)$$. We now need to choose the public key $$e$$ such that

$$1

If I am not mistaken there should be $$\varphi(\varphi(n))-1$$ many possible $$e$$'s ; we have to add $$-1$$ since we want to exclude $$e \ne 1$$.

Is there a "clever" algorithm to find all possible $$e$$'s other than to apply Euclid's algorithm on all numbers below $$\varphi(n)$$ and checks whether they are coprime to it?

• In practice people choose $e=3$ or $e=2^{16}+1$, which are prime and thus surely relatively prime to $\phi(n)=(p-1)(q-1)$. – Henno Brandsma Nov 2 '18 at 20:11
• then $e^2$, too. – kelalaka Nov 2 '18 at 20:35
• @HennoBrandsma: not necessarily; if p and q are only required to be primes, p-1 and q-1 could easily have factorization including 3 (fairly likely) or F4 (less likely but possible), or pretty much any other small prime. Instead RSA keygen normally fixes e first, and then searches for p,q primes of the desired size with the additional requirement that p-1 and q-1 are coprime to the given e; see e.g. B.3.3 in FIPS186-4 (or -3). – dave_thompson_085 Nov 3 '18 at 8:19
• @dave_thompson_085 $p$ and $q$ are usually chosen such that $p\pm 1$ and $q\pm 1$ contain no small prime factors, either. – Henno Brandsma Nov 3 '18 at 8:56

We know that $$\varphi(x) \ge\sqrt{\frac{x}{2}}$$. The size of $$\varphi(n)$$ is roughly the same of $$n$$, so $$\varphi(\varphi(n))-1$$ is still a intractably large number. This means finding all possible e's is infeasible because there are too many. No matter what algorithm you use, there is no way you can find all of them in polynomial time (in the security parameter).