Tutorial :MD5 hash calculates differently on server


I am running some code that I have written in C which calls the md5 hashing functionality from a hashing library that someone else wrote (md5.c & md5.h). The odd behavior I have been seeing is:

hashing working perfectly = I hash a string, and it comes out to the exact hash that I have verified it to be with multiple other sources.

  1. Hashing functionality works perfectly when compiling and running on my OSX machine and the hash that is computed is exactly as it should be.

  2. Same code, no changes is uploaded and compiled on the Linux based server and it computes a different (wrong) hash.

Does anyone have any insight on how exactly this would be possible? Its been driving crazy for the past week and I do not understand why this is even possible. I have also tested it on another machine, compiled and executed and it works perfectly. Its just when I upload it to the server that the hash is no longer correct.

The hashing functionality file can be found at: http://people.csail.mit.edu/rivest/Md5.c

SOLVED: Thanks everyone It was the 64-bit arch issue. Its mighty annoying that that slipped my mind to consider that when debugging.......


Try to replace (Md5.c line 41)

typedef unsigned long int UINT4;


typedef uint32_t UINT4;

(include stdint.h if needed)

On a 64 bits machine long int are (usually) 64 bits long instead of 32


I tried on a 64 bits opteron this solves the problem.


Is the machine that seems to not be working a different architecture (32-bit vs. 64-bit) than the others? If the MD5 implementation is dependent on machine word size (I haven't checked the code), this can cause the hash to be different.


Different compilers can have different levels of standard compliance. If you run into a sub-standard compiler you can have hard times seeing that well-tested code has been compiled to something working entirely different.

It can also happen that the target system is 64-bit and the code has 64-bit portability issues.

The only way to solve the problem is to debug where exactly the two versions of your code behave differently.


Did you make sure you are reading in binary mode? Otherwise a newline will be converted differently in a different OS.


Sorry, no. If I compile that and run it on my linux x86 box it produces the same result as the md5sum utility:

  peregrino:$ md5sum csrc/Md5.c   d27fd5f04426a3ccb2390d7517f21b9c  csrc/Md5.c  peregrino:$ bin/Md5 csrc/Md5.c   d27fd5f04426a3ccb2390d7517f21b9c csrc/Md5.c  

On my x64 box:

  sandiego:$ bin/Md5 src/Md5.c   09679964608e3335c5c3e14572373eef src/Md5.c  

So it does seem to be a 64 bit issue, rather than a linux issue.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »