Bitcoin Core 31.99.0
P2P Digital Currency
poly1305.cpp
Go to the documentation of this file.
1// Copyright (c) 2019-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 <bench/bench.h>
6#include <crypto/poly1305.h>
7// IWYU incorrectly suggests removing this header.
8// See https://github.com/include-what-you-use/include-what-you-use/issues/2014.
9#include <util/byte_units.h> // IWYU pragma: keep
10
11#include <cstddef>
12#include <cstdint>
13#include <span>
14#include <vector>
15
16/* Number of bytes to process per iteration */
17static constexpr uint64_t BUFFER_SIZE_TINY = 64;
18static constexpr uint64_t BUFFER_SIZE_SMALL = 256;
19static constexpr uint64_t BUFFER_SIZE_LARGE{1_MiB};
20
21static void POLY1305(benchmark::Bench& bench, size_t buffersize)
22{
23 std::vector<std::byte> tag(Poly1305::TAGLEN, {});
24 std::vector<std::byte> key(Poly1305::KEYLEN, {});
25 std::vector<std::byte> in(buffersize, {});
26 bench.batch(in.size()).unit("byte").run([&] {
27 Poly1305{key}.Update(in).Finalize(tag);
28 });
29}
30
32{
34}
35
37{
39}
40
41static void POLY1305_1MB(benchmark::Bench& bench)
42{
44}
45
static constexpr uint64_t BUFFER_SIZE_LARGE
Definition: poly1305.cpp:19
static constexpr uint64_t BUFFER_SIZE_TINY
Definition: poly1305.cpp:17
BENCHMARK(POLY1305_64BYTES)
static constexpr uint64_t BUFFER_SIZE_SMALL
Definition: poly1305.cpp:18
static void POLY1305_256BYTES(benchmark::Bench &bench)
Definition: poly1305.cpp:36
static void POLY1305(benchmark::Bench &bench, size_t buffersize)
Definition: poly1305.cpp:21
static void POLY1305_64BYTES(benchmark::Bench &bench)
Definition: poly1305.cpp:31
static void POLY1305_1MB(benchmark::Bench &bench)
Definition: poly1305.cpp:41
C++ wrapper with std::byte span interface around poly1305_donna code.
Definition: poly1305.h:39
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
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:649
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1308
Bench & batch(T b) noexcept
Sets the batch size.
Definition: nanobench.h:1332
Bench & unit(char const *unit)
Sets the operation unit.