aboutsummaryrefslogtreecommitdiff
path: root/src/util/perf_crypto_rsa.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/perf_crypto_rsa.c')
-rw-r--r--src/util/perf_crypto_rsa.c211
1 files changed, 0 insertions, 211 deletions
diff --git a/src/util/perf_crypto_rsa.c b/src/util/perf_crypto_rsa.c
deleted file mode 100644
index aba61786f..000000000
--- a/src/util/perf_crypto_rsa.c
+++ /dev/null
@@ -1,211 +0,0 @@
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 Christian Grothoff
23 * @file util/perf_crypto_rsa.c
24 * @brief measure performance of RSA signing
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include <gauger.h>
29
30
31/**
32 * Evaluate RSA performance.
33 *
34 * @param len keylength to evaluate with
35 */
36static void
37eval (unsigned int len)
38{
39 struct GNUNET_TIME_Absolute start;
40 struct GNUNET_CRYPTO_RsaSignature *sig;
41 struct GNUNET_CRYPTO_RsaSignature *rsig;
42 struct GNUNET_CRYPTO_RsaPublicKey *public_key;
43 struct GNUNET_CRYPTO_RsaPrivateKey *private_key;
44 struct GNUNET_CRYPTO_RsaBlindingKeySecret bsec[10];
45 unsigned int i;
46 char sbuf[128];
47 void *bbuf;
48 size_t bbuf_len;
49 struct GNUNET_HashCode hc;
50
51 start = GNUNET_TIME_absolute_get ();
52 for (i = 0; i < 10; i++)
53 {
54 private_key = GNUNET_CRYPTO_rsa_private_key_create (len);
55 GNUNET_CRYPTO_rsa_private_key_free (private_key);
56 }
57 printf ("10x %u-key generation took %s\n",
58 len,
59 GNUNET_STRINGS_relative_time_to_string (
60 GNUNET_TIME_absolute_get_duration (start),
61 GNUNET_YES));
62 GNUNET_snprintf (sbuf,
63 sizeof(sbuf),
64 "RSA %u-key generation",
65 len);
66 GAUGER ("UTIL", sbuf,
67 64 * 1024 / (1
68 + GNUNET_TIME_absolute_get_duration
69 (start).rel_value_us / 1000LL), "keys/ms");
70 private_key = GNUNET_CRYPTO_rsa_private_key_create (len);
71 public_key = GNUNET_CRYPTO_rsa_private_key_get_public (private_key);
72 for (i = 0; i < 10; i++)
73 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
74 &bsec[i], sizeof(bsec[0]));
75 /*
76 start = GNUNET_TIME_absolute_get ();
77 for (i=0;i<10;i++)
78 rsa_blinding_key_derive(public_key, &bsec[i]);
79 printf ("10x %u-blinding key generation took %s\n",
80 len,
81 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
82 GNUNET_YES));
83 GNUNET_snprintf (sbuf,
84 sizeof (sbuf),
85 "RSA %u-blinding key generation",
86 len);
87 GAUGER ("UTIL", sbuf,
88 64 * 1024 / (1 +
89 GNUNET_TIME_absolute_get_duration
90 (start).rel_value_us / 1000LL), "keys/ms");
91 */
92 start = GNUNET_TIME_absolute_get ();
93 GNUNET_CRYPTO_hash ("test", 4, &hc);
94 for (i = 0; i < 10; i++)
95 {
96 GNUNET_CRYPTO_rsa_blind (&hc,
97 &bsec[i],
98 public_key,
99 &bbuf,
100 &bbuf_len);
101 GNUNET_free (bbuf);
102 }
103 printf ("10x %u-blinding took %s\n",
104 len,
105 GNUNET_STRINGS_relative_time_to_string (
106 GNUNET_TIME_absolute_get_duration (start),
107 GNUNET_YES));
108 GNUNET_snprintf (sbuf,
109 sizeof(sbuf),
110 "RSA %u-blinding",
111 len);
112 GAUGER ("UTIL",
113 sbuf,
114 64 * 1024 / (1
115 + GNUNET_TIME_absolute_get_duration
116 (start).rel_value_us / 1000LL), "ops/ms");
117 GNUNET_CRYPTO_rsa_blind (&hc,
118 &bsec[0],
119 public_key,
120 &bbuf,
121 &bbuf_len);
122 start = GNUNET_TIME_absolute_get ();
123 for (i = 0; i < 10; i++)
124 {
125 sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key,
126 bbuf,
127 bbuf_len);
128 GNUNET_CRYPTO_rsa_signature_free (sig);
129 }
130 printf ("10x %u-signing took %s\n",
131 len,
132 GNUNET_STRINGS_relative_time_to_string (
133 GNUNET_TIME_absolute_get_duration (start),
134 GNUNET_YES));
135 GNUNET_snprintf (sbuf,
136 sizeof(sbuf),
137 "RSA %u-signing",
138 len);
139 GAUGER ("UTIL",
140 sbuf,
141 64 * 1024 / (1
142 + GNUNET_TIME_absolute_get_duration
143 (start).rel_value_us / 1000LL), "ops/ms");
144 sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key,
145 bbuf,
146 bbuf_len);
147 start = GNUNET_TIME_absolute_get ();
148 for (i = 0; i < 10; i++)
149 {
150 rsig = GNUNET_CRYPTO_rsa_unblind (sig,
151 &bsec[0],
152 public_key);
153 GNUNET_CRYPTO_rsa_signature_free (rsig);
154 }
155 printf ("10x %u-unblinding took %s\n",
156 len,
157 GNUNET_STRINGS_relative_time_to_string (
158 GNUNET_TIME_absolute_get_duration (start),
159 GNUNET_YES));
160 GNUNET_snprintf (sbuf,
161 sizeof(sbuf),
162 "RSA %u-unblinding",
163 len);
164 GAUGER ("UTIL",
165 sbuf,
166 64 * 1024 / (1
167 + GNUNET_TIME_absolute_get_duration
168 (start).rel_value_us / 1000LL), "ops/ms");
169 rsig = GNUNET_CRYPTO_rsa_unblind (sig,
170 &bsec[0],
171 public_key);
172 start = GNUNET_TIME_absolute_get ();
173 for (i = 0; i < 10; i++)
174 {
175 GNUNET_assert (GNUNET_OK ==
176 GNUNET_CRYPTO_rsa_verify (&hc,
177 rsig,
178 public_key));
179 }
180 printf ("10x %u-verifying took %s\n",
181 len,
182 GNUNET_STRINGS_relative_time_to_string (
183 GNUNET_TIME_absolute_get_duration (start),
184 GNUNET_YES));
185 GNUNET_snprintf (sbuf,
186 sizeof(sbuf),
187 "RSA %u-verification",
188 len);
189 GAUGER ("UTIL",
190 sbuf,
191 64 * 1024 / (1
192 + GNUNET_TIME_absolute_get_duration
193 (start).rel_value_us / 1000LL), "ops/ms");
194 GNUNET_CRYPTO_rsa_signature_free (sig);
195 GNUNET_CRYPTO_rsa_public_key_free (public_key);
196 GNUNET_CRYPTO_rsa_private_key_free (private_key);
197 GNUNET_free (bbuf);
198}
199
200
201int
202main (int argc, char *argv[])
203{
204 eval (1024);
205 eval (2048);
206 /* eval (4096); */
207 return 0;
208}
209
210
211/* end of perf_crypto_rsa.c */