[PYTHON-CRYPTO] First draft of secret-key encryption PEP

Andrew Kuchling akuchlin at mems-exchange.org
Tue Sep 18 21:28:17 CEST 2001

On Tue, Sep 18, 2001 at 10:56:31AM -0400, Rich Salz wrote:
>For symmetric keys is it really important to distinguish between encrypt
>and decrypt?  Or rather to insist on it?

Encryption and decryption are not necessarily symmetric, even if the
keys are.  Look at an explanation of IDEA, for example; see
http://home.ecn.ab.ca/~jsavard/crypto/co0404.htm .

>Particularly as these are typically bulk encryption, I think a
>file-oriented interface is more useful (and important -- i don't want to
>keep two copies of my divx encoded video stream in core :).  Something
>       arc4 = ARC4(.....
>       arc.write('......')
>       plain = arc4.read()
>etc.  read and write calls can be intermixed.

Great idea!  Do you care more about programming convenience or raw
performance?  If it's convenience, that how about if encryption
modules simply registered a codec?  That way something like this would

import codecs
f = codecs.open('output', 'wb', encoding='DES',
                mode= DES.ECB    # Hmm... that constant will be annoying.
                                 # Maybe the feedback mode should be a string?
f.write('This will be encrypted\n')

This would go through some layers of Python code, so it wouldn't be
absolutely optimal performance.  I'm reluctant to require that every
implementor of an encryption module re-implement sizable chunks of the
file object API (read(), readline(), writelines(), &c.)

Not sure how to handle padding...  Also, making this work will require
some patches to codecs.py, which I'll bring up on python-dev.


More information about the python-crypto mailing list