[pycrypto] Bug in PyCrypto 2.6.1

Mirko Dziadzka mirko.dziadzka at gmail.com
Mon Dec 1 08:13:12 PST 2014


HI

Some thoughts about this …

> _RSA.RSAobj.size.__doc__ says: Return the maximum number of bits that can be handled by this key

An RSA key can only encrypt data smaller than this key. So if we have an 2048 bit RSA key, it can encrypt some 2048 bit values, but not all. So 2047 should be the safe value here.

IMHO this -1 is correct here.

    Mirko



On 01.12.2014, at 16:23, Lorenz Quack <don at amberfisharts.com> wrote:

> Hi Luis,
> 
> Thanks for reporting!
> I agree that this seems like strange/wrong behaviour.
> Especially when realise that the docs seem to contradict the behaviour.
> _RSA.RSAobj.size.__doc__ says: Return the maximum number of bits that can be handled by this key.
> But this works fine:
> >>> key.encrypt(1<<key.size(), "")
> Note that 1 << x has x+1 bits so that the above key happily encrypts key.size()+1 bits.
> 
> The only thing holding me back from strait out calling it a bug is that
> 1) this is very old code dating back to 2003.
> and 2) the -1 is actively coded there but with out explanation
> 
> As a pointer to others the relevant places are:
> /lib/Crypto/PublicKey/_RSA.py:80
> /src/_fastmath.c:949
> 
> If it is decided that this is a bug and should be fixed one should also look at other keys, e.g. DSA which seems to do the same -1 calculation.
> 
> Cheers,
> Lorenz
> 
> 
> 
> On 01/12/14 07:35, Luis González Fernández wrote:
>> Hello All:
>> 
>> 
>> I found a strange bug in size() function that return a wrong key size after creating or importing an RSA key. The return
>> value for the size funciont seems to be keysize-1.
>> 
>> Here a demo of the bug:
>> 
>> 
>> luisgf at NCC1701B:~$ python3
>> Python 3.4.0 (default, Apr 11 2014, 13:05:11)
>> [GCC 4.8.2] on linux
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> from Crypto.PublicKey import RSA
>> >>> key = RSA.generate(2048)
>> >>> key.size()
>> 2047
>> >>>
>> 
>> 
>> Regards.
>> 
>> --
>> 
>> --
>> Luis González Fernández
>> https://www.luisgf.es
>> PGP ID: C918B80F (DD6F BFC1 FC14 4C81 34F8 EA1E 6BCB C27F C918 B80F)
>> Twitter: @luisgf_2001 / Jabber:luisgf at mijabber.es
>> 
>> 
>> 
>> _______________________________________________
>> pycrypto mailing list
>> pycrypto at lists.dlitz.net
>> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>> 
> 
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto



More information about the pycrypto mailing list