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_paillier.c
24 * @brief measure performance of Paillier encryption
27 #include "gnunet_util_lib.h"
32 main (int argc, char *argv[])
34 struct GNUNET_TIME_Absolute start;
35 struct GNUNET_CRYPTO_PaillierPublicKey public_key;
36 struct GNUNET_CRYPTO_PaillierPrivateKey private_key;
37 struct GNUNET_CRYPTO_PaillierCiphertext c1;
41 start = GNUNET_TIME_absolute_get ();
43 GNUNET_CRYPTO_paillier_create (&public_key,
45 printf ("10x key generation took %s\n",
46 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
48 GAUGER ("UTIL", "Paillier key generation",
50 GNUNET_TIME_absolute_get_duration
51 (start).rel_value_us / 1000LL), "keys/ms");
53 m1 = gcry_mpi_new (0);
54 m1 = gcry_mpi_set_ui (m1, 1);
55 /* m1 = m1 * 2 ^ (GCPB - 3) */
56 gcry_mpi_mul_2exp (m1,
58 GNUNET_CRYPTO_PAILLIER_BITS - 3);
59 start = GNUNET_TIME_absolute_get ();
61 GNUNET_CRYPTO_paillier_encrypt (&public_key,
65 printf ("10x encryption took %s\n",
66 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
68 GAUGER ("UTIL", "Paillier encryption",
70 GNUNET_TIME_absolute_get_duration
71 (start).rel_value_us / 1000LL), "ops/ms");
73 start = GNUNET_TIME_absolute_get ();
75 GNUNET_CRYPTO_paillier_decrypt (&private_key,
79 printf ("10x decryption took %s\n",
80 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
82 GAUGER ("UTIL", "Paillier decryption",
84 GNUNET_TIME_absolute_get_duration
85 (start).rel_value_us / 1000LL), "ops/ms");
91 /* end of perf_crypto_paillier.c */