mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-10 10:52:31 -05:00
![Sebastian Falbesoner](/assets/img/avatar_default.png)
Making the `GenerateRandomKey` helper available to other modules via key.{h.cpp} allows us to create random private keys directly at instantiation of CKey, in contrast to the two-step process of creating the instance and then having to call `MakeNewKey(...)`.
29 lines
978 B
C++
29 lines
978 B
C++
// Copyright (c) 2022-2023 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <bench/bench.h>
|
|
|
|
#include <key.h>
|
|
#include <random.h>
|
|
|
|
static void EllSwiftCreate(benchmark::Bench& bench)
|
|
{
|
|
ECC_Start();
|
|
|
|
CKey key = GenerateRandomKey();
|
|
uint256 entropy = GetRandHash();
|
|
|
|
bench.batch(1).unit("pubkey").run([&] {
|
|
auto ret = key.EllSwiftCreate(MakeByteSpan(entropy));
|
|
/* Use the first 32 bytes of the ellswift encoded public key as next private key. */
|
|
key.Set(UCharCast(ret.data()), UCharCast(ret.data()) + 32, true);
|
|
assert(key.IsValid());
|
|
/* Use the last 32 bytes of the ellswift encoded public key as next entropy. */
|
|
std::copy(ret.begin() + 32, ret.begin() + 64, MakeWritableByteSpan(entropy).begin());
|
|
});
|
|
|
|
ECC_Stop();
|
|
}
|
|
|
|
BENCHMARK(EllSwiftCreate, benchmark::PriorityLevel::HIGH);
|