Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Honored Contributor I
740 Views

working on hashing algorithm SHA-2

I am working on implementing the hashing algorithm SHA-2(256) , while working on the algorithm I faced some problems on the padding section, actually according to the algo provided by wikipedia shows the length appending to be done without appending the 1 bit or 0x80 or the padding at the end of the message which is inconsistent with the SHA-1. 

 

If anyone has worked on the SHA-2(256) can you pls guide me? I am totally lost.
0 Kudos
3 Replies
Highlighted
Honored Contributor I
18 Views

I implemented SHA-512, and I don't really get what you don't understand in the description. The message must be padded with a '1' bit, then enough '0' bits, and finally a 64-bit value which indicates the message length in bits. This is also what is described on this wikipedia page (https://en.wikipedia.org/wiki/sha-2). When they say "append length of message (without the '1' bit or padding)", it means that the length value is the length of your message without the padding bits, it doesn't mean that you don't add the padding bits themselves to the last data word.

0 Kudos
Highlighted
Honored Contributor I
18 Views

 

--- Quote Start ---  

I implemented SHA-512, and I don't really get what you don't understand in the description. The message must be padded with a '1' bit, then enough '0' bits, and finally a 64-bit value which indicates the message length in bits. This is also what is described on this wikipedia page (https://en.wikipedia.org/wiki/sha-2). When they say "append length of message (without the '1' bit or padding)", it means that the length value is the length of your message without the padding bits, it doesn't mean that you don't add the padding bits themselves to the last data word. 

--- Quote End ---  

 

I know what you said, my question is when i append the value of the message will it always have to be a separate 512 bit data sequence starting with 0s or we can append the length where we are doing the padding, if the space is available at the end of the 512 bit , like we do in sha-1.
0 Kudos
Highlighted
Honored Contributor I
18 Views

When you cut your data in words of 512 bits, if you have enough unused bits in the last word (65 or more) then you don't need to add a separate 512-bit word. Just pad that last data word with the '1', if necessary some '0's, and the 64-bit length value.

0 Kudos