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_paillier.c
22 * @brief measure performance of Paillier encryption
25 #include "gnunet_util_lib.h"
30 main (int argc, char *argv[])
32 struct GNUNET_TIME_Absolute start;
33 struct GNUNET_CRYPTO_PaillierPublicKey public_key;
34 struct GNUNET_CRYPTO_PaillierPrivateKey private_key;
35 struct GNUNET_CRYPTO_PaillierCiphertext c1;
39 start = GNUNET_TIME_absolute_get ();
41 GNUNET_CRYPTO_paillier_create (&public_key,
43 printf ("10x key generation took %s\n",
44 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
46 GAUGER ("UTIL", "Paillier key generation",
48 GNUNET_TIME_absolute_get_duration
49 (start).rel_value_us / 1000LL), "keys/ms");
51 m1 = gcry_mpi_new (0);
52 m1 = gcry_mpi_set_ui (m1, 1);
53 /* m1 = m1 * 2 ^ (GCPB - 3) */
54 gcry_mpi_mul_2exp (m1,
56 GNUNET_CRYPTO_PAILLIER_BITS - 3);
57 start = GNUNET_TIME_absolute_get ();
59 GNUNET_CRYPTO_paillier_encrypt (&public_key,
63 printf ("10x encryption took %s\n",
64 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
66 GAUGER ("UTIL", "Paillier encryption",
68 GNUNET_TIME_absolute_get_duration
69 (start).rel_value_us / 1000LL), "ops/ms");
71 start = GNUNET_TIME_absolute_get ();
73 GNUNET_CRYPTO_paillier_decrypt (&private_key,
77 printf ("10x decryption took %s\n",
78 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
80 GAUGER ("UTIL", "Paillier decryption",
82 GNUNET_TIME_absolute_get_duration
83 (start).rel_value_us / 1000LL), "ops/ms");
89 /* end of perf_crypto_paillier.c */