dlitz/pycrypto — pull request #35 by sebastinas (2013-02-10 11:32:00+00:00)
Title: AES-NI support

Since I've just got access to an AES-NI capable CPU, so I ported the _AES module to use the instructions available to speed up pycrypto's AES support. There is now a module called _AESNI that is used instead of _AES if the CPU supports the instruction set.

So let me explain all the changes:
* ./configure detects if the compiler supports the instruction set (gcc needs the -maes switch for that)
* ./configure detects if the header files defining the stubs for these instructions is available (to the best of my knowledge, it's called wmmintrin.h everywhere)
* ./configure detects if the header cpuid.h is available
* Crypto.Util.cpuid has a function to check if the instruction set is supported by the CPU during the runtime. Note that this is important for all the binary distributions.
* Crypto.Cipher.AES uses _AES if the _AESNI module wasn't build or if the CPU doesn't support the instructions or if the user explicitly disabled it with AES.new(..., use_aesni=False).
* The AES test suite runs the tests for both _AES and _AESNI if the CPU supports the instructions.

There is still some work to be done. The Crypto.Util.cpuid needs be ported to Windows. (I don't have access to a Windows machine so I couldn't test it or port it myself.)

Using AES-NI improved pycrypto's AES performance about 4 times on my Core i5-3570K in a quick test (encrypting and decrypting 32 MiB of data). If someone is interested in some more benchmarks, I'm happy to provide them.