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/>.
20 * @author Christian Grothoff
21 * @file util/perf_crypto_rsa.c
22 * @brief measure performance of RSA signing
25 #include "gnunet_util_lib.h"
30 * Evaluate RSA performance.
32 * @param len keylength to evaluate with
35 eval (unsigned int len)
37 struct GNUNET_TIME_Absolute start;
38 struct GNUNET_CRYPTO_RsaSignature *sig;
39 struct GNUNET_CRYPTO_RsaSignature *rsig;
40 struct GNUNET_CRYPTO_RsaPublicKey *public_key;
41 struct GNUNET_CRYPTO_RsaPrivateKey *private_key;
42 struct GNUNET_CRYPTO_RsaBlindingKeySecret bsec[10];
47 struct GNUNET_HashCode hc;
49 start = GNUNET_TIME_absolute_get ();
52 private_key = GNUNET_CRYPTO_rsa_private_key_create (len);
53 GNUNET_CRYPTO_rsa_private_key_free (private_key);
55 printf ("10x %u-key generation took %s\n",
57 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
59 GNUNET_snprintf (sbuf,
61 "RSA %u-key generation",
65 GNUNET_TIME_absolute_get_duration
66 (start).rel_value_us / 1000LL), "keys/ms");
67 private_key = GNUNET_CRYPTO_rsa_private_key_create (len);
68 public_key = GNUNET_CRYPTO_rsa_private_key_get_public (private_key);
70 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
71 &bsec[i], sizeof (bsec[0]));
73 start = GNUNET_TIME_absolute_get ();
75 rsa_blinding_key_derive(public_key, &bsec[i]);
76 printf ("10x %u-blinding key generation took %s\n",
78 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
80 GNUNET_snprintf (sbuf,
82 "RSA %u-blinding key generation",
86 GNUNET_TIME_absolute_get_duration
87 (start).rel_value_us / 1000LL), "keys/ms");
89 start = GNUNET_TIME_absolute_get ();
90 GNUNET_CRYPTO_hash ("test", 4, &hc);
93 GNUNET_CRYPTO_rsa_blind (&hc,
99 printf ("10x %u-blinding took %s\n",
101 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
103 GNUNET_snprintf (sbuf,
110 GNUNET_TIME_absolute_get_duration
111 (start).rel_value_us / 1000LL), "ops/ms");
112 GNUNET_CRYPTO_rsa_blind (&hc,
116 start = GNUNET_TIME_absolute_get ();
119 sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key,
121 GNUNET_CRYPTO_rsa_signature_free (sig);
123 printf ("10x %u-signing took %s\n",
125 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
127 GNUNET_snprintf (sbuf,
134 GNUNET_TIME_absolute_get_duration
135 (start).rel_value_us / 1000LL), "ops/ms");
136 sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key,
139 start = GNUNET_TIME_absolute_get ();
142 rsig = GNUNET_CRYPTO_rsa_unblind (sig,
145 GNUNET_CRYPTO_rsa_signature_free (rsig);
147 printf ("10x %u-unblinding took %s\n",
149 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
151 GNUNET_snprintf (sbuf,
158 GNUNET_TIME_absolute_get_duration
159 (start).rel_value_us / 1000LL), "ops/ms");
160 rsig = GNUNET_CRYPTO_rsa_unblind (sig,
163 start = GNUNET_TIME_absolute_get ();
166 GNUNET_assert (GNUNET_OK ==
167 GNUNET_CRYPTO_rsa_verify (&hc,
171 printf ("10x %u-verifying took %s\n",
173 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
175 GNUNET_snprintf (sbuf,
177 "RSA %u-verification",
182 GNUNET_TIME_absolute_get_duration
183 (start).rel_value_us / 1000LL), "ops/ms");
184 GNUNET_CRYPTO_rsa_signature_free (sig);
185 GNUNET_CRYPTO_rsa_public_key_free (public_key);
186 GNUNET_CRYPTO_rsa_private_key_free (private_key);
192 main (int argc, char *argv[])
201 /* end of perf_crypto_rsa.c */