MD5 source code not outputting correct values

女生的网名这么多〃 提交于 2019-12-11 00:19:23

问题


I'm trying to run the md5 source code on my linux machine. I got the code from here: https://tools.ietf.org/html/rfc1321.

At the bottom of the link, it claims that the output of the MD5 test suite should be the following:

MD5 test suite:
MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
d174ab98d277d9f5a5611c2c9f419d9f
MD5 ("123456789012345678901234567890123456789012345678901234567890123456
78901234567890") = 57edf4a22be3c955ac49da2e2107b67a

In my md5 folder I have the following:

global.h
md5c.c
md5.h
mddriver.c

When I tried to compile at first it threw an error in mddriver.c saying that 'line 20 MD5 is undefined' (or something similar), so I changed line 20 from '#define MD MD5' to '#define MD 5'. This works and seems to make sense given the rest of the code.

I compile using the following while in the MD5 folder:

gcc -Wall *.c -o out

and this created the file 'out' that I can run using

./out -x

where the argument '-x' is to run the test suite. However, I get the following output for './out -x':

MD5 test suite:
MD5 ("") = e4c23762ed2823a27e62a64b95c024e7
MD5 ("a") = 793a9bc07e209b286fa416d6ee29a85d
MD5 ("abc") = 7999dc75e8da648c6727e137c5b77803
MD5 ("message digest") = 840793371ec58a6cc84896a5153095de
MD5 ("abcdefghijklmnopqrstuvwxyz") = 98ef94f1f01ac7b91918c6747fdebd96
MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = dabcd637cde443764c4f8aa099cf23be
MD5 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = e29c01a1e2a663c26b4a68bf7ec42df7

which is obviously not the same. Am I missing something? If you would like me to recreate the 'MD5 not declared' error let me know. Thanks.


回答1:


MD5 is an old algorithm and the source code in the RFC may not have been written with 64 bit machines in mind. It is therefore likely that the code fails on different processor architectures.

In order to compile on a 64 bit machine you'll need to pass the -m32 flag to gcc. On linux, you might need to install the libc6-dev-i386 package as well.



来源:https://stackoverflow.com/questions/33989390/md5-source-code-not-outputting-correct-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!