aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-09 21:05:51 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-09 21:05:51 +0000
commit42a8f472a6cc15f7352b68c0175511f683353fc8 (patch)
treed858deb54968f5af6d52e2068b8761c9d8f86d20 /src
parentbd958988bbc935dcd953e174f9c3ec20baf965cd (diff)
downloadgnunet-42a8f472a6cc15f7352b68c0175511f683353fc8.tar.gz
gnunet-42a8f472a6cc15f7352b68c0175511f683353fc8.zip
add paillier benchmark
Diffstat (limited to 'src')
-rw-r--r--src/util/perf_crypto_paillier.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/util/perf_crypto_paillier.c b/src/util/perf_crypto_paillier.c
new file mode 100644
index 000000000..ac257b64f
--- /dev/null
+++ b/src/util/perf_crypto_paillier.c
@@ -0,0 +1,91 @@
1/*
2 This file is part of GNUnet.
3 (C) 2014 Christian Grothoff (and other contributing authors)
4
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.
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 General Public License for more details.
14
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
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
31int
32main (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 (GNUNET_TIME_absolute_get_duration (start),
47 GNUNET_YES));
48 GAUGER ("UTIL", "Paillier key generation",
49 64 * 1024 / (1 +
50 GNUNET_TIME_absolute_get_duration
51 (start).rel_value_us / 1000LL), "keys/ms");
52
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,
57 m1,
58 GNUNET_CRYPTO_PAILLIER_BITS - 3);
59 start = GNUNET_TIME_absolute_get ();
60 for (i=0;i<10;i++)
61 GNUNET_CRYPTO_paillier_encrypt (&public_key,
62 m1,
63 2,
64 &c1);
65 printf ("10x encryption took %s\n",
66 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
67 GNUNET_YES));
68 GAUGER ("UTIL", "Paillier encryption",
69 64 * 1024 / (1 +
70 GNUNET_TIME_absolute_get_duration
71 (start).rel_value_us / 1000LL), "ops/ms");
72
73 start = GNUNET_TIME_absolute_get ();
74 for (i=0;i<10;i++)
75 GNUNET_CRYPTO_paillier_decrypt (&private_key,
76 &public_key,
77 &c1,
78 m1);
79 printf ("10x decryption took %s\n",
80 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
81 GNUNET_YES));
82 GAUGER ("UTIL", "Paillier decryption",
83 64 * 1024 / (1 +
84 GNUNET_TIME_absolute_get_duration
85 (start).rel_value_us / 1000LL), "ops/ms");
86
87
88 return 0;
89}
90
91/* end of perf_crypto_paillier.c */