Confused on using SHA256 code from Bitcoin Core I was looking at Bitcoin Core code to use its SHA256 code but am confused on where I should be looking at.

In bitcoin/src/crypto/sha256.h there is CSHA256 

and in bitcoin/src/crypto/sha256.cpp there are namespaces named sha256_sse4, sha256_shani.

And then there is bitcoin/src/hash.h

Explanations and guidance would be greatly appreciated.
sha256.h has the exported (visible from outside) methods and functions. To compute SHA256, you should #include that.


sha256_sse4.cpp
sha256_sse41.cpp
sha256_avx2.cpp
sha256_shani.cpp


contain SHA256 transform functions (used in SHA256.Write), each specialized for different processors with different instruction sets. Above is the list in order, most of the computers support SSE4, but only a few support SHA-NI instruction set, which is the fastest way a new processor can calculate SHA256.

sha256.cpp contains other methods that aren't a bottleneck, functions that check which instruction sets are supported, tests, as well as a pure-C++ transform function for older and non-x86 computers.

hash.h favors polymorphism via C++ templates.

Examples:


hash std::vector&lt;something&gt; vch to std::vector&lt;something&gt; vchHash
hash std::vector&lt;something&gt; in to std::vector&lt;something&gt; WitnessV0ScriptHash
hash uint8_t * nonce.begin(), uint8_t *  hash.begin(), unsigned char pubkey[], std::vector&lt;unsigned char&gt; vchSig to std::vector&lt;unsigned char&gt; entry
hash op_true to witness_program