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.
17 * @author Christian Grothoff
18 * @file util/perf_crypto_paillier.c
19 * @brief measure performance of Paillier encryption
22 #include "gnunet_util_lib.h"
27 main (int argc, char *argv[])
29 struct GNUNET_TIME_Absolute start;
30 struct GNUNET_CRYPTO_PaillierPublicKey public_key;
31 struct GNUNET_CRYPTO_PaillierPrivateKey private_key;
32 struct GNUNET_CRYPTO_PaillierCiphertext c1;
36 start = GNUNET_TIME_absolute_get ();
38 GNUNET_CRYPTO_paillier_create (&public_key,
40 printf ("10x key generation took %s\n",
41 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
43 GAUGER ("UTIL", "Paillier key generation",
45 GNUNET_TIME_absolute_get_duration
46 (start).rel_value_us / 1000LL), "keys/ms");
48 m1 = gcry_mpi_new (0);
49 m1 = gcry_mpi_set_ui (m1, 1);
50 /* m1 = m1 * 2 ^ (GCPB - 3) */
51 gcry_mpi_mul_2exp (m1,
53 GNUNET_CRYPTO_PAILLIER_BITS - 3);
54 start = GNUNET_TIME_absolute_get ();
56 GNUNET_CRYPTO_paillier_encrypt (&public_key,
60 printf ("10x encryption took %s\n",
61 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
63 GAUGER ("UTIL", "Paillier encryption",
65 GNUNET_TIME_absolute_get_duration
66 (start).rel_value_us / 1000LL), "ops/ms");
68 start = GNUNET_TIME_absolute_get ();
70 GNUNET_CRYPTO_paillier_decrypt (&private_key,
74 printf ("10x decryption took %s\n",
75 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
77 GAUGER ("UTIL", "Paillier decryption",
79 GNUNET_TIME_absolute_get_duration
80 (start).rel_value_us / 1000LL), "ops/ms");
86 /* end of perf_crypto_paillier.c */