aboutsummaryrefslogtreecommitdiff
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.c113
1 files changed, 57 insertions, 56 deletions
diff --git a/src/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c
index 91679afa5..1f2182909 100644
--- a/src/util/perf_crypto_asymmetric.c
+++ b/src/util/perf_crypto_asymmetric.c
@@ -31,7 +31,8 @@ static struct GNUNET_TIME_Absolute start;
31 31
32#define l 500 32#define l 500
33 33
34struct TestSig { 34struct TestSig
35{
35 struct GNUNET_CRYPTO_EccSignaturePurpose purp; 36 struct GNUNET_CRYPTO_EccSignaturePurpose purp;
36 struct GNUNET_HashCode h; 37 struct GNUNET_HashCode h;
37 struct GNUNET_CRYPTO_EddsaSignature sig; 38 struct GNUNET_CRYPTO_EddsaSignature sig;
@@ -39,26 +40,26 @@ struct TestSig {
39 40
40 41
41static void 42static void
42log_duration(const char *cryptosystem, 43log_duration (const char *cryptosystem,
43 const char *description) 44 const char *description)
44{ 45{
45 struct GNUNET_TIME_Relative t; 46 struct GNUNET_TIME_Relative t;
46 char s[64]; 47 char s[64];
47 48
48 sprintf(s, "%6s %15s", cryptosystem, description); 49 sprintf (s, "%6s %15s", cryptosystem, description);
49 t = GNUNET_TIME_absolute_get_duration(start); 50 t = GNUNET_TIME_absolute_get_duration (start);
50 t = GNUNET_TIME_relative_divide(t, l); 51 t = GNUNET_TIME_relative_divide (t, l);
51 fprintf(stdout, 52 fprintf (stdout,
52 "%s: %10s\n", 53 "%s: %10s\n",
53 s, 54 s,
54 GNUNET_STRINGS_relative_time_to_string(t, 55 GNUNET_STRINGS_relative_time_to_string (t,
55 GNUNET_NO)); 56 GNUNET_NO));
56 GAUGER("UTIL", s, t.rel_value_us, "us"); 57 GAUGER ("UTIL", s, t.rel_value_us, "us");
57} 58}
58 59
59 60
60int 61int
61main(int argc, char *argv[]) 62main (int argc, char *argv[])
62{ 63{
63 int i; 64 int i;
64 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe[l]; 65 struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe[l];
@@ -67,62 +68,62 @@ main(int argc, char *argv[])
67 struct GNUNET_CRYPTO_EddsaPublicKey dspub[l]; 68 struct GNUNET_CRYPTO_EddsaPublicKey dspub[l];
68 struct TestSig sig[l]; 69 struct TestSig sig[l];
69 70
70 start = GNUNET_TIME_absolute_get(); 71 start = GNUNET_TIME_absolute_get ();
71 for (i = 0; i < l; i++)
72 {
73 sig[i].purp.purpose = 0;
74 sig[i].purp.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
75 + sizeof(struct GNUNET_HashCode));
76 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK,
77 &sig[i].h,
78 sizeof(sig[i].h));
79 }
80 log_duration("", "Init");
81
82 start = GNUNET_TIME_absolute_get();
83 for (i = 0; i < l; i++) 72 for (i = 0; i < l; i++)
84 eddsa[i] = GNUNET_CRYPTO_eddsa_key_create(); 73 {
85 log_duration("EdDSA", "create key"); 74 sig[i].purp.purpose = 0;
86 75 sig[i].purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
87 start = GNUNET_TIME_absolute_get(); 76 + sizeof(struct GNUNET_HashCode));
77 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
78 &sig[i].h,
79 sizeof(sig[i].h));
80 }
81 log_duration ("", "Init");
82
83 start = GNUNET_TIME_absolute_get ();
88 for (i = 0; i < l; i++) 84 for (i = 0; i < l; i++)
89 GNUNET_CRYPTO_eddsa_key_get_public(eddsa[i], &dspub[i]); 85 eddsa[i] = GNUNET_CRYPTO_eddsa_key_create ();
90 log_duration("EdDSA", "get public"); 86 log_duration ("EdDSA", "create key");
91 87
92 start = GNUNET_TIME_absolute_get(); 88 start = GNUNET_TIME_absolute_get ();
93 for (i = 0; i < l; i++) 89 for (i = 0; i < l; i++)
94 GNUNET_assert(GNUNET_OK == 90 GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]);
95 GNUNET_CRYPTO_eddsa_sign(eddsa[i], 91 log_duration ("EdDSA", "get public");
96 &sig[i].purp,
97 &sig[i].sig));
98 log_duration("EdDSA", "sign HashCode");
99 92
100 start = GNUNET_TIME_absolute_get(); 93 start = GNUNET_TIME_absolute_get ();
101 for (i = 0; i < l; i++) 94 for (i = 0; i < l; i++)
102 GNUNET_assert(GNUNET_OK == 95 GNUNET_assert (GNUNET_OK ==
103 GNUNET_CRYPTO_eddsa_verify(0, 96 GNUNET_CRYPTO_eddsa_sign (eddsa[i],
104 &sig[i].purp, 97 &sig[i].purp,
105 &sig[i].sig, 98 &sig[i].sig));
106 &dspub[i])); 99 log_duration ("EdDSA", "sign HashCode");
107 log_duration("EdDSA", "verify HashCode");
108 100
109 start = GNUNET_TIME_absolute_get(); 101 start = GNUNET_TIME_absolute_get ();
102 for (i = 0; i < l; i++)
103 GNUNET_assert (GNUNET_OK ==
104 GNUNET_CRYPTO_eddsa_verify (0,
105 &sig[i].purp,
106 &sig[i].sig,
107 &dspub[i]));
108 log_duration ("EdDSA", "verify HashCode");
109
110 start = GNUNET_TIME_absolute_get ();
110 for (i = 0; i < l; i++) 111 for (i = 0; i < l; i++)
111 ecdhe[i] = GNUNET_CRYPTO_ecdhe_key_create(); 112 ecdhe[i] = GNUNET_CRYPTO_ecdhe_key_create ();
112 log_duration("ECDH", "create key"); 113 log_duration ("ECDH", "create key");
113 114
114 start = GNUNET_TIME_absolute_get(); 115 start = GNUNET_TIME_absolute_get ();
115 for (i = 0; i < l; i++) 116 for (i = 0; i < l; i++)
116 GNUNET_CRYPTO_ecdhe_key_get_public(ecdhe[i], &dhpub[i]); 117 GNUNET_CRYPTO_ecdhe_key_get_public (ecdhe[i], &dhpub[i]);
117 log_duration("ECDH", "get public"); 118 log_duration ("ECDH", "get public");
118 119
119 start = GNUNET_TIME_absolute_get(); 120 start = GNUNET_TIME_absolute_get ();
120 for (i = 0; i < l - 1; i += 2) 121 for (i = 0; i < l - 1; i += 2)
121 { 122 {
122 GNUNET_CRYPTO_ecc_ecdh(ecdhe[i], &dhpub[i + 1], &sig[i].h); 123 GNUNET_CRYPTO_ecc_ecdh (ecdhe[i], &dhpub[i + 1], &sig[i].h);
123 GNUNET_CRYPTO_ecc_ecdh(ecdhe[i + 1], &dhpub[i], &sig[i + 1].h); 124 GNUNET_CRYPTO_ecc_ecdh (ecdhe[i + 1], &dhpub[i], &sig[i + 1].h);
124 } 125 }
125 log_duration("ECDH", "do DH"); 126 log_duration ("ECDH", "do DH");
126 127
127 return 0; 128 return 0;
128} 129}