Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Newer Intel and AMD processors have hardware support for implementing AES using the instruction set AES-NI (instructions AESENC, AESKEYGENASSIST etc). Do you know of any clean example implementation using these instructions? In assembly (x86-64 or 32) or using wmmintrin.h (I use gcc and gas, but nasm is ok too).

I found a couple of implementations but they were cluttered with ifdefs and hard to follow macros. It would be nice to begin with a clean and easy to read implementation of, say, encrypting just one block using AES 128 and then build on from there.

share|improve this question
Might be one of those questions that should be transferred to stackoverflow.... – Maarten Bodewes Apr 12 '12 at 10:19
I found this one:… But it was closed because the question was not formulated as a question (and still not answered). – Albert Veli Apr 12 '12 at 11:42
What I mean is that this question could in that case be merged with the already existing one on the same subject. – Albert Veli Apr 12 '12 at 12:31
I would not know how to do that. I can edit the original question or I can transfer this one, but I would not know how to merge... – Maarten Bodewes Apr 13 '12 at 1:25

Have you looked at the OpenSSL implementation? At a quick glance, it looks reasonably clean to me.

You can find the OpenSSL source here. Within the source, there are several implementations in the directory "\crypto\aes\asm\". The standard x64 is in file "". The assembly is generated by Perl, code, however, but it looks like it's pretty straight forward to read.

share|improve this answer
Thanks! It looks good. I will try to compile code to expand key and encrypt/decrypt a block this weekend. – Albert Veli Apr 13 '12 at 9:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.