You are on page 1of 29

Middle Technical University

Electrical Engineering Technical


College
Computer Engineering Techniques
Department

Presented by

Karrar Shakir Muttair


Email : karraralnomani123@gmail.com
Contents
➢ Hash Function
• Applications of Cryptographic Hash Functions.
• SHA-1 Algorithm.
• Steps of SHA-1 Algorithm.
• Example.

2
Hash Function
In cryptography, A hash function is simply an algorithm that takes a string of any length
and reduces it to a unique fixed-length string as shown in Figure 1.

Figure 1. Cryptographic Hash Function; h = H(M). 3


Applications of Cryptographic Hash Functions
➢ Message Authentication.
• Message authentication is a mechanism or service used to verify the integrity of a
message.
• Message authentication assures that data received are exactly as sent (i.e., there is no
modification, insertion, deletion, or replay) as shown in Figure 2.

Figure 2. Use of hash function to check data integrity. 4


Applications of Cryptographic Hash Functions
➢ Digital Signatures.
• Another important application, which is similar to the message authentication
application, is the digital signature.
• In the case of the digital signature, the hash value of a message is encrypted with a
user’s private key.

➢ Other Applications.
• Hash functions are commonly used to create a one-way password file.
• Hash functions can be used for intrusion detection and virus detection.

5
Hash Algorithms
Hashes are used to ensure data and message integrity, and password validity, and are the basis
of many other cryptographic systems.

Table 1. Comparison of Secure Hash Algorithm (SHA) Parameters.

6
𝐇𝟎 = 𝐇𝟏 = 𝐇𝟐 = 𝐇𝟑 = 𝐇𝟒 = 𝟑𝟐 𝐛𝐢𝐭𝐬
𝐇𝟎 𝐇𝟏 𝐇𝟐 𝐇𝟑 𝐇𝟒 𝐇𝟎 + 𝐇𝟏 + 𝐇𝟐 + 𝐇𝟑 + 𝐇𝟒 = 𝟏𝟔𝟎 𝐛𝐢𝐭𝐬
Message

A B C D E
512 bits 𝐅𝟏 , 𝐊 𝟏 , 𝐖𝐢 , 𝐢 = 𝟎 𝐭𝐨 𝟏𝟗 20 Rounds

A B C D E
𝐅𝟐 , 𝐊 𝟐 , 𝐖𝐢 , 𝐢 = 𝟐𝟎 𝐭𝐨 𝟑𝟗 20 Rounds

A B C D E
𝐅𝟑 , 𝐊 𝟑 , 𝐖𝐢 , 𝐢 = 𝟒𝟎 𝐭𝐨 𝟓𝟗 20 Rounds

A B C D E
𝐅𝟒 , 𝐊 𝟒 , 𝐖𝐢 , 𝐢 = 𝟔𝟎 𝐭𝐨 𝟕𝟗 20 Rounds
A B C D E

7 Figure 3. SHA-1 Processing of a Single 512-Bit Block. 𝐇𝟎 𝐇𝟏 𝐇𝟐 𝐇 𝟑 𝐇𝟒


𝐇𝟎 𝐇𝟏 𝐇𝟐 𝐇𝟑 𝐇𝟒

𝐀 𝐁 𝐂 𝐃 𝐄

𝐀𝐧𝐞𝐰 = (𝐀𝐨𝐥𝐝 Left Rotate 5) + 𝐅𝐢 +


𝐄𝐨𝐥𝐝 + 𝐊 𝐢 + W[i] 𝐅𝐢
𝐁𝐧𝐞𝐰 = 𝐀𝐨𝐥𝐝
Left Rotate 5
𝐂𝐧𝐞𝐰 = 𝐁𝐨𝐥𝐝 Left Rotate 30
𝐃𝐧𝐞𝐰 = 𝐂𝐨𝐥𝐝 𝐖𝐢
Left Rotate 30
𝐄𝐧𝐞𝐰 = 𝐃𝐨𝐥𝐝
𝐊𝐢

Figure 3. Elementary SHA-1 Operation (Single Round). 𝐀 𝐁 𝐂 𝐃 𝐄 8


ASCII Table

9
Steps of SHA-1 Algorithm

Step 1: Initialize Variables.


𝐇𝟎 𝐨𝐥𝐝 = 67452301 𝐇𝟎 𝐨𝐥𝐝 = 01100111010001010010001100000001
𝐇𝟏 𝐨𝐥𝐝 = EFCDAB89 𝐇𝟏 𝐨𝐥𝐝 = 11101111110011011010101110001001
𝐇𝟐 𝐨𝐥𝐝 = 98BADCFE 𝐇𝟐 𝐨𝐥𝐝 = 10011000101110101101110011111110
𝐇𝟑 𝐨𝐥𝐝 = 10325476 𝐇𝟑 𝐨𝐥𝐝 = 00010000001100100101010001110110
𝐇𝟒 𝐨𝐥𝐝 = C3D2E1F0 𝐇𝟒 𝐨𝐥𝐝 = 11000011110100101110000111110000

10
Steps of SHA-1 Algorithm
Step 2: Pick a Message.
For example, message: A Test

Step 3: Put a space between the characters.

A T e s t

Step 4: Convert characters to ASCII codes.

A Test

65 32 84 101 115 116


11
Steps of SHA-1 Algorithm
Step 5: Convert numbers into binary.
01000001 00100000 01010100 01100101 01110011 01110100

Step 6: Put the numbers together.


010000010010000001010100011001010111001101110100

Step 7: Add '1' to the End.


0100000100100000010101000110010101110011011101001

12
Steps of SHA-1 Algorithm
Step 8: Append a "0" at the end until you reach 448 bits.

01000001001000000101010001100101011100110111010010000000
0000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000
0000000

13
Steps of SHA-1 Algorithm
Step 9: Append the original message length.

010000010010000001010100011001010111001101110100

48 bits

110000

0000000000000000000000000000000000000000000000000000000000110000
14
Steps of SHA-1 Algorithm
Step 10: Put the numbers together.
010000010010000001010100011001010111001101110100100000000
00000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000110000

15
Steps of SHA-1 Algorithm
Step 11: Divide the 512 bits into 16 words, each word containing 32 bits.
𝐖𝟎 : 01000001001000000101010001100101
𝐖𝟏 : 01110011011101001000000000000000
𝐖𝟐 : 00000000000000000000000000000000
𝐖𝟑 : 00000000000000000000000000000000
𝐖𝟒 : 00000000000000000000000000000000
𝐖𝟓 : 00000000000000000000000000000000
𝐖𝟔 : 00000000000000000000000000000000
𝐖𝟕 : 00000000000000000000000000000000
𝐖𝟖 : 00000000000000000000000000000000
𝐖𝟗 : 00000000000000000000000000000000
𝐖𝟏𝟎 : 00000000000000000000000000000000
𝐖𝟏𝟏 : 00000000000000000000000000000000
𝐖𝟏𝟐 : 00000000000000000000000000000000
𝐖𝟏𝟑 : 00000000000000000000000000000000
𝐖𝟏𝟒 : 00000000000000000000000000000000
𝐖𝟏𝟓 : 00000000000000000000000000110000 16
Steps of SHA-1 Algorithm
Step 12: Extend into 80 Words.
𝐅𝐨𝐫 𝐢 𝐟𝐫𝐨𝐦 𝟏𝟔 𝐭𝐨 𝟕𝟗
𝐖[𝐢] = (𝐖[𝐢 − 𝟑] 𝐗𝐎𝐑 𝐖[𝐢 − 𝟖] 𝐗𝐎𝐑 𝐖[𝐢 − 𝟏𝟒] 𝐗𝐎𝐑 𝐖[𝐢 − 𝟏𝟔]) 𝐋𝐞𝐟𝐭 𝐑𝐨𝐭𝐚𝐭𝐞 𝟏
End
W[13]: 00000000000000000000000000000000
W[8]: 00000000000000000000000000000000
W[13] XOR W[8] 00000000000000000000000000000000
Now we XOR that with word number W[ i -14 ]:
W[2]: 00000000000000000000000000000000
(W[13] XOR W[ 8]) XOR W[2] 00000000000000000000000000000000
Now we XOR that with word number W[ i -16 ]
W[0]: 01000001001000000101010001100101
((W[13] XOR W[8]) XOR W[2]) XOR W[0] 01000001001000000101010001100101
Left Rotate 1: 10000010010000001010100011001010

𝐖𝟏𝟔 : 10000010010000001010100011001010
17
Steps of SHA-1 Algorithm
𝐖𝟒𝟎 : 01010010101011011000110011010110
𝐖𝟎 : 01000001001000000101010001100101
𝐖𝟒𝟏 : 11011110010010000001111011100001
𝐖𝟏 : 01110011011101001000000000000000
𝐖𝟒𝟐 : 01101000010000010001110000010001
𝐖𝟐 : 00000000000000000000000000000000
𝐖𝟒𝟑 : 00101000111100011001111110101011
𝐖𝟑 : 00000000000000000000000000000000
Step 12: Extend into 80 words. 𝐖𝟒 : 00000000000000000000000000000000
𝐖𝟓 : 00000000000000000000000000000000
𝐖𝟒𝟒 : 00000011001111011000100100010111
𝐖𝟒𝟓 : 11111100110001001100000110100110
𝐖𝟒𝟔 : 00010000101001100111010111011101
𝐖𝟔 : 00000000000000000000000000000000
𝐖𝟒𝟕 : 10100001000110010101101011001001
𝐖𝟕 : 00000000000000000000000000000000
𝐖𝟒𝟖 : 11011101110000010001100111100111
𝐖𝟖 : 00000000000000000000000000000000
𝐖𝟒𝟗 : 01100001101110100100110110100110
𝐖𝟗 : 00000000000000000000000000000000
𝐖𝟓𝟎 : 01101000010101000110010111110110
𝐖𝟏𝟎 : 00000000000000000000000000000000
𝐖𝟓𝟏 : 00101110100100110100011011110111
𝐖𝟏𝟏 : 00000000000000000000000000000000
𝐖𝟓𝟐 : 11010010101101011000101100101010
𝐖𝟏𝟐 : 00000000000000000000000000000000
𝐖𝟓𝟑 : 11010011110010011110001000011010
𝐖𝟏𝟑 : 00000000000000000000000000000000
𝐖𝟓𝟒 : 00010100001110111111001110110110
𝐖𝟏𝟒 : 00000000000000000000000000000000
𝐖𝟓𝟓 : 00110101010110011111110100001011
𝐖𝟏𝟓 : 00000000000000000000000000110000
𝐖𝟓𝟔 : 01101001110010001101011001110100
𝐖𝟏𝟔 : 10000010010000001010100011001010
𝐖𝟓𝟕 : 00000110011100000111111010110101
𝐖𝟏𝟕 : 11100110111010010000000000000000
𝐖𝟓𝟖 : 01101100111000100001101111110110
𝐖𝟏𝟖 : 00000000000000000000000001100000
𝐖𝟓𝟗 : 00100110110111011001110100011101
𝐖𝟏𝟗 : 00000100100000010101000110010101
𝐖𝟔𝟎 : 10001110101111000001001010101011
𝐖𝟐𝟎 : 11001101110100100000000000000001
𝐖𝟔𝟏 : 11000101111011001100010100000111
𝐖𝟐𝟏 : 00000000000000000000000011000000
𝐖𝟔𝟐 : 11111111000000100000010100100011
𝐖𝟐𝟐 : 00001001000000101010001100101010
𝐖𝟔𝟑 : 11110110100011011111000110011110
𝐖𝟐𝟑 : 10011011101001000000000001100011
𝐖𝟔𝟒 : 00110011011000101101111011000100
𝐖𝟐𝟒 : 00000100100000010101000000010101
𝐖𝟔𝟓 : 01101100101101101110000110001111
𝐖𝟐𝟓 : 11011111110101110100011001010101
𝐖𝟔𝟔 : 01000001000111000000100101101000
𝐖𝟐𝟔 : 00110111010010000000000000000111
𝐖𝟔𝟕 : 11010001110010111100111001101001
𝐖𝟐𝟕 : 00000000000000000000001100000000
𝐖𝟔𝟖 : 01001001000010010001011101110000
𝐖𝟐𝟖 : 00100100000010101000110010101000
𝐖𝟔𝟗 : 11000100110000011010011011111100
𝐖𝟐𝟗 : 01101110100100000000000111101110
𝐖𝟕𝟎 : 10100110011101011101110100010000
𝐖𝟑𝟎 : 00010110100001000001000111000001
𝐖𝟕𝟏 : 00011001010110101100101010100001
𝐖𝟑𝟏 : 10110010100011110001100111110110
𝐖𝟕𝟐 : 11100101000100110110101101110101
𝐖𝟑𝟐 : 11010000101000111111001010100011
𝐖𝟕𝟑 : 11010100110111011011111001101111
𝐖𝟑𝟑 : 01010110011101100000110000000010
𝐖𝟕𝟒 : 01110100001100011001010100101001
𝐖𝟑𝟒 : 10010000001010100011001100100000
𝐖𝟕𝟓 : 10101111110100111111101000001101
𝐖𝟑𝟓 : 10101000010001010100000111101101
𝐖𝟕𝟔 : 11011000110101010111110100101111
𝐖𝟑𝟔 : 01101101010110000100011100000011
𝐖𝟕𝟕 : 00000111001000100000111010011001
𝐖𝟑𝟕 : 11001010001111000110010011011010
𝐖𝟕𝟖 : 10001011100011011111100111110101
𝐖𝟑𝟖 : 01100110100001010100011000100111
𝐖𝟑𝟗 : 00110111010010000011000110000111
𝐖𝟕𝟗 : 10110111011010010100111100111110 18
Steps of SHA-1 Algorithm
Step 13: Set the letters A to E equal to the variables 𝐇𝟎 to 𝐇𝟒 .
A = 𝐇𝟎

B = 𝐇𝟏

C = 𝐇𝟐

D = 𝐇𝟑

E = 𝐇𝟒
Step 14: Depending on what number word is being input, one of four functions will be
run on it.
WORDS 𝟎 − 𝟏𝟗 GO TO FUNCTION 1
WORDS 𝟐𝟎 − 𝟑9 GO TO FUNCTION 2
WORDS 𝟒𝟎 − 𝟓𝟗 GO TO FUNCTION 3
WORDS 𝟔𝟎 − 𝟕9 GO TO FUNCTION 4 19
Steps of SHA-1 Algorithm
Step 15: Function 1 is to set the variable (𝐅𝟏 ) equal to:
𝐅𝟏 = (𝐁 𝐀𝐍𝐃 𝐂) 𝐎𝐑 (!B 𝐀𝐍𝐃 𝐃)
B: 11101111110011011010101110001001
C: 10011000101110101101110011111110
B AND C 10001000100010001000100010001000
!B: 00010000001100100101010001110110
D: 00010000001100100101010001110110
!B AND D 00010000001100100101010001110110
B AND C: 10001000100010001000100010001000
!B AND D: 00010000001100100101010001110110
𝐅𝟏 = (𝐁 𝐀𝐍𝐃 𝐂) 𝐎𝐑 (!B 𝐀𝐍𝐃 𝐃)
𝐅𝟏 : 10011000101110101101110011111110
Key '𝐊 𝟏 ' for Function 1 equal to: 01011010100000100111100110011001 20
Steps of SHA-1 Algorithm
Step 16: Find the new (A, B, C, D, and E) values for Words 𝟎 −𝟏𝟗 based
on the following equations:

𝐀𝐧𝐞𝐰 = (𝐀𝐨𝐥𝐝 Left Rotate 5) + 𝐅𝟏 + 𝐄𝐨𝐥𝐝 + 𝐊 𝟏 + W[i]


𝐁𝐧𝐞𝐰 = 𝐀𝐨𝐥𝐝
𝐂𝐧𝐞𝐰 = 𝐁𝐨𝐥𝐝 Left Rotate 30
𝐃𝐧𝐞𝐰 = 𝐂𝐨𝐥𝐝
𝐄𝐧𝐞𝐰 = 𝐃𝐨𝐥𝐝

21
Steps of SHA-1 Algorithm
Step 17: Function 2 is to set the variable (𝐅𝟐 ) equal to:
𝐅𝟐 = B XOR C XOR D
B: 11011100100010001001111001110101
C: 10110101000101000100100011110000
B XOR C 01101001100111001101011010000101
D: 01001110101011001011101010110111
𝐅𝟐 = B XOR C XOR D
𝐅𝟐 : 00100111001100000110110000110010

Key '𝐊 𝟐 ' for Function 2 equal to: 01101110110110011110101110100001

22
Steps of SHA-1 Algorithm
Step 18: Find the new (A, B, C, D, and E) values for Words 𝟐𝟎 − 𝟑9 based
on the following equations:

𝐀𝐧𝐞𝐰 = (𝐀𝐨𝐥𝐝 Left Rotate 5) + 𝐅𝟐 + 𝐄𝐨𝐥𝐝 + 𝐊 𝟐 + W[i]


𝐁𝐧𝐞𝐰 = 𝐀𝐨𝐥𝐝
𝐂𝐧𝐞𝐰 = 𝐁𝐨𝐥𝐝 Left Rotate 30
𝐃𝐧𝐞𝐰 = 𝐂𝐨𝐥𝐝
𝐄𝐧𝐞𝐰 = 𝐃𝐨𝐥𝐝

23
Steps of SHA-1 Algorithm
Step 19: Function 3 is to set the variable (𝐅𝟑 ) equal to:
𝐅𝟑 = (B AND C) OR (B AND D) OR (C AND D)
B: 01000100110000000111111001110111
C: 00011010100110110011101010111011
B AND C 00000000100000000011101000110011
B: 01000100110000000111111001110111
D: 01010011011001010110101011100100
B AND D 01000000010000000110101001100100
C: 00011010100110110011101010111011
D: 01010011011001010110101011100100
C AND D 00010010000000010010101010100000
(B AND C) OR (B AND D) 01000000110000000111101001110111
𝐅𝟑 = (B AND C) OR (B AND D) OR (C AND D): 01010010110000010111101011110111
Key '𝐊 𝟑 ' for Function 3 equal to: 10001111000110111011110011011100 24
Steps of SHA-1 Algorithm
Step 20: Find the new (A, B, C, D, and E) values for Words 𝟒𝟎 − 𝟓𝟗 based
on the following equations:

𝐀𝐧𝐞𝐰 = (𝐀𝐨𝐥𝐝 Left Rotate 5) + 𝐅𝟑 + 𝐄𝐨𝐥𝐝 + 𝐊 𝟑 + W[i]


𝐁𝐧𝐞𝐰 = 𝐀𝐨𝐥𝐝
𝐂𝐧𝐞𝐰 = 𝐁𝐨𝐥𝐝 Left Rotate 30
𝐃𝐧𝐞𝐰 = 𝐂𝐨𝐥𝐝
𝐄𝐧𝐞𝐰 = 𝐃𝐨𝐥𝐝

25
Steps of SHA-1 Algorithm
Step 21: Function 4 is exactly same as Function 2 except that we will set
'𝐊 𝟒 ' equal to 11001010011000101100000111010110

Step 22: Find the new (A, B, C, D, and E) values for Words 𝟔𝟎 − 𝟕9 based
on the following equations:

𝐀𝐧𝐞𝐰 = (𝐀𝐨𝐥𝐝 Left Rotate 5) + 𝐅𝟒 + 𝐄𝐨𝐥𝐝 + 𝐊 𝟒 + W[i]


𝐁𝐧𝐞𝐰 = 𝐀𝐨𝐥𝐝
𝐂𝐧𝐞𝐰 = 𝐁𝐨𝐥𝐝 Left Rotate 30
𝐃𝐧𝐞𝐰 = 𝐂𝐨𝐥𝐝
𝐄𝐧𝐞𝐰 = 𝐃𝐨𝐥𝐝

26
Steps of SHA-1 Algorithm
Step 23: The end, once the main steps have finished there is very little left to do.
𝐇𝟎 𝐧𝐞𝐰 = 𝐇𝟎 𝐨𝐥𝐝 + 𝐀 𝐧𝐞𝐰 𝐇𝟎 𝐧𝐞𝐰 = 10001111000011000000100001010101
𝐇𝟏 𝐧𝐞𝐰 = 𝐇𝟏 𝐨𝐥𝐝 + 𝐁𝐧𝐞𝐰 𝐇𝟏 𝐧𝐞𝐰 = 10010001010101100011001111100100
𝐇𝟐 𝐧𝐞𝐰 = 𝐇𝟐 𝐨𝐥𝐝 + 𝐂𝐧𝐞𝐰 𝐇𝟐 𝐧𝐞𝐰 = 10100111110111100001100101000110
𝐇𝟑 𝐧𝐞𝐰 = 𝐇𝟑 𝐨𝐥𝐝 + 𝐃𝐧𝐞𝐰 𝐇𝟑 𝐧𝐞𝐰 = 10001011001110000111010011001000
𝐇𝟒 𝐧𝐞𝐰 = 𝐇𝟒 𝐨𝐥𝐝 + 𝐄𝐧𝐞𝐰 𝐇𝟒 = 10010000000111011111000001000011
𝐧𝐞𝐰

Step 24: Finally, the variables are converted into Hexadecimal and joined together.
𝐇𝟎 𝐧𝐞𝐰 𝐇𝟏 𝐧𝐞𝐰 𝐇𝟐 𝐧𝐞𝐰 𝐇𝟑 𝐧𝐞𝐰 𝐇𝟒 𝐧𝐞𝐰
8F0C0855 915633E4 A7DE1946 8B3874C8 901DF043
8F0C0855915633E4A7DE19468B3874C8901DF043
27
Reference
“Cryptography and Network Security Principles”, By Marcia J. Horton,
William Stallings, 7th edition, 2017.

28

You might also like