Bitcoin Forum
November 14, 2018, 12:39:25 PM *
News: Latest Bitcoin Core release: 0.17.0 [Torrent].
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: SHA256 implementation fails on 2 of 9 tests  (Read 2496 times)
pieppiep
Hero Member
*****
Offline Offline

Activity: 890
Merit: 500


Look ARROUND!


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?


.........................................
             █████████████████
         ███ ██     █     ██ ███
       ██ █████     █     █████ ██
     ███   █   █  █████  █   █   ███
   ███     █    ███ █ ███    █     ███
  ██  ███ ██ ███    █    ███ ██ ███  ██
  ██     ████       █      █████     ██
 ███   ██ █  ███    █    ███  █ ██   ███
 █ █ ██   █     ██  █  ██     █   ██ █ █
█████     █       █████       █     █████
 █ █ ██   █   ████  █  ████   █   ██ █ █
 ███   ████ ██      █      ██ ████   ███
  ██  █  █████      █      █████  █  ██
  ██ ██   ██ ████   █  ████  ██   ██ ██
   ██      █     ██████      █     ███
     ████  █   ██████████    █  ████
       ██ █████     █    ██████ ██
         ███  ██    █   ███  ███
            █████████████████
ARROUND









.









.
Telegram
ANN Thread
Bounty Thread
Whitepaper
1542199165
Hero Member
*
Offline Offline

Posts: 1542199165

View Profile Personal Message (Offline)

Ignore
1542199165
Reply with quote  #2

1542199165
Report to moderator
1542199165
Hero Member
*
Offline Offline

Posts: 1542199165

View Profile Personal Message (Offline)

Ignore
1542199165
Reply with quote  #2

1542199165
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1542199165
Hero Member
*
Offline Offline

Posts: 1542199165

View Profile Personal Message (Offline)

Ignore
1542199165
Reply with quote  #2

1542199165
Report to moderator
1542199165
Hero Member
*
Offline Offline

Posts: 1542199165

View Profile Personal Message (Offline)

Ignore
1542199165
Reply with quote  #2

1542199165
Report to moderator
1542199165
Hero Member
*
Offline Offline

Posts: 1542199165

View Profile Personal Message (Offline)

Ignore
1542199165
Reply with quote  #2

1542199165
Report to moderator
pieppiep
Hero Member
*****
Offline Offline

Activity: 890
Merit: 500


Look ARROUND!


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.


.........................................
             █████████████████
         ███ ██     █     ██ ███
       ██ █████     █     █████ ██
     ███   █   █  █████  █   █   ███
   ███     █    ███ █ ███    █     ███
  ██  ███ ██ ███    █    ███ ██ ███  ██
  ██     ████       █      █████     ██
 ███   ██ █  ███    █    ███  █ ██   ███
 █ █ ██   █     ██  █  ██     █   ██ █ █
█████     █       █████       █     █████
 █ █ ██   █   ████  █  ████   █   ██ █ █
 ███   ████ ██      █      ██ ████   ███
  ██  █  █████      █      █████  █  ██
  ██ ██   ██ ████   █  ████  ██   ██ ██
   ██      █     ██████      █     ███
     ████  █   ██████████    █  ████
       ██ █████     █    ██████ ██
         ███  ██    █   ███  ███
            █████████████████
ARROUND









.









.
Telegram
ANN Thread
Bounty Thread
Whitepaper
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!