1
1
#include < benchmark/benchmark.h>
2
2
3
- #include " facade_helper.hpp"
4
- #include " sha512.h"
3
+ #include " ed25519.h"
5
4
6
5
std::string random_str (size_t size) {
7
6
unsigned int SEED = 1337 ;
@@ -13,22 +12,22 @@ std::string random_str(size_t size) {
13
12
return s;
14
13
}
15
14
16
- static void SignMsg (benchmark::State &state) {
15
+ static void Sign (benchmark::State &state) {
17
16
std::string msg;
18
- private_key_t priv;
19
- public_key_t pub;
20
- signature_t sig;
17
+ private_key_t priv{} ;
18
+ public_key_t pub{} ;
19
+ signature_t sig{} ;
21
20
22
21
// use the same keypair for all signing operations
23
- ed25519_create_keypair (pub, priv );
22
+ ed25519_create_keypair (&priv, &pub );
24
23
25
24
for (auto _ : state) {
26
25
state.PauseTiming ();
27
26
msg = random_str (state.range (0 ));
28
27
state.ResumeTiming ();
29
28
30
- ed25519_sign (sig, reinterpret_cast <const unsigned char *>(msg.data ()),
31
- msg.size (), pub, priv);
29
+ ed25519_sign (& sig, reinterpret_cast <const unsigned char *>(msg.data ()),
30
+ msg.size (), & pub, & priv);
32
31
}
33
32
}
34
33
@@ -39,13 +38,13 @@ static void VerifyCorrectSig(benchmark::State &state) {
39
38
signature_t sig;
40
39
41
40
// use the same keypair for all signing operations
42
- ed25519_create_keypair (pub, priv );
43
- ed25519_sign (sig, reinterpret_cast <const unsigned char *>(msg.data ()),
44
- msg.size (), pub, priv);
41
+ ed25519_create_keypair (&priv, &pub );
42
+ ed25519_sign (& sig, reinterpret_cast <const unsigned char *>(msg.data ()),
43
+ msg.size (), & pub, & priv);
45
44
46
45
for (auto _ : state) {
47
- ed25519_verify (sig, reinterpret_cast <const unsigned char *>(msg.data ()),
48
- msg.size (), pub);
46
+ ed25519_verify (& sig, reinterpret_cast <const unsigned char *>(msg.data ()),
47
+ msg.size (), & pub);
49
48
}
50
49
}
51
50
@@ -56,16 +55,16 @@ static void VerifyIncorrectSig(benchmark::State &state) {
56
55
signature_t sig;
57
56
58
57
// use the same keypair for all signing operations
59
- ed25519_create_keypair (pub, priv );
60
- ed25519_sign (sig, reinterpret_cast <const unsigned char *>(msg.data ()),
61
- msg.size (), pub, priv);
58
+ ed25519_create_keypair (&priv, &pub );
59
+ ed25519_sign (& sig, reinterpret_cast <const unsigned char *>(msg.data ()),
60
+ msg.size (), & pub, & priv);
62
61
// intentionally break the signature
63
- sig[0 ] = 0 ;
64
- sig[1 ] = 1 ;
62
+ sig. data [0 ] = 0 ;
63
+ sig. data [1 ] = 1 ;
65
64
66
65
for (auto _ : state) {
67
- ed25519_verify (sig, reinterpret_cast <const unsigned char *>(msg.data ()),
68
- msg.size (), pub);
66
+ ed25519_verify (& sig, reinterpret_cast <const unsigned char *>(msg.data ()),
67
+ msg.size (), & pub);
69
68
}
70
69
}
71
70
@@ -74,11 +73,26 @@ static void GenerateKeypair(benchmark::State &state) {
74
73
public_key_t pub;
75
74
76
75
for (auto _ : state) {
77
- ed25519_create_keypair (pub, priv);
76
+ ed25519_create_keypair (&priv, &pub);
77
+ }
78
+ }
79
+
80
+ static void SHA512 (benchmark::State &state) {
81
+ unsigned char hash[SHA_512_SIZE];
82
+ std::string msg;
83
+
84
+ for (auto _ : state) {
85
+ state.PauseTiming ();
86
+ msg = random_str (state.range (0 ));
87
+ state.ResumeTiming ();
88
+
89
+ sha512 (hash, reinterpret_cast <const unsigned char *>(msg.data ()),
90
+ msg.size ());
78
91
}
79
92
}
80
93
81
- BENCHMARK (SignMsg)->RangeMultiplier(10 )->Range(1 , 1000000 );
94
+ BENCHMARK (Sign)->RangeMultiplier(10 )->Range(1 , 1000000 );
95
+ BENCHMARK (SHA512)->RangeMultiplier(10 )->Range(1 , 1000000 );
82
96
BENCHMARK (VerifyCorrectSig);
83
97
BENCHMARK (VerifyIncorrectSig);
84
98
BENCHMARK (GenerateKeypair);
0 commit comments