Inside Bitcoin
Opening the selected file…
Inside Bitcoin
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) 2020-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#include <crypto/hmac_sha256.h>6#include <crypto/hmac_sha512.h>7#include <crypto/ripemd160.h>8#include <crypto/sha1.h>9#include <crypto/sha256.h>10#include <crypto/sha3.h>11#include <crypto/sha512.h>12#include <hash.h>13#include <test/fuzz/FuzzedDataProvider.h>14#include <test/fuzz/fuzz.h>15#include <test/fuzz/util.h>17#include <cstdint>18#include <vector>20FUZZ_TARGET(crypto)21{22FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};23std::vector<uint8_t> data = ConsumeRandomLengthByteVector(fuzzed_data_provider);24if (data.empty()) {25auto new_size = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 4096);26auto x = fuzzed_data_provider.ConsumeIntegral<uint8_t>();27data.resize(new_size, x);28}30CHash160 hash160;31CHash256 hash256;32CHMAC_SHA256 hmac_sha256{data.data(), data.size()};33CHMAC_SHA512 hmac_sha512{data.data(), data.size()};34CRIPEMD160 ripemd160;35CSHA1 sha1;36CSHA256 sha256;37CSHA512 sha512;38SHA3_256 sha3;39CSipHasher sip_hasher{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>()};41LIMITED_WHILE (fuzzed_data_provider.ConsumeBool(), 30) {42CallOneOf(43fuzzed_data_provider,44[&] {45if (fuzzed_data_provider.ConsumeBool()) {46data = ConsumeRandomLengthByteVector(fuzzed_data_provider);47if (data.empty()) {48auto new_size = fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 4096);49auto x = fuzzed_data_provider.ConsumeIntegral<uint8_t>();50data.resize(new_size, x);51}52}54(void)hash160.Write(data);55(void)hash256.Write(data);56(void)hmac_sha256.Write(data.data(), data.size());57(void)hmac_sha512.Write(data.data(), data.size());58(void)ripemd160.Write(data.data(), data.size());59(void)sha1.Write(data.data(), data.size());60(void)sha256.Write(data.data(), data.size());61(void)sha3.Write(data);62(void)sha512.Write(data.data(), data.size());63(void)sip_hasher.Write(data);65(void)Hash(data);66(void)Hash160(data);67(void)sha512.Size();68},69[&] {70(void)hash160.Reset();71(void)hash256.Reset();72(void)ripemd160.Reset();73(void)sha1.Reset();74(void)sha256.Reset();75(void)sha3.Reset();76(void)sha512.Reset();77},78[&] {79CallOneOf(80fuzzed_data_provider,81[&] {82data.resize(CHash160::OUTPUT_SIZE);83hash160.Finalize(data);84},85[&] {86data.resize(CHash256::OUTPUT_SIZE);87hash256.Finalize(data);88},89[&] {90data.resize(CHMAC_SHA256::OUTPUT_SIZE);91hmac_sha256.Finalize(data.data());92},93[&] {94data.resize(CHMAC_SHA512::OUTPUT_SIZE);95hmac_sha512.Finalize(data.data());96},97[&] {98data.resize(CRIPEMD160::OUTPUT_SIZE);99ripemd160.Finalize(data.data());100},101[&] {102data.resize(CSHA1::OUTPUT_SIZE);103sha1.Finalize(data.data());104},105[&] {106data.resize(CSHA256::OUTPUT_SIZE);107sha256.Finalize(data.data());108},109[&] {110data.resize(CSHA512::OUTPUT_SIZE);111sha512.Finalize(data.data());112},113[&] {114data.resize(1);115data[0] = sip_hasher.Finalize() % 256;116},117[&] {118data.resize(SHA3_256::OUTPUT_SIZE);119sha3.Finalize(data);120});121});122}123if (fuzzed_data_provider.ConsumeBool()) {124uint64_t state[25];125for (size_t i = 0; i < 25; ++i) {126state[i] = fuzzed_data_provider.ConsumeIntegral<uint64_t>();127}128KeccakF(state);129}130}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.