Bitcoin Forum
October 23, 2017, 10:16:00 AM *
News: Latest stable version of Bitcoin Core: 0.15.0.1  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: different implementations of SHA256  (Read 760 times)
redPanda
Member
**
Offline Offline

Activity: 65


View Profile
March 17, 2015, 07:10:13 PM
 #1

Are there different implementations of SHA256 ?

from the bx library:

>bx sha256 800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D
8147786c4d15106333bf278d71dadaf1079ef2d2440a4dde37d747ded5403592

from https://en.bitcoin.it/wiki/Wallet_import_format
sha256 (800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
8147786c4d15106333bf278d71dadaf1079ef2d2440a4dde37d747ded5403592

and

from c++ crypto++:
sha256(800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
E2E4146A36E9C455CF95A4F259F162C353CD419CC3FD0E69AE36D7D1B6CD2C09

from: http://www.xorbin.com/tools/sha256-hash-calculator
sha256(800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
e2e4146a36e9c455cf95a4f259f162c353cd419cc3fd0e69ae36d7d1b6cd2c09
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1508753760
Hero Member
*
Offline Offline

Posts: 1508753760

View Profile Personal Message (Offline)

Ignore
1508753760
Reply with quote  #2

1508753760
Report to moderator
1508753760
Hero Member
*
Offline Offline

Posts: 1508753760

View Profile Personal Message (Offline)

Ignore
1508753760
Reply with quote  #2

1508753760
Report to moderator
cr1776
Legendary
*
Offline Offline

Activity: 1680


View Profile
March 18, 2015, 12:00:38 AM
 #2

Are there different implementations of SHA256 ?

from the bx library:

>bx sha256 800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D
8147786c4d15106333bf278d71dadaf1079ef2d2440a4dde37d747ded5403592

from https://en.bitcoin.it/wiki/Wallet_import_format
sha256 (800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
8147786c4d15106333bf278d71dadaf1079ef2d2440a4dde37d747ded5403592

and

from c++ crypto++:
sha256(800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
E2E4146A36E9C455CF95A4F259F162C353CD419CC3FD0E69AE36D7D1B6CD2C09

from: http://www.xorbin.com/tools/sha256-hash-calculator
sha256(800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
e2e4146a36e9c455cf95a4f259f162c353cd419cc3fd0e69ae36d7d1b6cd2c09

The difference is in hashing the string (an ASCII representation of a hex number) instead of the actual hex number itself.

The wiki hashes the number, the calculator is hashing the string.
redPanda
Member
**
Offline Offline

Activity: 65


View Profile
March 18, 2015, 02:34:23 PM
 #3

I finally got the right output:
instead of doing:
Code:
// WRONG
string myString("800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D");
string myStringSHA = SHA256(myString)
I used:
Code:
// OK
string digest;
StringSource(myString, true, new HexDecoder(new StringSink(digest)));
string myStringSHA = SHA256(digest);
Thanks a lot Smiley

   
cr1776
Legendary
*
Offline Offline

Activity: 1680


View Profile
March 18, 2015, 03:10:36 PM
 #4

I finally got the right output:
instead of doing:
Code:
// WRONG
string myString("800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D");
string myStringSHA = SHA256(myString)
I used:
Code:
// OK
string digest;
StringSource(myString, true, new HexDecoder(new StringSink(digest)));
string myStringSHA = SHA256(digest);
Thanks a lot Smiley

   


Exactly!  ;-)

It can be tricky.
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!