CSI3002
Module 4:
Hash Functions: MD5
Fall Semester 2023-24
Dr. Sunil Kumar
Outline
• Requirements for Hash Functions
• Security of Hash Functions
• Message Digest (MD5)
• Secure Hash Function (SHA)
• MAC, HMAC
Hash Functions
• condenses arbitrary message to fixed size
h = H(M)
• outputs should be evenly distributed and apparently
random.
• cryptographic hash function.
• usually assume that the hash function is public and not
keyed
• cf. MAC which is keyed
• hash used to detect changes to message
• can use in various ways with message
• most often to create a digital signature
Black Diagram of Cryptographic
Hash Function
Applications of cryptographic
hash functions
• Message Authentication
• When a hash function is used to provide message
authentication, the hash function value is often referred
to as a message digest.
• message authentication code (MAC), also known as a
keyed hash function.
• combination of hashing and encryption.
• Digital signature
• One-way password file
• pseudorandom number generator (PRNG)
• intrusion detection and virus detection
Use of a Hash Function for Message Authentication
Use of a Hash Function for Digital Signatures
Requirements for Hash Functions
MD5
Message Digest
• Can provide data integrity and non-repudation
• Used to verify the authentication of a message
• Idea: compute a hash on the message and send it
along with the message
• Receiver can apply the same hash function on the
message and see whether the result coincides with
the received hash
Message Digest
• MD5 algorithm was developed by Professor Ronald L. Rivest
in 1991. According to RFC 1321,
• “MD5 message-digest algorithm takes as input a message of
arbitrary length and produces as output a 128-bit
"fingerprint" or "message digest" of the input …
• The MD5 algorithm is intended for digital signature
applications, where a large file must be "compressed" in a
secure manner before being encrypted with a private
(secret) key under a public-key cryptosystem such as RSA.”
MD5 Overview
MD5
1. Pad message so its length is 448 mod 512
2. Append a 64-bit original length value to message
3. Initialise 4-word (128-bit) MD buffer (A,B,C,D)
4. Process message in 16-word (512-bit) blocks:
• Using 4 rounds of 16 bit operations on message block
& buffer
• Add output to buffer input to form new buffer value
5. Output hash value is the final buffer value
Padding
• Given original message M, add padding bits “10*”
such that resulting length is 64 bits less than a
multiple of 512 bits.
• Append (original length in bits mod 264),
represented in 64 bits to the padded message
• Final message is chopped 512 bits a block
MD5 Process
• As many stages as the number of 512-bit blocks in the
final padded message
• Digest: 4 32-bit words: MD=A|B|C|D
• Every message block contains 16 32-bit words:
m0|m1|m2…|m15
• Digest MD0 initialized to:
A=01234567,
B=89abcdef,
C=fedcba98,
D=76543210
• Every stage consists of 4 passes over the message block, each
modifying MD
• Each block 4 rounds, each round 16 steps
Processing of Block mi - 4 Passes
mi MDi
ABCD=gF(ABCD,mi,T[1..16])
A
B C D
ABCD=gG(ABCD,mi,T[17..32])
ABCD=gH(ABCD,mi,T[33..48])
ABCD=gI(ABCD,mi,T[49..64])
+ + + +
MD i+1
𝑎 = 𝑏 + ((𝑎 + 𝑔(𝑏, 𝑐, 𝑑) + 𝑀[𝑖] + 𝑇[𝑘]) <<< 𝑠)
Addition modulo 232 (0x100000000)
Keep last 8 Hex digit
𝐌[𝒊]
1: F(B, C, D) = (B∧C)∨(¬B∧D)
2: G(B, C, D) = (B∧D)∨(C∧¬D)
3: H(B, C, D) =B⊕C⊕D
4: I(B, C, D) = C⊕(B∨¬D)
Execution of 1. F(B, C, D) = (B∧C)∨(¬B∧D)
MD5 =(89ABCDEF ∧ FEDCBA98) ∨ (¬89abcdef ∧76543210)
= 88888888 ∨ 76543210 = fedcba98
2. (01234567 + fedcba98) = ffffffff
Input of 1st round ffffffff mod 232(100000000) keep last 8 hex digit
• a = 01 23 45 67 =ffffffff
• b = 89 AB CD EF 3. (54686579+ ffffffff) =154686578
• c = FE DC BA 98 154686578 mod 100000000 = 54686578 (keep last 8
hex digit)
• d = 76 54 32 10
4. (54686578+d76aa478) = 12BD309F0
• M[0] = 54686579
mod 100000000= 2bd309f0
• s=7
5. 2bd309f0 <<< 7
• t[1] = D7 6A A4 78
=e984f815
6. (89abcdef+ e984f815) =17330C604
17330C604 mod 100000000 =7330C604
[Link]
Execution of MD5
b = 7330c684
Input of 1st round Input of 2nd round
• a = 01 23 45 67 • a = 76543210
• b = 89 AB CD EF • b = 7330c684
• c = FE DC BA 98 • c = 89abcdef
• d = 76 54 32 10 • d = fedcba98
• M[0] = 54686579 • M[0] = 54686579
• s=7 • s = 12
• t[1] = D7 6A A4 78 • t[2] = E8 C7 B7 56
Performance
Key size/hash Extrapolated PRB
size(bits) Speed Optimized
(Kbytes/sec.) (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
Input of 2nd round
• a = 76543210
• b = 7330c684
• c = 89abcdef
• d = fedcba98
• M[0] = 54686579
• s = 12
• t[2] = E8 C7 B7 56
1. Calculate g function for all 4 rounds.
2. Calculate next buffer values (a,b,c,d).
Reference
• Cryptography and Network Security-Principles and
Practice, 8th Edition, by Stallings William, published
by Pearson, 2020
• Cryptography and Network Security, 3rd Edition, by
Behrouz A Forouzan and Depdeep Mukhopadhyay,
published by McGrawHill, 2015
• Cryptography and Network Security, 3rd edition, by
Atul Kahate, published by McGrawHill, 2017
• [Link]
security/md5-algorithm-with-examples/