Lecture - 10 Cryptographic Hash Functions
Lecture - 10 Cryptographic Hash Functions
Cryptographic Hash
Functions
MACs, Digital Signatures, Hash Functions and Digital
Certificates
Message: M
H: Hash
Function
Message Digest D
D = H(M)
1
22‐Jul‐20
2
22‐Jul‐20
• Confidentiality
• Integrity
• Non‐repudiation
3
22‐Jul‐20
Solutions Offered
Physical World Electronic World
+ =
Encryption
+ =
Decryption
4
22‐Jul‐20
Secret‐Key Problem?
• All keys need to be
replaced, if one key is
compromised.
• Not practical for the
Internet environment.
• On the other hand,
the encryption speed
is fast.
• Suitable to encrypt
your personal data.
Public‐Private Encryption
Public key
Public key stored in the directory
Private key
Public Key
Private key
5
22‐Jul‐20
Message Encryption
(User A sends message to User B)
Encrypted
Text
Text
Encryption
User A
User A User B
Encrypted Encrypted
Text Text
Insecure Channel
6
22‐Jul‐20
User B
User B’s
Private key
Decryption
Original Text
Public
Crypto Engine
Original Crypto Engine
Document
Signed
Document
7
22‐Jul‐20
Digital Signature
• Digital signature can be used in all electronic
communications
• Web, e‐mail, e‐commerce
• It is an electronic stamp or seal that append to the
document.
• Ensure the document being unchanged during
transmission.
15
User B received
the document with
Verify the signature signature attached
by A’s public key stored
at the directory
User B
8
22‐Jul‐20
Message Message
Private
Encryption Decryption
Key
18
9
22‐Jul‐20
19
Hash Functions
• A hash function H accepts a variable‐length block of
data M as input and produces a fixed‐size hash value
• h = H(M)
• Principal object is data integrity
• Cryptographic hash function
• An algorithm for which it is computationally infeasible to find
either:
(a) a data object that maps to a pre‐specified hash result (the one‐
way property)
(b) two data objects that map to the same hash result
(the collision‐free property)
10
22‐Jul‐20
11
22‐Jul‐20
Message authentication
• A mechanism or service used to verify the integrity
of a message.
• Message authentication assures that data received
are exactly as sent.
Source A Destination B
H
M || E D M
Compare
K K
E(K, [M || H(M)])
H
H(M)
(a)
H
M || M
K K Compare
H E D
(b) E(K, H(M))
M || M || H
S
Compare
S || H H(M || S)
(c)
M || E D M || H
S
Compare
K K
E(K, [M || H(M || S)])
S || H
(d) H(M || S)
12
22‐Jul‐20
M || E
H K E(K,M||H(M))
H
D M
Compare
H(M)
K
Destination
H
M || M
K K Compare
H E D
E(K,H(M))
13
22‐Jul‐20
S || H
M || M
Compare
S || H H(M||S)
K
S || H E(KM||H(M||S
))
S || H
D M
Compare
K
H(M||S) Destination
14
22‐Jul‐20
Takes as input a secret key and a data block and produces a hash
value (MAC) which is associated with the protected message
• If the integrity of the message needs to be checked, the MAC
function can be applied to the message and the result compared
with the associated MAC value
• An attacker who alters the message will be unable to alter the
associated MAC value without knowledge of the secret key
Message
Authentication Using
Plain Encryption
30
15
22‐Jul‐20
31
Microsoft Word
32
Document
16
22‐Jul‐20
DESMAC or DAA
Use CBC
O1=EK (D1)
O2=EK (D2 ⊕ O1)
O3=EK (D3 ⊕ O2)
.
.
.
ON=EK (DN ⊕ ON-1)
33
Encryption
Message Message Message
Algorithm
MAC
Encryption
K MAC
Algorithm
34
17
22‐Jul‐20
Digital Signature
• Operation is similar to that of the MAC
• The hash value of a message is encrypted with a
user’s private key
• Anyone who knows the user’s public key can verify
the integrity of the message
• An attacker who wishes to alter the message would
need to know the user’s private key
• Implications of digital signatures go beyond just
message authentication
18
22‐Jul‐20
Source A Destination B
H
M || M
H E D
(a) E(PRa, H(M))
H
M || E D M
PRa PUa Compare
K K
E(K, [M || E(PRa, H(M))])
H E D
E(PRa, H(M))
(b)
Source Destination
H
M || M
PRa PUa Compare
H E D
E(PRa,H(M))
19
22‐Jul‐20
H
D M
PUa Compare
K D
E(PRa,H(M))
Destination
20
22‐Jul‐20
Two
Simple
Hash Functions
21
22‐Jul‐20
44
22
22‐Jul‐20
45
• x is the preimage of h
for a hash value h = • Occurs if we have x ≠
H(x) y and H(x) = H(y)
• Is a data block whose • Because we are using
hash function, using
the function H, is h hash functions for
data integrity,
• Because H is a many‐
to‐one mapping, for collisions are clearly
any given hash value h, undesirable
there will in general be
multiple preimages
23
22‐Jul‐20
Second
preimage resistant
Preimage Collision
resistant resistant
24
22‐Jul‐20
25
22‐Jul‐20
A Letter
in 238
Variation
(Letter is located on page 330 in textbook)
26
22‐Jul‐20
Y0 Y1 YL–1
b b b
n
IV = n f n f n n f CVL
CV0 CV1 CVL–1
54
27
22‐Jul‐20
Message‐Digest How to
input Message
56
28
22‐Jul‐20
Rfc1321.txt
57
MD5 Box
512-bit message chunks (16 words)
Initial F: (xy)(~x z)
128-bit vector G:(x z) (y ~ z)
H:xy z
I: y(x ~z)
+: binary sum
xy: x left rotate y bits
128-bit result 58
29
22‐Jul‐20
MD5 Steps
• The following five steps are performed to compute
the message digest of the message.
• Step 1. Append Padding Bits
• Step 2. Append Length
• Step 3. Initialize MD Buffer
• Step 4. Process Message in 16‐Word Blocks
• Step 5. Output
59
60
30
22‐Jul‐20
MD5: Padding
1 2 3 4
input Message
Initial Value
MD5 Transformation block by block
61
62
31
22‐Jul‐20
64
32
22‐Jul‐20
Step 4. Continued(4
Rounds)
2(i) = (1 + 5i)mod 16
3(i) = (5 + 3i)mod 16
4(i) = 7i mod 16
65
66
33
22‐Jul‐20
67
Step 4. Continued
68
34
22‐Jul‐20
Step 4.
Continued
69
70
35
22‐Jul‐20
Step 5. Output
• The message digest produced as output is A, B, C,
D.
• That is, we begin with the low‐order byte of A, and
end with the high‐order byte of D.
71
36
22‐Jul‐20
N 1024 bits
128 bits
L bits
Message 1000000 . . . 0 L
F F F
+ + +
IV = H0 H1 H2 HN
hash code
512 bits 512 bits 512 bits
37
22‐Jul‐20
Mi Hi–1
message
schedule 64
a b c d e f g h
W0 K0
Round 0
a b c d e f g h
Wt Kt
Round t
a b c d e f g h
W79 K79
Round 79
+ + + + + + + +
Hi
SHA‐512 bf597fc7beef0ee4
c6e00bf33da88fc2
142929670a0e6e70
d5a79147930aa725 06ca6351e003826f
Constants 27b70a8546d22ffc
53380d139d95b3df
650a73548baf63de
92722c851482353b
2e1b21385c26c926
766a0abb3c77b2a8
4d2c6dfc5ac42aed
81c2c92e47edaee6
38
22‐Jul‐20
a b c d e f g h
Maj Ch +
+
+ + Wt
+ + Kt
a b c d e f g h
512 bits
1024 bits W0 W1 W9 W14 Wt–16 Wt–15 Wt–7 Wt–2 W63 W65 W71 W76
Mi
0 1 0 1 0 1
+ + +
64 bits
39
22‐Jul‐20
The padded message consists blocks M1, M2, … MN. Each message block Mi consists of 16 64-
bit words Mi,0, Mi,1 … Mi,15. All addition is performed modulo 264.
for i = 1 to N
1. Prepare the message schedule W:
for t = 0 to 15
Wt = Mi,t
for t = 16 to 79
Wt 1512 Wt2 Wt7 0512 Wt15 Wt16
2. Initialize the working variables
a = Hi–1,0 e = Hi–1,4
b = Hi–1,1 f = Hi–1,5
c = Hi–1,2 g = Hi–1,6
d = Hi–1,3 h = Hi–1,7
3. Perform the main hash computation
for t = 0 to 79
T1 = h + Ch(e, f, g) + e + W + K
512
1 t t
T2 = 0 512
a + Maj(a, b, c)
h = g
g = f
f = e
e = d + T1
d = c
c = b
b = a
a = T1 + T2
4. Compute the intermediate hash value
Hi,0 = a + Hi–1,0 Hi,4 = e + Hi–1,4
Hi,1 = b + Hi–1,1 Hi,5 = f + Hi–1,5
Hi,2 = c + Hi–1,2 Hi,6 = g + Hi–1,6
Hi,3 = d + Hi–1,3 Hi,7 = h + Hi–1,7
return {HN,0 || HN,1 || HN,2 || HN,3 || HN,4 || HN,5 || HN,6 || HN,7}
SHA‐3
SHA‐1 has not yet been "broken”
• No one has demonstrated a technique for
producing collisions in a practical amount
of time
• Considered to be insecure and has been
phased out for SHA‐2
40
22‐Jul‐20
k r bits
n bits
message pad
P0 P1 Pk–1
(a) Input
l bits
r bits r bits r bits
Z0 Z1
Zj–1
(b) Output
41
22‐Jul‐20
b b
r c r c
r c
0 0
r c r
c
P0 0 Z0
f f
P1 0c Z1
c
(b) Squeezing phase
P2 0
c
Pk–1 0
SHA‐3 Parameters
Message 224 256 384 512
Digest Size
Message Size no maximum no maximum no maximum no maximum
Block Size 1152 1088 832 576
(bitrate r)
Word Size 64 64 64 64
Number of 24 24 24 24
Rounds
Capacity c 448 512 768 1024
Collision 2112 2128 2192 2256
resistance
Second 2224 2256 2384 2512
preimage
resistance
Note:All sizes and security levels are measured in bits.
42
22‐Jul‐20
theta step
SHA‐3
Round 0
pi π step
Function f
theta step
pi π step
chi step
43
22‐Jul‐20
44
22‐Jul‐20
45
22‐Jul‐20
Summary
• Summarize the • Understand the
applications of differences among
preimage resistant,
cryptographic hash second preimage
functions resistant, and
collision resistant
• Explain why a hash properties
function used for • Present an overview
message of the basic structure
authentication needs of cryptographic hash
to be secured functions
• Describe how
• Understand the cipherblock chaining
operation of SHA‐512 can be used to
construct a hash
function
46