The Hardware Side of Cryptography

6 August 2008

Fast 9600 bps Serial Encryptor based on A5/1 Algorithm

A5/1 is a kind of stream cipher commonly used in GSM networks. This cipher scrambles data from handset to Base Trasceiver Station (BTS). This cipher consists of 3 different LFSR with different tapping and a special clocking method called “Majority Rule”. Majority rule stated that an LFSR will be clocked if middle bit is equal to majority bit and majority bit is defined as a function of all middle bit of three LFSR. Majority bit is set if at least two out of three middle bit is set, otherwise zero.

Here i presented you a way to perform RS232 serial encryption using A5/1 Algorithm. This post is basically an extension of previous post about A5/1 Implementation on PIC16f84. Previous experiment, shown me that a single bit A5/1 output costs about 82 cycles (82 micro seconds) on 4 MHz PIC16F84 microcontroller. In the other hand, RS232 specification said that the bit gap of 9600 bps asynchronous transmission is approximately 104 micro seconds.

Based on those two facts, i was encouraging my self to write another code that implements A5/1 algorithm as a serial encryptor. Since generating 1 bit A5/1 output costs 82 micro seconds and 1 bit gap of 9600 bps transmission is about 104 micro seconds, hence i concluded that A5/1 stream generation can be done while microcontroller is receiving data from RS232 terminal. The concept is basically easy, i just replace bit delay routine by bit generating process, so that 8 bit A5/1 stream is generated when 8 bit data received asynchronously through RS232.

By employing this tricky way, i can reduce the time required to process bit stream. This way also reduce gaps between two bytes. These all characteristics made A5/1 becoming a reliable candidate for RS232 encryptor application.

Now, lets talk about its reality. I coded and compiled this cipher using MPLAB v8.0 and simulated the result using Oshon Soft PIC IDE Simulator. The result was satisfactory. If you wish to apply this in such a real hardware, please use 4MHz PIC16F84 microcontroller. Please make sure that you use RA0 as transmitting bit and RA1 as receiving bit. For additional things such RS232 to TTL converter, there are many way to convert RS232 to TTL or vice versa. You can use any of them as long as it is works.

Screenshot

How to Use: to initialize this encryptor, follow these steps below:

  1. Send 3 bytes frame setting, stare from frame 0 which is MSB.
  2. Send 8 bytes key setting, start from key 0 which is MSB.
  3. Allow 16.63 ms delay for key scheduling
  4. Encryptor is ready to use, please use 9600 bps speed

RELATED STUFF

Source Code | v1.0
PIC16F84 Datasheet
Mid-Range Reference Manual
MPLAB v8.0

Reference:
A5/1 Strem Cipher
Pedagogical A5/1 Implementation

3 Comments »

  1. Hahaha… Makin kagum aku.😀

    Comment by chandramde — 19 December 2008 @ 2:34 pm

  2. nice stuff
    Great work

    Comment by Rebel Simcard — 27 December 2008 @ 2:54 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: