Bitcoin Core  24.99.0
P2P Digital Currency
chacha20.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2022 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/chacha20.h>
8 
9 /* Number of bytes to process per iteration */
10 static const uint64_t BUFFER_SIZE_TINY = 64;
11 static const uint64_t BUFFER_SIZE_SMALL = 256;
12 static const uint64_t BUFFER_SIZE_LARGE = 1024*1024;
13 
14 static void CHACHA20(benchmark::Bench& bench, size_t buffersize)
15 {
16  std::vector<uint8_t> key(32,0);
17  ChaCha20 ctx(key.data());
18  ctx.SetIV(0);
19  ctx.Seek64(0);
20  std::vector<uint8_t> in(buffersize,0);
21  std::vector<uint8_t> out(buffersize,0);
22  bench.batch(in.size()).unit("byte").run([&] {
23  ctx.Crypt(in.data(), out.data(), in.size());
24  });
25 }
26 
28 {
29  CHACHA20(bench, BUFFER_SIZE_TINY);
30 }
31 
33 {
35 }
36 
37 static void CHACHA20_1MB(benchmark::Bench& bench)
38 {
40 }
41 
static const uint64_t BUFFER_SIZE_LARGE
Definition: chacha20.cpp:12
BENCHMARK(CHACHA20_64BYTES, benchmark::PriorityLevel::HIGH)
static void CHACHA20_256BYTES(benchmark::Bench &bench)
Definition: chacha20.cpp:32
static void CHACHA20(benchmark::Bench &bench, size_t buffersize)
Definition: chacha20.cpp:14
static const uint64_t BUFFER_SIZE_TINY
Definition: chacha20.cpp:10
static void CHACHA20_1MB(benchmark::Bench &bench)
Definition: chacha20.cpp:37
static void CHACHA20_64BYTES(benchmark::Bench &bench)
Definition: chacha20.cpp:27
static const uint64_t BUFFER_SIZE_SMALL
Definition: chacha20.cpp:11
Unrestricted ChaCha20 cipher.
Definition: chacha20.h:46
void SetIV(uint64_t iv)
set the 64-bit nonce.
Definition: chacha20.h:66
void Seek64(uint64_t pos)
set the 64bit block counter (pos seeks to byte position 64*pos).
Definition: chacha20.h:69
void Crypt(const unsigned char *input, unsigned char *output, size_t bytes)
enciphers the message <input> of length <bytes> and write the enciphered representation into <output>...
Definition: chacha20.cpp:297
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:623
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1230
Bench & batch(T b) noexcept
Sets the batch size.
Definition: nanobench.h:1254
Bench & unit(char const *unit)
Sets the operation unit.
@ HIGH
Definition: bench.h:47