diff options
Diffstat (limited to 'src/lib/util/perf_crypto_cs.c')
-rw-r--r-- | src/lib/util/perf_crypto_cs.c | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/src/lib/util/perf_crypto_cs.c b/src/lib/util/perf_crypto_cs.c new file mode 100644 index 000000000..43f32aae0 --- /dev/null +++ b/src/lib/util/perf_crypto_cs.c | |||
@@ -0,0 +1,184 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2014 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @author Lucien Heuzeveldt <lucienclaude.heuzeveldt@students.bfh.ch> | ||
23 | * @author Gian Demarmels <gian@demarmels.org> | ||
24 | * @file util/perf_crypto_cs.c | ||
25 | * @brief measure performance of Clause Blind Schnorr Signatures | ||
26 | */ | ||
27 | |||
28 | |||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include <gauger.h> | ||
32 | |||
33 | #define ITER 10 | ||
34 | |||
35 | /** | ||
36 | * Evaluate Clause Blind Schnorr Signature performance. | ||
37 | * | ||
38 | */ | ||
39 | static void | ||
40 | eval () | ||
41 | { | ||
42 | struct GNUNET_TIME_Absolute start; | ||
43 | unsigned int i; | ||
44 | |||
45 | struct GNUNET_CRYPTO_CsPrivateKey priv; | ||
46 | struct GNUNET_CRYPTO_CsPublicKey pub; | ||
47 | |||
48 | struct GNUNET_CRYPTO_CsRSecret r_priv[2]; | ||
49 | struct GNUNET_CRYPTO_CsRPublic r_pub[2]; | ||
50 | |||
51 | char message[] = "test message"; | ||
52 | size_t message_len = strlen ("test message"); | ||
53 | |||
54 | // derive a test nonce | ||
55 | struct GNUNET_CRYPTO_CsNonce nonce; | ||
56 | GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_hkdf (nonce.nonce, | ||
57 | sizeof(nonce.nonce), | ||
58 | GCRY_MD_SHA512, | ||
59 | GCRY_MD_SHA256, | ||
60 | "nonce", | ||
61 | strlen ("nonce"), | ||
62 | "nonce_secret", | ||
63 | strlen ("nonce_secret"), | ||
64 | NULL, | ||
65 | 0)); | ||
66 | |||
67 | struct GNUNET_CRYPTO_CsBlindingSecret bs[2]; | ||
68 | struct GNUNET_CRYPTO_CsC blinded_cs[2]; | ||
69 | struct GNUNET_CRYPTO_CsRPublic blinded_r_pub[2]; | ||
70 | struct GNUNET_CRYPTO_CsBlindS blinded_s; | ||
71 | struct GNUNET_CRYPTO_CsS signature_scalar; | ||
72 | struct GNUNET_CRYPTO_CsSignature sig; | ||
73 | |||
74 | // BENCHMARK keygen | ||
75 | start = GNUNET_TIME_absolute_get (); | ||
76 | |||
77 | for (i = 0; i < ITER; i++) | ||
78 | { | ||
79 | GNUNET_CRYPTO_cs_private_key_generate (&priv); | ||
80 | GNUNET_CRYPTO_cs_private_key_get_public (&priv, &pub); | ||
81 | } | ||
82 | printf ("10x key generation took %s\n", | ||
83 | GNUNET_STRINGS_relative_time_to_string ( | ||
84 | GNUNET_TIME_absolute_get_duration (start), | ||
85 | GNUNET_YES)); | ||
86 | |||
87 | |||
88 | // BENCHMARK r derive and calc R pub | ||
89 | start = GNUNET_TIME_absolute_get (); | ||
90 | for (i = 0; i < ITER; i++) | ||
91 | { | ||
92 | GNUNET_CRYPTO_cs_r_derive (&nonce, &priv, r_priv); | ||
93 | GNUNET_CRYPTO_cs_r_get_public (&r_priv[0], &r_pub[0]); | ||
94 | GNUNET_CRYPTO_cs_r_get_public (&r_priv[1], &r_pub[1]); | ||
95 | } | ||
96 | printf ("10x r0, r1 derive and R1,R2 calculation took %s\n", | ||
97 | GNUNET_STRINGS_relative_time_to_string ( | ||
98 | GNUNET_TIME_absolute_get_duration (start), | ||
99 | GNUNET_YES)); | ||
100 | |||
101 | |||
102 | // BENCHMARK derive blinding secrets | ||
103 | start = GNUNET_TIME_absolute_get (); | ||
104 | for (i = 0; i < ITER; i++) | ||
105 | { | ||
106 | GNUNET_CRYPTO_cs_blinding_secrets_derive (&nonce, | ||
107 | bs); | ||
108 | } | ||
109 | printf ("10x derive blinding secrets took %s\n", | ||
110 | GNUNET_STRINGS_relative_time_to_string ( | ||
111 | GNUNET_TIME_absolute_get_duration (start), | ||
112 | GNUNET_YES)); | ||
113 | |||
114 | |||
115 | // BENCHMARK calculating C | ||
116 | start = GNUNET_TIME_absolute_get (); | ||
117 | for (i = 0; i < ITER; i++) | ||
118 | { | ||
119 | GNUNET_CRYPTO_cs_calc_blinded_c (bs, | ||
120 | r_pub, | ||
121 | &pub, | ||
122 | message, | ||
123 | message_len, | ||
124 | blinded_cs, | ||
125 | blinded_r_pub); | ||
126 | } | ||
127 | printf ("10x calculating the blinded c took %s\n", | ||
128 | GNUNET_STRINGS_relative_time_to_string ( | ||
129 | GNUNET_TIME_absolute_get_duration (start), | ||
130 | GNUNET_YES)); | ||
131 | |||
132 | |||
133 | // BENCHMARK sign derive | ||
134 | unsigned int b; | ||
135 | start = GNUNET_TIME_absolute_get (); | ||
136 | for (i = 0; i < ITER; i++) | ||
137 | { | ||
138 | b = GNUNET_CRYPTO_cs_sign_derive (&priv, | ||
139 | r_priv, | ||
140 | blinded_cs, | ||
141 | &nonce, | ||
142 | &blinded_s); | ||
143 | } | ||
144 | printf ("10x signing blinded c took %s\n", | ||
145 | GNUNET_STRINGS_relative_time_to_string ( | ||
146 | GNUNET_TIME_absolute_get_duration (start), | ||
147 | GNUNET_YES)); | ||
148 | |||
149 | |||
150 | // BENCHMARK unblind signature | ||
151 | start = GNUNET_TIME_absolute_get (); | ||
152 | |||
153 | for (i = 0; i < ITER; i++) | ||
154 | { | ||
155 | GNUNET_CRYPTO_cs_unblind (&blinded_s, &bs[b], &signature_scalar); | ||
156 | sig.r_point = blinded_r_pub[b]; | ||
157 | sig.s_scalar = signature_scalar; | ||
158 | } | ||
159 | printf ("10x unblinding s took %s\n", | ||
160 | GNUNET_STRINGS_relative_time_to_string ( | ||
161 | GNUNET_TIME_absolute_get_duration (start), | ||
162 | GNUNET_YES)); | ||
163 | |||
164 | // BENCHMARK verify signature | ||
165 | start = GNUNET_TIME_absolute_get (); | ||
166 | for (i = 0; i < ITER; i++) | ||
167 | { | ||
168 | GNUNET_CRYPTO_cs_verify (&sig, | ||
169 | &pub, | ||
170 | message, | ||
171 | message_len); | ||
172 | } | ||
173 | printf ("10x verifying signatures took %s\n", | ||
174 | GNUNET_STRINGS_relative_time_to_string ( | ||
175 | GNUNET_TIME_absolute_get_duration (start), | ||
176 | GNUNET_YES)); | ||
177 | } | ||
178 | |||
179 | int | ||
180 | main (int argc, char *argv[]) | ||
181 | { | ||
182 | eval (); | ||
183 | return 0; | ||
184 | } | ||