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/common.h>6#include <test/fuzz/FuzzedDataProvider.h>7#include <test/fuzz/fuzz.h>8#include <test/fuzz/util.h>10#include <array>11#include <cassert>12#include <cstdint>13#include <cstring>14#include <vector>16FUZZ_TARGET(crypto_common)17{18FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};19const uint16_t random_u16 = fuzzed_data_provider.ConsumeIntegral<uint16_t>();20const uint32_t random_u32 = fuzzed_data_provider.ConsumeIntegral<uint32_t>();21const uint64_t random_u64 = fuzzed_data_provider.ConsumeIntegral<uint64_t>();22const std::vector<uint8_t> random_bytes_2 = ConsumeFixedLengthByteVector(fuzzed_data_provider, 2);23const std::vector<uint8_t> random_bytes_4 = ConsumeFixedLengthByteVector(fuzzed_data_provider, 4);24const std::vector<uint8_t> random_bytes_8 = ConsumeFixedLengthByteVector(fuzzed_data_provider, 8);26std::array<uint8_t, 2> writele16_arr;27WriteLE16(writele16_arr.data(), random_u16);28assert(ReadLE16(writele16_arr.data()) == random_u16);30std::array<uint8_t, 4> writele32_arr;31WriteLE32(writele32_arr.data(), random_u32);32assert(ReadLE32(writele32_arr.data()) == random_u32);34std::array<uint8_t, 8> writele64_arr;35WriteLE64(writele64_arr.data(), random_u64);36assert(ReadLE64(writele64_arr.data()) == random_u64);38std::array<uint8_t, 2> writebe16_arr;39WriteBE16(writebe16_arr.data(), random_u16);40assert(ReadBE16(writebe16_arr.data()) == random_u16);42std::array<uint8_t, 4> writebe32_arr;43WriteBE32(writebe32_arr.data(), random_u32);44assert(ReadBE32(writebe32_arr.data()) == random_u32);46std::array<uint8_t, 8> writebe64_arr;47WriteBE64(writebe64_arr.data(), random_u64);48assert(ReadBE64(writebe64_arr.data()) == random_u64);50const uint16_t readle16_result = ReadLE16(random_bytes_2.data());51std::array<uint8_t, 2> readle16_arr;52WriteLE16(readle16_arr.data(), readle16_result);53assert(std::memcmp(random_bytes_2.data(), readle16_arr.data(), 2) == 0);55const uint32_t readle32_result = ReadLE32(random_bytes_4.data());56std::array<uint8_t, 4> readle32_arr;57WriteLE32(readle32_arr.data(), readle32_result);58assert(std::memcmp(random_bytes_4.data(), readle32_arr.data(), 4) == 0);60const uint64_t readle64_result = ReadLE64(random_bytes_8.data());61std::array<uint8_t, 8> readle64_arr;62WriteLE64(readle64_arr.data(), readle64_result);63assert(std::memcmp(random_bytes_8.data(), readle64_arr.data(), 8) == 0);65const uint32_t readbe32_result = ReadBE32(random_bytes_4.data());66std::array<uint8_t, 4> readbe32_arr;67WriteBE32(readbe32_arr.data(), readbe32_result);68assert(std::memcmp(random_bytes_4.data(), readbe32_arr.data(), 4) == 0);70const uint64_t readbe64_result = ReadBE64(random_bytes_8.data());71std::array<uint8_t, 8> readbe64_arr;72WriteBE64(readbe64_arr.data(), readbe64_result);73assert(std::memcmp(random_bytes_8.data(), readbe64_arr.data(), 8) == 0);74}
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.