Bitcoin ABC  0.26.3
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 
static const uint64_t BUFFER_SIZE_LARGE
Definition: chacha20.cpp:14
BENCHMARK(CHACHA20_64BYTES)
static void CHACHA20_256BYTES(benchmark::Bench &bench)
Definition: chacha20.cpp:31
static void CHACHA20(benchmark::Bench &bench, size_t buffersize)
Definition: chacha20.cpp:16
static const uint64_t BUFFER_SIZE_TINY
Definition: chacha20.cpp:12
static void CHACHA20_1MB(benchmark::Bench &bench)
Definition: chacha20.cpp:35
static void CHACHA20_64BYTES(benchmark::Bench &bench)
Definition: chacha20.cpp:27
static const uint64_t BUFFER_SIZE_SMALL
Definition: chacha20.cpp:13
secp256k1_context * ctx
A class for ChaCha20 256-bit stream cipher developed by Daniel J.
Definition: chacha20.h:15
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
ANKERL_NANOBENCH(NODISCARD) std Bench & batch(T b) noexcept
Sets the batch size.
Bench & unit(char const *unit)
Sets the operation unit.