MD5 hash calculates differently on server

前端 未结 5 1971
一个人的身影
一个人的身影 2020-12-16 19:24

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

相关标签:
5条回答
  • 2020-12-16 20:05

    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.

    0 讨论(0)
  • 2020-12-16 20:21

    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.

    0 讨论(0)
  • 2020-12-16 20:24

    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.

    0 讨论(0)
  • 2020-12-16 20:26

    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.

    0 讨论(0)
  • 2020-12-16 20:29

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

    0 讨论(0)
提交回复
热议问题