Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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 */
12static const uint64_t BUFFER_SIZE_TINY = 64;
13static const uint64_t BUFFER_SIZE_SMALL = 256;
14static const uint64_t BUFFER_SIZE_LARGE = 1024 * 1024;
15
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
30
34
38
#define BENCHMARK(n)
Definition bench.h:65
static const uint64_t BUFFER_SIZE_LARGE
Definition chacha20.cpp:14
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
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85