I really couldn't find a simple wrapper to pycrypto that would encrypt data correctly in Python 3.
So I tried to follow the instructions at http://www.daemonology.net/blog/2009-06-11-cryptographic-right-answers.html (written by HN's cperciva) and wrote https://github.com/andrewcooke/simple-crypt
Is that OK? Given the problems Tarsnap had with CTR mode, was it wrong to follow those instructions anyway? Have I got the offset handling right?
It seemed like it would be better to write this once, get it revised here, and then publish it (I'll make an egg for pypi once it seems OK) than quietly write my own and let others do the same (it was surprisingly complex - I mention the Tarsnap issues because after reading about them realised I had the same error...).
Apologies if I overlooked an existing package. And thanks for any constructive criticism.
Bad Things^TM will happen if multiple messages (or different parts of a single message) are ever encrypted with the same key. Seriously, screwups like this have shortened wars.
Put some type of magic constant in front of this. You'll be glad you did later when you have to change the format or simply the PBKDF2 count. but later... def _expand_key(salt, password): ... return PBKDF2(....)I don't see where you're telling PBKDF2 what hash to use for its HMAC. It's probably defaulting to something like SHA-1.