diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-10 14:40:06 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-10 14:40:06 +0000 |
commit | 4add4c6a6302ff01539e246f68aaf13299414fd6 (patch) | |
tree | 2f5343a10726d165c35c98c48eb59247a5ab3a63 | |
parent | 9351b1e9bdf2b067b6db06562c26ba658cff42b8 (diff) | |
download | gnunet-4add4c6a6302ff01539e246f68aaf13299414fd6.tar.gz gnunet-4add4c6a6302ff01539e246f68aaf13299414fd6.zip |
-updated tests
-rw-r--r-- | src/util/test_crypto_ecdhe.c | 64 | ||||
-rw-r--r-- | src/util/test_crypto_ecdsa.c (renamed from src/util/test_crypto_ecc.c) | 149 | ||||
-rw-r--r-- | src/util/test_crypto_eddsa.c | 204 |
3 files changed, 316 insertions, 101 deletions
diff --git a/src/util/test_crypto_ecdhe.c b/src/util/test_crypto_ecdhe.c new file mode 100644 index 000000000..a6f96d9f1 --- /dev/null +++ b/src/util/test_crypto_ecdhe.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2002-2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | |||
20 | */ | ||
21 | /** | ||
22 | * @file util/test_crypto_ecdhe.c | ||
23 | * @brief testcase for ECC ECDHE public key crypto | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include <gcrypt.h> | ||
29 | |||
30 | |||
31 | int | ||
32 | main (int argc, char *argv[]) | ||
33 | { | ||
34 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv1; | ||
35 | struct GNUNET_CRYPTO_EcdhePrivateKey *priv2; | ||
36 | struct GNUNET_CRYPTO_EcdhePublicKey pub1; | ||
37 | struct GNUNET_CRYPTO_EcdhePublicKey pub2; | ||
38 | struct GNUNET_HashCode ecdh1; | ||
39 | struct GNUNET_HashCode ecdh2; | ||
40 | |||
41 | if (! gcry_check_version ("1.5.0")) | ||
42 | { | ||
43 | FPRINTF (stderr, | ||
44 | _ | ||
45 | ("libgcrypt has not the expected version (version %s is required).\n"), | ||
46 | "1.5.0"); | ||
47 | return 0; | ||
48 | } | ||
49 | GNUNET_log_setup ("test-crypto-ecdhe", "WARNING", NULL); | ||
50 | |||
51 | priv1 = GNUNET_CRYPTO_ecdhe_key_create (); | ||
52 | priv2 = GNUNET_CRYPTO_ecdhe_key_create (); | ||
53 | GNUNET_CRYPTO_ecdhe_key_get_public (priv1, &pub1); | ||
54 | GNUNET_CRYPTO_ecdhe_key_get_public (priv2, &pub2); | ||
55 | GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &ecdh1); | ||
56 | GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &ecdh2); | ||
57 | GNUNET_assert (0 == memcmp (&ecdh1, &ecdh2, | ||
58 | sizeof (struct GNUNET_HashCode))); | ||
59 | GNUNET_free (priv1); | ||
60 | GNUNET_free (priv2); | ||
61 | return 0; | ||
62 | } | ||
63 | |||
64 | /* end of test_crypto_ecdhe.c */ | ||
diff --git a/src/util/test_crypto_ecc.c b/src/util/test_crypto_ecdsa.c index c89568bb9..27c0fb137 100644 --- a/src/util/test_crypto_ecc.c +++ b/src/util/test_crypto_ecdsa.c | |||
@@ -19,8 +19,8 @@ | |||
19 | 19 | ||
20 | */ | 20 | */ |
21 | /** | 21 | /** |
22 | * @file util/test_crypto_ecc.c | 22 | * @file util/test_crypto_ecdsa.c |
23 | * @brief testcase for ECC public key crypto | 23 | * @brief testcase for ECC ECDSA public key crypto |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
@@ -30,26 +30,24 @@ | |||
30 | 30 | ||
31 | #define ITER 25 | 31 | #define ITER 25 |
32 | 32 | ||
33 | #define KEYFILE "/tmp/test-gnunet-crypto-ecc.key" | ||
34 | |||
35 | #define PERF GNUNET_YES | 33 | #define PERF GNUNET_YES |
36 | 34 | ||
37 | 35 | ||
38 | static struct GNUNET_CRYPTO_EccPrivateKey *key; | 36 | static struct GNUNET_CRYPTO_EcdsaPrivateKey *key; |
39 | 37 | ||
40 | 38 | ||
41 | static int | 39 | static int |
42 | testSignVerify () | 40 | testSignVerify () |
43 | { | 41 | { |
44 | struct GNUNET_CRYPTO_EccSignature sig; | 42 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
45 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 43 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
46 | struct GNUNET_CRYPTO_EccPublicSignKey pkey; | 44 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
47 | int i; | 45 | int i; |
48 | struct GNUNET_TIME_Absolute start; | 46 | struct GNUNET_TIME_Absolute start; |
49 | int ok = GNUNET_OK; | 47 | int ok = GNUNET_OK; |
50 | 48 | ||
51 | FPRINTF (stderr, "%s", "W"); | 49 | FPRINTF (stderr, "%s", "W"); |
52 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (key, &pkey); | 50 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey); |
53 | start = GNUNET_TIME_absolute_get (); | 51 | start = GNUNET_TIME_absolute_get (); |
54 | purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); | 52 | purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); |
55 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 53 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
@@ -57,30 +55,32 @@ testSignVerify () | |||
57 | for (i = 0; i < ITER; i++) | 55 | for (i = 0; i < ITER; i++) |
58 | { | 56 | { |
59 | FPRINTF (stderr, "%s", "."); | 57 | FPRINTF (stderr, "%s", "."); |
60 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecc_sign (key, &purp, &sig)) | 58 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig)) |
61 | { | 59 | { |
62 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecc_sign returned SYSERR\n"); | 60 | FPRINTF (stderr, |
61 | "%s", | ||
62 | "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); | ||
63 | ok = GNUNET_SYSERR; | 63 | ok = GNUNET_SYSERR; |
64 | continue; | 64 | continue; |
65 | } | 65 | } |
66 | if (GNUNET_SYSERR == | 66 | if (GNUNET_SYSERR == |
67 | GNUNET_CRYPTO_ecc_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig, | 67 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig, |
68 | &pkey)) | 68 | &pkey)) |
69 | { | 69 | { |
70 | printf ("GNUNET_CRYPTO_ecc_verify failed!\n"); | 70 | printf ("GNUNET_CRYPTO_ecdsa_verify failed!\n"); |
71 | ok = GNUNET_SYSERR; | 71 | ok = GNUNET_SYSERR; |
72 | continue; | 72 | continue; |
73 | } | 73 | } |
74 | if (GNUNET_SYSERR != | 74 | if (GNUNET_SYSERR != |
75 | GNUNET_CRYPTO_ecc_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | 75 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, |
76 | &purp, &sig, &pkey)) | 76 | &purp, &sig, &pkey)) |
77 | { | 77 | { |
78 | printf ("GNUNET_CRYPTO_ecc_verify failed to fail!\n"); | 78 | printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); |
79 | ok = GNUNET_SYSERR; | 79 | ok = GNUNET_SYSERR; |
80 | continue; | 80 | continue; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | printf ("%d ECC sign/verify operations %s\n", ITER, | 83 | printf ("%d ECDSA sign/verify operations %s\n", ITER, |
84 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | 84 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); |
85 | return ok; | 85 | return ok; |
86 | } | 86 | } |
@@ -89,47 +89,47 @@ testSignVerify () | |||
89 | static int | 89 | static int |
90 | testDeriveSignVerify () | 90 | testDeriveSignVerify () |
91 | { | 91 | { |
92 | struct GNUNET_CRYPTO_EccSignature sig; | 92 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
93 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 93 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
94 | struct GNUNET_CRYPTO_EccPrivateKey *dpriv; | 94 | struct GNUNET_CRYPTO_EcdsaPrivateKey *dpriv; |
95 | struct GNUNET_CRYPTO_EccPublicSignKey pkey; | 95 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
96 | struct GNUNET_CRYPTO_EccPublicSignKey dpub; | 96 | struct GNUNET_CRYPTO_EcdsaPublicKey dpub; |
97 | 97 | ||
98 | dpriv = GNUNET_CRYPTO_ecc_key_derive (key, "test-derive", "test-CTX"); | 98 | dpriv = GNUNET_CRYPTO_ecdsa_private_key_derive (key, "test-derive", "test-CTX"); |
99 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (key, &pkey); | 99 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey); |
100 | GNUNET_CRYPTO_ecc_public_key_derive (&pkey, "test-derive", "test-CTX", &dpub); | 100 | GNUNET_CRYPTO_ecdsa_public_key_derive (&pkey, "test-derive", "test-CTX", &dpub); |
101 | purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); | 101 | purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); |
102 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 102 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
103 | 103 | ||
104 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecc_sign (dpriv, &purp, &sig)) | 104 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (dpriv, &purp, &sig)) |
105 | { | 105 | { |
106 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecc_sign returned SYSERR\n"); | 106 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); |
107 | GNUNET_free (dpriv); | 107 | GNUNET_free (dpriv); |
108 | return GNUNET_SYSERR; | 108 | return GNUNET_SYSERR; |
109 | } | 109 | } |
110 | if (GNUNET_SYSERR == | 110 | if (GNUNET_SYSERR == |
111 | GNUNET_CRYPTO_ecc_verify (GNUNET_SIGNATURE_PURPOSE_TEST, | 111 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, |
112 | &purp, &sig, | 112 | &purp, &sig, |
113 | &dpub)) | 113 | &dpub)) |
114 | { | 114 | { |
115 | printf ("GNUNET_CRYPTO_ecc_verify failed!\n"); | 115 | printf ("GNUNET_CRYPTO_ecdsa_verify failed!\n"); |
116 | GNUNET_free (dpriv); | 116 | GNUNET_free (dpriv); |
117 | return GNUNET_SYSERR; | 117 | return GNUNET_SYSERR; |
118 | } | 118 | } |
119 | if (GNUNET_SYSERR != | 119 | if (GNUNET_SYSERR != |
120 | GNUNET_CRYPTO_ecc_verify (GNUNET_SIGNATURE_PURPOSE_TEST, | 120 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, |
121 | &purp, &sig, | 121 | &purp, &sig, |
122 | &pkey)) | 122 | &pkey)) |
123 | { | 123 | { |
124 | printf ("GNUNET_CRYPTO_ecc_verify failed to fail!\n"); | 124 | printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); |
125 | GNUNET_free (dpriv); | 125 | GNUNET_free (dpriv); |
126 | return GNUNET_SYSERR; | 126 | return GNUNET_SYSERR; |
127 | } | 127 | } |
128 | if (GNUNET_SYSERR != | 128 | if (GNUNET_SYSERR != |
129 | GNUNET_CRYPTO_ecc_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | 129 | GNUNET_CRYPTO_ecdsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, |
130 | &purp, &sig, &dpub)) | 130 | &purp, &sig, &dpub)) |
131 | { | 131 | { |
132 | printf ("GNUNET_CRYPTO_ecc_verify failed to fail!\n"); | 132 | printf ("GNUNET_CRYPTO_ecdsa_verify failed to fail!\n"); |
133 | GNUNET_free (dpriv); | 133 | GNUNET_free (dpriv); |
134 | return GNUNET_SYSERR; | 134 | return GNUNET_SYSERR; |
135 | } | 135 | } |
@@ -138,15 +138,13 @@ testDeriveSignVerify () | |||
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | |||
142 | |||
143 | #if PERF | 141 | #if PERF |
144 | static int | 142 | static int |
145 | testSignPerformance () | 143 | testSignPerformance () |
146 | { | 144 | { |
147 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 145 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
148 | struct GNUNET_CRYPTO_EccSignature sig; | 146 | struct GNUNET_CRYPTO_EcdsaSignature sig; |
149 | struct GNUNET_CRYPTO_EccPublicSignKey pkey; | 147 | struct GNUNET_CRYPTO_EcdsaPublicKey pkey; |
150 | int i; | 148 | int i; |
151 | struct GNUNET_TIME_Absolute start; | 149 | struct GNUNET_TIME_Absolute start; |
152 | int ok = GNUNET_OK; | 150 | int ok = GNUNET_OK; |
@@ -154,14 +152,15 @@ testSignPerformance () | |||
154 | purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); | 152 | purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); |
155 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 153 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
156 | FPRINTF (stderr, "%s", "W"); | 154 | FPRINTF (stderr, "%s", "W"); |
157 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (key, &pkey); | 155 | GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey); |
158 | start = GNUNET_TIME_absolute_get (); | 156 | start = GNUNET_TIME_absolute_get (); |
159 | for (i = 0; i < ITER; i++) | 157 | for (i = 0; i < ITER; i++) |
160 | { | 158 | { |
161 | FPRINTF (stderr, "%s", "."); | 159 | FPRINTF (stderr, "%s", "."); |
162 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecc_sign (key, &purp, &sig)) | 160 | if (GNUNET_SYSERR == GNUNET_CRYPTO_ecdsa_sign (key, &purp, &sig)) |
163 | { | 161 | { |
164 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_ecc_sign returned SYSERR\n"); | 162 | FPRINTF (stderr, "%s", |
163 | "GNUNET_CRYPTO_ecdsa_sign returned SYSERR\n"); | ||
165 | ok = GNUNET_SYSERR; | 164 | ok = GNUNET_SYSERR; |
166 | continue; | 165 | continue; |
167 | } | 166 | } |
@@ -174,70 +173,22 @@ testSignPerformance () | |||
174 | #endif | 173 | #endif |
175 | 174 | ||
176 | 175 | ||
177 | static int | ||
178 | testCreateFromFile () | ||
179 | { | ||
180 | struct GNUNET_CRYPTO_EccPublicSignKey p1; | ||
181 | struct GNUNET_CRYPTO_EccPublicSignKey p2; | ||
182 | |||
183 | key = GNUNET_CRYPTO_ecc_key_create_from_file (KEYFILE); | ||
184 | GNUNET_assert (NULL != key); | ||
185 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (key, &p1); | ||
186 | GNUNET_free (key); | ||
187 | key = GNUNET_CRYPTO_ecc_key_create_from_file (KEYFILE); | ||
188 | GNUNET_assert (NULL != key); | ||
189 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (key, &p2); | ||
190 | GNUNET_assert (0 == memcmp (&p1, &p2, sizeof (p1))); | ||
191 | GNUNET_free (key); | ||
192 | GNUNET_assert (0 == UNLINK (KEYFILE)); | ||
193 | key = GNUNET_CRYPTO_ecc_key_create_from_file (KEYFILE); | ||
194 | GNUNET_assert (NULL != key); | ||
195 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (key, &p2); | ||
196 | GNUNET_assert (0 != memcmp (&p1, &p2, sizeof (p1))); | ||
197 | GNUNET_free (key); | ||
198 | return GNUNET_OK; | ||
199 | } | ||
200 | |||
201 | |||
202 | static void | ||
203 | test_ecdh () | ||
204 | { | ||
205 | struct GNUNET_CRYPTO_EccPrivateKey *priv1; | ||
206 | struct GNUNET_CRYPTO_EccPrivateKey *priv2; | ||
207 | struct GNUNET_CRYPTO_EccPublicEncryptKey pub1; | ||
208 | struct GNUNET_CRYPTO_EccPublicEncryptKey pub2; | ||
209 | struct GNUNET_HashCode ecdh1; | ||
210 | struct GNUNET_HashCode ecdh2; | ||
211 | |||
212 | priv1 = GNUNET_CRYPTO_ecc_key_create (); | ||
213 | priv2 = GNUNET_CRYPTO_ecc_key_create (); | ||
214 | GNUNET_CRYPTO_ecc_key_get_public_for_encryption (priv1, &pub1); | ||
215 | GNUNET_CRYPTO_ecc_key_get_public_for_encryption (priv2, &pub2); | ||
216 | GNUNET_CRYPTO_ecc_ecdh (priv1, &pub2, &ecdh1); | ||
217 | GNUNET_CRYPTO_ecc_ecdh (priv2, &pub1, &ecdh2); | ||
218 | GNUNET_assert (0 == memcmp (&ecdh1, &ecdh2, | ||
219 | sizeof (struct GNUNET_HashCode))); | ||
220 | GNUNET_free (priv1); | ||
221 | GNUNET_free (priv2); | ||
222 | } | ||
223 | |||
224 | |||
225 | static void | 176 | static void |
226 | perf_keygen () | 177 | perf_keygen () |
227 | { | 178 | { |
228 | struct GNUNET_TIME_Absolute start; | 179 | struct GNUNET_TIME_Absolute start; |
229 | struct GNUNET_CRYPTO_EccPrivateKey *pk; | 180 | struct GNUNET_CRYPTO_EcdsaPrivateKey *pk; |
230 | int i; | 181 | int i; |
231 | 182 | ||
232 | start = GNUNET_TIME_absolute_get (); | 183 | start = GNUNET_TIME_absolute_get (); |
233 | for (i=0;i<10;i++) | 184 | for (i=0;i<10;i++) |
234 | { | 185 | { |
235 | fprintf (stderr, "."); | 186 | fprintf (stderr, "."); |
236 | pk = GNUNET_CRYPTO_ecc_key_create (); | 187 | pk = GNUNET_CRYPTO_ecdsa_key_create (); |
237 | GNUNET_free (pk); | 188 | GNUNET_free (pk); |
238 | } | 189 | } |
239 | fprintf (stderr, "\n"); | 190 | fprintf (stderr, "\n"); |
240 | printf ("Creating 10 ECC keys took %s\n", | 191 | printf ("Creating 10 ECDSA keys took %s\n", |
241 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | 192 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); |
242 | } | 193 | } |
243 | 194 | ||
@@ -256,7 +207,7 @@ main (int argc, char *argv[]) | |||
256 | return 0; | 207 | return 0; |
257 | } | 208 | } |
258 | GNUNET_log_setup ("test-crypto-ecc", "WARNING", NULL); | 209 | GNUNET_log_setup ("test-crypto-ecc", "WARNING", NULL); |
259 | key = GNUNET_CRYPTO_ecc_key_create (); | 210 | key = GNUNET_CRYPTO_ecdsa_key_create (); |
260 | if (GNUNET_OK != testDeriveSignVerify ()) | 211 | if (GNUNET_OK != testDeriveSignVerify ()) |
261 | { | 212 | { |
262 | failure_count++; | 213 | failure_count++; |
@@ -271,10 +222,6 @@ main (int argc, char *argv[]) | |||
271 | if (GNUNET_OK != testSignVerify ()) | 222 | if (GNUNET_OK != testSignVerify ()) |
272 | failure_count++; | 223 | failure_count++; |
273 | GNUNET_free (key); | 224 | GNUNET_free (key); |
274 | if (GNUNET_OK != testCreateFromFile ()) | ||
275 | failure_count++; | ||
276 | GNUNET_assert (0 == UNLINK (KEYFILE)); | ||
277 | test_ecdh (); | ||
278 | perf_keygen (); | 225 | perf_keygen (); |
279 | 226 | ||
280 | if (0 != failure_count) | 227 | if (0 != failure_count) |
@@ -287,4 +234,4 @@ main (int argc, char *argv[]) | |||
287 | return 0; | 234 | return 0; |
288 | } | 235 | } |
289 | 236 | ||
290 | /* end of test_crypto_ecc.c */ | 237 | /* end of test_crypto_ecdsa.c */ |
diff --git a/src/util/test_crypto_eddsa.c b/src/util/test_crypto_eddsa.c new file mode 100644 index 000000000..209eea5c6 --- /dev/null +++ b/src/util/test_crypto_eddsa.c | |||
@@ -0,0 +1,204 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2002-2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | |||
20 | */ | ||
21 | /** | ||
22 | * @file util/test_crypto_eddsa.c | ||
23 | * @brief testcase for ECC public key crypto | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_signatures.h" | ||
29 | #include <gcrypt.h> | ||
30 | |||
31 | #define ITER 25 | ||
32 | |||
33 | #define KEYFILE "/tmp/test-gnunet-crypto-eddsa.key" | ||
34 | |||
35 | #define PERF GNUNET_YES | ||
36 | |||
37 | |||
38 | static struct GNUNET_CRYPTO_EddsaPrivateKey *key; | ||
39 | |||
40 | |||
41 | static int | ||
42 | testSignVerify () | ||
43 | { | ||
44 | struct GNUNET_CRYPTO_EddsaSignature sig; | ||
45 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | ||
46 | struct GNUNET_CRYPTO_EddsaPublicKey pkey; | ||
47 | int i; | ||
48 | struct GNUNET_TIME_Absolute start; | ||
49 | int ok = GNUNET_OK; | ||
50 | |||
51 | FPRINTF (stderr, "%s", "W"); | ||
52 | GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey); | ||
53 | start = GNUNET_TIME_absolute_get (); | ||
54 | purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); | ||
55 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | ||
56 | |||
57 | for (i = 0; i < ITER; i++) | ||
58 | { | ||
59 | FPRINTF (stderr, "%s", "."); | ||
60 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig)) | ||
61 | { | ||
62 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); | ||
63 | ok = GNUNET_SYSERR; | ||
64 | continue; | ||
65 | } | ||
66 | if (GNUNET_SYSERR == | ||
67 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig, | ||
68 | &pkey)) | ||
69 | { | ||
70 | printf ("GNUNET_CRYPTO_eddsa_verify failed!\n"); | ||
71 | ok = GNUNET_SYSERR; | ||
72 | continue; | ||
73 | } | ||
74 | if (GNUNET_SYSERR != | ||
75 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | ||
76 | &purp, &sig, &pkey)) | ||
77 | { | ||
78 | printf ("GNUNET_CRYPTO_eddsa_verify failed to fail!\n"); | ||
79 | ok = GNUNET_SYSERR; | ||
80 | continue; | ||
81 | } | ||
82 | } | ||
83 | printf ("%d ECC sign/verify operations %s\n", ITER, | ||
84 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | ||
85 | return ok; | ||
86 | } | ||
87 | |||
88 | |||
89 | #if PERF | ||
90 | static int | ||
91 | testSignPerformance () | ||
92 | { | ||
93 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | ||
94 | struct GNUNET_CRYPTO_EddsaSignature sig; | ||
95 | struct GNUNET_CRYPTO_EddsaPublicKey pkey; | ||
96 | int i; | ||
97 | struct GNUNET_TIME_Absolute start; | ||
98 | int ok = GNUNET_OK; | ||
99 | |||
100 | purp.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); | ||
101 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | ||
102 | FPRINTF (stderr, "%s", "W"); | ||
103 | GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey); | ||
104 | start = GNUNET_TIME_absolute_get (); | ||
105 | for (i = 0; i < ITER; i++) | ||
106 | { | ||
107 | FPRINTF (stderr, "%s", "."); | ||
108 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig)) | ||
109 | { | ||
110 | FPRINTF (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); | ||
111 | ok = GNUNET_SYSERR; | ||
112 | continue; | ||
113 | } | ||
114 | } | ||
115 | printf ("%d EdDSA sign operations %s\n", ITER, | ||
116 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), | ||
117 | GNUNET_YES)); | ||
118 | return ok; | ||
119 | } | ||
120 | #endif | ||
121 | |||
122 | |||
123 | static int | ||
124 | testCreateFromFile () | ||
125 | { | ||
126 | struct GNUNET_CRYPTO_EddsaPublicKey p1; | ||
127 | struct GNUNET_CRYPTO_EddsaPublicKey p2; | ||
128 | |||
129 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); | ||
130 | GNUNET_assert (NULL != key); | ||
131 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p1); | ||
132 | GNUNET_free (key); | ||
133 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); | ||
134 | GNUNET_assert (NULL != key); | ||
135 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p2); | ||
136 | GNUNET_assert (0 == memcmp (&p1, &p2, sizeof (p1))); | ||
137 | GNUNET_free (key); | ||
138 | GNUNET_assert (0 == UNLINK (KEYFILE)); | ||
139 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); | ||
140 | GNUNET_assert (NULL != key); | ||
141 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p2); | ||
142 | GNUNET_assert (0 != memcmp (&p1, &p2, sizeof (p1))); | ||
143 | GNUNET_free (key); | ||
144 | return GNUNET_OK; | ||
145 | } | ||
146 | |||
147 | |||
148 | static void | ||
149 | perf_keygen () | ||
150 | { | ||
151 | struct GNUNET_TIME_Absolute start; | ||
152 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | ||
153 | int i; | ||
154 | |||
155 | start = GNUNET_TIME_absolute_get (); | ||
156 | for (i=0;i<10;i++) | ||
157 | { | ||
158 | fprintf (stderr, "."); | ||
159 | pk = GNUNET_CRYPTO_eddsa_key_create (); | ||
160 | GNUNET_free (pk); | ||
161 | } | ||
162 | fprintf (stderr, "\n"); | ||
163 | printf ("Creating 10 EdDSA keys took %s\n", | ||
164 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | ||
165 | } | ||
166 | |||
167 | |||
168 | int | ||
169 | main (int argc, char *argv[]) | ||
170 | { | ||
171 | int failure_count = 0; | ||
172 | |||
173 | if (! gcry_check_version ("1.5.0")) | ||
174 | { | ||
175 | FPRINTF (stderr, | ||
176 | _("libgcrypt has not the expected version (version %s is required).\n"), | ||
177 | "1.5.0"); | ||
178 | return 0; | ||
179 | } | ||
180 | GNUNET_log_setup ("test-crypto-eddsa", "WARNING", NULL); | ||
181 | key = GNUNET_CRYPTO_eddsa_key_create (); | ||
182 | #if PERF | ||
183 | if (GNUNET_OK != testSignPerformance ()) | ||
184 | failure_count++; | ||
185 | #endif | ||
186 | if (GNUNET_OK != testSignVerify ()) | ||
187 | failure_count++; | ||
188 | GNUNET_free (key); | ||
189 | if (GNUNET_OK != testCreateFromFile ()) | ||
190 | failure_count++; | ||
191 | GNUNET_assert (0 == UNLINK (KEYFILE)); | ||
192 | perf_keygen (); | ||
193 | |||
194 | if (0 != failure_count) | ||
195 | { | ||
196 | fprintf (stderr, | ||
197 | "\n\n%d TESTS FAILED!\n\n", | ||
198 | failure_count); | ||
199 | return -1; | ||
200 | } | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | /* end of test_crypto_eddsa.c */ | ||