Skip to content

Commit 42d759f

Browse files
dhruvPieter Wuille
authored andcommitted
Bench tests for CKey->EllSwift
Co-Authored-By: Pieter Wuille <[email protected]>
1 parent 2e5a8a4 commit 42d759f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/Makefile.bench.include

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ bench_bench_bitcoin_SOURCES = \
2929
bench/data.h \
3030
bench/descriptors.cpp \
3131
bench/duplicate_inputs.cpp \
32+
bench/ellswift.cpp \
3233
bench/examples.cpp \
3334
bench/gcs_filter.cpp \
3435
bench/hashpadding.cpp \

src/bench/ellswift.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2022-2023 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 <bench/bench.h>
6+
7+
#include <key.h>
8+
#include <random.h>
9+
10+
static void EllSwiftCreate(benchmark::Bench& bench)
11+
{
12+
ECC_Start();
13+
14+
CKey key;
15+
key.MakeNewKey(true);
16+
17+
uint256 entropy = GetRandHash();
18+
19+
bench.batch(1).unit("pubkey").run([&] {
20+
auto ret = key.EllSwiftCreate(AsBytes(Span{entropy}));
21+
/* Use the first 32 bytes of the ellswift encoded public key as next private key. */
22+
key.Set(UCharCast(ret.data()), UCharCast(ret.data()) + 32, true);
23+
assert(key.IsValid());
24+
/* Use the last 32 bytes of the ellswift encoded public key as next entropy. */
25+
std::copy(ret.begin() + 32, ret.begin() + 64, AsBytePtr(entropy.data()));
26+
});
27+
28+
ECC_Stop();
29+
}
30+
31+
BENCHMARK(EllSwiftCreate, benchmark::PriorityLevel::HIGH);

0 commit comments

Comments
 (0)