[pycrypto] same RSA.construct fails on OSX

Legrandin gooksankoo at hoiptorrow.mailexpire.com
Fri Jan 20 08:33:01 EST 2012

Hi Antoine,

> The following code runs fine on a number of platforms, but fails on OSX
> (I believe it may have started failing after I added gmp/fastmath)
> m = 6297666796491112384985580404233259073480862181882692247331293512441057109594629677274269303703414891974879> e = 65537
> p = 0
> k = RSA.construct((long(m), long(e), long(p)))
> print("recreate_key=%s" % k)
> On OSX I get:
> ValueError: Unable to compute factors p and q from exponent d.

This is the correct behavior with current pycrypto version (2.5), no
matter if you use fast or slow math.
Your code is trying to reconstruct an RSA private key, but you pass a
private exponent (which you call p, even if typically is called d)
with value 0. That is an error, the private exponent must be e^{-1}
mod phi(m), which clearly cannot be zero.

API is described here

With previous version you had to provide at least 5 elements,
m+e+d+p+q (I don't recall how they complain if you provide only 3).

> What can I do to correct this (and still use fastmath)?
> Shouldn't this be detected as a problem with fastmath, at build time?

There is nothing to correct I think.

More information about the pycrypto mailing list