Re: MD5 hash query

From: Joe Cooper <>
Date: Fri, 28 Dec 2001 07:05:58 -0600

Robert Collins wrote:

> ----- Original Message -----
> From: "Joe Cooper" <>
>>>As for the method conversion: it gets fed into the MD5 in binary, so
> you
>>>need to feed the binary value in. (ie if size(method)==4, and GET is
> 1,
>>>then the result will be 0x00000001 - but don't forget to adjust for
> your
>>I've now fiddled with several methods of feeding binary data into the
>>hashing module--but I'm not sure if any of them result in the actual
>>result needed. Regardless of whether the correct data format is being
>>fed, the resulting hash is still incorrect.
>>I've tried both 16 bit and 32 bit binary (via a pack/unpack pair), as
>>well as the Perl 5.6 sprintf %b conversion. method_t is an unsigned
>>int, so I think it's 32 bits on my box--and I must assume the same
>>endianness that Perl generates from an unpack operation on the same
>>machine. None result in a matching MD5...
> Ok, here's my 4c.
> Firstly add a debug statement to the hash creation that outputs an
> escaped string (ie '\\0' instead of a literal '\0'. That will give you
> an exact picture of what went into a given hash.

Done. The unpack/pack combo is spitting out what I expected it to (but
I don't know if that's what the MD5 needs to see):

00000000000000000000000000000001 (32 bit network endianess)
00000001000000000000000000000000 (32 bit machine endianess)

I tried both along with 16 bit versions. No go.

> Secondly, find some way of feeding that into perls MD5 module. Note -
> and this is the most important thing - that feeding '1' in when the
> binary value is '\1' is wrong. I'm no perl programmer, so pack/unpack
> don't mean much to me, but if they perform _any_ conversion you will get
> the wrong results.

I'm afraid I'm not getting this part? Isn't conversion what /is/ needed
here, if I'm starting with a base ten 1 and need a binary 1 to be fed
into MD5?

And I'm also a little lacking in perl insight to be sure of whether I'm
really feeding binary, or a string representation of the binary. If I'm
reading the docs right (and my test script is acting like I think it is)
the packed format is 'really' binary, while the unpacked form of that
packed string is a string representation of the binary. I've fed both
into MD5 with no matches.

I'm going to have to sleep on this for a bit, I think (it's 7AM, and
I've been working on the MD5 stuff since about 7PM)...

I welcome further thoughts, of course. I'll be banging my head on it
some more in a few hours.

Thanks, Robert.

Joe Cooper <>
Web Caching Appliances and Support
Received on Fri Dec 28 2001 - 06:04:27 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:42 MST