2019-03-27 11:46:07 +01:00
|
|
|
// Copyright (c) 2019 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2019-07-18 15:52:17 +02:00
|
|
|
#include <vector>
|
2019-03-27 11:46:07 +01:00
|
|
|
|
|
|
|
#include <bench/bench.h>
|
|
|
|
#include <crypto/poly1305.h>
|
|
|
|
|
|
|
|
/* Number of bytes to process per iteration */
|
|
|
|
static constexpr uint64_t BUFFER_SIZE_TINY = 64;
|
|
|
|
static constexpr uint64_t BUFFER_SIZE_SMALL = 256;
|
|
|
|
static constexpr uint64_t BUFFER_SIZE_LARGE = 1024*1024;
|
|
|
|
|
2021-06-26 12:03:16 +02:00
|
|
|
static void POLY1305(benchmark::Bench& bench, size_t buffersize)
|
2019-03-27 11:46:07 +01:00
|
|
|
{
|
|
|
|
std::vector<unsigned char> tag(POLY1305_TAGLEN, 0);
|
|
|
|
std::vector<unsigned char> key(POLY1305_KEYLEN, 0);
|
|
|
|
std::vector<unsigned char> in(buffersize, 0);
|
2021-06-26 12:03:16 +02:00
|
|
|
bench.batch(in.size()).unit("byte").run([&] {
|
2019-03-27 11:46:07 +01:00
|
|
|
poly1305_auth(tag.data(), in.data(), in.size(), key.data());
|
2021-06-26 12:03:16 +02:00
|
|
|
});
|
2019-03-27 11:46:07 +01:00
|
|
|
}
|
|
|
|
|
2021-06-26 12:03:16 +02:00
|
|
|
static void POLY1305_64BYTES(benchmark::Bench& bench)
|
2019-03-27 11:46:07 +01:00
|
|
|
{
|
2021-06-26 12:03:16 +02:00
|
|
|
POLY1305(bench, BUFFER_SIZE_TINY);
|
2019-03-27 11:46:07 +01:00
|
|
|
}
|
|
|
|
|
2021-06-26 12:03:16 +02:00
|
|
|
static void POLY1305_256BYTES(benchmark::Bench& bench)
|
2019-03-27 11:46:07 +01:00
|
|
|
{
|
2021-06-26 12:03:16 +02:00
|
|
|
POLY1305(bench, BUFFER_SIZE_SMALL);
|
2019-03-27 11:46:07 +01:00
|
|
|
}
|
|
|
|
|
2021-06-26 12:03:16 +02:00
|
|
|
static void POLY1305_1MB(benchmark::Bench& bench)
|
2019-03-27 11:46:07 +01:00
|
|
|
{
|
2021-06-26 12:03:16 +02:00
|
|
|
POLY1305(bench, BUFFER_SIZE_LARGE);
|
2019-03-27 11:46:07 +01:00
|
|
|
}
|
|
|
|
|
2021-06-26 12:03:16 +02:00
|
|
|
BENCHMARK(POLY1305_64BYTES);
|
|
|
|
BENCHMARK(POLY1305_256BYTES);
|
|
|
|
BENCHMARK(POLY1305_1MB);
|