Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2014-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_CRYPTO_SHA256_H6#define BITCOIN_CRYPTO_SHA256_H8#include <cstddef>9#include <cstdint>10#include <string>12/** A hasher class for SHA-256. */13class CSHA25614{15private:16uint32_t s[8];17unsigned char buf[64];18uint64_t bytes{0};20public:21static constexpr size_t OUTPUT_SIZE{32};23CSHA256();24CSHA256& Write(const unsigned char* data, size_t len);25void Finalize(unsigned char hash[OUTPUT_SIZE]);26CSHA256& Reset();27};29namespace sha256_implementation {30enum UseImplementation : uint8_t {31STANDARD = 0,32USE_SSE4 = 1 << 0,33USE_AVX2 = 1 << 1,34USE_SHANI = 1 << 2,35USE_SSE4_AND_AVX2 = USE_SSE4 | USE_AVX2,36USE_SSE4_AND_SHANI = USE_SSE4 | USE_SHANI,37USE_ALL = USE_SSE4 | USE_AVX2 | USE_SHANI,38};39}41/** Autodetect the best available SHA256 implementation.42* Returns the name of the implementation.43*/44std::string SHA256AutoDetect(sha256_implementation::UseImplementation use_implementation = sha256_implementation::USE_ALL);46/** Compute multiple double-SHA256's of 64-byte blobs.47* output: pointer to a blocks*32 byte output buffer48* input: pointer to a blocks*64 byte input buffer49* blocks: the number of hashes to compute.50*/51void SHA256D64(unsigned char* output, const unsigned char* input, size_t blocks);53#endif // BITCOIN_CRYPTO_SHA256_H