0% found this document useful (0 votes)
14 views32 pages

Bcse309l Module 4 MD5

MD5 is a cryptographic hash function developed in 1991 by Ronald Rivest that converts input messages of any length into a fixed 128-bit output. It is commonly used for file authentication and secure password storage. The algorithm involves padding the input message, appending length bits, initializing buffers, and processing the message in blocks.

Uploaded by

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

Bcse309l Module 4 MD5

MD5 is a cryptographic hash function developed in 1991 by Ronald Rivest that converts input messages of any length into a fixed 128-bit output. It is commonly used for file authentication and secure password storage. The algorithm involves padding the input message, appending length bits, initializing buffers, and processing the message in blocks.

Uploaded by

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

BCSE309L – Cryptography and Network

Security
Message Digest (MD5)

2
Message Digest (MD5)
• MD5 was developed in 1991 by Ronald Rivest
• 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.
• MD5 algorithm stands for the message-digest
algorithm.
• The output of MD5 (Digest size) is always 128 bits.

Plaintext = multiples of 512 bits


Message digest = 128 bits

3
Message Digest (MD5)
• Uses
 It is used for file authentication.
 In a web application, it is used for security
purposes. e.g. Secure password of users etc.
 Using this algorithm, We can store our password in
128 bits format

4
Message Digest (MD5)

• Working of MD5 Algorithm


1. Append Padding Bits
2. Append Length Bits
3. Initialize MD buffer
4. Process Each 512-bit Block

5
Message Digest (MD5)

L  No. of blocks

6
Message Digest (MD5)
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 64 bits less than the exact multiple of 512

Length(original message + padding bits) = 512 * i – 64 where i = 1,2,3 . . .

7
Message Digest (MD5)
Example:
• Plaintext Message: “ They are deterministic”
ASCII
T  54  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
9
Message Digest (MD5)
Append Padding Bits
Length(original message + padding bits) = 512 * i – 64 where i = 1,2,3 . . .
= 512*1-64
= 512 – 64
= 448
Original message + padding = 448
176 + padding bits = 448
padding bits = 448-176
= 272 bits
= 1(1 bit) + 0 (271 bits)

01010100 01101000 01100101 01111001 00100000 01100001 01110010 01100101 272/8=34


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

10
Message Digest (MD5)
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.
 Simply, here we add the 64-bit as a length bit in the output of
the first step.
i.e. output of first step = 512 * n – 64
length bits = 64.

 After adding both, the length of the message = 512 * n 11


Message Digest (MD5)
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 00000000 00000000 00000000

Length of original message = 176


= 10110000
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 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 10110000 12
Message Digest (MD5)
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 cd ef
Need 4 buffers (A, B, C, D) –
C = fe dc ba 98
D = 76 54 32 10 Store 32*4=128 bits

13
Message Digest (MD5)

4. Process each block: Length of message = 512 * n

 Each 512-bit block gets broken down further into 16 sub-


blocks of 32 bits each. Each block= 512 bits
 There are four rounds of operations, with each round
utilizing all the 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]

14
Message Digest (MD5)
512-bit M needs to be split into sixteen 32-bit “words”
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 00000000
M8 – 00000000 00000000 00000000 00000000
M9 – 00000000 00000000 00000000 00000000
M10 – 00000000 00000000 00000000 00000000
M11 – 00000000 00000000 00000000 00000000
M12 – 00000000 00000000 00000000 00000000
M13 – 00000000 00000000 00000000 00000000
M14 – 00000000 00000000 00000000 00000000
M15 – 00000000 00000000 00000000 10110000
Message Digest (MD5)

M0 – 01010100 01101000 01100101 01111001 M0 – 54686579


M1 – 00100000 01100001 01110010 01100101 M1 – 20617265
M2 – 00100000 01100100 01100101 01110100 M2 – 20646574
M3 – 01100101 01110010 01101101 01101001 M3 – 65726D69
M4 – 01101110 01101001 01110011 01110100 M4 – 6E697374
M5 – 01101001 01100011 10000000 00000000 M5 – 69638000
M6 – 00000000 00000000 00000000 00000000 M6 – 00000000
M7 – 00000000 00000000 00000000 00000000 M7 – 00000000
M8 – 00000000 00000000 00000000 00000000 M8 – 00000000
M9 – 00000000 00000000 00000000 00000000 M9 – 00000000
M10 – 00000000 00000000 00000000 00000000 M10 – 00000000
M11 – 00000000 00000000 00000000 00000000 M11 – 00000000
M12 – 00000000 00000000 00000000 00000000 M12 – 00000000
M13 – 00000000 00000000 00000000 00000000 M13 – 00000000
M14 – 00000000 00000000 00000000 00000000 M14 – 00000000
M15 – 00000000 00000000 00000000 10110000 M15 – 000000B0
Operation carried out
Message Digest (MD5) on Every 512 bit block

• 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

17
Message Digest (MD5)
• Initialization vector
M0 – 54686579
A – 01234567 M1 – 20617265
M2 – 20646574
B – 89abcdef M3 – 65726D69
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
M15 – 000000B0

18
Message Digest (MD5)
• Initialization vector
M0 – 54686579
A – 01234567 M1 – 20617265
M2 – 20646574
B – 89abcdef M3 – 65726D69
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
M15 – 000000B0

19
Round Operation

The values for K are is derived from the formula

K1 – D76AA478 K17 – F61E2562 K33 – FFFA3942 K49 – F4292244


K2 – E8C7B756 K18 – C040B340 K34 – 8771F681 K50 – 432AFF97
K3 – 242070DB K19 – 265E5A51 K35 – 699D6122 K51 – AB9423A7
K4 – C1BDCEEE K20 – E9B6C7AA K36 – FDE5380C K52 – FC93A039
K5 – F57COFA K21 – D62F105D K37– A4BEEA44 K53 – 655B59C3
K6 – 4787C62A K22 – 02441453 K38 – 4BDECFA9 K54 – 8F0CCC92
K7 – A8304613 K23 – D8A1E681 K39 – F6BB4B60 K55 – FFEFF47D
K8 – FD469501 K24 – E7D3FBC8 K40 – BEBFBC70 K56 – 85845DD1
K9 – 698098D8 K25 – 21E1CDE6 K41 – 289B7EC6 K57 – 6FA87E4F
K10 – 8B44F7AF K26 – C33707D6 K42 – EAA127FA K58 – FE2CE6E0
K11 – FFFF5BB1 K27 – F4D50D87 K43 – D4EF3085 K59 – A3014314
K12 – 895CD7BE K28 – 455A14ED K44 – 04881D05 K60 – 4E0811A1
K13 – 6B901122 K29 – A9E3E905 K45 – D9D4D039 K61 – F7537E82
K14 – FD987193 K30 – FCEFA3F8 K46 – E6DB99E5 K62 – BD3AF235
K15 – A679438E K31 – 676F02D9 K47 – 1FA27CF8 K63 – 2AD7D2BB
K16 – 49B40821 K32 – 8D2A4C8A K48 – C4AC5665 K64 – EB86D391 20
Round1 Round2 Round3 Round4
Message Digest (MD5)
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 G function
– 3rd for the H function
– 4th for the I function.
21
Message Digest (MD5)

F(B,C,D) = (B AND C) OR (NOT B AND D)


G(B,C,D) = (B AND C) OR (C AND NOT D)
H(B,C,D) = B XOR C XOR D
I(B,C,D) = C XOR (B OR NOT D)

22
Message Digest (MD5)

• Each round has 16 steps of the form:


b = b+((a+f(b,c,d)+M[i]+K[i])<<<s)
g(b,c,d) is a different nonlinear
function in each 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
• …
• M[15]  32bits

23
Message Digest (MD5)
• 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

F(B,C,D) = (B AND C) OR (NOT B AND D)


G(B,C,D) = (B AND C) OR (C AND NOT D)
H(B,C,D) = B XOR C XOR D
I(B,C,D) = C XOR (B OR NOT D)

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

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
Yfedcba98
Z100000000 (232)
(X + Y) mod Z
= (01234567 + fedcba98) mod 100000000
= ffffffff mod 100000000
= ffffffff 26
MD5 F, G, H and I functions

F(B, C, D) = (B∧C)∨(¬B∧D)
G(B, C, D) = (B∧D)∨(C∧¬D)
H(B, C, D) =B⊕C⊕D
I(B, C, D) = C⊕(B∨¬D)

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


F(B, C, D) = 88888888 OR 76543210
= fedcba98 M0 – 54686579
M1 – 20617265
M2 – 20646574
M3 – 65726D69
Modular Addition  ffffffff M4 – 6E697374
M5 – 69638000
M6 – 00000000
M7 – 00000000
(X + Y) mod Z M8 – 00000000
M9 – 00000000
X  M0 = 54686579 M10 – 00000000
Y ffffffff M11 – 00000000
M12 – 00000000
Z100000000 (232) M13 – 00000000
(X + Y) mod Z M14 – 00000000
M15 – 000000B0
= (54686579 + ffffffff) mod 100000000
= 154686578 27
K1 – D76AA478
MD5 F, G, H and I functions K2 – E8C7B756
K3 – 242070DB
K4 – C1BDCEEE
K5 – F57COFA
K6 – 4787C62A
F(B, C, D) = (B∧C)∨(¬B∧D) K7 – A8304613
K8 – FD469501
G(B, C, D) = (B∧D)∨(C∧¬D) K9 – 698098D8
H(B, C, D) =B⊕C⊕D K10 – 8B44F7AF
K11 – FFFF5BB1
I(B, C, D) = C⊕(B∨¬D) K12 – 895CD7BE
K13 – 6B901122
K14 – FD987193
K15 – A679438E
K16 – 49B40821
Round1

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


F(B, C, D) = 88888888 OR 76543210
= fedcba98

Modular Addition  154686578

(X + Y) mod Z
X  K0 = d76aa478
Y 154686578
Z100000000 (232)
(X + Y) mod Z
= (d76aa478 + 54686578) mod 100000000
= 2bd309f0 28
The values for K are is derived from the formula

K17 – F61E2562 K33 – FFFA3942


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

F(B, C, D) = (B∧C)∨(¬B∧D)
G(B, C, D) = (B∧D)∨(C∧¬D)
H(B, C, D) =B⊕C⊕D
I(B, C, D) = C⊕(B∨¬D)

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


F(B, C, D) = 88888888 OR 76543210
= fedcba98

Modular Addition  2bd309f0


0010 1011 1101 0011 0000 1001 1111 0000
Left bit shift

30
MD5 F, G, H and I functions

F(B, C, D) = (B∧C)∨(¬B∧D)
G(B, C, D) = (B∧D)∨(C∧¬D)
H(B, C, D) =B⊕C⊕D
I(B, C, D) = C⊕(B∨¬D)

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


F(B, C, D) = 88888888 OR 76543210
= fedcba98

Modular Addition  2bd309f0


0010 1011 1101 0011 0000 1001 1111 0000
Left bit shift

31
A – 01234567
2bd309f0 B – 89abcdef
C – fedcba98
D – 76543210
001 0101 1110 1001 1000 0100 1111 1000 0xxx xxxx
Shift 7 bits left
1110 1001 1000 0100 1111 1000 0001 0101
In hexa
e984f815
(X + Y) mod Z
X  B = 89abcdef
Y e984f815
Z100000000 (232)
(X + Y) mod Z
= (89abcdef + e984f895) mod 100000000
= 7330C604
First operation in Round1 is completed
A – 76543210
B – 7330c604 Similarly do other 63 operations and generate
C – 89abcdef the final Message Digest of 128 bits
D – fedcba98

You might also like