AttributeError: 'module' object has no attribute 'digest_size' in PyCrypto

Axel Ulrich <[email protected]>
Newsgroups gmane.comp.python.cryptography
Message-ID <LISTSERV%[email protected]>
I got above error after I installed PyCrypto and Paramiko on Windows XP ,
Python 2.5.  I saw this error somewhere when I google'd for it, but no
solution was pointed out.
On my Ubuntu box, it runs fine however.
I am by no means an experienced Python programmer, but as most folks will
run into this on Windows regardless of installing a binary PyCrypto distro
or building it from source, the issue is in PyCrypto.Hash.SHA.  The issue is
that Windows file names are not case sensitive.  This library imports itself
rather than - what the author intended - importing the standard sha lib from
Python.  I got it fixed by changing PyCrypto.Hash.SHA as follows:

# Just use the SHA module from the Python standard library

__revision__ = "$Id: SHA.py,v 1.4 2002/07/11 14:31:19 akuchling Exp $"

# from sha import *
# import sha

from hashlib import sha1 as sha
new = sha

blocksize = 1        # legacy value (wrong in any useful sense)
digest_size = 20
digestsize = 20


if hasattr(sha, 'digestsize'):
    digest_size = digestsize
    del digestsize
del sha


Axel

Here the traceback before the fix:

Traceback (most recent call last):
  File "demo_sftp.py", line 30, in <module>
    import paramiko
  File "C:\dev\Python25\lib\site-packages\paramiko\__init__.py", line 69, in
<module>
    from transport import randpool, SecurityOptions, Transport
  File "C:\dev\Python25\lib\site-packages\paramiko\transport.py", line 32,
in <module>
    from paramiko import util
  File "C:\dev\Python25\lib\site-packages\paramiko\util.py", line 31, in
<module>
    from paramiko.common import *
  File "C:\dev\Python25\lib\site-packages\paramiko\common.py", line 107, in
<module>
    randpool = RandomPool()
  File "C:\dev\Python25\lib\site-packages\Crypto\Util\randpool.py", line
101, in __init__
    self._getPos = hash.digest_size
AttributeError: 'module' object has no attribute 'digest_size'
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.