Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

Does anyone have any examples of the MD5 algorithm for a microcontroller (preferably an 8-bit one)? Our project is going to use a Microchip PIC18 series device.

share|improve this question

5 Answers 5

up vote 11 down vote accepted

If you are looking for a C implementation, the Microchip TCP/IP stack has an implementation of MD5 in the Hashes.c file.

share|improve this answer
    
This is exactly what I needed. –  J. Polfer Mar 11 '10 at 21:39

Here's the MD5 implementation from the EtherNut (AVR based)

http://ethernut.svn.sourceforge.net/viewvc/ethernut/trunk/nut/gorp/hashes/md5.c?revision=2555&view=markup

share|improve this answer

I would stick with a known reputable implementation of MD5, and stay away from libraries you find from 3rd-party vendors. The original RFC 1321 which described MD5 has a sample C implementation.

Reminder: the known weaknesses for MD5 are collision attacks, and not preimage attacks, so it is suitable for some cryptographic applications but not others. If you don't know the difference you shouldn't be using it, but don't discard it altogether. See http://www.vpnc.org/hash.html.

share|improve this answer
1  
For cryptography, I'd steer clear of MD5 altogther... –  Toby Jaffey Mar 11 '10 at 22:10
1  
@Joby: appreciate the thought, but MD5 has aspects of it that are just fine for cryptography. You just have to know its strengths and weaknesses. –  Jason S Mar 15 '10 at 0:41
    
+1 for linking to the C source code in the original RFC. Even though I would probably go with the source code from Microchip, the same people that made the chip this is going to run on. –  davidcary Jun 9 '10 at 19:49

You can find a good description and some pseudocode for the MD5 algorithm wikipedia at http://en.wikipedia.org/wiki/MD5

You might also consider posting this question on stackoverflow since it is geared more towards programming questions.

share|improve this answer

from the wikipedia page on MD5:

... it has been shown that MD5 is not collision resistant as such, MD5 is not suitable for applications like SSL certificates or digital signatures that rely on this property.

and from the SSL researchers on the same page:

We also hope that use of MD5 in other applications will be reconsidered as well.

I understand that you probably don't want to hear this, but do you really need MD5? It shouldn't be used for cryptographic purposes as it is too insecure (and there are boatloads of rainbow tables available). If you are looking for something to just validate data, look into CRC (code here) which is computationally cheaper. If you are using it for cryptographic purposes though, then may I suggest moving to SHA? The only problem is that most cryptographically secure algorithms do not run particularly well on microcontrollers. I know it may seem like MD5 is "good enough", but the engineering way is to err on the side of caution.

share|improve this answer
1  
Don't completely rule out MD5: your statement of "It shouldn't be used for cryptographic purposes as it is too insecure" is too overgeneralized. –  Jason S Mar 15 '10 at 0:44
1  
Also don't use the fact that a hash algorithm has or doesn't have rainbow tables as a consideration to use it or not. If SHA doesn't have many rainbow tables now, it will. Append a secret "salt" to a message to get around that problem. –  Jason S Mar 15 '10 at 0:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.