RFE: add a reinit method to block ciphers
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Python-Crypto |
New
|
Wishlist
|
Unassigned |
Bug Description
Could you consider adding a reinit() method to block ciphers? Most crypto libraries provide one.
This would save creating a new object instead of resetting the cipher to the original IV. Below is a usage
comparison with python-mcrypt.
import base64
from mcrypt import MCRYPT
from Crypto.Cipher import AES
def beh64(data):
return base64.
CZ_KEY = "f52412c4ff1dac
CZ_IV = "0e32f4c96203f892"
aes = MCRYPT(
aes.init(CZ_KEY, CZ_IV)
def cz_arg(strn):
aes.reinit()
return beh64(aes.
def cz_arg2(strn):
aes2 = AES.new(CZ_KEY, AES.MODE_CBC, CZ_IV) # no reinit
pad = len(strn) % 16
if pad != 0:
strn = strn + ('\x00' * (16 - pad))
return beh64(aes2.
print cz_arg('abc')
print cz_arg2('abc')
print cz_arg('def')
print cz_arg2('def')
What would be the purpose of this? In general, (key, IV) pairs should never be reused for encryption, so I'm hesitant to add an interface that would encourage doing so.