MD5源代码不输出正确的值 [英] MD5 source code not outputting correct values

查看:204
本文介绍了MD5源代码不输出正确的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Linux机器上运行md5源代码。我从这里获得了代码: https://tools.ietf.org/html/rfc1321



在链接的底部,它声称MD5测试套件的输出应该如下所示:

< MD5(abc)= 900150983cd24fb0d6963f7d28e17f72 MD5()= d41d8cd98f00b204e9800998ecf8427e
MD5(a)= 0cc175b9c0f1b6a831c399e269772661
MD5( 消息文摘)= f96b697d7cb7938d525a2f31aaf161d0
MD5( ABCDEFGHIJKLMNOPQRSTUVWXYZ)= c3fcd3d76192e4007dfb496cca67e13b
MD5( ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789)=
d174ab98d277d9f5a5611c2c9f419d9f
MD5(123456789012345678901234567890123456789012345678901234567890123456
78901234567890)= 57edf4a22be3c955ac49da2e2107b67a

在我的md5文件夹中,我有以下内容:

  global.h 
md5c.c
md5.h
mddriver.c
code>

当我首先尝试编译时,它在mddriver.c中发出错误提示'第20行MD5未定义'(或类似的东西),所以我将第20行从'#define MD MD5 '到#define MD 5'。这可以工作,并且在代码的其余部分看起来很有意义。



我在MD5文件夹中使用以下代码进行编译:

  gcc -Wall * .c -o出

,并创建了我可以运行的文件'out'。

pre $ ./ out -x

code>

其中参数'-x'用于运行测试套件。然而,我得到'./out -x'的以下输出:

  MD5测试套件:
MD5 )= e4c23762ed2823a27e62a64b95c024e7
MD5( A)= 793a9bc07e209b286fa416d6ee29a85d
MD5( ABC)= 7999dc75e8da648c6727e137c5b77803
MD5( 消息文摘)= 840793371ec58a6cc84896a5153095de
MD5(ABCDEFGHIJKLMNOPQRSTUVWXYZ )= 98ef94f1f01ac7b91918c6747fdebd96
MD5( ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 )= dabcd637cde443764c4f8aa099cf23be
MD5( 12345678901234567890123456789012345678901234567890123456789012345678901234567890\" )= e29c01a1e2a663c26b4a68bf7ec42df7

这显然不一样。我错过了什么吗?如果您希望我重新创建未声明的MD5错误,请告诉我。谢谢。

解决方案

MD5是一种旧算法,RFC中的源代码可能没有用64位机器来编写。因此,代码在不同的处理器体系结构上可能会失败。

为了在64位机器上编译,您需要将-m32标志传递给gcc。在Linux上,您可能还需要安装libc6-dev-i386软件包。


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.

解决方案

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.

这篇关于MD5源代码不输出正确的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆