View previous topic :: View next topic |
Author |
Message |
evsource
Joined: 21 Nov 2006 Posts: 129
|
Hash function like MD5 or MD4 in CCS code for 18F2620 |
Posted: Tue Aug 25, 2009 6:03 pm |
|
|
Hi,
I need a function that can take two relatively short IDs (about 10 digits each), and produce some output that is unique. If I understand correctly, this is what a MD5 hash will do.
Is there a computationally less intensive way to do this?
Does anyone have the MD5, MD4, or suitable hash function they could provide the code for? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Aug 26, 2009 12:13 am |
|
|
A MD4/MD5 implementation can be found in RFC 1321 because it's used for the CHAP password algorithm. But's it's probably a bit extensive for a PIC18 project. Unintentionally, it has become my tool to reveal PCD arithmetic bugs. I hope, it compiles correctly with PCH, but I didn't yet try.
MD5 purpose is to make the signature unpredictable. If you don't need this strong cryptographic feature, simple CRC or XOR algorithms can do. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Aug 26, 2009 5:42 am |
|
|
To add an update, the RFC 1321 test code is consuming 13% ROM and 25% RAM of PIC18F2620, but it works correctly, different from PCD with PIC24. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Aug 26, 2009 1:58 pm |
|
|
If you want to create a not (easily) predictable code word generated from the two IDs I would simply use a CRC32 routine. This is much lighter on the PIC resources than an MD4 or MD5 algorithm (which are not recommended for security anyway).
The CRC routines are defined by a set of six parameters, see chapter 15 in http://www.cs.waikato.ac.nz/~312/crc.txt.
Changing one or two of these parameters to not common used values will make it very difficult to guess the coding algorithm used. |
|
|
pattousai
Joined: 23 Aug 2006 Posts: 37
|
|
Posted: Thu Apr 15, 2010 1:03 pm |
|
|
FvM wrote: | To add an update, the RFC 1321 test code is consuming 13% ROM and 25% RAM of PIC18F2620, but it works correctly, different from PCD with PIC24.
|
If I understand correctly, you already have the implementation of the RFC 1321. By any chance you could make that public?
Thanks a lot! |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Apr 15, 2010 10:56 pm |
|
|
I simply compiled the code published in RF1321. It worked correctly with PIC18F2620 and PCH.
As reported, the MD5 code also has (unintentionally) become a testcase to check for PCD bugs. I wish, CCS would use it too, before releasing new versions. |
|
|
|