I found the what is at fault here, the following program demonstrates the error:
#!/usr/bin/python
from M2Crypto import BN, EVP, RSA, util, Rand, m2, X509
from binascii import hexlify, unhexlify
i=0
while True:
i=i+1
try:
iv = (hex(BN.rand(16 * 8))[2:34]).replace('L', 'c')
uh = unhexlify(iv)
except:
print "found failure, i=%s, iv=%s len=(%s)\n" % (i,iv,len(iv))
raise
basically,
iv = (hex(BN.rand(16 * 8))[2:34]).replace('L', 'c')
is not guaranteed to create something that is consumable by unhexlify.
Run it, and you'll very quickly see something like:
$ /tmp/go.py
found failure, i=36, iv=3f99a2dfad8a6d936772bd181f8653c len=(31)
Traceback (most recent call last):
File "/tmp/go.py", line 11, in <module>
uh = unhexlify(iv)
TypeError: Odd-length string
I found the what is at fault here, the following program demonstrates the error:
#!/usr/bin/python ).replace( 'L', 'c')
from M2Crypto import BN, EVP, RSA, util, Rand, m2, X509
from binascii import hexlify, unhexlify
i=0
while True:
i=i+1
try:
iv = (hex(BN.rand(16 * 8))[2:34]
uh = unhexlify(iv)
except:
print "found failure, i=%s, iv=%s len=(%s)\n" % (i,iv,len(iv))
raise
basically, ).replace( 'L', 'c')
iv = (hex(BN.rand(16 * 8))[2:34]
is not guaranteed to create something that is consumable by unhexlify.
Run it, and you'll very quickly see something like:
$ /tmp/go.py 6d936772bd181f8 653c len=(31)
found failure, i=36, iv=3f99a2dfad8a
Traceback (most recent call last):
File "/tmp/go.py", line 11, in <module>
uh = unhexlify(iv)
TypeError: Odd-length string