Bitcoin ABC  0.24.10
P2P Digital Currency
chacha20.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019 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 <iostream>
6 
7 #include <bench/bench.h>
8 #include <crypto/chacha20.h>
9 #include <hash.h>
10 
11 /* Number of bytes to process per iteration */
12 static const uint64_t BUFFER_SIZE_TINY = 64;
13 static const uint64_t BUFFER_SIZE_SMALL = 256;
14 static const uint64_t BUFFER_SIZE_LARGE = 1024 * 1024;
15 
16 static void CHACHA20(benchmark::Bench &bench, size_t buffersize) {
17  std::vector<uint8_t> key(32, 0);
18  ChaCha20 ctx(key.data(), key.size());
19  ctx.SetIV(0);
20  ctx.Seek(0);
21  std::vector<uint8_t> in(buffersize, 0);
22  std::vector<uint8_t> out(buffersize, 0);
23  bench.batch(in.size()).unit("byte").run(
24  [&] { ctx.Crypt(in.data(), out.data(), in.size()); });
25 }
26 
27 static void CHACHA20_64BYTES(benchmark::Bench &bench) {
28  CHACHA20(bench, BUFFER_SIZE_TINY);
29 }
30 
31 static void CHACHA20_256BYTES(benchmark::Bench &bench) {
33 }
34 
35 static void CHACHA20_1MB(benchmark::Bench &bench) {
37 }
38 
ankerl::nanobench::Bench::batch
ANKERL_NANOBENCH(NODISCARD) std Bench & batch(T b) noexcept
Sets the batch size.
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:583
chacha20.h
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1134
ankerl::nanobench::Bench::unit
Bench & unit(char const *unit)
Sets the operation unit.
CHACHA20_256BYTES
static void CHACHA20_256BYTES(benchmark::Bench &bench)
Definition: chacha20.cpp:31
CHACHA20_1MB
static void CHACHA20_1MB(benchmark::Bench &bench)
Definition: chacha20.cpp:35
BUFFER_SIZE_LARGE
static const uint64_t BUFFER_SIZE_LARGE
Definition: chacha20.cpp:14
bench.h
ctx
secp256k1_context * ctx
Definition: bench_multiset.c:12
BENCHMARK
BENCHMARK(CHACHA20_64BYTES)
CHACHA20_64BYTES
static void CHACHA20_64BYTES(benchmark::Bench &bench)
Definition: chacha20.cpp:27
BUFFER_SIZE_TINY
static const uint64_t BUFFER_SIZE_TINY
Definition: chacha20.cpp:12
ChaCha20
A class for ChaCha20 256-bit stream cipher developed by Daniel J.
Definition: chacha20.h:15
CHACHA20
static void CHACHA20(benchmark::Bench &bench, size_t buffersize)
Definition: chacha20.cpp:16
BUFFER_SIZE_SMALL
static const uint64_t BUFFER_SIZE_SMALL
Definition: chacha20.cpp:13