[pycrypto] same RSA.construct fails on OSX

Legrandin gooksankoo at hoiptorrow.mailexpire.com
Sun Jan 22 15:55:42 EST 2012

Hi Antoine,

>> Do you need a public key or a private key?
> As per above, public if d==0, private otherwise.

>> If you need a private key and you want it to work with all pycrypto
>> versions, go and look for the remaining 2 parameters (p and q)... ;-)

Here I was wrong, I just had a look at the code.
If you pass three arguments, you always build a private key in any
version of pycrypto,
assuming that the third parameter (d) is really the correct private exponent.
p and q are not strictly needed.

If d is zero though, construct() in pycrypto <2.5 will succeed but you
will end with a key which may still be potentially used a private key,
even if it shouldn't.
In other words, sign&decrypt won't fail but their output will be wrong.

The code you came up with:

>>> if d==0:
>>>  k = RSA.construct((long(m), long(e)))
>>> else:
>>>  k = RSA.construct((long(m), long(e), long(d)))

seems the most correct in your situation.

More information about the pycrypto mailing list