[TriLUG] md5sum disagrees with libmd5-rfc and Digest::MD5

Steve Litt slitt at troubleshooters.com
Tue Apr 25 15:58:36 EDT 2006


Hi all,

I have a problem that's killing me, and there seems to be no info on it 
anywhere on the Internet, so I've massively crossposted in hope of an answer. 
If I find one, I'll let all of you know.

I created workalikes for the md5sum command using L. Peter Deutsch's 
libmd5-rfc and Perl's Digest::MD5. Those workalikes agree with each other but 
disagree with the output of the MD5sum program for the same input. Unless 
Digest::MD5 is built from Deutsch's code, this either casts an accusing 
finger at md5sum, or there's some basic fact I don't understand.

Here is an example of all three programs finding an md5 digest in hex format 
for the string "abc":

[slitt at mydesk ~]$ echo abc | md5sum -t
0bee89b07a248e27c83fc3d5951213c1  -
[slitt at mydesk ~]$ echo abc | md5sum -b
0bee89b07a248e27c83fc3d5951213c1 *-
[slitt at mydesk ~]$ md5sum -t abc.txt
0bee89b07a248e27c83fc3d5951213c1  abc.txt
[slitt at mydesk ~]$ md5sum -b abc.txt
0bee89b07a248e27c83fc3d5951213c1 *abc.txt
[slitt at mydesk ~]$ ./deutsch.bin abc
900150983cd24fb0d6963f7d28e17f72
[slitt at mydesk ~]$ /d/at/perl/md5/md5test.pl abc
Hello world
900150983cd24fb0d6963f7d28e17f72
[slitt at mydesk ~]$

As you can see, the perl program and the program made with Deutsch's code 
agree with each other and disagree with all possible running's of md5sum.

I'm using Mandriva 2006 on an Athlon XP2600 with 1.5GB RAM and a couple >200GB 
hard drives. The md5sum command I'm using is stock.

Below my sig is listings for my perl program using Digest::MD5 and my C 
program using Deutsch's libmd5-rfc code.

Thanks

SteveT

Steve Litt
Author: 
   * Universal Troubleshooting Process courseware
   * Troubleshooting Techniques of the Successful Technologist
   * Rapid Learning: Secret Weapon of the Successful Technologist
Webmaster
   * Troubleshooters.Com
   * http://www.troubleshooters.com


#include "md5.h"
#include <math.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
	{
	md5_state_t state;
	md5_byte_t digest[16];
	int ssi;

	memset(digest, 32, sizeof(digest));
	md5_init(&state);
	md5_append(&state, (const md5_byte_t *)argv[1], strlen(argv[1]));
	md5_finish(&state, digest);
/*	printf("%s ==md5==> ", argv[1]);*/
	for(ssi=0; ssi < 16; ssi++)
		{
		printf("%02x", digest[ssi]);
		}
	printf("\n");
	}


#!/usr/bin/perl -w
use strict;

use Digest::MD5

print "Hello world\n";


my $ctx = Digest::MD5->new;

my $data=$ARGV[1];
$ctx->add("abc");
#$ctx->addfile(*FILE);

my $digest;
$digest = $ctx->hexdigest;
print $digest, "\n";
#$digest = $ctx->hexdigest;
#print $digest, "\n";
#$digest = $ctx->b64digest;
#print $digest, "\n";



More information about the TriLUG mailing list