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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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 ();
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 (GNUNET_TIME_absolute_get_duration (start),
61 GNUNET_snprintf (sbuf,
63 "RSA %u-key generation",
67 GNUNET_TIME_absolute_get_duration
68 (start).rel_value_us / 1000LL), "keys/ms");
69 private_key = GNUNET_CRYPTO_rsa_private_key_create (len);
70 public_key = GNUNET_CRYPTO_rsa_private_key_get_public (private_key);
72 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
73 &bsec[i], sizeof (bsec[0]));
75 start = GNUNET_TIME_absolute_get ();
77 rsa_blinding_key_derive(public_key, &bsec[i]);
78 printf ("10x %u-blinding key generation took %s\n",
80 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
82 GNUNET_snprintf (sbuf,
84 "RSA %u-blinding key generation",
88 GNUNET_TIME_absolute_get_duration
89 (start).rel_value_us / 1000LL), "keys/ms");
91 start = GNUNET_TIME_absolute_get ();
92 GNUNET_CRYPTO_hash ("test", 4, &hc);
95 GNUNET_CRYPTO_rsa_blind (&hc,
101 printf ("10x %u-blinding took %s\n",
103 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
105 GNUNET_snprintf (sbuf,
112 GNUNET_TIME_absolute_get_duration
113 (start).rel_value_us / 1000LL), "ops/ms");
114 GNUNET_CRYPTO_rsa_blind (&hc,
118 start = GNUNET_TIME_absolute_get ();
121 sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key,
123 GNUNET_CRYPTO_rsa_signature_free (sig);
125 printf ("10x %u-signing took %s\n",
127 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
129 GNUNET_snprintf (sbuf,
136 GNUNET_TIME_absolute_get_duration
137 (start).rel_value_us / 1000LL), "ops/ms");
138 sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key,
141 start = GNUNET_TIME_absolute_get ();
144 rsig = GNUNET_CRYPTO_rsa_unblind (sig,
147 GNUNET_CRYPTO_rsa_signature_free (rsig);
149 printf ("10x %u-unblinding took %s\n",
151 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
153 GNUNET_snprintf (sbuf,
160 GNUNET_TIME_absolute_get_duration
161 (start).rel_value_us / 1000LL), "ops/ms");
162 rsig = GNUNET_CRYPTO_rsa_unblind (sig,
165 start = GNUNET_TIME_absolute_get ();
168 GNUNET_assert (GNUNET_OK ==
169 GNUNET_CRYPTO_rsa_verify (&hc,
173 printf ("10x %u-verifying took %s\n",
175 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
177 GNUNET_snprintf (sbuf,
179 "RSA %u-verification",
184 GNUNET_TIME_absolute_get_duration
185 (start).rel_value_us / 1000LL), "ops/ms");
186 GNUNET_CRYPTO_rsa_signature_free (sig);
187 GNUNET_CRYPTO_rsa_public_key_free (public_key);
188 GNUNET_CRYPTO_rsa_private_key_free (private_key);
194 main (int argc, char *argv[])
203 /* end of perf_crypto_rsa.c */