No, we do not know an algorithm running in linear time (or even polynomial time, relative to the number of digits in $n$) that outputs 'true' if $n$ is the product of exactly two prime numbers, and 'false' otherwise.
If such an algorithm existed, I do not see that it would imply possibility to factor $n$, or otherwise break RSA. For sure, it would not be a good test that an RSA key is secure (we know ways to generate valid RSA keys that in fact are factorisable by one knowing some secret, and can't be detected even with knowledge of the factorization of $n$).
To my knowledge, the closest thing we have is
- testing if $n$ is prime, and in that case output "false";
- else, try factoring $n$ using a state of the art implementation of ECM (e.g. EECM-MPFQ) for an effort having good odds to factor $n$ assuming its smallest factor was about $n^{1/3}$, and
- if that fails to exhibit a factor, either
- output "likely true" if that's good enough a result, or
- factor $n$ using GNFS then proceed
- run a primality test on the exhibited factors and output "true" (for two prime factors) or "false" (otherwise).
For small odds of falsely outputting "likely true" (including zero if we are willing to run GNFS), that algorithm is sub-exponential (in the number of digits in $n$), but super-polynomial.
With the above negative answer, the question as formulated explicitly does not ask if we can test in polynomial time whether $\gcd(\phi(n),e)=1$ given $(n,e)$; but I wish I knew the answer!
e
andphi(n)
are co-prime. $\endgroup$