[pycrypto] _fastmath None !!

Lorenz Quack don at amberfisharts.com
Wed May 19 07:50:51 CST 2010


Hi,

the code looks fine too me.
I also ran it and had no problems. Even when generating the keys on my 32-bit Netbook and loading them on my 64-bit 
desktop I couldn't reproduce the problem (both with and without gmp installed). However both use pycrypto 2.1.0.

Without being able to reproduce the problem I'm afraid I won't be able to help you. Sorry.

cheers and good luck
//Lorenz



On 05/19/2010 06:17 AM, jd wrote:
> Ok... here is attached program.
>
> The problem seems to be
> a. Either package specific (pycrypto package installed using easy_install and/or from rpm as dependency from paramiko.)
>     I use virtual env, and when I install pycrypto using easy_install, the _fastmath.so is not present in the egg.
>
> b. serialization of keys in to file.
>
> Basically, if u run the attached program it works on all my test machines.
> If you create the keys and save them on one machine, and try to read them (comment the key generation, saving part), then it does not work on some machines.
>
> I am using picke and base64, to my knowledge both should work across m/c architecture (32bit, 64bit) and different python versions. Or I am mistaken ?
>
> One observation is that the keys generated and saved on a 32 bit machines are running in to the problem when read on a 64 bit machine.  But if I generate it on a 64 bit machine.. it seems to work on a 32 bit machine.
>
> NOTE: This is just one variable... the machines have different python version, different linux distro..etc.
>
> Thanks in advance.
>
> /Jd
> p.s. I am going to switch serialization and see if that helps.
>
> --- On Tue, 5/18/10, Lorenz Quack<don at amberfisharts.com>  wrote:
>
>> From: Lorenz Quack<don at amberfisharts.com>
>> Subject: Re: [pycrypto] _fastmath None !!
>> To: "PyCrypto discussion list"<pycrypto at lists.dlitz.net>
>> Date: Tuesday, May 18, 2010, 3:20 AM
>> Hi
>>
>> On 05/18/2010 08:19 AM, jd wrote:
>>>
>>> Hi Lorenz,
>>>       Thanks for quick response.
>>>
>>> It is happening on someone else's machine, I have
>> requested them to check and send me details.
>>>
>>> In the mean time I looked that the code.
>>> In RSA.py
>>>
>>> try:
>>>        from Crypto.PublicKey import
>> _fastmath
>>> except ImportError:
>>>        _fastmath = None
>>>
>>>
>>> Could this be problem ?
>>
>> I don't think so. That should happen when PyCrypto was
>> compiled without gmp support.
>> According to my analysis the relevant parts are the
>> __setstate__ method in the class _RSAobj
>> and the __init__ in the class RSAImplementation.
>> In the __init__ the attribute _math is set which is later
>> being accessed by both the construct
>> method and in the _RSAobj.__setstate__ method.
>> The way the _math attribute is set seems pretty safe to me
>> so I believe things must be going
>> astray somewhere else. But it's hard to tell without any
>> code.
>>
>> cheers
>> //Lorenz
>>
>>
>>> Thanks
>>> /Jd
>>>
>>>
>>> --- On Mon, 5/17/10, Lorenz Quack<don at amberfisharts.com>
>> wrote:
>>>
>>>> From: Lorenz Quack<don at amberfisharts.com>
>>>> Subject: Re: [pycrypto] _fastmath None !!
>>>> To: "PyCrypto discussion list"<pycrypto at lists.dlitz.net>
>>>> Date: Monday, May 17, 2010, 8:40 AM
>>>> Hi again,
>>>>
>>>> no idea what's going wrong. normally pycrypto
>> should fall
>>>> back to _slowmath (a pure python implementation)
>> when gmp is
>>>>
>>>> not installed meaning _fastmath is not available
>> (_fastmath
>>>> is a C implementation using gmp).
>>>>
>>>> Maybe you could prvide some more information, like
>> python
>>>> version, pycrypto version, is gmp installed?
>>>> Also it would be a good idea to provide a
>>>> small/minimalistic example demonstrating the
>> problem.
>>>> That way it is easyier to figure out if it's a bug
>> in
>>>> pycrypto or in your code.
>>>>
>>>> cheers,
>>>> //Lorenz
>>>>
>>>>
>>>>
>>>> On 05/17/2010 04:48 PM, jd wrote:
>>>>> Hi Guys
>>>>>          I am serializing
>> the pycrypto keys
>>>> using pickle.. as suggested in one of recent
>> posts. It is
>>>> working fine, but giving following problem on
>> cenos 5.1.
>>>> (stack at the bottom of email)
>>>>>
>>>>> 'NoneType' object has no attribute
>> 'rsa_construct'
>>>>>
>>>>>
>>>>>          I looked at the
>> code.. it seems
>>>> while constructing _fastmath is used. Any
>> workarounds /
>>>> fixes ? I do not think changing to saving tuple
>> would help
>>>> as it would also need to use __setstate__..
>>>>>
>>>>> Help is greatly appreciated.
>>>>> Thanks
>>>>> /Jd
>>>>>
>>>>> File "/tg2env/bin/paster", line 7, in ?
>>>>>          sys.exit(
>>>>>        File
>>>>
>> "/tg2env/lib/python2.4/site-packages/PasteScript-1.7.3-py2.4.egg/paste/script/command.py",
>>>> line 84, in run
>>>>>          invoke(command,
>> command_name,
>>>> options, args[1:])
>>>>>        File
>>>>
>> "/tg2env/lib/python2.4/site-packages/PasteScript-1.7.3-py2.4.egg/paste/script/command.py",
>>>> line 123, in invoke
>>>>>          exit_code =
>> runner.run(args)
>>>>>        File
>>>>
>> "/tg2env/lib/python2.4/site-packages/PasteScript-1.7.3-py2.4.egg/paste/script/command.py",
>>>> line 218, in run
>>>>>          result =
>> self.command()
>>>>>        File
>>>>
>> "/tg2env/lib/python2.4/site-packages/PasteScript-1.7.3-py2.4.egg/paste/script/serve.py",
>>>> line 276, in command
>>>>>          relative_to=base,
>>>> global_conf=vars)
>>>>>        File
>>>>
>> "/tg2env/lib/python2.4/site-packages/PasteScript-1.7.3-py2.4.egg/paste/script/serve.py",
>>>> line 311, in loadapp
>>>>>          return loadapp(
>>>>>        File
>>>>
>> "/tg2env/lib/python2.4/site-packages/PasteDeploy-1.3.3-py2.4.egg/paste/deploy/loadwsgi.py",
>>>> line 204, in loadapp
>>>>>          return loadobj(APP,
>> uri,
>>>> name=name, **kw)
>>>>>        File
>>>>
>> "/tg2env/lib/python2.4/site-packages/PasteDeploy-1.3.3-py2.4.egg/paste/deploy/loadwsgi.py",
>>>> line 225, in loadobj
>>>>>          return
>> context.create()
>>>>>        File
>>>>
>> "/tg2env/lib/python2.4/site-packages/PasteDeploy-1.3.3-py2.4.egg/paste/deploy/loadwsgi.py",
>>>> line 625, in create
>>>>>          return
>>>> self.object_type.invoke(self)
>>>>>        File
>>>>
>> "/tg2env/lib/python2.4/site-packages/PasteDeploy-1.3.3-py2.4.egg/paste/deploy/loadwsgi.py",
>>>> line 110, in invoke
>>>>>          return
>> fix_call(context.object,
>>>> context.global_conf, **context.local_conf)
>>>>>        File
>>>>
>> "/tg2env/lib/python2.4/site-packages/PasteDeploy-1.3.3-py2.4.egg/paste/deploy/util/fixtypeerror.py",
>>>> line 57, in fix_call
>>>>>          val =
>> callable(*args, **kw)
>>>>>        File
>>>>
>> "/m2svn/trunk/src/app/web/app/app/config/middleware.py",
>>>> line 46, in make_app
>>>>>          if
>> verify_license():
>>>>>        File
>>>>
>> "/m2svn/trunk/src/app/web/app/app/core/utils/utils.py",
>> line
>>>> 2221, in verify_license
>>>>>          l_info =
>>>> read_license_using_embeded(license_file)
>>>>>        File
>>>>
>> "/m2svn/trunk/src/app/web/app/app/core/utils/utils.py",
>> line
>>>> 2202, in read_license_using_embeded
>>>>>          pub_key
>> =get_embeded_key()
>>>>>        File
>>>>
>> "/m2svn/trunk/src/app/web/app/app/core/utils/utils.py",
>> line
>>>> 2197, in get_embeded_key
>>>>>          key =
>> pickle.loads(str)
>>>>>        File
>> "/usr/lib64/python2.4/pickle.py",
>>>> line 1394, in loads
>>>>>          return
>> Unpickler(file).load()
>>>>>        File
>> "/usr/lib64/python2.4/pickle.py",
>>>> line 872, in load
>>>>>
>> dispatch[key](self)
>>>>>        File
>> "/usr/lib64/python2.4/pickle.py",
>>>> line 1237, in load_build
>>>>>          setstate(state)
>>>>>        File
>>>>
>> "build/bdist.linux-x86_64/egg/Crypto/PublicKey/RSA.py",
>> line
>>>> 171, in __setstate__
>>>>> AttributeError: 'NoneType' object has no
>> attribute
>>>> 'rsa_construct'
>>>>>



More information about the pycrypto mailing list