diff options
Diffstat (limited to 'src/util/test_crypto_eddsa.c')
-rw-r--r-- | src/util/test_crypto_eddsa.c | 108 |
1 files changed, 68 insertions, 40 deletions
diff --git a/src/util/test_crypto_eddsa.c b/src/util/test_crypto_eddsa.c index 87990cbac..5baf696b1 100644 --- a/src/util/test_crypto_eddsa.c +++ b/src/util/test_crypto_eddsa.c | |||
@@ -35,11 +35,11 @@ | |||
35 | #define PERF GNUNET_YES | 35 | #define PERF GNUNET_YES |
36 | 36 | ||
37 | 37 | ||
38 | static struct GNUNET_CRYPTO_EddsaPrivateKey *key; | 38 | static struct GNUNET_CRYPTO_EddsaPrivateKey key; |
39 | 39 | ||
40 | 40 | ||
41 | static int | 41 | static int |
42 | testSignVerify () | 42 | testSignVerify (void) |
43 | { | 43 | { |
44 | struct GNUNET_CRYPTO_EddsaSignature sig; | 44 | struct GNUNET_CRYPTO_EddsaSignature sig; |
45 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 45 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
@@ -48,7 +48,8 @@ testSignVerify () | |||
48 | int ok = GNUNET_OK; | 48 | int ok = GNUNET_OK; |
49 | 49 | ||
50 | fprintf (stderr, "%s", "W"); | 50 | fprintf (stderr, "%s", "W"); |
51 | GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey); | 51 | GNUNET_CRYPTO_eddsa_key_get_public (&key, |
52 | &pkey); | ||
52 | start = GNUNET_TIME_absolute_get (); | 53 | start = GNUNET_TIME_absolute_get (); |
53 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 54 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
54 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 55 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
@@ -56,34 +57,45 @@ testSignVerify () | |||
56 | for (unsigned int i = 0; i < ITER; i++) | 57 | for (unsigned int i = 0; i < ITER; i++) |
57 | { | 58 | { |
58 | fprintf (stderr, "%s", "."); fflush (stderr); | 59 | fprintf (stderr, "%s", "."); fflush (stderr); |
59 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign_ (key, &purp, &sig)) | 60 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign_ (&key, |
61 | &purp, | ||
62 | &sig)) | ||
60 | { | 63 | { |
61 | fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); | 64 | fprintf (stderr, |
65 | "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); | ||
62 | ok = GNUNET_SYSERR; | 66 | ok = GNUNET_SYSERR; |
63 | continue; | 67 | continue; |
64 | } | 68 | } |
65 | if (GNUNET_SYSERR == | 69 | if (GNUNET_SYSERR == |
66 | GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, &purp, &sig, | 70 | GNUNET_CRYPTO_eddsa_verify_ (GNUNET_SIGNATURE_PURPOSE_TEST, |
71 | &purp, | ||
72 | &sig, | ||
67 | &pkey)) | 73 | &pkey)) |
68 | { | 74 | { |
69 | printf ("GNUNET_CRYPTO_eddsa_verify failed!\n"); | 75 | fprintf (stderr, |
76 | "GNUNET_CRYPTO_eddsa_verify failed!\n"); | ||
70 | ok = GNUNET_SYSERR; | 77 | ok = GNUNET_SYSERR; |
71 | continue; | 78 | continue; |
72 | } | 79 | } |
73 | if (GNUNET_SYSERR != | 80 | if (GNUNET_SYSERR != |
74 | GNUNET_CRYPTO_eddsa_verify_ ( | 81 | GNUNET_CRYPTO_eddsa_verify_ ( |
75 | GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, | 82 | GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, |
76 | &purp, &sig, &pkey)) | 83 | &purp, |
84 | &sig, | ||
85 | &pkey)) | ||
77 | { | 86 | { |
78 | printf ("GNUNET_CRYPTO_eddsa_verify failed to fail!\n"); | 87 | fprintf (stderr, |
88 | "GNUNET_CRYPTO_eddsa_verify failed to fail!\n"); | ||
79 | ok = GNUNET_SYSERR; | 89 | ok = GNUNET_SYSERR; |
80 | continue; | 90 | continue; |
81 | } | 91 | } |
82 | } | 92 | } |
83 | fprintf (stderr, "\n"); | 93 | fprintf (stderr, "\n"); |
84 | printf ("%d EdDSA sign/verify operations %s\n", ITER, | 94 | printf ("%d EdDSA sign/verify operations %s\n", |
95 | ITER, | ||
85 | GNUNET_STRINGS_relative_time_to_string ( | 96 | GNUNET_STRINGS_relative_time_to_string ( |
86 | GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | 97 | GNUNET_TIME_absolute_get_duration (start), |
98 | GNUNET_YES)); | ||
87 | return ok; | 99 | return ok; |
88 | } | 100 | } |
89 | 101 | ||
@@ -101,12 +113,17 @@ testSignPerformance () | |||
101 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 113 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
102 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); | 114 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
103 | fprintf (stderr, "%s", "W"); | 115 | fprintf (stderr, "%s", "W"); |
104 | GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey); | 116 | GNUNET_CRYPTO_eddsa_key_get_public (&key, |
117 | &pkey); | ||
105 | start = GNUNET_TIME_absolute_get (); | 118 | start = GNUNET_TIME_absolute_get (); |
106 | for (unsigned int i = 0; i < ITER; i++) | 119 | for (unsigned int i = 0; i < ITER; i++) |
107 | { | 120 | { |
108 | fprintf (stderr, "%s", "."); fflush (stderr); | 121 | fprintf (stderr, "%s", "."); |
109 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign_ (key, &purp, &sig)) | 122 | fflush (stderr); |
123 | if (GNUNET_SYSERR == | ||
124 | GNUNET_CRYPTO_eddsa_sign_ (&key, | ||
125 | &purp, | ||
126 | &sig)) | ||
110 | { | 127 | { |
111 | fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); | 128 | fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); |
112 | ok = GNUNET_SYSERR; | 129 | ok = GNUNET_SYSERR; |
@@ -114,7 +131,8 @@ testSignPerformance () | |||
114 | } | 131 | } |
115 | } | 132 | } |
116 | fprintf (stderr, "\n"); | 133 | fprintf (stderr, "\n"); |
117 | printf ("%d EdDSA sign operations %s\n", ITER, | 134 | printf ("%d EdDSA sign operations %s\n", |
135 | ITER, | ||
118 | GNUNET_STRINGS_relative_time_to_string ( | 136 | GNUNET_STRINGS_relative_time_to_string ( |
119 | GNUNET_TIME_absolute_get_duration (start), | 137 | GNUNET_TIME_absolute_get_duration (start), |
120 | GNUNET_YES)); | 138 | GNUNET_YES)); |
@@ -126,43 +144,53 @@ testSignPerformance () | |||
126 | 144 | ||
127 | 145 | ||
128 | static int | 146 | static int |
129 | testCreateFromFile () | 147 | testCreateFromFile (void) |
130 | { | 148 | { |
131 | struct GNUNET_CRYPTO_EddsaPublicKey p1; | 149 | struct GNUNET_CRYPTO_EddsaPublicKey p1; |
132 | struct GNUNET_CRYPTO_EddsaPublicKey p2; | 150 | struct GNUNET_CRYPTO_EddsaPublicKey p2; |
133 | 151 | ||
134 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); | 152 | GNUNET_assert (0 <= |
135 | GNUNET_assert (NULL != key); | 153 | GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE, |
136 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p1); | 154 | GNUNET_YES, |
137 | GNUNET_free (key); | 155 | &key)); |
138 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); | 156 | GNUNET_CRYPTO_eddsa_key_get_public (&key, |
139 | GNUNET_assert (NULL != key); | 157 | &p1); |
140 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p2); | 158 | GNUNET_assert (GNUNET_NO == |
141 | GNUNET_assert (0 == memcmp (&p1, &p2, sizeof(p1))); | 159 | GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE, |
142 | GNUNET_free (key); | 160 | GNUNET_YES, |
161 | &key)); | ||
162 | GNUNET_CRYPTO_eddsa_key_get_public (&key, | ||
163 | &p2); | ||
164 | GNUNET_assert (0 == | ||
165 | GNUNET_memcmp (&p1, | ||
166 | &p2)); | ||
143 | GNUNET_assert (0 == unlink (KEYFILE)); | 167 | GNUNET_assert (0 == unlink (KEYFILE)); |
144 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); | 168 | GNUNET_assert (GNUNET_OK == |
145 | GNUNET_assert (NULL != key); | 169 | GNUNET_CRYPTO_eddsa_key_from_file (KEYFILE, |
146 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p2); | 170 | GNUNET_NO, |
147 | GNUNET_assert (0 != memcmp (&p1, &p2, sizeof(p1))); | 171 | &key)); |
148 | GNUNET_free (key); | 172 | GNUNET_CRYPTO_eddsa_key_get_public (&key, |
173 | &p2); | ||
174 | GNUNET_assert (0 != | ||
175 | GNUNET_memcmp (&p1, | ||
176 | &p2)); | ||
149 | return GNUNET_OK; | 177 | return GNUNET_OK; |
150 | } | 178 | } |
151 | 179 | ||
152 | 180 | ||
153 | static void | 181 | static void |
154 | perf_keygen () | 182 | perf_keygen (void) |
155 | { | 183 | { |
156 | struct GNUNET_TIME_Absolute start; | 184 | struct GNUNET_TIME_Absolute start; |
157 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 185 | struct GNUNET_CRYPTO_EddsaPrivateKey pk; |
158 | 186 | ||
159 | fprintf (stderr, "%s", "W"); | 187 | fprintf (stderr, "%s", "W"); |
160 | start = GNUNET_TIME_absolute_get (); | 188 | start = GNUNET_TIME_absolute_get (); |
161 | for (unsigned int i = 0; i < 10; i++) | 189 | for (unsigned int i = 0; i < 10; i++) |
162 | { | 190 | { |
163 | fprintf (stderr, "."); fflush (stderr); | 191 | fprintf (stderr, "."); |
164 | pk = GNUNET_CRYPTO_eddsa_key_create (); | 192 | fflush (stderr); |
165 | GNUNET_free (pk); | 193 | GNUNET_CRYPTO_eddsa_key_create (&pk); |
166 | } | 194 | } |
167 | fprintf (stderr, "\n"); | 195 | fprintf (stderr, "\n"); |
168 | printf ("10 EdDSA keys created in %s\n", | 196 | printf ("10 EdDSA keys created in %s\n", |
@@ -179,22 +207,22 @@ main (int argc, char *argv[]) | |||
179 | if (! gcry_check_version ("1.6.0")) | 207 | if (! gcry_check_version ("1.6.0")) |
180 | { | 208 | { |
181 | fprintf (stderr, | 209 | fprintf (stderr, |
182 | _ ( | 210 | "libgcrypt has not the expected version (version %s is required).\n", |
183 | "libgcrypt has not the expected version (version %s is required).\n"), | ||
184 | "1.6.0"); | 211 | "1.6.0"); |
185 | return 0; | 212 | return 0; |
186 | } | 213 | } |
187 | if (getenv ("GNUNET_GCRYPT_DEBUG")) | 214 | if (getenv ("GNUNET_GCRYPT_DEBUG")) |
188 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); | 215 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); |
189 | GNUNET_log_setup ("test-crypto-eddsa", "WARNING", NULL); | 216 | GNUNET_log_setup ("test-crypto-eddsa", |
190 | key = GNUNET_CRYPTO_eddsa_key_create (); | 217 | "WARNING", |
218 | NULL); | ||
219 | GNUNET_CRYPTO_eddsa_key_create (&key); | ||
191 | #if PERF | 220 | #if PERF |
192 | if (GNUNET_OK != testSignPerformance ()) | 221 | if (GNUNET_OK != testSignPerformance ()) |
193 | failure_count++; | 222 | failure_count++; |
194 | #endif | 223 | #endif |
195 | if (GNUNET_OK != testSignVerify ()) | 224 | if (GNUNET_OK != testSignVerify ()) |
196 | failure_count++; | 225 | failure_count++; |
197 | GNUNET_free (key); | ||
198 | if (GNUNET_OK != testCreateFromFile ()) | 226 | if (GNUNET_OK != testCreateFromFile ()) |
199 | failure_count++; | 227 | failure_count++; |
200 | GNUNET_assert (0 == unlink (KEYFILE)); | 228 | GNUNET_assert (0 == unlink (KEYFILE)); |