18-Message Digest (MD5) - 25-02-2025
18-Message Digest (MD5) - 25-02-2025
Dr. Somasundaram S K
Assistant Professor Senior Grade 2
School of Computer Science and
Engineering,
Vellore Institute of Technology,
Vellore – 632 014
Phone No: +91 9843665115
Mail ID: somasundaram.sk@vit.ac.in
Location: PRP Block – 218D
Message Digest (MD5)
• MD5 was developed in 1991 by Ronald Rivest
• MD5 algorithm stands for the Message-Digest
algorithm
• MD5 is a cryptographic hash function algorithm that
takes the message as input of any length and changes
it into a fixed-length message of 16 bytes or 128 bits
• The output of MD5 (Digest =size)
Plaintext is always
Multiples 128 bits
of 512
bits
Message digest = 128 bits
Message Digest (MD5) - Uses
Using this algorithm, we can secure our password in 128
bits format
It is used for file authentication
In a web application, it is used for security purposes. e.g.
Secure password of users etc.
Working of MD5 Algorithm
3. Initialize MD buffer
ASCI
T I54 01010100
h 68 01101000
e 65 01100101
y 79 01111001
…
01010100 01101000 01100101 01111001 00100000 01100001
01110010 01100101 00100000 01100100 01100101 01110100
01100101 01110010 01101101 01101001 01101110 01101001
01110011 01110100 01101001 01100011
Total 22 letters including blank space 22*8 = 176 bits
Cont…
Original message + padding = 448 mod 512
176 + padding bits = 448 mod 512
padding bits = 448-176
= 272 bits
= 1(1 bit) + 0 (271 bits)
After adding both (pad+ length), the length of the message = 512 * n
Example
Append Length
Bits
01010100 01101000 01100101 01111001 00100000 01100001 01110010
01100101 00100000 01100100 01100101 01110100 01100101 01110010
01101101 01101001 01101110 01101001 01110011 01110100 01101001
01100011 10000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Length of00000000
original message 176 (Decimal) = 10110000 (Binary)
00000000=00000000
This is the end of the padding scheme, while the preceding 56 bits are all filled up with zeros
01010100 01101000 01100101 01111001 00100000 01100001 01110010
01100101 00100000 01100100 01100101 01110100 01100101 01110010
01101101 01101001 01101110 01101001 01110011 01110100 01101001
01100011 10000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Message Digest (MD5) – Step (3)
3. Initialize MD buffer (to store output)
A = 01 23
45 67 Each buffers = 32bits
B = 89 ab Need 4 buffers (A, B, C, D) – Store
cd ef 32*4=128 bits
C = fe dc ba
98
D = 76 54
Message Digest (MD5) – Step (4)
Length of message = 512 * n
4. Process each block: Each block= 512 bits
Each 512-bit block gets broken down further into 16 sub-
blocks of 32bits each
There are four rounds of operations, with each round
utilizing all the 16 sub-blocks, the buffers, and a constant
array value
This constant array can be denoted as K[1] K[64]
Each of the sub-blocks are denoted as M[0] M[15]
Message Digest (MD5) - Example
512-bit M needs to be split into sixteen 32-bit “blocks”
M0 – 01010100 01101000 01100101
01111001
M1 – 00100000 01100001 01110010
01100101
M2 – 00100000 01100100 01100101
01110100
M3 – 01100101 01110010 01101101
01101001
M4 – 01101110 01101001 01110011
01110100
M5 – 01101001 01100011 10000000
00000000
M6 – 00000000 00000000 00000000
00000000
M7 – 00000000 00000000 00000000
Message Digest (MD5) – Example (cont…)
Constant
array K1 – D76AA478 K17 – F61E2562 K33 – FFFA3942 K49 –
K2 – E8C7B756 K18 – C040B340 K34 – 8771F681 F4292244
K3 – 242070DB K19 – 265E5A51 K35 – 699D6122 K50 –
K4 – C1BDCEEE K20 – E9B6C7AA K36 – 432AFF97
K5 – F57COFA K21 – D62F105D FDE5380C K51 –
K6 – 4787C62A K22 – 02441453 K37– A4BEEA44 AB9423A7
K7 – A8304613 K23 – D8A1E681 K38 – K52 –
K8 – FD469501 K24 – E7D3FBC8 4BDECFA9 FC93A039
K9 – 698098D8 K25 – 21E1CDE6 K39 – K53 –
K10 – 8B44F7AF K26 – C33707D6 F6BB4B60 655B59C3
K11 – FFFF5BB1 K27 – F4D50D87 K40 – K54 –
K12 – 895CD7BE K28 – 455A14ED BEBFBC70 8F0CCC92
K13 – 6B901122 K29 – A9E3E905 K41 – K55 –
K14 – FD987193 K30 – FCEFA3F8 289B7EC6 FFEFF47D
K15 – A679438E K31 – 676F02D9 K42 – K56 –
K16 – 49B40821 K32 – 8D2A4C8A EAA127FA 85845DD1
K43 – K57 –
Round Round Round Round
Operations in rounds
Each block 4 rounds of operation
• In each round 16 operations are performed
• Total 64 operations are performed in 4 rounds
• 1st round 16 operations will be performed
• 2nd round 16 operations will be performed
• 3rd round 16 operations will be performed
• 4th round 16 operations will be performed
(X + Y) mod Z
X 54686579 (M0)
Y ffffffff (output of previous step)
Z100000000 (232)
(X + Y) mod Z
= (54686579 + ffffffff) mod
100000000
MD5 F, G, H and I functions
(X + Y) mod Z
X d76aa478 (K1)
Y 154686578 (output of previous step)
Z100000000 (232)
(X + Y) mod Z
= (d76aa478 + 54686578) mod 100000000
= 2bd309f0
MD5 F, G, H and I functions