The Hardware Side of Cryptography

30 June 2008

Implementing Anubis Block cipher on PIC18F4550

Filed under: encryption — Tags: , , — edipermadi @ 12:18 pm

This morning, i started to code Anubis Block cipher on PIC184550. The block cipher that designed by Vincent Rijmen and Paulo S. L. M. Barreto. Though this cipher has large size memory requirement for lookup, this cipher is actually quite simple to understand. Fortunately PIC18F4550 has large data and program memory, so it can accomodate Anubis cipher.

Now i have two things to do, the RC5 block cipher and Anubis block cipher. For RC5 cipher, I’m currently in a stage of verifying my RC5 code against vector test. For Anubis cipher, i just started to write the code.

Today, i got Power Electronics mid-term exam to do. Everithing gone crazy this week. Hopefully i can publish those two code this week. Cheers!

23 June 2008

Implementing the RC5 block cipher on PIC18F4550

Filed under: encryption — Tags: , , , — edipermadi @ 5:01 pm

After sucessfully developing AES (Rijndael) cipher for PIC16F84, PIC16F877 and PIC18F4550. I wish to implement another RSA made cipher called RC5. I’ll start reading the specification first then i’ll start code that algorithm. Although this week is going to be bussy enough, i’m trying to finish that code as fast as i could. I’ll post that code as usual. Keep visiting this blog and happy coding forever :D .

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

15 June 2008

Implementing the RC4 stream cipher on PIC18F4550

Filed under: encryption — Tags: , , , , — edipermadi @ 12:29 pm

Today, i’m started developing RC4 cipher on PIC18F4550. This cipher was originally developed by Ron Rivest for RSA Security as a trade secret. Eventually, someone posted it to Cypherpunks and sci.crypt Mailing List. Now, RC4 belong to everyone who want to use it :) . You may note that the cipher was pretty simple and straightforward. However, since this cipher require large size of RAM for computation. I decided to write the code on PIC18F4550 instead of PIC16F877.

After sitting for more than six hours, finally i was able to code RC4 stream cipher for PIC18F4550. That was an enjoyful moment to me. The code was developed and simulated using MPLAB v8.0 and some PHP script to simulate encryption byte per byte, of course to ensure that everything is under control.

RC4 was the fastest cipher i have ever coded, it reach almost 25 cycles per byte 8) , That was amazing, 8) . See two screenshots below and feel free to use and modify the code under the term of GNU Public License v3.0. Have a nice day and happy coding :D .

Plain Text

Cipher Text

RELATED STUFF

Download:
Source Code v1.0
PIC18F4550 Datasheet
MPLAB v8.0

Reference:
RC4 Cipher
Ron Rivest
RSA Security

2 June 2008

Implementing Enigma Railway Cipher Machine on PIC16F84

Enigma Railway is one of simple type of Enigma variants. It has 3 types of rotor and one type of reflector and it has no steckerboard at all. You may only alter those three rotor positions, rotor offsets, and ring setting. You will find that Enigma Railway is a good place to start learning How enigma machine works. Yeah, because it was quite simple and straightforward :p .

I also wrote a program to emulate Enigma Railway Cipher based on PIC16F84. It was written and simulated using MPLAB 8.0 and it works the same as specification. The screenshots are shown below.

Enigma Railway Plain Text

Enigma Railway Cipher Text

I splitted the source code into two versions. Version 1.0 comes without “Germany Keyboard Permutation” and  version 2.x comes with Germany Keyboard Permutation (A mapped to Q, B mapped to W and so on). I verified and tested this source code against several test vector. I simulated my code and compared the result with Enigma Railway Simulator and guess what! Both of them were showing the same results :) .

I hope this post will inspire you guys to write better code for Enigma Railway emulator based on PIC16F84. Next time i’ll try to code another Enigma which is more complicated. Have a nice day and happy coding :D .

RELATED STUFF

Download:
Basic Enigma Railway (without Keyboard Permutation) | v1.0 | v1.1 | v1.2
Advanced Enigma Railway (with Keyboard Permutation) | v2.0
PIC16F84 Datasheet
Mid-Range Reference Manual
MPLAB v8.0
Enigma Railway Simulator

Reference:
Enigma Machine
Enigma Rotor Details
Crypt Analysis of Enigma

Blog at WordPress.com.