MD5 hash ?

Programming, for all ages and all languages.
Post Reply
User avatar
Sam111
Member
Member
Posts: 385
Joined: Mon Nov 03, 2008 6:06 pm

MD5 hash ?

Post by Sam111 »

I am just having one problem in my understanding of the MD5 hash

//Pre-processing:
append "1" bit to message
append "0" bits until message length in bits ≡ 448 (mod 512)
append bit /* bit (not byte) length of unpadded message as 64-bit little-endian integer */ to message


Does this step mean append a 1 on the right side or left side of my message.
For example if my message was

10100010101010111010101 does it become
110100010101010111010101 or 101000101010101110101011

And after that do I pad with zeros on the right or left of the one.
example
100000000000000...my message ... followed by 64 bit length in little endian of my message
or my message ... 100000000000000.... followed by 64 bit length in little endian of my message

Thanks for any help on this.
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Re: MD5 hash ?

Post by mark3094 »

As far as I understand it, with MD5 padding (which is the same as MD4 padding) you add a 1 and the 0's to the end of the message
Does this step mean append a 1 on the right side or left side of my message.
For example if my message was

10100010101010111010101 does it become
110100010101010111010101 or 101000101010101110101011
It would be the second one.


If you're interested in implementing security, I'd highly recommend reading 'Network Security, private communication in a public world, 2nd ed', by Kaufman, Perlman and Speciner.
Pages 133 and 136 have the information you need on MD4 and MD5 hashes.
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

Re: MD5 hash ?

Post by eddyb »

It's on wikipedia and the specs. To make it simple for you:
You're most likely going to work on byte arrays, not bit streams.
Just add 0x80, fill the rest with zero, then cast the last part to uint64_t and set it to byte length * 8. You'd need some converting if not on little endian.
Post Reply