One of the ways that RSA keys get consistently owned is when they're generated without enough entropy. Dan Kaminsky refers to a study which found that 1 in 200 RSA keys were badly generated and these were the ones that were found, not to mention the millions of others that were not found.

Thus, a good, properly seeded RNG is needed during RSA keypair generation for GPG, SSL, SSH, etc. wherever RSA key generation happens.

Phuctor is an online tool which searches for PGP RSA key pairs and factors them. Surprisingly, they even factored a 4096bit RSA key in the strong set which was badly generated with the first factor being the number 231 (3 * 77). (According to Polynomial, they only factored a corrupt subkey, which should have no real-world impact.)

When I'm generating RSA public/private keypairs for SSL, SSH, GPG, etc., is there an offline tool I can use to determine how hard and how large the primes are? Can I estimate the computational difficulty in factoring this given RSA key pair so I can determine whether they were generated properly?

Obviously, I use a secure desktop computer for key-pair generation (and optionally /dev/random), as Linux's RNG is seeded by "mouse and keyboard activity, disk I/O operations, and specific interrupts"(source, PDF) which virtual machines often don't have. While this should be enough, I like to understand the underlying methods and would like to test my key pairs to ensure security.


In general, there is no clear distinction between "hard to factor" and "not hard to factor" RSA keys. This is a continuum. For instance, the ECM algorithm (that uses elliptic curves in a smart way to factor integers) tend to have a computational cost that depends on the size of the smallest factor of the target integer. If you try harder then you can find larger factors. The consequence is that even if you spend one full day of computations to "try" with ECM your modulus for small factors, and find none, then you don't know if an attacker with more patience might not find a factor by devoting two days of computation.

There is no known method that can test a given integer and return the size of its factors, without actually recomputing the factors, which is (hopefully !) computationally infeasible for a proper RSA key.

Testing RSA keys after generation is a fool's quest. This is a nice thing to do to detect some poor implementations, not poor keys. Moreover, it detects only certain classes of poor keys (specifically, those with small factors). It does not detect poorly seeded RNG used in an otherwise correct RSA private key generation. This highlights an important point: while having very small factors is a sure sign of flawed key generation, having only large factors does not guarantee secure generation.

For proper security, ensure that keys are properly generated by auditing the key generation process, not the result.

| improve this answer | |
  • It so happens that, in late July 2016, Phuctor revealed seven keys produced on machines with - evidently - defective or sabotaged RNG. Mr. Leek, incidentally, is mistaken, we use D. Bernstein's pairwise-GCD algorithm - which reveals any instance of a duplicated factor between any two RSA keys in the database - regardless of integer size. For so long as the moduli in question fit in machine memory. – Stanislav Datskovskiy Aug 5 '16 at 1:18
  • @StanislavDatskovskiy How does that contradict the answer? Pairwise GCD only works against some poor implementations and it doesn't give you the size of the factors without finding the factors. – CodesInChaos Aug 5 '16 at 8:12

How about the other keys we found? Some of them have valid self-signatures. As in, a naive user querying SKS for an email address without regard to fingerprint will be shown one of these as the top search result. And, for all we know, they will display a valid fingerprint on some broken PGP-compatible system.

If, as Mr. Böck would have us believe, we had found that 'cosmic rays' or 'disk corruption' are able to generate valid PGP key-self-signatures - we'd be collecting the gold at Stockholm for this find, rather than settling for this small change.

| improve this answer | |
  • I'm assuming your response is to @Polynomial's comment above? Your theory for the source of these keys being bad RNG, right? Thanks for linking to the new post, just read it. – Naftuli Kay May 20 '15 at 20:45

Offline RSA strong prime test similar to Phuctor?

Yes. https://github.com/gdisneyleugers/NED-RSA. I've tried it successfully against 128 bit keys. I haven't had the time yet to try it against 1024 bit keys, but it does work as advertised - weak values during generation result in weaker keys.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.