Sign up ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

Let's say that you have some small number of RSA signatures of known data: you know some pairs $(m_k, c_k)$ such that ${c_k}^e \equiv m_k \pmod n$. If you know $e$, because probably it's one of $\{3, 17, 65537\}$, is it possible to recover $n$?

share|improve this question
Note: I tend to write ${c_k}^e\equiv m_k\pmod n$ using \pmod rather than \mod (thanks to Maarten Bodewes for making just that). Hint: by definition that means $n$ is a divisor of ${c_k}^e-m_k$, and you know or can guess everything in several of these expressions. Note: recovering $n$, which is normally assumed public, hardly qualifies as a key recovery attack. – fgrieu Nov 4 at 9:21

2 Answers 2

up vote 3 down vote accepted

calculate $$gcd(c_1^e - m_1 , c_2^e- m_2, \dots , c_k^e-m_k)$$

With a bit luck this should get $n$.
It will be an interesting exercise to calculate the probability of success based on the number of cleartect/ciphertext pairs.

share|improve this answer
How does a GCD work with numbers that are in the 134-million-bit range (2048-bit modulus and $e = 65537$)? – Myria Nov 4 at 19:19
Any algorithm's complexity is some function which depends on the input size of its parameters. I doubt that you find anything more efficient as a gcd calculation. – Cryptostasis Nov 4 at 21:18
Even with just two signatures, the method will spit $n$ most of the times (>60%); and when it does not, it will almost always spit $n$ times a small integer, which is easy to factor out, revealing $n$. In Mathematica, computation time is not worth measuring for $e≤$ 257, and is like 40s for $e=$ 65537 and 2048-bit $n$. Using optimized GCD routines like that of GMP would give significant speedup. – fgrieu Nov 5 at 8:45
Note: you really want to compute $\gcd(c_1^e -\widetilde{m_1},c_2^e -\widetilde{m_2})$ where $\widetilde{m_j}$ is $m_j$ modified by whatever deterministic padding is used for signature (identity for textbook RSA signature, RSASSA-PKCS1-V1_5..). With randomized padding, the method won't work. – fgrieu Nov 5 at 14:47
@fgrieu For simplification, I'm assuming that $m$ is the post-padding message, and that I know what it is (i.e. it's deterministic as in PKCS #1 v1.5). – Myria Nov 6 at 2:07

Note: In my answer below I neglected to consider that the the messages for the associated signatures are also known, and that this could enable the existence of a practical algorithm to recover the modulus. While I haven't done the legwork to verify, fgrieu's comment below indicates that recovery of the modulus may very well be practical. I'm leaving my original answer below for those who are curious.

For any practical number of RSA signatures, no, you will not be able to recover the entirety of the modulus $n$. You can however, with enough signatures, come up with a reasonable estimate for the value of the most significant bits of $n$ using Frequentist analysis.

It was exactly this sort of characterization of the RSA modulus that broke the key privacy scheme used on Australia's Health Care Card.

share|improve this answer
In the question, we know not only the signatures, but also the messages, thus we can do much better than Frequentist analysis. The method in Cryptostasis's answer does work (assuming any known deterministic padding scheme), as I just confirmed by experiment with realistic parameters. Even with just two (message, signature) pairs, and regardless of $e$, it will spit $n$ with odds better than 60%; and when it does not, it will almost always spit $n$ times a small factor, that is easily found and removed. – fgrieu Nov 5 at 14:37
Footnote: if a randomized signature padding is used, e.g. RSAES-OAEP of PKCS#1v2, which is increasingly common, then the original answer applies, AFAIK. – fgrieu Nov 6 at 6:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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