Background of Secure Hash Function (SHA) and SHA-512.

1. Background Regarding SHA 

These Days, the most widely used hash function is secure hash function (SHA). SHA was developed by National Institute of Standards and Technology (NIST). After that, when some weakness found in SHA then with some additional revision the new version of SHA is launched Which is called as SHA-1 and the previous version of SHA was called as SHA-0. SHA is basically based on MD4, and its design closely models MD4.

Fig. 1 defines the Secure Hash code that is somehow important for SHA. 


Fig. General structure of Secure Hash Code

SHA-1 produces a hash value of 160 bits. In 2002, NIST produced a revised version of standard, FIPS 180-2, that defines three new version of SHA, with hash value lengths of 256, 384, and 512, know as SHA-256, SHA-384, SHA-512. Collectively, this hash algorithm are comes under the category of SHA-2. 

2. SHA-512 Logic :

This algorithm takes an input a message having maximum length less than 2^(128) bits and produces as output a 512-bit message digest. The input is processed on 1024 bit blocks. 

Figure 2. explains the overall processing of a message to produce a digest. 


Fig. 2 : Message Digest Generation Using SHA-512


The processing of SHA-512 is condensed as below : 

Step 1 : Append Padding Bits : The message is padded so that its length is congruent to 896 modulo 1024 [length congruent 896 (modulo 1024)]. The padding bits are always added even if the message is already of desired length. Thus, the number of padding bits is in the range of 1 to 1024. The padding consists of a single 1 bit followed by the necessary number of 0 bits. 

Step 2 : Append Length : A block of 128 bits is appended to the message. This block is treated as an unsigned 128-bit integers and contains the length of the original message (before padding)

Note 1 : The outcome of first two steps yields a message that is an integer multiple of 1024 bits in length. The expended message is represented as the sequence of 1024 bit block M1, M2, ---, Mn. So that the total length of the expanded message is N x 1024 bits. 

Step 3 : Initialize Hash Buffer (IV) :  A 512 bit buffer is used to hold intermediate and final results of the hash function. The buffer can be represented as eight 64 bit registers (a, b, c, d, e, f, g, h). These registers are initialized to the following 64 bit integers (hexadecimal values.)

a = 6A09E667F3BCC908                e = 510E527FADE682D1

b = BB67AE8584CAA7BB             f = 9B05688C2B3E6C1F

c = 3C6EF372FE94F82B                 g = 9B05688C2B3E6C1F

d = A54FF53A5F1D36F1                h = 5BE0CD19137E2179

Note 2 : These values are stored in big endian format, which is the most significant byte if a word in the low address byte position. These words were obtained by taking the first sixty four bits if fractional parts of the square root of the first eight prime number. 

Note 3: How to calculate the value of constants a,b,...,h ??😬 --

a = [frac(√23).2^64]

b = [frac(√29).2^64]

:

:

h = -------

Now why we take prime number ?? The reason behind is that the square root of prime number is irrational 😎 and it looks, means the results like a random number. 

and it is consider from 9th prime number the number are quite smaller and 512 = 2^9. 

Note 4: Why length congruent to 896 (modulo 1024) because the message is considered as N x 1024 and  last bit is 128 bits (L) so 1024 - 128 = 896

Step 4 : Process message in 1024 bit (128 words) blocks : It's a heart of the algorithm which consists of 4 rounds and each round further consists of 20 steps called as a round. So it consists of 80 rounds, this module is labeled as 'F'. 

Each round takes an input the 512 bit buffer value, abcdefgh, and updates the contents of the buffer (as shown in Fig. 3). Each round also make use of an additive constants Kt, where 0<=t<=79 indicates one of the rounds. The word represents the first 64 bits of the fractional parts of the cube root of the first 80 prime numbers. The constant provide a randomized set of 64 bit pattern which should eliminate any regularities in the input data.  

The output of the 80th round is added to the input to the first round (Hi-1) to provide Hi. 

Fig. 3 : SHA-512 Processing of a single 1024 bit block. 

Step 5 : Output : After all N 1024 bit blocks have been processed the output from the Nth stage is the 512 bit message digest. 

We can summarize the behavior of SHA-512 as follows:

    Ho = IV

    Hi = Sum 64(Hi-1, abcdefgh)

    MD = Hn

Where, 

IV =   initial value of the abcedefgh buffer., 

abcdefgh = The output of the last round of processing of the ith message block. 

N = The number of blocks in the message (including padding and length fields)

Sum 64 = addition modulo 2^64 performed separately on each word of the pair of the inputs. 

MD = final message digest value. 

3. SHA-512 Round Function 

Each round is defined by the following set of equations:


Two observations can be made about the round functions.

1. Six of the eight words of the output of the round function involve simply permutation (b, c, d, f, g, h) by means of rotation. This is indicated by unshaded in Figure 4. 

2. Only two of the output words (a, e) are generated by substitution. Word e is a function of input variables (d, e, f, g, h), as well as the round word Wt and the constant Kt. Word a is a function of all of the input variables except d, as well as the round word Wt and the constant Kt. 

It remains to indicate how 64 bit word values are derived from 1024 bit message. The first 16 values of the Wt are taken directly from the 16 words of the current block. The remaining values are defined as - 



Fig. 4: Elementary SHA-512 operation (Single Round) 

Figure 5 summarizes the SHA-512 Logic :
Fig. 5 : SHA-512 Logic

****************************************Thank-You***********************************

Comments

Post a Comment

Popular posts from this blog

Homomorphic Encryption: A Basic Idea

Elliptic Curve Cryptography (ECC) and ECDSA

Fast Base Conversion and Its Application