aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-03-19 15:17:10 +0000
committerBart Polot <bart@net.in.tum.de>2015-03-19 15:17:10 +0000
commit074f31e3b425a55ee17ac83c1953652d232d3a38 (patch)
treeb0c2288d0a88a3288e89cd6c4b195c180f9262ed /src/util
parentc641b74c2e060528100168f44c074526798c1623 (diff)
downloadgnunet-074f31e3b425a55ee17ac83c1953652d232d3a38.tar.gz
gnunet-074f31e3b425a55ee17ac83c1953652d232d3a38.zip
- added asymmetric crytp perf
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am6
-rw-r--r--src/util/perf_crypto_asymmetric.c115
2 files changed, 121 insertions, 0 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index b49378c9b..ee7ccec26 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -206,6 +206,7 @@ if HAVE_BENCHMARKS
206 perf_crypto_hash \ 206 perf_crypto_hash \
207 perf_crypto_paillier \ 207 perf_crypto_paillier \
208 perf_crypto_symmetric \ 208 perf_crypto_symmetric \
209 perf_crypto_asymmetric \
209 perf_malloc 210 perf_malloc
210endif 211endif
211 212
@@ -573,6 +574,11 @@ perf_crypto_symmetric_SOURCES = \
573perf_crypto_symmetric_LDADD = \ 574perf_crypto_symmetric_LDADD = \
574 libgnunetutil.la 575 libgnunetutil.la
575 576
577perf_crypto_asymmetric_SOURCES = \
578 perf_crypto_asymmetric.c
579perf_crypto_asymmetric_LDADD = \
580 libgnunetutil.la
581
576perf_crypto_paillier_SOURCES = \ 582perf_crypto_paillier_SOURCES = \
577 perf_crypto_paillier.c 583 perf_crypto_paillier.c
578perf_crypto_paillier_LDADD = \ 584perf_crypto_paillier_LDADD = \
diff --git a/src/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c
new file mode 100644
index 000000000..26355d6ab
--- /dev/null
+++ b/src/util/perf_crypto_asymmetric.c
@@ -0,0 +1,115 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2015 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 Bart Polot
23 * @file util/perf_crypto_asymmetric.c
24 * @brief measure performance of public key functions
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include <gauger.h>
29
30struct GNUNET_TIME_Absolute start;
31const int l = 50;
32
33struct TestSig {
34 struct GNUNET_CRYPTO_EccSignaturePurpose purp;
35 struct GNUNET_HashCode h;
36 struct GNUNET_CRYPTO_EddsaSignature sig;
37};
38
39static void
40log_duration (const char *system, const char *description)
41{
42 struct GNUNET_TIME_Relative t;
43 char s[64];
44
45 sprintf (s, "%6s %15s", system, description);
46 t = GNUNET_TIME_absolute_get_duration (start);
47 t = GNUNET_TIME_relative_divide (t, l);
48 FPRINTF (stdout, "%s: %10s\n", s,
49 GNUNET_STRINGS_relative_time_to_string(t, GNUNET_NO));
50
51 GAUGER ("UTIL", s, t.rel_value_us, "us");
52}
53
54int
55main (int argc, char *argv[])
56{
57 int i;
58 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe[l];
59 struct GNUNET_CRYPTO_EcdhePublicKey dhpub[l];
60 struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa[l];
61 struct GNUNET_CRYPTO_EddsaPublicKey dspub[l];
62 struct TestSig sig[l];
63
64 start = GNUNET_TIME_absolute_get();
65 for (i = 0; i < l; i++)
66 {
67 sig[i].purp.purpose = 0;
68 sig[i].purp.size = htonl (sizeof (struct TestSig));
69 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
70 &sig[i].h, sizeof (&sig[0].h));
71 }
72 log_duration ("", "Init");
73
74 start = GNUNET_TIME_absolute_get();
75 for (i = 0; i < l; i++)
76 eddsa[i] = GNUNET_CRYPTO_eddsa_key_create();
77 log_duration ("EdDSA", "create key");
78
79 start = GNUNET_TIME_absolute_get();
80 for (i = 0; i < l; i++)
81 GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]);
82 log_duration ("EdDSA", "get pubilc");
83
84 start = GNUNET_TIME_absolute_get();
85 for (i = 0; i < l; i++)
86 GNUNET_CRYPTO_eddsa_sign (eddsa[i], &sig[i].purp, &sig[i].sig);
87 log_duration ("EdDSA", "sign HashCode");
88
89 start = GNUNET_TIME_absolute_get();
90 for (i = 0; i < l; i++)
91 GNUNET_CRYPTO_eddsa_verify (0, &sig[i].purp, &sig[i].sig, &dspub[i]);
92 log_duration ("EdDSA", "verify HashCode");
93
94 start = GNUNET_TIME_absolute_get();
95 for (i = 0; i < l; i++)
96 ecdhe[i] = GNUNET_CRYPTO_ecdhe_key_create();
97 log_duration ("ECDH", "create key");
98
99 start = GNUNET_TIME_absolute_get();
100 for (i = 0; i < l; i++)
101 GNUNET_CRYPTO_ecdhe_key_get_public (ecdhe[i], &dhpub[i]);
102 log_duration ("ECDH", "get public");
103
104 start = GNUNET_TIME_absolute_get();
105 for (i = 0; i < l; i+=2)
106 {
107 GNUNET_CRYPTO_ecc_ecdh (ecdhe[i], &dhpub[i+1], &sig[i].h);
108 GNUNET_CRYPTO_ecc_ecdh (ecdhe[i+1], &dhpub[i], &sig[i+i].h);
109 }
110 log_duration ("ECDH", "do DH");
111
112 return 0;
113}
114
115/* end of perf_crypto_asymmetric.c */