1 // Copyright (c) 2019-2020 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 
6 #include <bench/bench.h>
7 #include <crypto/poly1305.h>
8 
9 /* Number of bytes to process per iteration */
10 static constexpr uint64_t BUFFER_SIZE_TINY  = 64;
11 static constexpr uint64_t BUFFER_SIZE_SMALL = 256;
12 static constexpr uint64_t BUFFER_SIZE_LARGE = 1024*1024;
13 
14 static void POLY1305(benchmark::Bench& bench, size_t buffersize)
15 {
EvictionProtectionCommon(benchmark::Bench & bench,int num_candidates,std::function<void (NodeEvictionCandidate &)> candidate_setup_fn)16     std::vector<unsigned char> tag(POLY1305_TAGLEN, 0);
17     std::vector<unsigned char> key(POLY1305_KEYLEN, 0);
18     std::vector<unsigned char> in(buffersize, 0);
19     bench.batch(in.size()).unit("byte").run([&] {
20         poly1305_auth(tag.data(), in.data(), in.size(), key.data());
21     });
22 }
23 
24 static void POLY1305_64BYTES(benchmark::Bench& bench)
25 {
26     POLY1305(bench, BUFFER_SIZE_TINY);
27 }
28 
29 static void POLY1305_256BYTES(benchmark::Bench& bench)
30 {
31     POLY1305(bench, BUFFER_SIZE_SMALL);
32 }
__anon115adf3f0102null33 
34 static void POLY1305_1MB(benchmark::Bench& bench)
35 {
36     POLY1305(bench, BUFFER_SIZE_LARGE);
37 }
38 
39 BENCHMARK(POLY1305_64BYTES);
40 BENCHMARK(POLY1305_256BYTES);
EvictionProtection0Networks250Candidates(benchmark::Bench & bench)41 BENCHMARK(POLY1305_1MB);
42