0% found this document useful (0 votes)
6 views29 pages

18-Message Digest (MD5) - 25-02-2025

MD5 is a cryptographic hash function developed in 1991 that converts messages of any length into a fixed-length output of 128 bits. It is commonly used for password security and file authentication. The algorithm involves several steps, including padding the message, appending length bits, initializing buffers, and processing the message in blocks through multiple rounds of operations.

Uploaded by

selmon.bhoy.321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views29 pages

18-Message Digest (MD5) - 25-02-2025

MD5 is a cryptographic hash function developed in 1991 that converts messages of any length into a fixed-length output of 128 bits. It is commonly used for password security and file authentication. The algorithm involves several steps, including padding the message, appending length bits, initializing buffers, and processing the message in blocks through multiple rounds of operations.

Uploaded by

selmon.bhoy.321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

BCSE309L - Cryptography and Network Security

Module 4 – Message Digest (MD5)

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

1. Append Padding Bits

2. Append Length Bits

3. Initialize MD buffer

4. Process each 512-bit block


Message Digest (MD5) - Working
L  No. of blocks
Message Digest (MD5) – Step (1)
1. Append Padding Bits
 In the first step, we add padding bits in the original message
in such a way that the total length of the message is 64bits
less than the exact multiple of 512
Length (original message + padding bits) = 512 * i – 64 where i
= 1,2,3 . . .
Example
• Plaintext Message: “ They are deterministic”

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)

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 00000000 00000000 00000000
272/8 = 34 X 8bits
appended
Message Digest (MD5) – Step (2)
2. Append Length Bits
 Add length bit in the output of the first step in such a way that the
total number of the bits is the perfect multiple of 512
 Add 64-bit as a length bit in the output of the first step
i.e. output of first step = 512 * i – 64
length = 64 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)

 Initialize four different buffers, namely A, B, C, and D


 These buffers are 32 bits each and are initialized as follows:

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…)

M0 – 01010100 01101000 01100101 M0 – 54686579


01111001 (Binary) (Hex)
M1 – 00100000 01100001 01110010 M1 – 20617265
01100101 M2 – 20646574
M2 – 00100000 01100100 01100101 M3 – 65726D69
01110100 M4 – 6E697374
M3 – 01100101 01110010 01101101
M5 – 69638000
01101001
M6 – 00000000
M4 – 01101110 01101001 01110011
M7 – 00000000
01110100
M5 – 01101001 01100011 10000000 M8 – 00000000
00000000 M9 – 00000000
M6 – 00000000 00000000 00000000 M10 – 00000000
00000000 M11 – 00000000
M7 – 00000000 00000000 00000000 M12 – 00000000
Message Digest (MD5) – step (4)

• Each of these M inputs (512 bits) are used in


every single round, they are added in
different orders
In second round:
M1, M6, M11, M0, M5, M10, M15, M4, M9, M14, M3,
M8, M13, M2, M7, M12
In third round:
M5, M8, M11, M14, M1, M4, M7, M10, M13, M0, M3,
M6, M9, M12, M15, M2
In fourth round:
M0, M7, M14, M5, M12, M3, M10, M1, M8, M15, M6,
M13, M4, M11, M2, M9
Message Digest (MD5) –
Steps (cont…)
• Initialization vector
M0 – 54686579
A – 01234567
M1 – 20617265
(Hex) M2 – 20646574
M3 – 65726D69
B – 89abcdef
M4 – 6E697374
C – fedcba98 M5 – 69638000
M6 – 00000000
D – 76543210
M7 – 00000000
M8 – 00000000
M9 – 00000000
M10 – 00000000
M11 – 00000000
M12 – 00000000
M13 – 00000000
M14 – 00000000
Message Digest (MD5) -
Steps
Initialization vector
M0 – 54686579
A – 01234567
M1 – 20617265
B – 89abcdef
M2 – 20646574
C – fedcba98
M3 – 65726D69
D – 76543210
M4 – 6E697374
M5 – 69638000
M6 – 00000000
M7 – 00000000
M8 – 00000000
M9 – 00000000
M10 – 00000000
M11 – 00000000
M12 – 00000000
M13 – 00000000
M14 – 00000000
M15 – 000000B0
The values for K are is derived from the formula

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

• We apply a different function on each round i.e. for the


• 1st round, we apply the F function
• 2nd round, we apply the G function
• 3rd round, we apply the H function
• 4th round, we apply the I function
Message Digest (MD5) - Steps
• Each round has 16 operations of the g(b,c,d) is a different non-
form: linear function in each
b = b+((a+f(b,c,d)+M[i]+K[i])<<<s) round (F,G,H,I)
• Constant array : K[1]  K[64]
• K[1-16]
• K[17-32]
• K[33-48]
• K[49-64]

• Each of the sub-blocks : M[0] 


M[15]
• M[0]  32bits
• M[1]  32bits
• …

Message Digest (MD5) - Steps
• g(b,c,d) is a different nonlinear function in each round
(F,G,H,I)
• Perform OR, AND, XOR, and NOT (basically these are
logic gates) for calculating functions
• Use 3 buffers for each function
Round 1: F(B,C,D) = (B AND C) OR (NOT B AND D)
Round 2: G(B,C,D) = (B AND C) OR (C AND NOT D)
Round 3: H(B,C,D) = B XOR C XOR D
Round 4: I(B,C,D) = C XOR (B OR NOT D)
A–
01234567
B–
89abcdef
C–
fedcba98
D–
76543210

The values for K are is derived from the formula

K1 – D76AA478 K17 – F61E2562 K33 – FFFA3942 K49 – MD5 F, G, H and I functions


F4292244
K2 – E8C7B756 K18 – C040B340 K34 – 8771F681 K50 – 432AFF97 M0 –
K3 – 242070DB K19 – 265E5A51 K35 – 699D6122 K51 –
F(B,
AB9423A7
C, D) = (B∧C)∨(¬B∧D)
54686579
K4 – C1BDCEEE K20 – E9B6C7AA K36 – FDE5380C K52 – G(B, C, D) = (B∧D)∨(C∧¬D)
FC93A039 M1 – 20617265
K21 – D62F105D K37– A4BEEA44 K53
K5 – F57COFA
K38 – 4BDECFA9 K54
– H(B, C, D) =B⊕C⊕D
655B59C3 M2 –
K6 – 4787C62A K22 – 02441453 – 8F0CCC92
K7 – A8304613 K23 – D8A1E681 K39 – F6BB4B60 K55 –
I(B, C, D) = C⊕(B∨¬D)
FFEFF47D
20646574
K8 – FD469501 K24 – E7D3FBC8 K40 – BEBFBC70 K56 M3 –
– 85845DD1
K9 – 698098D8 K25 – 21E1CDE6 K41 – 289B7EC6 K57 – 6FA87E4F 65726D69
K10 – 8B44F7AF K26 – C33707D6 K42 – EAA127FA K58 – FE2CE6E0 M4 –
K11 – FFFF5BB1 K27 – F4D50D87 K43 – D4EF3085 K59 – A3014314 6E697374
K12 – 895CD7BE K28 – 455A14ED K44 – 04881D05 K60 – 4E0811A1 M5 –
K13 – 6B901122 K29 – A9E3E905 K45 – D9D4D039 K61 – F7537E82 69638000
K14 – FD987193 K30 – FCEFA3F8 K46 – E6DB99E5 K62 – BD3AF235 M6 –
K15 – A679438E K31 – 676F02D9 K47 – 1FA27CF8 K63 – 2AD7D2BB 00000000
K16 – 49B40821 K32 – 8D2A4C8A K48 – C4AC5665 K64 – EB86D391 M –7
Round Round Round Round 00000000
MD5 F, G, H and I functions
IV
F(B, C, D) = (B∧C)∨(¬B∧D)
A – 01234567
G(B, C, D) = (B∧D)∨(C∧¬D) B – 89abcdef
H(B, C, D) =B⊕C⊕D C – fedcba98
I(B, C, D) = C⊕(B∨¬D) D – 76543210

F (89abcdef, fedcba98, 76543210) = (89abcdef AND fedcba98) OR (NOT-89abcdef


AND 76543210)
F(B, C, D) = 88888888 OR 76543210
= fedcba98
Modular Addition  (X + Y) mod Z
X01234567 (A)
Yfedcba98 (Output of F)
Z100000000 (232)
(X + Y) mod Z
= (01234567 + fedcba98) mod 100000000
= ffffffff mod 100000000
= ffffffff
MD5 F, G, H and I functions

Modular Addition  ffffffff

(X + Y) mod Z
X  54686579 (M0)
Y ffffffff (output of previous step)
Z100000000 (232)
(X + Y) mod Z
= (54686579 + ffffffff) mod
100000000
MD5 F, G, H and I functions

Modular Addition  154686578

(X + Y) mod Z
X  d76aa478 (K1)
Y 154686578 (output of previous step)
Z100000000 (232)
(X + Y) mod Z
= (d76aa478 + 54686578) mod 100000000
= 2bd309f0
MD5 F, G, H and I functions

Modular Addition  2bd309f0

0010 1011 1101 0011 0000


1001 1111 0000
Left bit shift
A–
2bd309f0 01234567
B–
89abcdef
C–
0010 1011 1101 0011 0000 1001 1111 0000
fedcba98
xxxx xxx D–
Shift 7 bits left 76543210
1110 1001 1000 0100 1111 1000 0001 0101
In hexa
e984f815
(X + Y) mod Z
X  89abcdef (B)
Y e984f815 (output of shift
operation)
Z100000000 (232)
(X + Y) mod Z
= (89abcdef + e984f895) mod First operation in Round1 is
A–
100000000 76543210 completed
Similarly, do other 63 operations and
B– generate the final Message Digest of 128
= 7330C604 7330c604 bits
Performance
Key size/hash Extrapolated Physical
size(bits) Speed Resource
(Kbytes/sec.) Block (PRB)
Optimized
(Kbytes/sec.)
TEA 128 700 -
DES 56 350 7746
Triple-DES 112 120 2842
IDEA 128 700 4469
RSA 512 7 -
SHA 160 750 25162
MD5 128 1740 62425

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy