/ src / bench / ellswift.cpp
ellswift.cpp
 1  // Copyright (c) 2022-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  #include <bench/bench.h>
 6  #include <key.h>
 7  #include <pubkey.h>
 8  #include <random.h>
 9  #include <span.h>
10  #include <uint256.h>
11  
12  #include <algorithm>
13  #include <cassert>
14  
15  static void EllSwiftCreate(benchmark::Bench& bench)
16  {
17      ECC_Context ecc_context{};
18  
19      CKey key = GenerateRandomKey();
20      uint256 entropy = GetRandHash();
21  
22      bench.batch(1).unit("pubkey").run([&] {
23          auto ret = key.EllSwiftCreate(MakeByteSpan(entropy));
24          /* Use the first 32 bytes of the ellswift encoded public key as next private key. */
25          key.Set(ret.data(), ret.data() + 32, true);
26          assert(key.IsValid());
27          /* Use the last 32 bytes of the ellswift encoded public key as next entropy. */
28          std::copy(ret.begin() + 32, ret.begin() + 64, MakeWritableByteSpan(entropy).begin());
29      });
30  }
31  
32  BENCHMARK(EllSwiftCreate);