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_eddsa.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_eddsa.c')
-rw-r--r-- | src/util/test_crypto_eddsa.c | 202 |
1 files changed, 103 insertions, 99 deletions
diff --git a/src/util/test_crypto_eddsa.c b/src/util/test_crypto_eddsa.c index 2119e3080..f51316463 100644 --- a/src/util/test_crypto_eddsa.c +++ b/src/util/test_crypto_eddsa.c | |||
@@ -39,7 +39,7 @@ static struct GNUNET_CRYPTO_EddsaPrivateKey *key; | |||
39 | 39 | ||
40 | 40 | ||
41 | static int | 41 | static int |
42 | testSignVerify() | 42 | testSignVerify () |
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,47 +48,48 @@ testSignVerify() | |||
48 | struct GNUNET_TIME_Absolute start; | 48 | struct GNUNET_TIME_Absolute start; |
49 | int ok = GNUNET_OK; | 49 | int ok = GNUNET_OK; |
50 | 50 | ||
51 | fprintf(stderr, "%s", "W"); | 51 | fprintf (stderr, "%s", "W"); |
52 | GNUNET_CRYPTO_eddsa_key_get_public(key, &pkey); | 52 | GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey); |
53 | start = GNUNET_TIME_absolute_get(); | 53 | start = GNUNET_TIME_absolute_get (); |
54 | purp.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 54 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
55 | purp.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TEST); | 55 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
56 | 56 | ||
57 | for (i = 0; i < ITER; i++) | 57 | for (i = 0; i < ITER; i++) |
58 | { | ||
59 | fprintf (stderr, "%s", "."); fflush (stderr); | ||
60 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig)) | ||
58 | { | 61 | { |
59 | fprintf(stderr, "%s", "."); fflush(stderr); | 62 | fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); |
60 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign(key, &purp, &sig)) | 63 | ok = GNUNET_SYSERR; |
61 | { | 64 | continue; |
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 | } | 65 | } |
83 | printf("%d EdDSA 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_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 EdDSA 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 | #if PERF | 90 | #if PERF |
90 | static int | 91 | static int |
91 | testSignPerformance() | 92 | testSignPerformance () |
92 | { | 93 | { |
93 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; | 94 | struct GNUNET_CRYPTO_EccSignaturePurpose purp; |
94 | struct GNUNET_CRYPTO_EddsaSignature sig; | 95 | struct GNUNET_CRYPTO_EddsaSignature sig; |
@@ -97,112 +98,115 @@ testSignPerformance() | |||
97 | struct GNUNET_TIME_Absolute start; | 98 | struct GNUNET_TIME_Absolute start; |
98 | int ok = GNUNET_OK; | 99 | int ok = GNUNET_OK; |
99 | 100 | ||
100 | purp.size = htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); | 101 | purp.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)); |
101 | purp.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TEST); | 102 | purp.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TEST); |
102 | fprintf(stderr, "%s", "W"); | 103 | fprintf (stderr, "%s", "W"); |
103 | GNUNET_CRYPTO_eddsa_key_get_public(key, &pkey); | 104 | GNUNET_CRYPTO_eddsa_key_get_public (key, &pkey); |
104 | start = GNUNET_TIME_absolute_get(); | 105 | start = GNUNET_TIME_absolute_get (); |
105 | for (i = 0; i < ITER; i++) | 106 | for (i = 0; i < ITER; i++) |
107 | { | ||
108 | fprintf (stderr, "%s", "."); fflush (stderr); | ||
109 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign (key, &purp, &sig)) | ||
106 | { | 110 | { |
107 | fprintf(stderr, "%s", "."); fflush(stderr); | 111 | fprintf (stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); |
108 | if (GNUNET_SYSERR == GNUNET_CRYPTO_eddsa_sign(key, &purp, &sig)) | 112 | ok = GNUNET_SYSERR; |
109 | { | 113 | continue; |
110 | fprintf(stderr, "%s", "GNUNET_CRYPTO_eddsa_sign returned SYSERR\n"); | ||
111 | ok = GNUNET_SYSERR; | ||
112 | continue; | ||
113 | } | ||
114 | } | 114 | } |
115 | printf("%d EdDSA sign operations %s\n", ITER, | 115 | } |
116 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start), | 116 | printf ("%d EdDSA sign operations %s\n", ITER, |
117 | GNUNET_YES)); | 117 | GNUNET_STRINGS_relative_time_to_string ( |
118 | GNUNET_TIME_absolute_get_duration (start), | ||
119 | GNUNET_YES)); | ||
118 | return ok; | 120 | return ok; |
119 | } | 121 | } |
120 | #endif | 122 | #endif |
121 | 123 | ||
122 | 124 | ||
123 | static int | 125 | static int |
124 | testCreateFromFile() | 126 | testCreateFromFile () |
125 | { | 127 | { |
126 | struct GNUNET_CRYPTO_EddsaPublicKey p1; | 128 | struct GNUNET_CRYPTO_EddsaPublicKey p1; |
127 | struct GNUNET_CRYPTO_EddsaPublicKey p2; | 129 | struct GNUNET_CRYPTO_EddsaPublicKey p2; |
128 | 130 | ||
129 | key = GNUNET_CRYPTO_eddsa_key_create_from_file(KEYFILE); | 131 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); |
130 | GNUNET_assert(NULL != key); | 132 | GNUNET_assert (NULL != key); |
131 | GNUNET_CRYPTO_eddsa_key_get_public(key, &p1); | 133 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p1); |
132 | GNUNET_free(key); | 134 | GNUNET_free (key); |
133 | key = GNUNET_CRYPTO_eddsa_key_create_from_file(KEYFILE); | 135 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); |
134 | GNUNET_assert(NULL != key); | 136 | GNUNET_assert (NULL != key); |
135 | GNUNET_CRYPTO_eddsa_key_get_public(key, &p2); | 137 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p2); |
136 | GNUNET_assert(0 == memcmp(&p1, &p2, sizeof(p1))); | 138 | GNUNET_assert (0 == memcmp (&p1, &p2, sizeof(p1))); |
137 | GNUNET_free(key); | 139 | GNUNET_free (key); |
138 | GNUNET_assert(0 == unlink(KEYFILE)); | 140 | GNUNET_assert (0 == unlink (KEYFILE)); |
139 | key = GNUNET_CRYPTO_eddsa_key_create_from_file(KEYFILE); | 141 | key = GNUNET_CRYPTO_eddsa_key_create_from_file (KEYFILE); |
140 | GNUNET_assert(NULL != key); | 142 | GNUNET_assert (NULL != key); |
141 | GNUNET_CRYPTO_eddsa_key_get_public(key, &p2); | 143 | GNUNET_CRYPTO_eddsa_key_get_public (key, &p2); |
142 | GNUNET_assert(0 != memcmp(&p1, &p2, sizeof(p1))); | 144 | GNUNET_assert (0 != memcmp (&p1, &p2, sizeof(p1))); |
143 | GNUNET_free(key); | 145 | GNUNET_free (key); |
144 | return GNUNET_OK; | 146 | return GNUNET_OK; |
145 | } | 147 | } |
146 | 148 | ||
147 | 149 | ||
148 | static void | 150 | static void |
149 | perf_keygen() | 151 | perf_keygen () |
150 | { | 152 | { |
151 | struct GNUNET_TIME_Absolute start; | 153 | struct GNUNET_TIME_Absolute start; |
152 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; | 154 | struct GNUNET_CRYPTO_EddsaPrivateKey *pk; |
153 | int i; | 155 | int i; |
154 | 156 | ||
155 | fprintf(stderr, "%s", "W"); | 157 | fprintf (stderr, "%s", "W"); |
156 | start = GNUNET_TIME_absolute_get(); | 158 | start = GNUNET_TIME_absolute_get (); |
157 | for (i = 0; i < 10; i++) | 159 | for (i = 0; i < 10; i++) |
158 | { | 160 | { |
159 | fprintf(stderr, "."); fflush(stderr); | 161 | fprintf (stderr, "."); fflush (stderr); |
160 | pk = GNUNET_CRYPTO_eddsa_key_create(); | 162 | pk = GNUNET_CRYPTO_eddsa_key_create (); |
161 | GNUNET_free(pk); | 163 | GNUNET_free (pk); |
162 | } | 164 | } |
163 | for (; i < 25; i++) | 165 | for (; i < 25; i++) |
164 | fprintf(stderr, "."); | 166 | fprintf (stderr, "."); |
165 | fflush(stderr); | 167 | fflush (stderr); |
166 | printf("10 EdDSA keys created in %s\n", | 168 | printf ("10 EdDSA keys created in %s\n", |
167 | GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(start), GNUNET_YES)); | 169 | GNUNET_STRINGS_relative_time_to_string ( |
170 | GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); | ||
168 | } | 171 | } |
169 | 172 | ||
170 | 173 | ||
171 | int | 174 | int |
172 | main(int argc, char *argv[]) | 175 | main (int argc, char *argv[]) |
173 | { | 176 | { |
174 | int failure_count = 0; | 177 | int failure_count = 0; |
175 | 178 | ||
176 | if (!gcry_check_version("1.6.0")) | 179 | if (! gcry_check_version ("1.6.0")) |
177 | { | 180 | { |
178 | fprintf(stderr, | 181 | fprintf (stderr, |
179 | _("libgcrypt has not the expected version (version %s is required).\n"), | 182 | _ ( |
180 | "1.6.0"); | 183 | "libgcrypt has not the expected version (version %s is required).\n"), |
181 | return 0; | 184 | "1.6.0"); |
182 | } | 185 | return 0; |
183 | if (getenv("GNUNET_GCRYPT_DEBUG")) | 186 | } |
184 | gcry_control(GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); | 187 | if (getenv ("GNUNET_GCRYPT_DEBUG")) |
185 | GNUNET_log_setup("test-crypto-eddsa", "WARNING", NULL); | 188 | gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0); |
186 | key = GNUNET_CRYPTO_eddsa_key_create(); | 189 | GNUNET_log_setup ("test-crypto-eddsa", "WARNING", NULL); |
190 | key = GNUNET_CRYPTO_eddsa_key_create (); | ||
187 | #if PERF | 191 | #if PERF |
188 | if (GNUNET_OK != testSignPerformance()) | 192 | if (GNUNET_OK != testSignPerformance ()) |
189 | failure_count++; | 193 | failure_count++; |
190 | #endif | 194 | #endif |
191 | if (GNUNET_OK != testSignVerify()) | 195 | if (GNUNET_OK != testSignVerify ()) |
192 | failure_count++; | 196 | failure_count++; |
193 | GNUNET_free(key); | 197 | GNUNET_free (key); |
194 | if (GNUNET_OK != testCreateFromFile()) | 198 | if (GNUNET_OK != testCreateFromFile ()) |
195 | failure_count++; | 199 | failure_count++; |
196 | GNUNET_assert(0 == unlink(KEYFILE)); | 200 | GNUNET_assert (0 == unlink (KEYFILE)); |
197 | perf_keygen(); | 201 | perf_keygen (); |
198 | 202 | ||
199 | if (0 != failure_count) | 203 | if (0 != failure_count) |
200 | { | 204 | { |
201 | fprintf(stderr, | 205 | fprintf (stderr, |
202 | "\n\n%d TESTS FAILED!\n\n", | 206 | "\n\n%d TESTS FAILED!\n\n", |
203 | failure_count); | 207 | failure_count); |
204 | return -1; | 208 | return -1; |
205 | } | 209 | } |
206 | return 0; | 210 | return 0; |
207 | } | 211 | } |
208 | 212 | ||