use NULL value in load_path_suffix to NOT load any files
[oweals/gnunet.git] / src / util / perf_crypto_paillier.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2014 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
19  */
20
21 /**
22  * @author Christian Grothoff
23  * @file util/perf_crypto_paillier.c
24  * @brief measure performance of Paillier encryption
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include <gauger.h>
29
30
31 int
32 main (int argc, char *argv[])
33 {
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;
38   gcry_mpi_t m1;
39   unsigned int i;
40
41   start = GNUNET_TIME_absolute_get ();
42   for (i = 0; i < 10; i++)
43     GNUNET_CRYPTO_paillier_create (&public_key,
44                                    &private_key);
45   printf ("10x key generation took %s\n",
46           GNUNET_STRINGS_relative_time_to_string (
47             GNUNET_TIME_absolute_get_duration (start),
48             GNUNET_YES));
49   GAUGER ("UTIL", "Paillier key generation",
50           64 * 1024 / (1
51                        + GNUNET_TIME_absolute_get_duration
52                          (start).rel_value_us / 1000LL), "keys/ms");
53
54   m1 = gcry_mpi_new (0);
55   m1 = gcry_mpi_set_ui (m1, 1);
56   /* m1 = m1 * 2 ^ (GCPB - 3) */
57   gcry_mpi_mul_2exp (m1,
58                      m1,
59                      GNUNET_CRYPTO_PAILLIER_BITS - 3);
60   start = GNUNET_TIME_absolute_get ();
61   for (i = 0; i < 10; i++)
62     GNUNET_CRYPTO_paillier_encrypt (&public_key,
63                                     m1,
64                                     2,
65                                     &c1);
66   printf ("10x encryption took %s\n",
67           GNUNET_STRINGS_relative_time_to_string (
68             GNUNET_TIME_absolute_get_duration (start),
69             GNUNET_YES));
70   GAUGER ("UTIL", "Paillier encryption",
71           64 * 1024 / (1
72                        + GNUNET_TIME_absolute_get_duration
73                          (start).rel_value_us / 1000LL), "ops/ms");
74
75   start = GNUNET_TIME_absolute_get ();
76   for (i = 0; i < 10; i++)
77     GNUNET_CRYPTO_paillier_decrypt (&private_key,
78                                     &public_key,
79                                     &c1,
80                                     m1);
81   printf ("10x decryption took %s\n",
82           GNUNET_STRINGS_relative_time_to_string (
83             GNUNET_TIME_absolute_get_duration (start),
84             GNUNET_YES));
85   GAUGER ("UTIL", "Paillier decryption",
86           64 * 1024 / (1
87                        + GNUNET_TIME_absolute_get_duration
88                          (start).rel_value_us / 1000LL), "ops/ms");
89
90
91   return 0;
92 }
93
94
95 /* end of perf_crypto_paillier.c */