Security Stuff!!
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode

Secure Hashing Algorithm

Secure Hashing Algorithm (SHA) is based on the hash function MD4 ,SHA was developed by National Institute of Standards and Technology (NIST) and published in 1993 known as SHA-0, and then published SHA-1 in 1995 that produces a hash value of 160 bits, Then SHA-2 with a hash value length of 256,384 and 512 bits known as SHA-256 SHA-384 and SHA-512 respectively.

SHA-512

SHA-512 takes as input a message with a maximum length less than \(2^{128}\) and produces 512 bits.
The block length is 1024 bits.
The processes consists of:
1- Append Padding Bits:
Padding is always added even if the message is already of the desire length, the padding consists of a single 1 bit followed by the necessary number of 0 bits, the message padded so that its length 896 mod 1024.
L + 1 + K = 896 (mod 1024)
L = Length of the original message
K = Number of zeros
2- Append Length:
A block of 128 bits is appended to the message and contains the length of the original message.

Example:
Suppose the original message = “01100001 01100010 01100011 01100100 01100101”
Then after padding it with a single 1 bit = “01100001 01100010 01100011 01100100 01100101 1”
Length of the original message L=40 , The number of zeros K= 855
Then the message after append padding step in Hex =

61626364 65800000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000000  

Since L=40, Then we add 128 bits in the end of message “00000000 00000000 00000000 00000028”
The final padded message in Hex

61626364 65800000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000000  
00000000 00000000 00000000 00000028  

3- Initialize Hash Buffer:
A 512 bit buffer can be represented as eight 64 bit register (a,b,c,d,e,f,g,h)
These values were obtained by taking the first sixty bit of the fractional parts of the square roots of the first eight prime numbers, and these values are stored in big-Indian format.

a = 6a09e667f3bcc908  
b = bb67ae8584caa73b  
c = 3c6ef372fe94f82b  
d = a54ff53a5f1d36f1  
e = 510e527fade682d1  
f = 9b05688c2b3e6c1f  
g = 1f83d9abfb41bd6b  
h = 5be0cd19137e2179  

4- Process The Message In 1024 Bits:
SHA-512 consists of 80 rounds takes as input 512 bit value (a,b,c,d,e,f,g,h) and then update the contents of the buffer, and then take \({K}_{t}\) Where 0 <= t <= 79 and these words represent the first 64 bits of the fractional parts of the cube root of the first 80 prime numbers

428a2f98d728ae22 7137449123ef65cd b5c0fbcfec4d3b2f e9b5dba58189dbbc  
3956c25bf348b538 59f111f1b605d019 923f82a4af194f9b ab1c5ed5da6d8118  
d807aa98a3030242 12835b0145706fbe 243185be4ee4b28c 550c7dc3d5ffb4e2  
72be5d74f27b896f 80deb1fe3b1696b1 9bdc06a725c71235 c19bf174cf692694  
e49b69c19ef14ad2 efbe4786384f25e3 0fc19dc68b8cd5b5 240ca1cc77ac9c65  
2de92c6f592b0275 4a7484aa6ea6e483 5cb0a9dcbd41fbd4 76f988da831153b5  
983e5152ee66dfab a831c66d2db43210 b00327c898fb213f bf597fc7beef0ee4  
c6e00bf33da88fc2 d5a79147930aa725 06ca6351e003826f 142929670a0e6e70  
27b70a8546d22ffc 2e1b21385c26c926 4d2c6dfc5ac42aed 53380d139d95b3df  
650a73548baf63de 766a0abb3c77b2a8 81c2c92e47edaee6 92722c851482353b  
a2bfe8a14cf10364 a81a664bbc423001 c24b8b70d0f89791 c76c51a30654be30  
d192e819d6ef5218 d69906245565a910 f40e35855771202a 106aa07032bbd1b8  
19a4c116b8d2d0c8 1e376c085141ab53 2748774cdf8eeb99 34b0bcb5e19b48a8  
391c0cb3c5c95a63 4ed8aa4ae3418acb 5b9cca4f7763e373 682e6ff3d6b2b8a3  
748f82ee5defb2fc 78a5636f43172f60 84c87814a1f0ab72 8cc702081a6439ec  
90befffa23631e28 a4506cebde82bde9 bef9a3f7b2c67915 c67178f2e372532b  
ca273eceea26619c d186b8c721c0c207 eada7dd6cde0eb1e f57d4f7fee6ed178  
06f067aa72176fba 0a637dc5a2c898a6 113f9804bef90dae 1b710b35131c471b  
28db77f523047d84 32caab7b40c72493 3c9ebe0a15c9bebc 431d67c49c100d4c  
4cc5d4becb3e42b6 597f299cfc657e2a 5fcb6fab3ad6faec 6c44198c4a475817  

also each round makes use of 64 bit value derived from the current 1024 bit block being processing and each round defined by the following equations:

h = g  
g = f  
f = e  
e = d+T1  
d = c  
c = b  
b = a  
a = T1+T2  

Where t = step number 0<= t <= 79

If e then f else g

\(ROTR^{n}\) (x): Circular right shift of the 64 bit argument x by n bits.
\({W}_{t}\)  a 64 bit word derived from the current 512 bit input block.
\({K}_{t}\): a 64 bit additive constant.

\({W}_{t}\) values are derived from 1024 bit message, the first 16 values of \({W}_{t}\) are taken directly from 16 words of the current block and the remaining derived from :

Where


\(ROTR^{n}\) (x) = Circular right shift of 64 bit argument x by n bits.
\(SHR^{n}\)  (x)  = Left shift of 64 bit argument by n bits with padding by zeros on the right.
+ = Addition modulo  \(2^{64}\).

Finally, the output of 80th round is added to the input of the first round (a,b,c,d,e,f,g,h) and the addition is done independently for each of the eight words in buffer with each of the corresponding word(a,b,c,d,e,f,g,h) by using addition modulo \(2^{64}\), then the output is 512 bit message digest.