Secure Hash Algorithm (SHA): Its Importance and Mechanism

Reading Time: 3 minutes

Do you want to know about how the online communication is made secure. So we have a lot of algorithms for the same and Secure Hash Algorithm (SHA) is one of those. So lets dig deep into that!

While talking about information security, you might have come across a word called cryptography & which means the change in the real message that is hard to read for everyone except the sender & the receiver of that message. So what does cryptography do to make our communication secure? In cryptography, many algorithms are there to use to make messages ciphertexts. So one of the algorithms in cryptography is the Secure Hash Algorithm (SHA). The different flavors of SHA are SHA-0, SHA-1, SHA-224, SHA-256, SHA-384 & SHA-512. SHA-1. SHA-1 was introduced in 1995 & is now considered insecure since 2005.

The major tech giants browsers like Microsoft, Google, Apple, Mozilla have stopped accepting SHA-1 SSL (Secure Sockets Layer) certificates by 2017. SHA-2 is one of the strongest hash functions available. Its 256-bit key makes it a good partner for AES i.e. Advanced Encryption Standard. SHA-2 actually consists of SHA-224, SHA-256, SHA-384 & SHA-512. SHA- 256 is the most commonly used because of its shorter output which helps to save bandwidth. SHA-512 can also be used but it is faster on 64-bit processors while SHA-256 works on 32-bit processors.

Working & Mechanism of Secure Hash Algorithm (SHA)

Coming to working with Secure Hash Algorithm (SHA), we’ll talk about the basic version of the algorithm i..e SHA-1 or Secure Hash Algorithm 1. So SHA-1 will produce a 160-bit hash value by feeding the string message as a bit string of length less than 264 known as a message digest.

So in here, the algorithm will take 512-bits of a block of data in a loop, one at a time. The message will be divided into n blocks of 512-bits each. And if the message is exactly 512-bits in length then the loop will only run one time. And in the end, the output will be a hash value.

The internal state of the message will change and it will look in the image below.

The hash blocks have the data and they have a size of 32-bits each. When the loop will run for more than one message block (512-bit), the values of hn will change as we have a message. The internal state is then passed to the compression function where 80 rounds will be performed of char function. This will give us new values of A B C D E. 

The values of hn (h0, h1, h2, h3, h4) are then added to A B C D E to create new values called Hn (H0, H1, H2, H3, H4). Here we are done, but the original message may get lost if we go over a 4-byte value. The new values after adding will be our new hash for short messages. For bigger messages, the values of Hn will be taken as first and the process will go on in a loop for as many blocks as we have of the message.  

For more information

Scala Future

Written by 

Shubham Saini is a DevOps Engineer who loves to play with DevOps tools, Security methods and is also interested in Ethical Hacking & Cyber Security. He is a gamer also.