10
$\begingroup$

I want to write AES from scratch without using the built in libraries of java. I know there are hundreds of AES programs (and websites) out there but I can't seem to find a site that gives me the details I think I would/should need to write my own Java program.

I know that AES has S-boxes like DES has. Were would I look for them? Also, I would like more info on the AES "counter mode".

$\endgroup$
3
  • $\begingroup$ Just a note: For productive use, you often want to use existing implementations instead of creating your own, since they probably are better shielded against side-channel attacks, and might also be more efficient (e.g. might use AES-specific instructions on modern processors). For learning about the internal workings it is a good idea to implement it yourself, though. $\endgroup$ Sep 29, 2011 at 23:50
  • 1
    $\begingroup$ For reference, a Java implementation of FIPS AES can be found in the Bouncy Castle open source project: bouncycastle.org/specifications.html $\endgroup$
    – Gary
    Sep 30, 2011 at 15:24
  • $\begingroup$ My python implementation of AES is supposed to be very easy to read, and it's got a good few comments. For what it's worth, it might help you or someone else implementing aes: code.google.com/p/zs-crypto/source/browse/zs/cipher/aes.py. A tip: read this code together with the wikipedia articles on AES. Most of the maths turns out to be really straightforward. $\endgroup$ Nov 9, 2011 at 9:17

3 Answers 3

12
$\begingroup$

The AES standard is reasonably clear, and (theoretically) sufficient to implement the AES itself. For block cipher modes of operation (including counter mode), see NIST Special Publication 800-38A.

$\endgroup$
0
4
$\begingroup$

One thing I would like to add to Thomas's answer: when implementing a cipher, it's useful to have a test vector with the cipher intermediate states (if you get it right the first time, you don't need it; if you get a detail wrong, it makes finding that detail a lot easier).

The document http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf has all those intermediate states (both for the key expansion and the actual block encrypt operations; the decrypt is just a reversal of the encrypt operations, so they don't need to spell it out explicitly).

$\endgroup$
2
  • $\begingroup$ While I do thanks you for the help. Thomas Pornin first link is the same as the one you posted. $\endgroup$ Sep 29, 2011 at 15:42
  • 1
    $\begingroup$ Oops, I missed that his 'The AES standard' was a link... $\endgroup$
    – poncho
    Sep 29, 2011 at 20:51
3
$\begingroup$

In the Rijndael proposal document a clear explanation of the possible implementations is given. It was later completed by D. J. Bernstein (https://cr.yp.to/aes-speed.html) with further optimizations. However as said before, be careful of the possible side channel attacks which may applied to your implementation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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