aboutsummaryrefslogtreecommitdiff
path: root/src/util/perf_crypto_cs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/perf_crypto_cs.c')
-rw-r--r--src/util/perf_crypto_cs.c185
1 files changed, 185 insertions, 0 deletions
diff --git a/src/util/perf_crypto_cs.c b/src/util/perf_crypto_cs.c
new file mode 100644
index 000000000..a8c72052b
--- /dev/null
+++ b/src/util/perf_crypto_cs.c
@@ -0,0 +1,185 @@
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#include "platform.h"
29#include "gnunet_util_lib.h"
30#include <gauger.h>
31
32#define ITER 10
33
34/**
35 * Evaluate Clause Blind Schnorr Signature performance.
36 *
37 */
38static void
39eval ()
40{
41 struct GNUNET_TIME_Absolute start;
42 unsigned int i;
43
44 struct GNUNET_CRYPTO_CsPrivateKey priv;
45 struct GNUNET_CRYPTO_CsPublicKey pub;
46
47 struct GNUNET_CRYPTO_CsRSecret r_priv[2];
48 struct GNUNET_CRYPTO_CsRPublic r_pub[2];
49
50 char message[] = "test message";
51 size_t message_len = strlen ("test message");
52
53 // derive a test nonce
54 struct GNUNET_CRYPTO_CsNonce nonce;
55 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_hkdf (nonce.nonce,
56 sizeof(nonce.nonce),
57 GCRY_MD_SHA512,
58 GCRY_MD_SHA256,
59 "nonce",
60 strlen ("nonce"),
61 "nonce_secret",
62 strlen ("nonce_secret"),
63 NULL,
64 0));
65
66 struct GNUNET_CRYPTO_CsBlindingSecret bs[2];
67 struct GNUNET_CRYPTO_CsC blinded_cs[2];
68 struct GNUNET_CRYPTO_CsRPublic blinded_r_pub[2];
69 struct GNUNET_CRYPTO_CsBlindS blinded_s;
70 struct GNUNET_CRYPTO_CsS signature_scalar;
71 struct GNUNET_CRYPTO_CsSignature sig;
72
73 // BENCHMARK keygen
74 start = GNUNET_TIME_absolute_get ();
75
76 for (i = 0; i < ITER; i++)
77 {
78 GNUNET_CRYPTO_cs_private_key_generate (&priv);
79 GNUNET_CRYPTO_cs_private_key_get_public (&priv, &pub);
80 }
81 printf ("10x key generation took %s\n",
82 GNUNET_STRINGS_relative_time_to_string (
83 GNUNET_TIME_absolute_get_duration (start),
84 GNUNET_YES));
85
86
87 // BENCHMARK r derive and calc R pub
88 start = GNUNET_TIME_absolute_get ();
89 for (i = 0; i < ITER; i++)
90 {
91 GNUNET_CRYPTO_cs_r_derive (&nonce, &priv, r_priv);
92 GNUNET_CRYPTO_cs_r_get_public (&r_priv[0], &r_pub[0]);
93 GNUNET_CRYPTO_cs_r_get_public (&r_priv[1], &r_pub[1]);
94 }
95 printf ("10x r0, r1 derive and R1,R2 calculation took %s\n",
96 GNUNET_STRINGS_relative_time_to_string (
97 GNUNET_TIME_absolute_get_duration (start),
98 GNUNET_YES));
99
100
101 // BENCHMARK derive blinding secrets
102 start = GNUNET_TIME_absolute_get ();
103 for (i = 0; i < ITER; i++)
104 {
105 GNUNET_CRYPTO_cs_blinding_secrets_derive (&nonce,
106 sizeof(struct
107 GNUNET_CRYPTO_CsNonce),
108 bs);
109 }
110 printf ("10x derive blinding secrets took %s\n",
111 GNUNET_STRINGS_relative_time_to_string (
112 GNUNET_TIME_absolute_get_duration (start),
113 GNUNET_YES));
114
115
116 // BENCHMARK calculating C
117 start = GNUNET_TIME_absolute_get ();
118 for (i = 0; i < ITER; i++)
119 {
120 GNUNET_CRYPTO_cs_calc_blinded_c (bs,
121 r_pub,
122 &pub,
123 message,
124 message_len,
125 blinded_cs,
126 blinded_r_pub);
127 }
128 printf ("10x calculating the blinded c took %s\n",
129 GNUNET_STRINGS_relative_time_to_string (
130 GNUNET_TIME_absolute_get_duration (start),
131 GNUNET_YES));
132
133
134 // BENCHMARK sign derive
135 unsigned int b;
136 start = GNUNET_TIME_absolute_get ();
137 for (i = 0; i < ITER; i++)
138 {
139 b = GNUNET_CRYPTO_cs_sign_derive (&priv,
140 r_priv,
141 blinded_cs,
142 &nonce,
143 &blinded_s);
144 }
145 printf ("10x signing blinded c took %s\n",
146 GNUNET_STRINGS_relative_time_to_string (
147 GNUNET_TIME_absolute_get_duration (start),
148 GNUNET_YES));
149
150
151 // BENCHMARK unblind signature
152 start = GNUNET_TIME_absolute_get ();
153
154 for (i = 0; i < ITER; i++)
155 {
156 GNUNET_CRYPTO_cs_unblind (&blinded_s, &bs[b], &signature_scalar);
157 sig.r_point = blinded_r_pub[b];
158 sig.s_scalar = signature_scalar;
159 }
160 printf ("10x unblinding s took %s\n",
161 GNUNET_STRINGS_relative_time_to_string (
162 GNUNET_TIME_absolute_get_duration (start),
163 GNUNET_YES));
164
165 // BENCHMARK verify signature
166 start = GNUNET_TIME_absolute_get ();
167 for (i = 0; i < ITER; i++)
168 {
169 GNUNET_CRYPTO_cs_verify (&sig,
170 &pub,
171 message,
172 message_len);
173 }
174 printf ("10x verifying signatures took %s\n",
175 GNUNET_STRINGS_relative_time_to_string (
176 GNUNET_TIME_absolute_get_duration (start),
177 GNUNET_YES));
178}
179
180int
181main (int argc, char *argv[])
182{
183 eval ();
184 return 0;
185}