summaryrefslogtreecommitdiff
path: root/src/util/perf_crypto_asymmetric.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/perf_crypto_asymmetric.c')
-rw-r--r--src/util/perf_crypto_asymmetric.c95
1 files changed, 47 insertions, 48 deletions
diff --git a/src/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c
index f42706bda..91679afa5 100644
--- a/src/util/perf_crypto_asymmetric.c
+++ b/src/util/perf_crypto_asymmetric.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @author Bart Polot 22 * @author Bart Polot
@@ -31,8 +31,7 @@ static struct GNUNET_TIME_Absolute start;
31 31
32#define l 500 32#define l 500
33 33
34struct TestSig 34struct TestSig {
35{
36 struct GNUNET_CRYPTO_EccSignaturePurpose purp; 35 struct GNUNET_CRYPTO_EccSignaturePurpose purp;
37 struct GNUNET_HashCode h; 36 struct GNUNET_HashCode h;
38 struct GNUNET_CRYPTO_EddsaSignature sig; 37 struct GNUNET_CRYPTO_EddsaSignature sig;
@@ -40,26 +39,26 @@ struct TestSig
40 39
41 40
42static void 41static void
43log_duration (const char *cryptosystem, 42log_duration(const char *cryptosystem,
44 const char *description) 43 const char *description)
45{ 44{
46 struct GNUNET_TIME_Relative t; 45 struct GNUNET_TIME_Relative t;
47 char s[64]; 46 char s[64];
48 47
49 sprintf (s, "%6s %15s", cryptosystem, description); 48 sprintf(s, "%6s %15s", cryptosystem, description);
50 t = GNUNET_TIME_absolute_get_duration (start); 49 t = GNUNET_TIME_absolute_get_duration(start);
51 t = GNUNET_TIME_relative_divide (t, l); 50 t = GNUNET_TIME_relative_divide(t, l);
52 fprintf (stdout, 51 fprintf(stdout,
53 "%s: %10s\n", 52 "%s: %10s\n",
54 s, 53 s,
55 GNUNET_STRINGS_relative_time_to_string (t, 54 GNUNET_STRINGS_relative_time_to_string(t,
56 GNUNET_NO)); 55 GNUNET_NO));
57 GAUGER ("UTIL", s, t.rel_value_us, "us"); 56 GAUGER("UTIL", s, t.rel_value_us, "us");
58} 57}
59 58
60 59
61int 60int
62main (int argc, char *argv[]) 61main(int argc, char *argv[])
63{ 62{
64 int i; 63 int i;
65 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe[l]; 64 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe[l];
@@ -70,60 +69,60 @@ main (int argc, char *argv[])
70 69
71 start = GNUNET_TIME_absolute_get(); 70 start = GNUNET_TIME_absolute_get();
72 for (i = 0; i < l; i++) 71 for (i = 0; i < l; i++)
73 { 72 {
74 sig[i].purp.purpose = 0; 73 sig[i].purp.purpose = 0;
75 sig[i].purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) 74 sig[i].purp.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
76 + sizeof (struct GNUNET_HashCode)); 75 + sizeof(struct GNUNET_HashCode));
77 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, 76 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK,
78 &sig[i].h, 77 &sig[i].h,
79 sizeof (sig[i].h)); 78 sizeof(sig[i].h));
80 } 79 }
81 log_duration ("", "Init"); 80 log_duration("", "Init");
82 81
83 start = GNUNET_TIME_absolute_get(); 82 start = GNUNET_TIME_absolute_get();
84 for (i = 0; i < l; i++) 83 for (i = 0; i < l; i++)
85 eddsa[i] = GNUNET_CRYPTO_eddsa_key_create(); 84 eddsa[i] = GNUNET_CRYPTO_eddsa_key_create();
86 log_duration ("EdDSA", "create key"); 85 log_duration("EdDSA", "create key");
87 86
88 start = GNUNET_TIME_absolute_get(); 87 start = GNUNET_TIME_absolute_get();
89 for (i = 0; i < l; i++) 88 for (i = 0; i < l; i++)
90 GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]); 89 GNUNET_CRYPTO_eddsa_key_get_public(eddsa[i], &dspub[i]);
91 log_duration ("EdDSA", "get public"); 90 log_duration("EdDSA", "get public");
92 91
93 start = GNUNET_TIME_absolute_get(); 92 start = GNUNET_TIME_absolute_get();
94 for (i = 0; i < l; i++) 93 for (i = 0; i < l; i++)
95 GNUNET_assert (GNUNET_OK == 94 GNUNET_assert(GNUNET_OK ==
96 GNUNET_CRYPTO_eddsa_sign (eddsa[i], 95 GNUNET_CRYPTO_eddsa_sign(eddsa[i],
97 &sig[i].purp, 96 &sig[i].purp,
98 &sig[i].sig)); 97 &sig[i].sig));
99 log_duration ("EdDSA", "sign HashCode"); 98 log_duration("EdDSA", "sign HashCode");
100 99
101 start = GNUNET_TIME_absolute_get(); 100 start = GNUNET_TIME_absolute_get();
102 for (i = 0; i < l; i++) 101 for (i = 0; i < l; i++)
103 GNUNET_assert (GNUNET_OK == 102 GNUNET_assert(GNUNET_OK ==
104 GNUNET_CRYPTO_eddsa_verify (0, 103 GNUNET_CRYPTO_eddsa_verify(0,
105 &sig[i].purp, 104 &sig[i].purp,
106 &sig[i].sig, 105 &sig[i].sig,
107 &dspub[i])); 106 &dspub[i]));
108 log_duration ("EdDSA", "verify HashCode"); 107 log_duration("EdDSA", "verify HashCode");
109 108
110 start = GNUNET_TIME_absolute_get(); 109 start = GNUNET_TIME_absolute_get();
111 for (i = 0; i < l; i++) 110 for (i = 0; i < l; i++)
112 ecdhe[i] = GNUNET_CRYPTO_ecdhe_key_create(); 111 ecdhe[i] = GNUNET_CRYPTO_ecdhe_key_create();
113 log_duration ("ECDH", "create key"); 112 log_duration("ECDH", "create key");
114 113
115 start = GNUNET_TIME_absolute_get(); 114 start = GNUNET_TIME_absolute_get();
116 for (i = 0; i < l; i++) 115 for (i = 0; i < l; i++)
117 GNUNET_CRYPTO_ecdhe_key_get_public (ecdhe[i], &dhpub[i]); 116 GNUNET_CRYPTO_ecdhe_key_get_public(ecdhe[i], &dhpub[i]);
118 log_duration ("ECDH", "get public"); 117 log_duration("ECDH", "get public");
119 118
120 start = GNUNET_TIME_absolute_get(); 119 start = GNUNET_TIME_absolute_get();
121 for (i = 0; i < l - 1; i+=2) 120 for (i = 0; i < l - 1; i += 2)
122 { 121 {
123 GNUNET_CRYPTO_ecc_ecdh (ecdhe[i], &dhpub[i+1], &sig[i].h); 122 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); 123 GNUNET_CRYPTO_ecc_ecdh(ecdhe[i + 1], &dhpub[i], &sig[i + 1].h);
125 } 124 }
126 log_duration ("ECDH", "do DH"); 125 log_duration("ECDH", "do DH");
127 126
128 return 0; 127 return 0;
129} 128}