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 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.
18 * @file util/perf_crypto_asymmetric.c
19 * @brief measure performance of public key functions
22 #include "gnunet_util_lib.h"
25 static struct GNUNET_TIME_Absolute start;
31 struct GNUNET_CRYPTO_EccSignaturePurpose purp;
32 struct GNUNET_HashCode h;
33 struct GNUNET_CRYPTO_EddsaSignature sig;
38 log_duration (const char *cryptosystem,
39 const char *description)
41 struct GNUNET_TIME_Relative t;
44 sprintf (s, "%6s %15s", cryptosystem, description);
45 t = GNUNET_TIME_absolute_get_duration (start);
46 t = GNUNET_TIME_relative_divide (t, l);
50 GNUNET_STRINGS_relative_time_to_string (t,
52 GAUGER ("UTIL", s, t.rel_value_us, "us");
57 main (int argc, char *argv[])
60 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe[l];
61 struct GNUNET_CRYPTO_EcdhePublicKey dhpub[l];
62 struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa[l];
63 struct GNUNET_CRYPTO_EddsaPublicKey dspub[l];
64 struct TestSig sig[l];
66 start = GNUNET_TIME_absolute_get();
67 for (i = 0; i < l; i++)
69 sig[i].purp.purpose = 0;
70 sig[i].purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)
71 + sizeof (struct GNUNET_HashCode));
72 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
76 log_duration ("", "Init");
78 start = GNUNET_TIME_absolute_get();
79 for (i = 0; i < l; i++)
80 eddsa[i] = GNUNET_CRYPTO_eddsa_key_create();
81 log_duration ("EdDSA", "create key");
83 start = GNUNET_TIME_absolute_get();
84 for (i = 0; i < l; i++)
85 GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]);
86 log_duration ("EdDSA", "get public");
88 start = GNUNET_TIME_absolute_get();
89 for (i = 0; i < l; i++)
90 GNUNET_assert (GNUNET_OK ==
91 GNUNET_CRYPTO_eddsa_sign (eddsa[i],
94 log_duration ("EdDSA", "sign HashCode");
96 start = GNUNET_TIME_absolute_get();
97 for (i = 0; i < l; i++)
98 GNUNET_assert (GNUNET_OK ==
99 GNUNET_CRYPTO_eddsa_verify (0,
103 log_duration ("EdDSA", "verify HashCode");
105 start = GNUNET_TIME_absolute_get();
106 for (i = 0; i < l; i++)
107 ecdhe[i] = GNUNET_CRYPTO_ecdhe_key_create();
108 log_duration ("ECDH", "create key");
110 start = GNUNET_TIME_absolute_get();
111 for (i = 0; i < l; i++)
112 GNUNET_CRYPTO_ecdhe_key_get_public (ecdhe[i], &dhpub[i]);
113 log_duration ("ECDH", "get public");
115 start = GNUNET_TIME_absolute_get();
116 for (i = 0; i < l - 1; i+=2)
118 GNUNET_CRYPTO_ecc_ecdh (ecdhe[i], &dhpub[i+1], &sig[i].h);
119 GNUNET_CRYPTO_ecc_ecdh (ecdhe[i+1], &dhpub[i], &sig[i+1].h);
121 log_duration ("ECDH", "do DH");
126 /* end of perf_crypto_asymmetric.c */