Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
crypto_poly1305.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <crypto/poly1305.h>
7#include <test/fuzz/fuzz.h>
8#include <test/fuzz/util.h>
9
10#include <cstdint>
11#include <vector>
12
23
25{
26 FuzzedDataProvider provider{buffer.data(), buffer.size()};
27
28 // Read key and instantiate two Poly1305 objects with it.
29 auto key = provider.ConsumeBytes<std::byte>(Poly1305::KEYLEN);
30 key.resize(Poly1305::KEYLEN);
31 Poly1305 poly_full{key}, poly_split{key};
32
33 // Vector that holds all bytes processed so far.
34 std::vector<std::byte> total_input;
35
36 // Process input in pieces.
37 LIMITED_WHILE(provider.remaining_bytes(), 100) {
39 poly_split.Update(in);
40 // Update total_input to match what was processed.
41 total_input.insert(total_input.end(), in.begin(), in.end());
42 }
43
44 // Process entire input at once.
45 poly_full.Update(total_input);
46
47 // Verify both agree.
48 std::array<std::byte, Poly1305::TAGLEN> tag_split, tag_full;
49 poly_split.Finalize(tag_split);
50 poly_full.Finalize(tag_full);
52}
std::vector< T > ConsumeBytes(size_t num_bytes)
C++ wrapper with std::byte span interface around poly1305_donna code.
Definition poly1305.h:39
void Finalize(std::span< std::byte > out) noexcept
Write authentication tag to 16-byte out.
Definition poly1305.h:64
Poly1305 & Update(std::span< const std::byte > msg) noexcept
Process message bytes.
Definition poly1305.h:57
static constexpr unsigned KEYLEN
Length of the keys expected by the constructor.
Definition poly1305.h:47
static constexpr unsigned TAGLEN
Length of the output produced by Finalize().
Definition poly1305.h:44
#define FUZZ_TARGET(...)
Definition fuzz.h:35
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition fuzz.h:22
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:73
assert(!tx.IsCoinBase())
FuzzedDataProvider & fuzzed_data_provider
Definition fees.cpp:38