The Hardware Side of Cryptography

17 June 2008

Fast AES Implementation on PIC18F4550

Filed under: encryption — Tags: , , , — edipermadi @ 7:14 pm

I have wrote two versions of AES (Rijndael) cipher code for 2 kind of microcontrollers, which are PIC16F84 and PIC16F877. Those microcontroller were able to run AES code well, but something is bothering me. I felt dissatisfied with Galois Field multiplication routine which run a bit slow due to instruction type limitation. PIC16F84 and PIC16F877 were not able to to directly implement “shift without carry”. These microcontrollers keep entering carry bit to bit 0 while doing shift left operation, and some times i feel a bit upset because of this.

To start writing this post, first i spent my time to learn PIC18F4550 instruction set and its architecture. I also spent my time to learn how lookup table was done on PIC18F4550 and also the sense of using PIC18F4550. Hmmm, now lets get ourself dirty :) .

Yeah, after sitting for 4 hours. I am finally able to port my Rijndael (AES) code from PIC16F877 to PIC18F4550 with major modifications on lookup table and GF(28) routine. Horray!!! :D . This new implementation gave me better improvement on decrypting routine and small improvement on encrypting routine. Nice progress, i love my new code :) . It works and also fast, that was what i looking for.

My AES (Rijndael) cipher implementation on PIC18F4550 is basically divided into six versions. The characteristic of each version are listed below.

  • Version 1.x is intended for unbuffered AES 128-bit
  • Version 2.x is intended for unbuffered AES 192-bit (not available yet)
  • Version 3.x is intended for unbuffered AES 256-bit
  • Version 4.x is intended for buffered AES 128-bit
  • Version 5.x is intended for buffered AES 192-bit
  • Version 6.x is intended for buffered AES 256-bit

The term buffered means that all subkeys are buffered, so that the program only need to generate subkeys once all use it all the time until the new subkey are generated. By doing this, we can speed up the code by excluding key scheduling routine.

In the other side, the implementation which has no buffered (unbuffered) will perform key scheduling to generate subkey on each iteration. That was the reason why unbuffered implementation is slower than buffered implementation. But note that buffered implementation require more memory to store its subkey. If you have lots of free memory, I suggest you to use the buffered one.

See two Screenshots below, i took those picture from MPLAB v8.0, the tools where i developed this code. Nice software and Its absolutely free!. Checkout microchip website for more updates.

Plain Text

Cipher Text

Check out also materials related to this post below. If you need AES (Rijndael) implementations on PIC16F84 and PIC16F877. Please check out these links: AES (Rijndael) PIC16F84 and AES (Rijndael) PIC16F877.

RELATED STUFF

Download:
Source Code AES 128-bit unbuffered | v1.0 | v1.1 | v1.2
Source Code AES 256-bit unbuffered | v3.0 | v3.1
Source Code AES 128-bit buffered | v4.0 | v4.1 | v4.2 | v4.3 | v4.4
Source Code AES 192-bit buffered | v5.0 | v5.1 | v5.2
Source Code AES 256-bit buffered | v6.0 | v6.1 | v6.2
PIC18F4550 Datasheet
MPLAB v8.0

References:
Advanced Encryption Standard
Joan Daemen
Vincent Rijmen

Simulator:
AES(Rijndael Simulator)

Official Webiste:
- http://www.microchip.com

Blog at WordPress.com.