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 behavi
Try to replace (Md5.c line 41)
typedef unsigned long int UINT4;
by
typedef uint32_t UINT4;
(include stdint.h if needed)
On a 64 bits machine long int are (usually) 64 bits long instead of 32
EDIT :
I tried on a 64 bits opteron this solves the problem.
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.
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.
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.
Did you make sure you are reading in binary mode? Otherwise a newline will be converted differently in a different OS.