SHA256 Personal Implementation Is Only Returning The Correct Hash Value For Input Messages With A Block Size That Doesn't Exceed 512 Bits

Question:

SOLVED

For a while I’ve been working on my own implementation of the SHA256 in Python to entertain my interest in mathematics and programming.

The problem I’m currently struggling with is that my implementation returns the correct hash value for shorter input messages (One 512 bit block), but returns an incorrect hash value for any larger messages (fails for 1024 and 1536)

In trying to solve this issue I’ve spent time validating the padding of the message as well as reviewing the overall program.

Link to Github project: https://github.com/Gajdascz/reportPySHA256

Using the Intermediate Results Example Provided I was able to find my issue and work through correcting it. My initial problem was that I was not breaking the message up into individual 512-bit blocks.Instead I was
Performing the hash on the entire combined block (1024 bit+). After figuring this out I re-worked most of the program as new problems arose requiring significant changes. As a result, my program not only performs the SHA256 algorithm, but also creates a dynamic report throughout the execution. I’ve added an updated link to the working project if anyone is interested, Thanks!

Asked By: gajdascz

||

Answers:

I don’t know the answer to your question, but you should look at this document which gives a step by step list of intermediate values you should expect when performing your SHA256 calculation. It has both 1-block and multi-block samples.

I knew this document existed, but found it by searching for "SHA256 intermediate results".

And please, please. This is just a toy you’re writing, right? There is no reason to be writing your own implementation of SHA-256.

Answered By: Frank Yellin