The Hardware Side of Cryptography

4 July 2008

Implementing RSA Public Key Cipher on PIC18F4550

Filed under: encryption — Tags: , , , , — edipermadi @ 11:21 am

Last night, i was coding RSA Public Key Cipher for PIC18F4550 microcontroller till 1.30 AM🙂 , phew . Actually, this is out of my plan. I am supposed to finisih coding Anubis and RC5 cipher but i suddenly wondering how RSA works in microcontroller Hmm…  ❓ . See, sometimes commiting plan is hard to me, i better work spontaneously. Yeah, regularity will bored me in a few nanoseconds. But nothing useless, RSA is a powerfull cipher compared to others. This cipher was invented by the threesome cool and damn genius Guys : Ron Rivest, Adi Shamir, and Leonard Adleman. Despite of its high security, RSA algorithm runs sluggy slow on PIC18F4550. For higher keylength, it also hogs PIC18F4550 data memory. I could not imagine what if code it on PIC16F84 or PIC16F877, Hmm👿 . For sure, i’ll code RSA cipher for PIC16F84 and PIC16F877, too see how slow it could be:mrgreen: .

I’ve tested the code against several test vecor and it shows exactly the same result. That was a nice news to hear. For example 887 mod 187 will result 11. I believe that this code is compatible with the RSA specification. However this is a free open source software that comes with no guarantee, so take your own risk if yiu wish to use this code.

In addition, i divided the RSA implementation into 7 version. Each version has its own characteristics listed below.

  • Version 1.x for 32-bit RSA implementation
  • Version 2.x for 64-bit RSA implementation
  • Version 3.x for 128-bit RSA implementation
  • Version 4.x for 256-bit RSA implementation
  • Version 5.x for 512-bit RSA implementation
  • Version 6.x for 1024-bit RSA implementation
  • Version 7.x for 2048-bit RSA implementation

See this screenshots below. First boxed row denote RSA input, second boxed row denote exponentiaion constant, third boxed row denote mod operation constant and fourth boxed row denote the result of RSA algorithm.

Encrypting Screenshot

Decrypting Screenshot

So far, the code only contains the core of RSA cipher, it has no capability of doing key scheduling i.e. key generating. I’ll code and upgrade all of that version gradually, so keep visiting this blog and please mail me your suggestion or even question.


RSA 32-bit | v1.0
RSA 64-bit | v2.0
PIC18F4550 Datasheet
MPLAB v8.0

Ron Rivest
Adi Shamir
Leonard Adleman

Official Website:
RSA Security

1 Comment »

  1. This software is using RSA

    Comment by Johny — 18 April 2009 @ 8:55 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

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

You are commenting using your 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

%d bloggers like this: