We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello, we made a straight forward port of the DES, MD5 and SHA1 algorithms from OpenSSL library (http://www.openssl.org) without optimizing the source code. The following code size is indicated in the .map when compiling using the default compiler settings of C166 v4.27 for a C167CS MCU (Hlarge memory model):
Module Code ROM RAM ============================= DES 25'246 4'631 162 MD5 20'738 16 4 SHA1 39'726 20 4
You can do MD5 for the 8051 in under 2k of code + constants. Graham Cole has some even tighter code. I imagine the 166 should be even better. I had much the same problem when I started looking at MD5. I grabbed some code from the net, and it was about 20k. It was "workstation C"; I'm sure the author thought a mere 20k was a perfectly adequate job. So I wound up rewriting the whole thing. A 10:1 reduction is not impossible. The major change needed for reducing the size was replacing all the macros (no doubt "for speed") with function calls, and making the parameters table-driven rather than inline. Also look out for assumptions that "int" is 32 bits, and that 32 bits is a good size for doing all your operations. In my case, I also saved a smidgen of code as I knew that my use of MD5 could not be reentrant, so I didn't need to pass a state parameter to allow multiple simultaneous calculations.
You can find a compact version of DES here: http://www.bds.dogma.net/des_page.htm In general, it should be possible to implement DES quite efficiently on an 8-bit processor. If you are interested in my version of MD5, please e-mail g r a h a m . c o l e @ b t . c o m