Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
chacha20.cpp
Go to the documentation of this file.
1
// Copyright (c) 2019-present 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
#include <
crypto/chacha20poly1305.h
>
9
#include <
span.h
>
10
11
#include <cstddef>
12
#include <cstdint>
13
#include <vector>
14
15
/* Number of bytes to process per iteration */
16
static
const
uint64_t
BUFFER_SIZE_TINY
= 64;
17
static
const
uint64_t
BUFFER_SIZE_SMALL
= 256;
18
static
const
uint64_t
BUFFER_SIZE_LARGE
= 1024*1024;
19
20
static
void
CHACHA20
(
benchmark::Bench
& bench,
size_t
buffersize)
21
{
22
std::vector<std::byte> key(32, {});
23
ChaCha20
ctx(key);
24
ctx.Seek({0, 0}, 0);
25
std::vector<std::byte> in(buffersize, {});
26
std::vector<std::byte> out(buffersize, {});
27
bench.
batch
(in.size()).
unit
(
"byte"
).
run
([&] {
28
ctx.Crypt(in, out);
29
});
30
}
31
32
static
void
FSCHACHA20POLY1305
(
benchmark::Bench
& bench,
size_t
buffersize)
33
{
34
std::vector<std::byte> key(32);
35
FSChaCha20Poly1305
ctx(key, 224);
36
std::vector<std::byte> in(buffersize);
37
std::vector<std::byte> aad;
38
std::vector<std::byte> out(buffersize +
FSChaCha20Poly1305::EXPANSION
);
39
bench.
batch
(in.size()).
unit
(
"byte"
).
run
([&] {
40
ctx.
Encrypt
(in, aad, out);
41
});
42
}
43
44
static
void
CHACHA20_64BYTES
(
benchmark::Bench
& bench)
45
{
46
CHACHA20
(bench,
BUFFER_SIZE_TINY
);
47
}
48
49
static
void
CHACHA20_256BYTES
(
benchmark::Bench
& bench)
50
{
51
CHACHA20
(bench,
BUFFER_SIZE_SMALL
);
52
}
53
54
static
void
CHACHA20_1MB
(
benchmark::Bench
& bench)
55
{
56
CHACHA20
(bench,
BUFFER_SIZE_LARGE
);
57
}
58
59
static
void
FSCHACHA20POLY1305_64BYTES
(
benchmark::Bench
& bench)
60
{
61
FSCHACHA20POLY1305
(bench,
BUFFER_SIZE_TINY
);
62
}
63
64
static
void
FSCHACHA20POLY1305_256BYTES
(
benchmark::Bench
& bench)
65
{
66
FSCHACHA20POLY1305
(bench,
BUFFER_SIZE_SMALL
);
67
}
68
69
static
void
FSCHACHA20POLY1305_1MB
(
benchmark::Bench
& bench)
70
{
71
FSCHACHA20POLY1305
(bench,
BUFFER_SIZE_LARGE
);
72
}
73
74
BENCHMARK
(
CHACHA20_64BYTES
);
75
BENCHMARK
(
CHACHA20_256BYTES
);
76
BENCHMARK
(
CHACHA20_1MB
);
77
BENCHMARK
(
FSCHACHA20POLY1305_64BYTES
);
78
BENCHMARK
(
FSCHACHA20POLY1305_256BYTES
);
79
BENCHMARK
(
FSCHACHA20POLY1305_1MB
);
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:68
BUFFER_SIZE_LARGE
static const uint64_t BUFFER_SIZE_LARGE
Definition
chacha20.cpp:18
FSCHACHA20POLY1305
static void FSCHACHA20POLY1305(benchmark::Bench &bench, size_t buffersize)
Definition
chacha20.cpp:32
CHACHA20_256BYTES
static void CHACHA20_256BYTES(benchmark::Bench &bench)
Definition
chacha20.cpp:49
CHACHA20
static void CHACHA20(benchmark::Bench &bench, size_t buffersize)
Definition
chacha20.cpp:20
BUFFER_SIZE_TINY
static const uint64_t BUFFER_SIZE_TINY
Definition
chacha20.cpp:16
CHACHA20_1MB
static void CHACHA20_1MB(benchmark::Bench &bench)
Definition
chacha20.cpp:54
CHACHA20_64BYTES
static void CHACHA20_64BYTES(benchmark::Bench &bench)
Definition
chacha20.cpp:44
FSCHACHA20POLY1305_64BYTES
static void FSCHACHA20POLY1305_64BYTES(benchmark::Bench &bench)
Definition
chacha20.cpp:59
BUFFER_SIZE_SMALL
static const uint64_t BUFFER_SIZE_SMALL
Definition
chacha20.cpp:17
FSCHACHA20POLY1305_1MB
static void FSCHACHA20POLY1305_1MB(benchmark::Bench &bench)
Definition
chacha20.cpp:69
FSCHACHA20POLY1305_256BYTES
static void FSCHACHA20POLY1305_256BYTES(benchmark::Bench &bench)
Definition
chacha20.cpp:64
chacha20.h
chacha20poly1305.h
ChaCha20
Unrestricted ChaCha20 cipher.
Definition
chacha20.h:76
FSChaCha20Poly1305
Forward-secure wrapper around AEADChaCha20Poly1305.
Definition
chacha20poly1305.h:83
FSChaCha20Poly1305::Encrypt
void Encrypt(std::span< const std::byte > plain, std::span< const std::byte > aad, std::span< std::byte > cipher) noexcept
Encrypt a message with a specified aad.
Definition
chacha20poly1305.h:121
FSChaCha20Poly1305::EXPANSION
static constexpr auto EXPANSION
Expansion when encrypting.
Definition
chacha20poly1305.h:105
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:627
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1234
ankerl::nanobench::Bench::batch
Bench & batch(T b) noexcept
Sets the batch size.
Definition
nanobench.h:1258
ankerl::nanobench::Bench::unit
Bench & unit(char const *unit)
Sets the operation unit.
span.h
Generated on
for Bitcoin Core by
1.17.0