aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util/perf_crypto_asymmetric.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/perf_crypto_asymmetric.c')
-rw-r--r--src/lib/util/perf_crypto_asymmetric.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/lib/util/perf_crypto_asymmetric.c b/src/lib/util/perf_crypto_asymmetric.c
new file mode 100644
index 000000000..c033a02ca
--- /dev/null
+++ b/src/lib/util/perf_crypto_asymmetric.c
@@ -0,0 +1,133 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2015 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 Bart Polot
23 * @file util/perf_crypto_asymmetric.c
24 * @brief measure performance of public key functions
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include <gauger.h>
30
31static struct GNUNET_TIME_Absolute start;
32
33#define l 500
34
35struct TestSig
36{
37 struct GNUNET_CRYPTO_EccSignaturePurpose purp;
38 struct GNUNET_HashCode h;
39 struct GNUNET_CRYPTO_EddsaSignature sig;
40};
41
42
43static void
44log_duration (const char *cryptosystem,
45 const char *description)
46{
47 struct GNUNET_TIME_Relative t;
48 char s[64];
49
50 sprintf (s, "%6s %15s", cryptosystem, description);
51 t = GNUNET_TIME_absolute_get_duration (start);
52 t = GNUNET_TIME_relative_divide (t, l);
53 fprintf (stdout,
54 "%s: %10s\n",
55 s,
56 GNUNET_STRINGS_relative_time_to_string (t,
57 GNUNET_NO));
58 GAUGER ("UTIL", s, t.rel_value_us, "us");
59}
60
61
62int
63main (int argc, char *argv[])
64{
65 int i;
66 struct GNUNET_CRYPTO_EcdhePrivateKey ecdhe[l];
67 struct GNUNET_CRYPTO_EcdhePublicKey dhpub[l];
68 struct GNUNET_CRYPTO_EddsaPrivateKey eddsa[l];
69 struct GNUNET_CRYPTO_EddsaPublicKey dspub[l];
70 struct TestSig sig[l];
71
72 start = GNUNET_TIME_absolute_get ();
73 for (i = 0; i < l; i++)
74 {
75 sig[i].purp.purpose = 0;
76 sig[i].purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
77 + sizeof(struct GNUNET_HashCode));
78 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
79 &sig[i].h,
80 sizeof(sig[i].h));
81 }
82 log_duration ("", "Init");
83
84 start = GNUNET_TIME_absolute_get ();
85 for (i = 0; i < l; i++)
86 GNUNET_CRYPTO_eddsa_key_create (&eddsa[i]);
87 log_duration ("EdDSA", "create key");
88
89 start = GNUNET_TIME_absolute_get ();
90 for (i = 0; i < l; i++)
91 GNUNET_CRYPTO_eddsa_key_get_public (&eddsa[i], &dspub[i]);
92 log_duration ("EdDSA", "get public");
93
94 start = GNUNET_TIME_absolute_get ();
95 for (i = 0; i < l; i++)
96 GNUNET_assert (GNUNET_OK ==
97 GNUNET_CRYPTO_eddsa_sign_ (&eddsa[i],
98 &sig[i].purp,
99 &sig[i].sig));
100 log_duration ("EdDSA", "sign HashCode");
101
102 start = GNUNET_TIME_absolute_get ();
103 for (i = 0; i < l; i++)
104 GNUNET_assert (GNUNET_OK ==
105 GNUNET_CRYPTO_eddsa_verify_ (0,
106 &sig[i].purp,
107 &sig[i].sig,
108 &dspub[i]));
109 log_duration ("EdDSA", "verify HashCode");
110
111 start = GNUNET_TIME_absolute_get ();
112 for (i = 0; i < l; i++)
113 GNUNET_CRYPTO_ecdhe_key_create (&ecdhe[i]);
114 log_duration ("ECDH", "create key");
115
116 start = GNUNET_TIME_absolute_get ();
117 for (i = 0; i < l; i++)
118 GNUNET_CRYPTO_ecdhe_key_get_public (&ecdhe[i], &dhpub[i]);
119 log_duration ("ECDH", "get public");
120
121 start = GNUNET_TIME_absolute_get ();
122 for (i = 0; i < l - 1; i += 2)
123 {
124 GNUNET_CRYPTO_ecc_ecdh (&ecdhe[i], &dhpub[i + 1], &sig[i].h);
125 GNUNET_CRYPTO_ecc_ecdh (&ecdhe[i + 1], &dhpub[i], &sig[i + 1].h);
126 }
127 log_duration ("ECDH", "do DH");
128
129 return 0;
130}
131
132
133/* end of perf_crypto_asymmetric.c */