written 6.1 years ago by |
MD-5 hashing algorithm
This algorithm is used to produce the message digest.
It produces 128 bit message digest.
It works in 5 stages
a. Padding
b. Append length
c. Divide into blocks
d. Initialize the chaining vectors
e. Process the blocks
Overview of MD5
Pad message so its length is 448 mod 572
Append a 64 bit length value to message
Initialize 4 word (128 bit) MD buffer (A, B, C, D)
Process message in 16 word (512 bit) blocks
a. Using 4 rounds of 16 bit operations on message block and buffer
b. Add output to buffer input to form new buffer value
Output hash value is the final buffer value.
a. Padding
Consider a message of size 100 bits, the main aim of this step is to make the length of the original message equal to a value which is 64 bit less than the exact multiple of 572
i.e for message of 1000 bits
i.e 512 X 3 is equal to 1536
1536-64 = 1472
1472-1000 = 472
Therefore 472 extra bits will be padded.
The padding bits consists of a single bit which is 1 followed by all 0’s.
The padding length is between 1 to 572
b. Append the length : The length of the message is 64 bits i.e. the length of the original message is expressed as 64 bit and this 64 bit are added after padding.
Total = 512 bits.
i.e the length of the total message is exact multiple of 512.
c. Divide into blocks :
Divide the input message obtained in the above step into blocks of size 512 bits.
d. Initialize the chaining variables :
In this step we initialize 4 chaining variables ‘A’, ‘B’, ‘C’, ‘D’ each of size 32 bit
The initial hexadecimal values of these chaining bits are shown as below:
These chaining variables are stored in four variables ‘a’, ‘b’, ‘c’, ‘d’.
e. Process the blocks :
In this step the actual algorithm begins each block of 512 bits is divided into 16 such blocks each of size 32 bits. There are four rounds in MD5, in each round there are 16 sub blocks as input and a ‘t’ array which consists of constants.
There are 64 constants and each constant is of size 32 bits.
Since there are four rounds and we use 16 constants for each round.
The algorithms first perform a process ‘G’ on the variables ‘b’, ‘c’, ‘d’.
Process ‘G’ for all the rounds will be different
After process ‘G’ is ours, we add the result to ‘a’
Add the result of ‘a’ with all 16 sub blocks
Add the above result with ‘t’ array
Performs circular left shift with ‘s’ bits and now add its result with ‘b’ the output of this step becomes the new ‘a’, ‘b’, ‘c’, ‘d’ for round 2