[PYTHON-CRYPTO] RandomPool instance has no attribute '__len__'
Alex Wied
alex.wied at GMAIL.COM
Sun Jul 8 14:49:00 CEST 2007
Greetings,
I trying to run the "Crypto.PublicKey: Public Key Algorithms" example from
pycrypt (under Python 2.5.1)
http://www.amk.ca/python/writing/pycrypt/
Here'y my code:
=== Begin RSATest.py ===
1) from Crypto.Cipher import *
2) from Crypto.Util import randpool
3) from Crypto.Hash import MD5
4) from Crypto.PublicKey import RSA
5)
6) class RSATest():
7)
8) def foo(self):
9)
10) plaintext = "this is some text"
11) RSAkey=RSA.generate(384, randpool.RandomPool)
12) hash=MD5.new(plaintext).digest()
13) signature=RSAkey.sign(hash, "")
14) print RSAkey.verify(hash, signature) # will check out
15) print RSAkey.verify(hash[:-1], signature)# will fail
16)
17)__name__ == "__main__":
18) d = RSATest()
19)d.foo()
=== End RSATest.py ===
I'm getting the following error when entering line 19 above:
AttributeError: RandomPool instance has no attribute '__len__'
Here's the stack trace:
=== Start trace ===
(...)
RSAkey=RSA.generate(384, randpool.RandomPool)
File "D:\Python25\Lib\site-packages\Crypto\PublicKey\RSA.py", line 40,
in generate
p = pubkey.getPrime(bits/2, randfunc)
File "D:\Python25\lib\site-packages\Crypto\Util\number.py", line 89, in
getPrime
number=getRandomNumber(N, randfunc) | 1
File "D:\Python25\lib\site-packages\Crypto\Util\number.py", line 53, in
getRandomNumber
value = bytes_to_long(S)
File "D:\Python25\lib\site-packages\Crypto\Util\number.py", line 185, in
bytes_to_long
length = len(s)
AttributeError: RandomPool instance has no attribute '__len__'
=== End trace ===
The error is raised in bytes_to_long() in number.py.
Did anybody else run into this problem? What am I doing wrong here?
Any help is much appreciated.
--Alex
More information about the python-crypto
mailing list