Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12367 Discussions

working on hashing algorithm SHA-2

Altera_Forum
Honored Contributor I
778 Views

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
Altera_Forum
Honored Contributor I
56 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.

Altera_Forum
Honored Contributor I
56 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.
Altera_Forum
Honored Contributor I
56 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.

Reply