Do perfect squares count as valid moduli for an RSA semi-prime? The question is pretty self-explanatory but basically I just want to ask if, when choosing the p and q primes that, when multiplied, become the modulus for an RSA public key, is there a risk that attackers can exploit if p and q are equal to each other?
The only requirement that I've seen up until now is that both p and q need to be primes but I never read anywhere about what happens if they are the same number. Basically, p = q and, as such, the square root of the N modulus is p. Is there an efficient algorithm that can detect this efficiently and, as such, factor the numbers and compute the private key? And, if such an algorithm exists, doesn't this mean that this can compromise existing RSA keys with such setups?
Is this even a realistic risk at all or is it just too unlikely to happen in practice?
There is a simple way to detect if a number is square because there is an efficient way to compute square roots.
This should not be a realistic threat as the chance of picking two $b$-bit primes uniformly at random and getting a match will be about $b(\log 2)/2^b$. Given that a broken random number generator that always returns the same value would cause this to happen, it should not be discounted as a threat. However many standards specify a minimum difference between $p$ and $q$ to block Fermat's difference of squares attack (e.g. ANSI X9.31) which should stop such moduli being generated. Moreover, if such moduli were generated, they would not function properly as RSA moduli as the decryption process would not work.