Bitcoin Forum
November 12, 2024, 07:36:23 AM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: different implementations of SHA256  (Read 875 times)
redPanda (OP)
Member
**
Offline Offline

Activity: 65
Merit: 16


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
cr1776
Legendary
*
Offline Offline

Activity: 4214
Merit: 1313


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 (OP)
Member
**
Offline Offline

Activity: 65
Merit: 16


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: 4214
Merit: 1313


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:  

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