Bitcoin Forum
June 28, 2024, 01:01:04 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: different implementations of SHA256  (Read 858 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: 4074
Merit: 1304


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: 4074
Merit: 1304


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!