Post
Topic
Board Altcoin Discussion
Re: Where is hashing algorithm code?
by
ItaCraft
on 15/02/2019, 21:01:59 UTC
According to the bitcoin source code, the hash for the block header can be seen from the file src/primitives/block.cpp under
Code:
uint256 CBlockHeader::GetHash() const
{
    return SerializeHash(*this);
}

https://github.com/bitcoin/bitcoin/blob/master/src/primitives/block.cpp#L13

Which return the value of SerializeHash(*this), That is declared on the file hash.h

Code:
/** Compute the 256-bit hash of an object's serialization. */
template
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
{
    CHashWriter ss(nType, nVersion);
    ss << obj;
    return ss.GetHash();
}

And according to the comment above it,
 /** Compute the 256-bit hash of an object's serialization. */

The SerializeHash will call CHashWriter and return the value of GetHash which is a simple sha256d hashing algorithm result


(Please, let me know if I'm wrong, I'm still studying bitcoin code)