Hash Functions and Message Integrity
Hash Functions and Message Integrity
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 1 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 2 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Collision Resistance
Second Pre-Image Resistance
• This property means it should be hard to
• This property means given an find two different inputs of any length
input and its hash, it should be that result in the same hash. This
hard to find a different input property is also referred to as collision
with the same hash. free hash function.
• In other words, if a hash • In other words, for a hash function h, it is
function h for an input x hard to find any two different inputs x
produces hash value h(x), then and y such that h(x) = h(y).
it should be difficult to find any • Since, hash function is compressing
other input value y such that function with fixed hash length, it is
h(y) = h(x). impossible for a hash function not to have
• This property of hash function collisions.
protects against an attacker • This property makes it very difficult for an
who has an input value and its attacker to find two input values with the
hash, and wants to substitute same hash.
different value as legitimate • Also, if a hash function is collision-
value in place of original input resistant then it is second pre-image
value. resistant.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Weak Hash
Strong
Function
Hash Function
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 3 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 4 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 5 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Mod
T[K] 232
Mod
232
B=A
C=B
D=C
A=D
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 6 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 7 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Example Example
• Do we need padding if the length of the original message is already a • Do we need padding if the length of the original message is already a
multiple of 1024 bits? multiple of 1024 bits?
Solution
• Yes we do, because we need to add the length field. So padding is
needed to make the new block a multiple of 1024 bits.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 8 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
ShRn(x)
+ Addition modulo 264
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Solution
• Each word in the range W16 to W79 is made from four previously-
made words.
• W60 is made as
+ + + Generated from first eight prime numbers (2,3,5,7,11,13,17 and 19)
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 9 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Conditional Function
Rotate Functions
Rotate (A) = ROTR28(A) XOR ROTR34(A) XOR ROTR39(A)
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 10 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Example Analysis
• We apply the Conditional function on E, F, and G buffers. If the leftmost • With a message digest of 512 bits, SHA-512 expected to be resistant
hexadecimal digits of these buffers are 0x9, 0xA, and 0xF respectively, what to all attacks, including collision attacks.
is the leftmost digit of the result?
• More research is required to confirm this.
Solution:
• The digits in binary are 1001, 1010, and 1111.
a. The first bits are 1, 1, and 1. The result is F1, which is 1.
b. The second bits are 0, 0, and 1. The result is G2, which is 1.
c. The third bits are 0, 1, and 1. The result is G3, which is 1.
d. The fourth bits are 1, 0, and 1. The result is F4, which is 0.
• The result is 1110, or 0xE in hexadecimal.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 11 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Problem Homework
• Using Word expansion of SHA – 512, find out the word W17 using the • Find the result of conditional (E,F,G) for the given data.
given data. • E= 51 0E 52 7F AD E6 82 D1
• W1 – 1111 • F= 9B 05 68 8C 2B 3E 6C 1F
• W2 – 2222 • G= 1F 83 D9 AB FB 41 BD 6B
• W10 – 3333 • Ans: 1F 85 C9 8C 7B 27 3D 3B
• W15 – 4444 • Find the result of majority (A,B,C) for the given data.
• Solution: • A= 6A 09 E6 67 F3 BC C9 08
• RotShift 1-8-7 (W2) = 3377 • B= BB 67 AE 85 84 CA A7 3B
• RotShift 19-61-6 (W15) =ABBB • C= 3C 6E F3 72 FE 94 F8 2B
• W17 = 2376 • Ans: 3A 6F E6 67 F6 9C E9 2B
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 12 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
• The difference between MDC and MAC is that, the second (MAC)
includes a secret (key) between the transmitter and the receiver.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 13 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
• We can combine the prefix and postfix MAC, with the same key or
two different keys
Prepared by: [Link].N.G., Asst Prof Senior, Dept of Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore. Analytics, SCOPE, VIT, Vellore.
K = b → Do nothing
K < b → Append 0 bits to the left of K
so that K=b
Hashed MAC (HMAC) K > b → Hash k to reduce it to length b Digital Signature
• NIST has issued a standard (FIPS198) • Conventional Signature
for a nested MAC which is referred • A person signs a document to show that the document was created by that
to as HMAC (hashed MAC). person or the document is approved by that person.
• The signature is a proof to the recipient that the document comes from the
b- Message block size correct entity.
n- size of Message Digest • Digital Signature
----------------------------------------------- • Alice sends a message to Bob.
ipad – 00110110 – 0x36 • Bob needs to check the authenticity of the message. i.e) the message comes
opad - 01011100 – 0x5C from Alice and not Eve.
Repeat ipad and opad b/8 times • So, Bob asks Alice to electronically sign the message.
• This electronic signature is called as digital signature.
Prepared by: [Link].N.G., Asst Prof Senior, Dept of
Analytics, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 14 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 15 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 16 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 17 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
5)Alice’s public key is (e1, e2, p, q); her private key is (d).
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 18 of 19
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore.
Prepared by: [Link].N.G., Asst Prof Senior, SCOPE, VIT, Vellore. Page 19 of 19