aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util/perf_crypto_paillier.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/perf_crypto_paillier.c')
-rw-r--r--src/lib/util/perf_crypto_paillier.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/lib/util/perf_crypto_paillier.c b/src/lib/util/perf_crypto_paillier.c
new file mode 100644
index 000000000..53c717a66
--- /dev/null
+++ b/src/lib/util/perf_crypto_paillier.c
@@ -0,0 +1,96 @@
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
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include <gauger.h>
30
31
32int
33main (int argc, char *argv[])
34{
35 struct GNUNET_TIME_Absolute start;
36 struct GNUNET_CRYPTO_PaillierPublicKey public_key;
37 struct GNUNET_CRYPTO_PaillierPrivateKey private_key;
38 struct GNUNET_CRYPTO_PaillierCiphertext c1;
39 gcry_mpi_t m1;
40 unsigned int i;
41
42 start = GNUNET_TIME_absolute_get ();
43 for (i = 0; i < 10; i++)
44 GNUNET_CRYPTO_paillier_create (&public_key,
45 &private_key);
46 printf ("10x key generation took %s\n",
47 GNUNET_STRINGS_relative_time_to_string (
48 GNUNET_TIME_absolute_get_duration (start),
49 GNUNET_YES));
50 GAUGER ("UTIL", "Paillier key generation",
51 64 * 1024 / (1
52 + GNUNET_TIME_absolute_get_duration
53 (start).rel_value_us / 1000LL), "keys/ms");
54
55 m1 = gcry_mpi_new (0);
56 m1 = gcry_mpi_set_ui (m1, 1);
57 /* m1 = m1 * 2 ^ (GCPB - 3) */
58 gcry_mpi_mul_2exp (m1,
59 m1,
60 GNUNET_CRYPTO_PAILLIER_BITS - 3);
61 start = GNUNET_TIME_absolute_get ();
62 for (i = 0; i < 10; i++)
63 GNUNET_CRYPTO_paillier_encrypt (&public_key,
64 m1,
65 2,
66 &c1);
67 printf ("10x encryption took %s\n",
68 GNUNET_STRINGS_relative_time_to_string (
69 GNUNET_TIME_absolute_get_duration (start),
70 GNUNET_YES));
71 GAUGER ("UTIL", "Paillier encryption",
72 64 * 1024 / (1
73 + GNUNET_TIME_absolute_get_duration
74 (start).rel_value_us / 1000LL), "ops/ms");
75
76 start = GNUNET_TIME_absolute_get ();
77 for (i = 0; i < 10; i++)
78 GNUNET_CRYPTO_paillier_decrypt (&private_key,
79 &public_key,
80 &c1,
81 m1);
82 printf ("10x decryption took %s\n",
83 GNUNET_STRINGS_relative_time_to_string (
84 GNUNET_TIME_absolute_get_duration (start),
85 GNUNET_YES));
86 GAUGER ("UTIL", "Paillier decryption",
87 64 * 1024 / (1
88 + GNUNET_TIME_absolute_get_duration
89 (start).rel_value_us / 1000LL), "ops/ms");
90
91
92 return 0;
93}
94
95
96/* end of perf_crypto_paillier.c */