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/poly1305.h>6#include <test/fuzz/FuzzedDataProvider.h>7#include <test/fuzz/fuzz.h>8#include <test/fuzz/util.h>10#include <cstdint>11#include <vector>13FUZZ_TARGET(crypto_poly1305)14{15FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};17const auto key = ConsumeFixedLengthByteVector<std::byte>(fuzzed_data_provider, Poly1305::KEYLEN);18const auto in = ConsumeRandomLengthByteVector<std::byte>(fuzzed_data_provider);20std::vector<std::byte> tag_out(Poly1305::TAGLEN);21Poly1305{key}.Update(in).Finalize(tag_out);22}24FUZZ_TARGET(crypto_poly1305_split)25{26FuzzedDataProvider provider{buffer.data(), buffer.size()};28// Read key and instantiate two Poly1305 objects with it.29auto key = provider.ConsumeBytes<std::byte>(Poly1305::KEYLEN);30key.resize(Poly1305::KEYLEN);31Poly1305 poly_full{key}, poly_split{key};33// Vector that holds all bytes processed so far.34std::vector<std::byte> total_input;36// Process input in pieces.37LIMITED_WHILE (provider.remaining_bytes(), 100) {38auto in = ConsumeRandomLengthByteVector<std::byte>(provider);39poly_split.Update(in);40// Update total_input to match what was processed.41total_input.insert(total_input.end(), in.begin(), in.end());42}44// Process entire input at once.45poly_full.Update(total_input);47// Verify both agree.48std::array<std::byte, Poly1305::TAGLEN> tag_split, tag_full;49poly_split.Finalize(tag_split);50poly_full.Finalize(tag_full);51assert(tag_full == tag_split);52}
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.