Python AES

Mar 31, 2009 00:00

I've recently found myself in desire of a pure Python AES implementation. I had started writing one a while ago, but I dropped it because the conversion from the initial Rijandel version in C was horribly tedious.

After looking around, I found a few different implementations, and picked one that wasn't too horrible, pyAES.py from http://brandon.sternefamily.net/articles/aestutorial.php (it has a padding bug that can crop up on decryption, can you discover it?). After cleaning up the interface, I benchmarked it at just under 4k/second encrypt/decrypt speed. We're not going to be breaking any records with that one ;) .

Tweaking pieces here and there (replacing galoisMult with table lookups, not re-expanding the encryption key over and over, etc.) got me to just under 30k/second encrypt/decrypt speed. Psyco doesn't help a whole lot, getting us up to about 70k/second.

I also went and implemented ECB (I have it raise an exception on call; it's a fundamentally broken mode, but it was so simple, why not), CBC, and CTR modes, in addition to the OFB mode included in the original source. I've got a CFB implementation, but something just isn't working right, and I'm a bit too sick to work through why.

I need to verify that it is as correct as the original implementation (which has a huge security hole with the consistent use of an initialization vector of nulls, btw), maybe tomorrow...

algorithms, software

Previous post Next post
Up