SHA By Matthew Ng Operations that SHA 1
SHA By: Matthew Ng
Operations that SHA 1 can perform �AND, XOR, Complement, Circular Left shift, and Addition Modulo �Circular Left Shift is done with s positions (0 ≤ s ≤ 31) – Denoted by ROTLs �Addition Modulo is 2 32
SHA-1 -Pad � This is pads the input. � The binary representation of |x| is l and it is at most 64 bits � If |l| < 64 bits then it is padded from the left with zeros to make 64 bits. � In the construction of y – one is appended to x and then concatenated with enough zeros so the length is congruent to 448 modulo 512. � A concatenation 64 bits that contain binary representation of the original length of x. � Divide the string by 512 and create a concatenation of n blocks each of them being 512 bits. � y = M 1 || M 2 || … || Mn
�SHA-1 -pad (x) : � D = (447 - |x|) Mod 512 � L = binary of |x| � y = x || 1 || 0 d || 1 � |x| ≤ 264 - 1 where |l| = 64
SHA-1 Algorithm (one round) • ABCDE are 32 -bit words in the state • F is a non-linear function that varies • <<<n is a left bit rotation by n places (n varies for each operation) • Wt is the expanded message word of round t • Kt is the round constant of round t • Boxes addition modulo 232
Let’s look at function f �The function is based on what round it is on. �If the round is between 0 and 19 � F(B, C, D) : (B ∧ C) ∨ ((~B) ∧ D) �If the round is between 20 and 39 � F(B, C, D): (B XOR C XOR D) �If the round is between 40 to 59 � F(B, C, D): (B ∧ C) ∨ (B ∧ D) ∨ (C ∧ D) �If the round is between 60 to 79 � F(B, C, D): (B XOR C XOR D)
Keys �The keys also depend on what the round is �When the round is between 0 to 19 � Kt = 5 A 827999 �When the round is between 20 to 39 � Kt = 6 ED 9 EBA 1 �When the round is between 40 to 59 � Kt = 8 F 1 BBCDC �When the round is between 60 to 79 � Kt = CA 62 C 1 D 6
Algorithm y = SHA-1 -Pad(x) //y = M 1 || M 2 ||. . || Mn //Initialize Variables H 0 = 67452301 H 1 = EFCDAB 89 H 2 = 98 BADCFE H 3 = 10325476 H 4 = CSD 2 E 1 F 0 For i = 1 to n Mi = W 0 || W 1 || … || W 15 //Wi is a word For t = 16 to 79 Wt = ROTL 1 (Wt-3 XOR Wt-8 XOR Wt-14 XOR Wt-16)
Algorithm Continued A = H 0 , B = H 1, C = H 2, D = H 3, E = H 4 For t = 0 to 79 temp = ROTL 5(A) + Ft(B, C, D) + E + Wi + Kt E = D, D = C, C = ROTL 30(B), B = A, A = temp H 0 = H 0 + A H 1 = H 1 + B H 2 = H 2 + C H 3 = H 3 + D H 4 = H 4 + E Return (H 0 || H 1 || H 2 || H 3 || H 4)
References �Stinson Textbook
- Slides: 10