Important property:
- One way from input to hash value, cannot reverse
- Different input cannot generate the same hash value
Actual SHA example:
- Choose a word to hash, eg CRYPTO
- Convert the word to ASCII
- Convert from ASCII to binary
(it becomes a 48 bit message)
- Join and add 1 at the end
- Add zeros to make message equal to 448 mod 512, a 48 bit message with the added one will need to have 399 zeros added to the end
- Add original message length to the 64 bit field (which is the left over field after the 448 modular arithmetic), and let the message become 16 sections of 32 bits
- Transform the 16 x 32 message into 80 words using step loop function, firstly, do ((14 XOR 9) XOR 3) XOR 1), we get
01000011010100100101100101010000
01010100010011111000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000000000
00000000000000000000000000110000
01000011010100100101100101010000
- Rotate left, we get
10000110101001001011001010100000
- Process is repeated until there are 80 words (one word = 32 bits)
- The 1st, 3rd, 9th 14th words are chosen from the algorithm:
for i from 16 to 79
w[i] = (w[i-3] xor w[i-8] xor w[i-14] xor w[i-16]) leftrotate 1
H0 - 01100111010001010010001100000001
H1 - 11101111110011011010101110001001
H2 - 10011000101110101101110011111110
H3 - 00010000001100100101010001110110
H4 – 11000011110100101110000111110000
- The Operations are combination of AND, OR and NOT operators
- The five variables are from first 32 bits of the fractional part of the square roots of the first 5 prime numbers
- The result : get five variables
H0 – 01000100101010010111000100110011
H1- 01010000111001010011100001011000
H2-11110000010110000100011000111101
H3-01001011111101111111000111100101
H4-01000010110110011100101001001011
- Convert the five variables to hex
H1- 50e53858
H2- f058463d
H3 - 4bf7f1e5
H4 - 42d9ca4b- Join the variables together, get the hash
44a9713350e53858f058463d4bf7f1e542d9ca4b
No comments:
Post a Comment