Bitcoin Forum
April 25, 2024, 06:12:43 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: SHA256 implementation fails on 2 of 9 tests  (Read 2565 times)
pieppiep (OP)
Hero Member
*****
Offline Offline

Activity: 1596
Merit: 502


View Profile
January 28, 2012, 11:46:43 PM
 #1

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?
1714025563
Hero Member
*
Offline Offline

Posts: 1714025563

View Profile Personal Message (Offline)

Ignore
1714025563
Reply with quote  #2

1714025563
Report to moderator
1714025563
Hero Member
*
Offline Offline

Posts: 1714025563

View Profile Personal Message (Offline)

Ignore
1714025563
Reply with quote  #2

1714025563
Report to moderator
"The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
pieppiep (OP)
Hero Member
*****
Offline Offline

Activity: 1596
Merit: 502


View Profile
January 29, 2012, 07:55:36 AM
 #2

I found it.
I made a mistake with the padding that only occurred with these 2 tests.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!