diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/util/test_crypto_ecdsa.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/util/test_crypto_ecdsa.c')
-rw-r--r-- | src/util/test_crypto_ecdsa.c | 264 |
1 files changed, 135 insertions, 129 deletions
diff --git a/src/util/test_crypto_ecdsa.c b/src/util/test_crypto_ecdsa.c index 797d61285..d6f406b47 100644 --- a/src/util/test_crypto_ecdsa.c +++ b/src/util/test_crypto_ecdsa.c | |||
@@ -37,7 +37,7 @@ static struct GNUNET_CRYPTO_EcdsaPrivateKey *key; | |||
37 | 37 | ||
38 | 38 | ||
39 | static int | 39 | static int |
40 | testSignVerify() | 40 | testSignVerify () |
41 | { | 41 | { |
42 | struct GNUNET_CRYPTO_EcdsaSignature sig; | 42 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
43 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 43 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
@@ -46,48 +46,49 @@ testSignVerify() | |||
46 | struct GNUNET_TIME_Absolute start; | 46 | struct GNUNET_TIME_Absolute start; |
47 | int ok = GNUNET_OK; | 47 | int ok = GNUNET_OK; |
48 | 48 | ||
49 | fprintf(stderr, "%s", "W"); | 49 | fprintf (stderr, "%s", "W"); |
50 | GNUNET_CRYPTO_ecdsa_key_get_public(key, &pkey); | 50 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey); |
51 | start = GNUNET_TIME_absolute_get(); | 51 | start = GNUNET_TIME_absolute_get (); |
52 | purp.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 52 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
53 | purp.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TEST); | 53 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
54 | 54 | ||
55 | for (i = 0; i < ITER; i++) | 55 | for (i = 0; i < ITER; i++) |
56 | { | ||
57 | fprintf (stderr, "%s", "."); fflush (stderr); | ||
58 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig)) | ||
56 | { | 59 | { |
57 | fprintf(stderr, "%s", "."); fflush(stderr); | 60 | fprintf (stderr, |
58 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign(key, &purp, &sig)) | 61 | "%s", |
59 | { | 62 | "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); |
60 | fprintf(stderr, | 63 | ok = GNUNET_SYSERR; |
61 | "%s", | 64 | continue; |
62 | "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); | ||
63 | ok = GNUNET_SYSERR; | ||
64 | continue; | ||
65 | } | ||
66 | if (GNUNET_SYSERR == | ||
67 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig, | ||
68 | &pkey)) | ||
69 | { | ||
70 | printf("GNUNET_CRYPTO_ecdsa_verify failed!\n"); | ||
71 | ok = GNUNET_SYSERR; | ||
72 | continue; | ||
73 | } | ||
74 | if (GNUNET_SYSERR != | ||
75 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | ||
76 | &purp, &sig, &pkey)) | ||
77 | { | ||
78 | printf("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); | ||
79 | ok = GNUNET_SYSERR; | ||
80 | continue; | ||
81 | } | ||
82 | } | 65 | } |
83 | printf("%d ECDSA sign/verify operations %s\n", ITER, | 66 | if (GNUNET_SYSERR == |
84 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start), GNUNET_YES)); | 67 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig, |
68 | &pkey)) | ||
69 | { | ||
70 | printf ("GNUNET_CRYPTO_ecdsa_verify failed!\n"); | ||
71 | ok = GNUNET_SYSERR; | ||
72 | continue; | ||
73 | } | ||
74 | if (GNUNET_SYSERR != | ||
75 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | ||
76 | &purp, &sig, &pkey)) | ||
77 | { | ||
78 | printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); | ||
79 | ok = GNUNET_SYSERR; | ||
80 | continue; | ||
81 | } | ||
82 | } | ||
83 | printf ("%d ECDSA sign/verify operations %s\n", ITER, | ||
84 | GNUNET_STRINGS_relative_time_to_string ( | ||
85 | GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | ||
85 | return ok; | 86 | return ok; |
86 | } | 87 | } |
87 | 88 | ||
88 | 89 | ||
89 | static int | 90 | static int |
90 | testDeriveSignVerify() | 91 | testDeriveSignVerify () |
91 | { | 92 | { |
92 | struct GNUNET_CRYPTO_EcdsaSignature sig; | 93 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
93 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 94 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
@@ -95,52 +96,54 @@ testDeriveSignVerify() | |||
95 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; | 96 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
96 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; | 97 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; |
97 | 98 | ||
98 | dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive(key, "test-derive", "test-CTX"); | 99 | dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (key, "test-derive", |
99 | GNUNET_CRYPTO_ecdsa_key_get_public(key, &pkey); | 100 | "test-CTX"); |
100 | GNUNET_CRYPTO_ecdsa_public_key_derive(&pkey, "test-derive", "test-CTX", &dpub); | 101 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey); |
101 | purp.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 102 | GNUNET_CRYPTO_ecdsa_public_key_derive (&pkey, "test-derive", "test-CTX", |
102 | purp.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TEST); | 103 | &dpub); |
103 | 104 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | |
104 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign(dpriv, &purp, &sig)) | 105 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
105 | { | 106 | |
106 | fprintf(stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); | 107 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (dpriv, &purp, &sig)) |
107 | GNUNET_free(dpriv); | 108 | { |
108 | return GNUNET_SYSERR; | 109 | fprintf (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); |
109 | } | 110 | GNUNET_free (dpriv); |
111 | return GNUNET_SYSERR; | ||
112 | } | ||
110 | if (GNUNET_SYSERR == | 113 | if (GNUNET_SYSERR == |
111 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_TEST, | 114 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, |
112 | &purp, &sig, | 115 | &purp, &sig, |
113 | &dpub)) | 116 | &dpub)) |
114 | { | 117 | { |
115 | printf("GNUNET_CRYPTO_ecdsa_verify failed!\n"); | 118 | printf ("GNUNET_CRYPTO_ecdsa_verify failed!\n"); |
116 | GNUNET_free(dpriv); | 119 | GNUNET_free (dpriv); |
117 | return GNUNET_SYSERR; | 120 | return GNUNET_SYSERR; |
118 | } | 121 | } |
119 | if (GNUNET_SYSERR != | 122 | if (GNUNET_SYSERR != |
120 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_TEST, | 123 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, |
121 | &purp, &sig, | 124 | &purp, &sig, |
122 | &pkey)) | 125 | &pkey)) |
123 | { | 126 | { |
124 | printf("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); | 127 | printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); |
125 | GNUNET_free(dpriv); | 128 | GNUNET_free (dpriv); |
126 | return GNUNET_SYSERR; | 129 | return GNUNET_SYSERR; |
127 | } | 130 | } |
128 | if (GNUNET_SYSERR != | 131 | if (GNUNET_SYSERR != |
129 | GNUNET_CRYPTO_ecdsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | 132 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, |
130 | &purp, &sig, &dpub)) | 133 | &purp, &sig, &dpub)) |
131 | { | 134 | { |
132 | printf("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); | 135 | printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); |
133 | GNUNET_free(dpriv); | 136 | GNUNET_free (dpriv); |
134 | return GNUNET_SYSERR; | 137 | return GNUNET_SYSERR; |
135 | } | 138 | } |
136 | GNUNET_free(dpriv); | 139 | GNUNET_free (dpriv); |
137 | return GNUNET_OK; | 140 | return GNUNET_OK; |
138 | } | 141 | } |
139 | 142 | ||
140 | 143 | ||
141 | #if PERF | 144 | #if PERF |
142 | static int | 145 | static int |
143 | testSignPerformance() | 146 | testSignPerformance () |
144 | { | 147 | { |
145 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 148 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
146 | struct GNUNET_CRYPTO_EcdsaSignature sig; | 149 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
@@ -149,93 +152,96 @@ testSignPerformance() | |||
149 | struct GNUNET_TIME_Absolute start; | 152 | struct GNUNET_TIME_Absolute start; |
150 | int ok = GNUNET_OK; | 153 | int ok = GNUNET_OK; |
151 | 154 | ||
152 | purp.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 155 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
153 | purp.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TEST); | 156 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
154 | fprintf(stderr, "%s", "W"); | 157 | fprintf (stderr, "%s", "W"); |
155 | GNUNET_CRYPTO_ecdsa_key_get_public(key, &pkey); | 158 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey); |
156 | start = GNUNET_TIME_absolute_get(); | 159 | start = GNUNET_TIME_absolute_get (); |
157 | for (i = 0; i < ITER; i++) | 160 | for (i = 0; i < ITER; i++) |
161 | { | ||
162 | fprintf (stderr, "%s", "."); fflush (stderr); | ||
163 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig)) | ||
158 | { | 164 | { |
159 | fprintf(stderr, "%s", "."); fflush(stderr); | 165 | fprintf (stderr, "%s", |
160 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign(key, &purp, &sig)) | 166 | "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); |
161 | { | 167 | ok = GNUNET_SYSERR; |
162 | fprintf(stderr, "%s", | 168 | continue; |
163 | "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); | ||
164 | ok = GNUNET_SYSERR; | ||
165 | continue; | ||
166 | } | ||
167 | } | 169 | } |
168 | printf("%d ECC sign operations %s\n", ITER, | 170 | } |
169 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start), | 171 | printf ("%d ECC sign operations %s\n", ITER, |
170 | GNUNET_YES)); | 172 | GNUNET_STRINGS_relative_time_to_string ( |
173 | GNUNET_TIME_absolute_get_duration (start), | ||
174 | GNUNET_YES)); | ||
171 | return ok; | 175 | return ok; |
172 | } | 176 | } |
173 | #endif | 177 | #endif |
174 | 178 | ||
175 | 179 | ||
176 | static void | 180 | static void |
177 | perf_keygen() | 181 | perf_keygen () |
178 | { | 182 | { |
179 | struct GNUNET_TIME_Absolute start; | 183 | struct GNUNET_TIME_Absolute start; |
180 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; | 184 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; |
181 | int i; | 185 | int i; |
182 | 186 | ||
183 | fprintf(stderr, "%s", "W"); | 187 | fprintf (stderr, "%s", "W"); |
184 | start = GNUNET_TIME_absolute_get(); | 188 | start = GNUNET_TIME_absolute_get (); |
185 | for (i = 0; i < 10; i++) | 189 | for (i = 0; i < 10; i++) |
186 | { | 190 | { |
187 | fprintf(stderr, "."); fflush(stderr); | 191 | fprintf (stderr, "."); fflush (stderr); |
188 | pk = GNUNET_CRYPTO_ecdsa_key_create(); | 192 | pk = GNUNET_CRYPTO_ecdsa_key_create (); |
189 | GNUNET_free(pk); | 193 | GNUNET_free (pk); |
190 | } | 194 | } |
191 | for (; i < 25; i++) | 195 | for (; i < 25; i++) |
192 | fprintf(stderr, "."); | 196 | fprintf (stderr, "."); |
193 | fflush(stderr); | 197 | fflush (stderr); |
194 | printf("10 ECDSA keys created in %s\n", | 198 | printf ("10 ECDSA keys created in %s\n", |
195 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start), GNUNET_YES)); | 199 | GNUNET_STRINGS_relative_time_to_string ( |
200 | GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | ||
196 | } | 201 | } |
197 | 202 | ||
198 | 203 | ||
199 | int | 204 | int |
200 | main(int argc, char *argv[]) | 205 | main (int argc, char *argv[]) |
201 | { | 206 | { |
202 | int failure_count = 0; | 207 | int failure_count = 0; |
203 | 208 | ||
204 | if (!gcry_check_version("1.6.0")) | 209 | if (! gcry_check_version ("1.6.0")) |
205 | { | 210 | { |
206 | fprintf(stderr, | 211 | fprintf (stderr, |
207 | _ | 212 | _ |
208 | ("libgcrypt has not the expected version (version %s is required).\n"), | 213 | ( |
209 | "1.6.0"); | 214 | "libgcrypt has not the expected version (version %s is required).\n"), |
210 | return 0; | 215 | "1.6.0"); |
211 | } | 216 | return 0; |
212 | if (getenv("GNUNET_GCRYPT_DEBUG")) | 217 | } |
213 | gcry_control(GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); | 218 | if (getenv ("GNUNET_GCRYPT_DEBUG")) |
214 | GNUNET_log_setup("test-crypto-ecc", "WARNING", NULL); | 219 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); |
215 | key = GNUNET_CRYPTO_ecdsa_key_create(); | 220 | GNUNET_log_setup ("test-crypto-ecc", "WARNING", NULL); |
216 | if (GNUNET_OK != testDeriveSignVerify()) | 221 | key = GNUNET_CRYPTO_ecdsa_key_create (); |
217 | { | 222 | if (GNUNET_OK != testDeriveSignVerify ()) |
218 | failure_count++; | 223 | { |
219 | fprintf(stderr, | 224 | failure_count++; |
220 | "\n\n%d TESTS FAILED!\n\n", failure_count); | 225 | fprintf (stderr, |
221 | return -1; | 226 | "\n\n%d TESTS FAILED!\n\n", failure_count); |
222 | } | 227 | return -1; |
228 | } | ||
223 | #if PERF | 229 | #if PERF |
224 | if (GNUNET_OK != testSignPerformance()) | 230 | if (GNUNET_OK != testSignPerformance ()) |
225 | failure_count++; | 231 | failure_count++; |
226 | #endif | 232 | #endif |
227 | if (GNUNET_OK != testSignVerify()) | 233 | if (GNUNET_OK != testSignVerify ()) |
228 | failure_count++; | 234 | failure_count++; |
229 | GNUNET_free(key); | 235 | GNUNET_free (key); |
230 | perf_keygen(); | 236 | perf_keygen (); |
231 | 237 | ||
232 | if (0 != failure_count) | 238 | if (0 != failure_count) |
233 | { | 239 | { |
234 | fprintf(stderr, | 240 | fprintf (stderr, |
235 | "\n\n%d TESTS FAILED!\n\n", | 241 | "\n\n%d TESTS FAILED!\n\n", |
236 | failure_count); | 242 | failure_count); |
237 | return -1; | 243 | return -1; |
238 | } | 244 | } |
239 | return 0; | 245 | return 0; |
240 | } | 246 | } |
241 | 247 | ||