2 This file is part of GNUnet.
3 Copyright (C) 2014 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @author Christian Grothoff
23 * @file util/perf_crypto_rsa.c
24 * @brief measure performance of RSA signing
27 #include "gnunet_util_lib.h"
32 * Evaluate RSA performance.
34 * @param len keylength to evaluate with
37 eval (unsigned int len)
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];
49 struct GNUNET_HashCode hc;
51 start = GNUNET_TIME_absolute_get ();
52 for (i = 0; i < 10; i++)
54 private_key = GNUNET_CRYPTO_rsa_private_key_create (len);
55 GNUNET_CRYPTO_rsa_private_key_free (private_key);
57 printf ("10x %u-key generation took %s\n",
59 GNUNET_STRINGS_relative_time_to_string (
60 GNUNET_TIME_absolute_get_duration (start),
62 GNUNET_snprintf (sbuf,
64 "RSA %u-key generation",
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]));
76 start = GNUNET_TIME_absolute_get ();
78 rsa_blinding_key_derive(public_key, &bsec[i]);
79 printf ("10x %u-blinding key generation took %s\n",
81 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
83 GNUNET_snprintf (sbuf,
85 "RSA %u-blinding key generation",
89 GNUNET_TIME_absolute_get_duration
90 (start).rel_value_us / 1000LL), "keys/ms");
91 */start = GNUNET_TIME_absolute_get ();
92 GNUNET_CRYPTO_hash ("test", 4, &hc);
93 for (i = 0; i < 10; i++)
95 GNUNET_CRYPTO_rsa_blind (&hc,
101 printf ("10x %u-blinding took %s\n",
103 GNUNET_STRINGS_relative_time_to_string (
104 GNUNET_TIME_absolute_get_duration (start),
106 GNUNET_snprintf (sbuf,
113 + GNUNET_TIME_absolute_get_duration
114 (start).rel_value_us / 1000LL), "ops/ms");
115 GNUNET_CRYPTO_rsa_blind (&hc,
119 start = GNUNET_TIME_absolute_get ();
120 for (i = 0; i < 10; i++)
122 sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key,
124 GNUNET_CRYPTO_rsa_signature_free (sig);
126 printf ("10x %u-signing took %s\n",
128 GNUNET_STRINGS_relative_time_to_string (
129 GNUNET_TIME_absolute_get_duration (start),
131 GNUNET_snprintf (sbuf,
138 + GNUNET_TIME_absolute_get_duration
139 (start).rel_value_us / 1000LL), "ops/ms");
140 sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key,
143 start = GNUNET_TIME_absolute_get ();
144 for (i = 0; i < 10; i++)
146 rsig = GNUNET_CRYPTO_rsa_unblind (sig,
149 GNUNET_CRYPTO_rsa_signature_free (rsig);
151 printf ("10x %u-unblinding took %s\n",
153 GNUNET_STRINGS_relative_time_to_string (
154 GNUNET_TIME_absolute_get_duration (start),
156 GNUNET_snprintf (sbuf,
163 + GNUNET_TIME_absolute_get_duration
164 (start).rel_value_us / 1000LL), "ops/ms");
165 rsig = GNUNET_CRYPTO_rsa_unblind (sig,
168 start = GNUNET_TIME_absolute_get ();
169 for (i = 0; i < 10; i++)
171 GNUNET_assert (GNUNET_OK ==
172 GNUNET_CRYPTO_rsa_verify (&hc,
176 printf ("10x %u-verifying took %s\n",
178 GNUNET_STRINGS_relative_time_to_string (
179 GNUNET_TIME_absolute_get_duration (start),
181 GNUNET_snprintf (sbuf,
183 "RSA %u-verification",
188 + GNUNET_TIME_absolute_get_duration
189 (start).rel_value_us / 1000LL), "ops/ms");
190 GNUNET_CRYPTO_rsa_signature_free (sig);
191 GNUNET_CRYPTO_rsa_public_key_free (public_key);
192 GNUNET_CRYPTO_rsa_private_key_free (private_key);
198 main (int argc, char *argv[])
207 /* end of perf_crypto_rsa.c */