Thursday, October 13, 2011

SHA-1 Algorithm : Information Security - BE [COMP,IT]

      The SHA1 encryption algorithm specifies a Secure Hash Algorithm (SHA1), which can be used to generate a condensed representation of a message called a message digest. The SHA1 is required for use with the Digital Signature Algorithm (DSA) as specified in the Digital Signature Standard (DSS) and whenever a secure hash algorithm is required. Both the transmitter and intended receiver of a message in computing and verifying a digital signature uses the SHA1.
       SHA1 is used for computing a condensed representation of a message or a data file. When a message of any length < 2 64 bits is input, the SHA1 produces a 160-bit output called a message digest. The message digest can then be input to the Digital Signature Algorithm (DSA), which generates or verifies the signature for the message.
     Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature


      The SHA1 is called secure because it is computationally infeasible to find a message which corresponds to a given message digest, or to find two different messages which produce the same message digest. Any change to a message in transit will, with very high probability, result in a different message digest, and the signature will fail to verify. 

   The following simplifies the specification of SHA-1 in an easy to digest form. First we will cover the general structure of the algorithm. Detail of the expansion and compression routines are covered separately


messageFirst we start with a message. The message is padded and the length of the message is added  to the end. It is then split into blocks of 512 bits (Figure 2).



message blocks

(Figure 2)



     The blocks are then processed one at a time. Each block must be expanded and compressed. The value after each compression is added to a 160bit buffer called the current hash state. After the last block is processed the current hash state is returned as the final hash. A overview of this procedure can be seen in Figure 3.



sha-1 general process overview

(Figure 3)



      Let’s look more closely at the expansion and compression functions. For expansion each 512 bit message block is separated into chunks of 32 bits. As you can see in Figure 4 these 16 chunks are then used to create 64 more chunks for a total of 80. Details of how this is done are described later.



expand block to 80 32 bit chunks

(Figure 4)





   Now all 80 of these chunks are compressed into a 160 bit value which is added to the current hash state   (Figure 5):




compress block into hash state

(Figure 5)



    Figure 5 shows one block being processed. The expansion and compression functions are repeated for each block with the return constantly being added to the current hash state buffer. 
return hash state as hash    Once all blocks have been processed it is this value that is returned as the hash of the message.


 3 tasks were generalized above: How the message is prepared before processing, how exactly the block is expanded to 80 chunks (Figure 4) and how those chunks are compressed (Figure 5). It is not essential to understand them in detail but should you desire, here are the details.


Message Preparation
The message is prepared in 4 steps:
  1. Append a single binary 1 bit to the message
  2. Split into blocks of 512 bits each (Figure 2 above)
  3. The last block must be equal to 448 so that we can append the message length (next step). If it is under pad with binary 0 bits until equal to 448. If over, pad until it is 512 bits and create an additional block of 448 binary 0 bits.
  4. Append the length of the original message to the last block. Represent this length as a 64 bit integer (making the last block equal to 512 bits).
I should also mention that before we process any blocks we must initiate the hash state buffer. The buffer is actually 5 separate 32 bit integers:
Animation of block expansion
  • h0 = 67452301
  • h1 = EFCDAB89
  • h2 = 98BADCFE
  • h3 = 10325476
  • h4 = C3D2E1F0
Block expansion
Each 512 bit block is split further into 32 bit chunks (“words“) as seen in Figure 4. These 16 chunks are then expanded to a total of 80. The processes of expansion is a simple XOR of 4 values. For instance, the next chunk, chunk 17, is created by XOR’ing together chunk 17-3, 17-8, 17-14 and 17-16. For chunk 18 run the same processes but subtracting from 18 instead of 17. This continues until all 80 have been created. This can clearly be seen in the animation to the right. (If the animation is not playing reload the page.)
-----------------------------------------------------------------------------------------


 Downloads for SHA Algorithm


Secure Hash Algorithm - PPT Download


Information_Security_Using_the_SHA-1_Algorithm.ppt

0 comments:

Post a Comment