Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

ecdsa.cpp
Go to the documentation of this file.
1 // Copyright (c) 2018 The Dash 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 
9 static void ECDSASign(benchmark::State& state)
10 {
11  std::vector<CKey> keys;
12  std::vector<uint256> hashes;
13  for (size_t i = 0; i < 100; i++) {
14  CKey k;
15  k.MakeNewKey(false);
16  keys.emplace_back(k);
17  hashes.emplace_back(::SerializeHash((int)i));
18  }
19 
20  // Benchmark.
21  size_t i = 0;
22  while (state.KeepRunning()) {
23  std::vector<unsigned char> sig;
24  keys[i].Sign(hashes[i], sig);
25  i = (i + 1) % keys.size();
26  }
27 }
28 
29 static void ECDSAVerify(benchmark::State& state)
30 {
31  std::vector<CPubKey> keys;
32  std::vector<uint256> hashes;
33  std::vector<std::vector<unsigned char>> sigs;
34  for (size_t i = 0; i < 100; i++) {
35  CKey k;
36  k.MakeNewKey(false);
37  keys.emplace_back(k.GetPubKey());
38  hashes.emplace_back(::SerializeHash((int)i));
39  std::vector<unsigned char> sig;
40  k.Sign(hashes[i], sig);
41  sigs.emplace_back(sig);
42  }
43 
44  // Benchmark.
45  size_t i = 0;
46  while (state.KeepRunning()) {
47  keys[i].Verify(hashes[i], sigs[i]);
48  i = (i + 1) % keys.size();
49  }
50 }
51 
53 {
54  std::vector<CPubKey> keys;
55  std::vector<uint256> hashes;
56  std::vector<std::vector<unsigned char>> sigs;
57  for (size_t i = 0; i < 1000; i++) {
58  CKey k;
59  k.MakeNewKey(false);
60  keys.emplace_back(k.GetPubKey());
61  hashes.emplace_back(::SerializeHash((int)i));
62  std::vector<unsigned char> sig;
63  k.Sign(hashes[i], sig);
64  sigs.emplace_back(sig);
65  }
66 
67  // Benchmark.
68  while (state.KeepRunning()) {
69  for (size_t i = 0; i < keys.size(); i++) {
70  keys[i].Verify(hashes[i], sigs[i]);
71  }
72  }
73 }
74 
#define BENCHMARK(n)
Definition: bench.h:92
CPubKey GetPubKey() const
Compute the public key from a private key.
Definition: key.cpp:179
bool KeepRunning()
Definition: bench.cpp:39
bool Sign(const uint256 &hash, std::vector< unsigned char > &vchSig, uint32_t test_case=0) const
Create a DER-serialized signature.
Definition: key.cpp:192
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
Compute the 256-bit hash of an object&#39;s serialization.
Definition: hash.h:254
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
Definition: key.cpp:158
static void ECDSAVerify_LargeBlock(benchmark::State &state)
Definition: ecdsa.cpp:52
static void ECDSAVerify(benchmark::State &state)
Definition: ecdsa.cpp:29
An encapsulated private key.
Definition: key.h:27
static void ECDSASign(benchmark::State &state)
Definition: ecdsa.cpp:9
Released under the MIT license