2 This file is part of GNUnet.
3 Copyright (C) 2015 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
23 * @file util/perf_crypto_asymmetric.c
24 * @brief measure performance of public key functions
27 #include "gnunet_util_lib.h"
30 static struct GNUNET_TIME_Absolute start;
36 struct GNUNET_CRYPTO_EccSignaturePurpose purp;
37 struct GNUNET_HashCode h;
38 struct GNUNET_CRYPTO_EddsaSignature sig;
43 log_duration (const char *cryptosystem,
44 const char *description)
46 struct GNUNET_TIME_Relative t;
49 sprintf (s, "%6s %15s", cryptosystem, description);
50 t = GNUNET_TIME_absolute_get_duration (start);
51 t = GNUNET_TIME_relative_divide (t, l);
55 GNUNET_STRINGS_relative_time_to_string (t,
57 GAUGER ("UTIL", s, t.rel_value_us, "us");
62 main (int argc, char *argv[])
65 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe[l];
66 struct GNUNET_CRYPTO_EcdhePublicKey dhpub[l];
67 struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa[l];
68 struct GNUNET_CRYPTO_EddsaPublicKey dspub[l];
69 struct TestSig sig[l];
71 start = GNUNET_TIME_absolute_get();
72 for (i = 0; i < l; i++)
74 sig[i].purp.purpose = 0;
75 sig[i].purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)
76 + sizeof (struct GNUNET_HashCode));
77 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
81 log_duration ("", "Init");
83 start = GNUNET_TIME_absolute_get();
84 for (i = 0; i < l; i++)
85 eddsa[i] = GNUNET_CRYPTO_eddsa_key_create();
86 log_duration ("EdDSA", "create key");
88 start = GNUNET_TIME_absolute_get();
89 for (i = 0; i < l; i++)
90 GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]);
91 log_duration ("EdDSA", "get public");
93 start = GNUNET_TIME_absolute_get();
94 for (i = 0; i < l; i++)
95 GNUNET_assert (GNUNET_OK ==
96 GNUNET_CRYPTO_eddsa_sign (eddsa[i],
99 log_duration ("EdDSA", "sign HashCode");
101 start = GNUNET_TIME_absolute_get();
102 for (i = 0; i < l; i++)
103 GNUNET_assert (GNUNET_OK ==
104 GNUNET_CRYPTO_eddsa_verify (0,
108 log_duration ("EdDSA", "verify HashCode");
110 start = GNUNET_TIME_absolute_get();
111 for (i = 0; i < l; i++)
112 ecdhe[i] = GNUNET_CRYPTO_ecdhe_key_create();
113 log_duration ("ECDH", "create key");
115 start = GNUNET_TIME_absolute_get();
116 for (i = 0; i < l; i++)
117 GNUNET_CRYPTO_ecdhe_key_get_public (ecdhe[i], &dhpub[i]);
118 log_duration ("ECDH", "get public");
120 start = GNUNET_TIME_absolute_get();
121 for (i = 0; i < l - 1; i+=2)
123 GNUNET_CRYPTO_ecc_ecdh (ecdhe[i], &dhpub[i+1], &sig[i].h);
124 GNUNET_CRYPTO_ecc_ecdh (ecdhe[i+1], &dhpub[i], &sig[i+1].h);
126 log_duration ("ECDH", "do DH");
131 /* end of perf_crypto_asymmetric.c */