Padding the message in SHA256

Thomas

I am trying to understand SHA256. On the Wikipedia page it says:

append the bit '1' to the message

append k bits '0', where k is the minimum number >= 0 such that the resulting message length (modulo 512 in bits) is 448.

append length of message (without the '1' bit or padding), in bits, as 64-bit big-endian integer (this will make the entire post-processed length a multiple of 512 bits)

So if my message is 01100001 01100010 01100011 I would first add a 1 to get

01100001 01100010 01100011 1

Then you would fill in 0s so that the total length is 448 mod 512:

01100001 01100010 01100011 10000000 0000 ... 0000

(So in this example, one would add 448 - 25 0s)

My question is: What does the last part mean? I would like to see an example.

Fred Foo

It means the message length, padded to 64 bits, with the bytes appearing in order of significance. So if the message length is 37113, that's 90 f9 in hex; two bytes. There are two basic(*) ways to represent this as a 64-bit integer,

00 00 00 00 00 00 90 f9  # big endian

and

f9 90 00 00 00 00 00 00  # little endian

The former convention follows the way numbers are usually written out in decimal: one hundred and two is written 102, with the most significant part (the "big end") being written first, the least significant ("little end") last. The reason that this is specified explicitly is that both conventions are used in practice; internet protocols use big endian, Intel-compatible processors use little endian, so if they were decimal machines, they'd write one hundred and two as 201.

(*) Actually there are 8! = 40320 ways to represent a 64-bit integer if 8-bit bytes are the smallest units to be permuted, but two are in actual use.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related