Bitcoin Forum

Bitcoin => Wallet software => Topic started by: pieppiep on January 28, 2012, 11:46:43 PM



Title: SHA256 implementation fails on 2 of 9 tests
Post by: pieppiep on January 28, 2012, 11:46:43 PM
I've build a little C# project to try to implement SHA256 myself and tested it with test vectors from set 1 from
https://www.cosic.esat.kuleuven.be/nessie/testvectors/hash/sha/Sha-2-256.unverified.test-vectors
I used the pseudo code from http://en.wikipedia.org/wiki/SHA-2

Vector 5 and 6 fails for my program with the following output :

Test failed for string : abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
Expected hash 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1
Result was    e9ee317b2c7807407297320147508a0e5becd7d32e27cafd66c6fd9635cc2c88
.Net version  248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1

Test failed for string : ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
Expected hash db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0
Result was    2f3d5a2408f1a3aadc21629aaf4f261b80e0ad096214efcbf0d6ae202d39eb0b
.Net version  db4bfcbd4da0cd85a60c3c37d3fbd8805c77f15fc6b1fdfe614ee0a7c8fdb4c0

Expected hash is the hash on the website with tests, result is my own calculated hash, .net version is the hash calculated with .net's System.Security.Cryptography.SHA256.
I can find many websites that just tell me the same thing, my hash is wrong.
I've tried to find it with debugging but I really have no clue where to look since the other 7 tests run just fine.

Can anyone supply me with the w[0..63] values and the a/b/c/d/e/f/g/h values for each of the 64 loops?


Title: Re: SHA256 implementation fails on 2 of 9 tests
Post by: pieppiep on January 29, 2012, 07:55:36 AM
I found it.
I made a mistake with the padding that only occurred with these 2 tests.