2 This file is part of GNUnet.
3 Copyright (C) 2014 Christian Grothoff (and other contributing authors)
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_rsa_Signature *sig;
41 struct GNUNET_CRYPTO_rsa_Signature *rsig;
42 struct GNUNET_CRYPTO_rsa_PublicKey *public_key;
43 struct GNUNET_CRYPTO_rsa_PrivateKey *private_key;
44 struct GNUNET_CRYPTO_rsa_BlindingKey *bkey;
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);
71 start = GNUNET_TIME_absolute_get ();
74 bkey = GNUNET_CRYPTO_rsa_blinding_key_create (len);
75 GNUNET_CRYPTO_rsa_blinding_key_free (bkey);
77 printf ("10x %u-blinding key generation took %s\n",
79 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
81 GNUNET_snprintf (sbuf,
83 "RSA %u-blinding key generation",
87 GNUNET_TIME_absolute_get_duration
88 (start).rel_value_us / 1000LL), "keys/ms");
89 bkey = GNUNET_CRYPTO_rsa_blinding_key_create (len);
90 start = GNUNET_TIME_absolute_get ();
91 GNUNET_CRYPTO_hash ("test", 4, &hc);
94 bbuf_len = GNUNET_CRYPTO_rsa_blind (&hc,
100 printf ("10x %u-blinding took %s\n",
102 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
104 GNUNET_snprintf (sbuf,
111 GNUNET_TIME_absolute_get_duration
112 (start).rel_value_us / 1000LL), "ops/ms");
113 bbuf_len = GNUNET_CRYPTO_rsa_blind (&hc,
117 start = GNUNET_TIME_absolute_get ();
120 sig = GNUNET_CRYPTO_rsa_sign (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 (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);
189 GNUNET_CRYPTO_rsa_blinding_key_free (bkey);
195 main (int argc, char *argv[])
204 /* end of perf_crypto_rsa.c */