[pycrypto] DES3 problem

Legrandin helderijs at gmail.com
Sun Dec 1 13:26:12 PST 2013


>> Since a cipher object is stateful, it can be used for either
>> encryption or decryption but not both.
>
> I don't understand that. In what way does it maintain state please?

If the data to encrypt is very long, you may need to invoke the method
encrypt() of a cipher on one smaller piece at a time. The object
maintains the state of the last encryption performed, so that it can
correctly process the data that will come next. If you call decrypt()
after encrypt(), the cipher will interpret its state as if it was a
"decryption" state, even though it is actually an "encryption" state.

Same applies if you start with decrypt() and then use encrypt().

That is really a flaw of the pycrypto API: it shouldn't allow one to
switch mid air between encryption and decryption.

>> The only exception is the ECB mode. Being it stateless, it lets you
>> intermix encryption and decryption.
>
> Thanks.
> (Nothing that I've found in the docs explains this?)

A little bit hidden here:

https://www.dlitz.net/software/pycrypto/api/current/Crypto.Cipher.blockalgo.BlockAlgo-class.html#encrypt


More information about the pycrypto mailing list