0
$\begingroup$

I am trying to code SHA256 from scratch to understand its implementation based on the wiki pseudo code as its clear enough. But I am running into problems with the calculation of W[i] for the first block. I am sure I am missing the logic somewhere. Given a data string of size 80 Bytes (in Hex): "02000000aaf8ab82362344f49083ee4edef795362cf135293564c4070000000000000000c009bb6222e9bc4cdb8f26b2e8a2f8d163509691a4038fa692abf9a474c9b21476800755c02e17181fe6c1c3"

After padding it results in the data string of 128 Bytes (in Hex): "02000000aaf8ab82362344f49083ee4edef795362cf135293564c4070000000000000000c009bb6222e9bc4cdb8f26b2e8a2f8d163509691a4038fa692abf9a474c9b21476800755c02e17181fe6c1c3800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280"

Now this is split into 2 chunks of 64 Byte each: "02000000aaf8ab82362344f49083ee4edef795362cf135293564c4070000000000000000c009bb6222e9bc4cdb8f26b2e8a2f8d163509691a4038fa692abf9a4"

"74c9b21476800755c02e17181fe6c1c3800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000280"

Now when we start processing the first chunk how do we populate the 64-entry message schedule array w[0..63] of 32-bit words. Wiki says: "(The initial values in w[0..63] don't matter, so many implementations zero them here)" copy chunk into first 16 words w[0..15] of the message schedule array

So I try to populate the message schedule array as as follows:

W[0]=0200

W[1]=0000

W[2]=aaf8

W[3]=ab82

W[4]=3623 and so on upto W[15].

The values W[16] to W[63] are all set to 0.

But these values seem incorrect. What am I doing wrong here. Can someone please point to what is wrong here?

$\endgroup$
3
$\begingroup$

W[0]=0200

Here's your problem - with SHA-256, each word is 32 bits, not 16.

So, this should be:

W[0] = 02000000 
W[1] = aaf8ab82
W[2] = 362344f4

etc...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.