Bitcoin ABC  0.22.12
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::State &state, 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  while (state.KeepRunning()) {
24  ctx.Crypt(in.data(), out.data(), in.size());
25  }
26 }
27 
28 static void CHACHA20_64BYTES(benchmark::State &state) {
29  CHACHA20(state, BUFFER_SIZE_TINY);
30 }
31 
32 static void CHACHA20_256BYTES(benchmark::State &state) {
34 }
35 
36 static void CHACHA20_1MB(benchmark::State &state) {
38 }
39 
static void CHACHA20(benchmark::State &state, size_t buffersize)
Definition: chacha20.cpp:16
static const uint64_t BUFFER_SIZE_SMALL
Definition: chacha20.cpp:13
secp256k1_context * ctx
static const uint64_t BUFFER_SIZE_LARGE
Definition: chacha20.cpp:14
static void CHACHA20_1MB(benchmark::State &state)
Definition: chacha20.cpp:36
bool KeepRunning()
Definition: bench.h:75
static void CHACHA20_256BYTES(benchmark::State &state)
Definition: chacha20.cpp:32
static void CHACHA20_64BYTES(benchmark::State &state)
Definition: chacha20.cpp:28
A class for ChaCha20 256-bit stream cipher developed by Daniel J.
Definition: chacha20.h:15
static const uint64_t BUFFER_SIZE_TINY
Definition: chacha20.cpp:12
BENCHMARK(CHACHA20_64BYTES, 500000)