The Hardware Side of Cryptography

13 January 2008

Implementing MD5 using PIC16F84

Filed under: Hash — Tags: , , , — edipermadi @ 7:51 am

i’ve search around google to find acticles on how to implement MD5 hash function in a microcontroller such PIC16F84 but results nothing. Just for for the sake of curiosity, suddenly i code MD5 algorithm into PIC16F84 assembly language. During debugging process. i dealt much with “big endian” and “little endian” format which is confusingūüôā . Finally i’ve done everything properly. I compared hash of “abc” string using DAMN Hash Calculator and using MPLAB simulator and got the same hash. It was amazing. I also simulate the code using Oshon Soft “PIC Simulator IDE” which gives me the same result as well. Big thanks to oshon soft, your shareware program helps me much.

To implement all of this i used approximately 900 bytes of PIC16F84 program memory. I have not optimize this code, please let me know if you have any other algorithm which is faster than the original one. Now I am currently trying to implement SHA1 or SHA160 using AT89S52 microcontroller. Hopefully someday i will implement all of hashing function on microcontroller.

I have modified the original code of this. The original code requires 20.45 ms to compute hash, however the modified one just takes 15.99 ms which is 4.4 ms faster.

Here some screenshot, i took it from damn hash calculator, MPLAB and PIC Simulator IDE.

Damn Hash Calculator

Damn Hash Calculator Screenshot

MPLAB Simulator 5.20

MPLAB 5.20 MD5 Screenshot

Oshon Soft PIC Simulator IDE

Oshon PIC IDE Simulator Screenshot

RELATED STUFF

Downloads:
Source Code | v1.0 | v1.1 | v1.2
PIC16F84 Datasheet
Mid-Range Reference Manual

References:
MD5
Ronald Rivest
RFC1321

Official Website:
–¬†Microchip
–¬†Ronald¬†Rivest
–¬†RSA¬†Security
–¬†PIC¬†IDE¬†Simulator

3 Comments »

  1. Hi.
    I cannot understand why you have to put byte 3 of input data to 0x80 and byte 55 to 0x18. I’ve changed that bytes to 0x00 and checksum in not anymore that expected.
    Thank you.

    Comment by Peppe Tundo — 26 January 2011 @ 12:26 am

  2. Hello there! I know this is kinda off topic but I was wondering if you knew where
    I could get a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having
    difficulty finding one? Thanks a lot!

    Comment by Maple — 28 July 2013 @ 12:45 am

  3. I have been looking for such code to the PIC 18F2550. Now, one found one that works. Thank you. If found responsible for the SHA-1 would be even more fun. Sorry my bad english.

    Comment by Jyrki — 13 October 2013 @ 8:07 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:

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: