diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/scalarproduct | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-scalarproduct.c | 441 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct-ecc.h | 13 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | 973 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c | 930 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.h | 15 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct_alice.c | 1141 | ||||
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct_bob.c | 1140 | ||||
-rw-r--r-- | src/scalarproduct/scalarproduct.h | 22 | ||||
-rw-r--r-- | src/scalarproduct/scalarproduct_api.c | 406 | ||||
-rw-r--r-- | src/scalarproduct/test_ecc_scalarproduct.c | 187 |
10 files changed, 2631 insertions, 2637 deletions
diff --git a/src/scalarproduct/gnunet-scalarproduct.c b/src/scalarproduct/gnunet-scalarproduct.c index 7a86b27d2..fa0e1ccda 100644 --- a/src/scalarproduct/gnunet-scalarproduct.c +++ b/src/scalarproduct/gnunet-scalarproduct.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -33,7 +33,7 @@ | |||
33 | #include "gnunet_protocols.h" | 33 | #include "gnunet_protocols.h" |
34 | #include "scalarproduct.h" | 34 | #include "scalarproduct.h" |
35 | 35 | ||
36 | #define LOG(kind,...) GNUNET_log_from (kind, "gnunet-scalarproduct",__VA_ARGS__) | 36 | #define LOG(kind, ...) GNUNET_log_from(kind, "gnunet-scalarproduct", __VA_ARGS__) |
37 | 37 | ||
38 | 38 | ||
39 | /** | 39 | /** |
@@ -79,40 +79,44 @@ static struct GNUNET_SCALARPRODUCT_ComputationHandle *computation; | |||
79 | * @param status if our job was successfully processed | 79 | * @param status if our job was successfully processed |
80 | */ | 80 | */ |
81 | static void | 81 | static void |
82 | responder_callback (void *cls, | 82 | responder_callback(void *cls, |
83 | enum GNUNET_SCALARPRODUCT_ResponseStatus status) | 83 | enum GNUNET_SCALARPRODUCT_ResponseStatus status) |
84 | { | 84 | { |
85 | switch (status) | 85 | switch (status) |
86 | { | 86 | { |
87 | case GNUNET_SCALARPRODUCT_STATUS_SUCCESS: | 87 | case GNUNET_SCALARPRODUCT_STATUS_SUCCESS: |
88 | ret = 0; | 88 | ret = 0; |
89 | LOG (GNUNET_ERROR_TYPE_INFO, | 89 | LOG(GNUNET_ERROR_TYPE_INFO, |
90 | "Session %s concluded.\n", | 90 | "Session %s concluded.\n", |
91 | GNUNET_h2s (&session_key)); | 91 | GNUNET_h2s(&session_key)); |
92 | break; | 92 | break; |
93 | case GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE: | 93 | |
94 | LOG (GNUNET_ERROR_TYPE_ERROR, | 94 | case GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE: |
95 | "Session %s failed: invalid response\n", | 95 | LOG(GNUNET_ERROR_TYPE_ERROR, |
96 | GNUNET_h2s (&session_key)); | 96 | "Session %s failed: invalid response\n", |
97 | break; | 97 | GNUNET_h2s(&session_key)); |
98 | case GNUNET_SCALARPRODUCT_STATUS_FAILURE: | 98 | break; |
99 | LOG (GNUNET_ERROR_TYPE_ERROR, | 99 | |
100 | "Session %s failed: service failure\n", | 100 | case GNUNET_SCALARPRODUCT_STATUS_FAILURE: |
101 | GNUNET_h2s (&session_key)); | 101 | LOG(GNUNET_ERROR_TYPE_ERROR, |
102 | break; | 102 | "Session %s failed: service failure\n", |
103 | case GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED: | 103 | GNUNET_h2s(&session_key)); |
104 | LOG (GNUNET_ERROR_TYPE_ERROR, | 104 | break; |
105 | "Session %s failed: service disconnect!\n", | 105 | |
106 | GNUNET_h2s (&session_key)); | 106 | case GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED: |
107 | break; | 107 | LOG(GNUNET_ERROR_TYPE_ERROR, |
108 | default: | 108 | "Session %s failed: service disconnect!\n", |
109 | LOG (GNUNET_ERROR_TYPE_ERROR, | 109 | GNUNET_h2s(&session_key)); |
110 | "Session %s failed: return code %d\n", | 110 | break; |
111 | GNUNET_h2s (&session_key), | 111 | |
112 | status); | 112 | default: |
113 | } | 113 | LOG(GNUNET_ERROR_TYPE_ERROR, |
114 | "Session %s failed: return code %d\n", | ||
115 | GNUNET_h2s(&session_key), | ||
116 | status); | ||
117 | } | ||
114 | computation = NULL; | 118 | computation = NULL; |
115 | GNUNET_SCHEDULER_shutdown (); | 119 | GNUNET_SCHEDULER_shutdown(); |
116 | } | 120 | } |
117 | 121 | ||
118 | 122 | ||
@@ -124,56 +128,60 @@ responder_callback (void *cls, | |||
124 | * @param result the result in gnu/gcry MPI format | 128 | * @param result the result in gnu/gcry MPI format |
125 | */ | 129 | */ |
126 | static void | 130 | static void |
127 | requester_callback (void *cls, | 131 | requester_callback(void *cls, |
128 | enum GNUNET_SCALARPRODUCT_ResponseStatus status, | 132 | enum GNUNET_SCALARPRODUCT_ResponseStatus status, |
129 | gcry_mpi_t result) | 133 | gcry_mpi_t result) |
130 | { | 134 | { |
131 | unsigned char *buf; | 135 | unsigned char *buf; |
132 | gcry_error_t rc; | 136 | gcry_error_t rc; |
133 | 137 | ||
134 | switch (status) | 138 | switch (status) |
135 | { | ||
136 | case GNUNET_SCALARPRODUCT_STATUS_SUCCESS: | ||
137 | if (0 == (rc = gcry_mpi_aprint (GCRYMPI_FMT_HEX, &buf, NULL, result))) | ||
138 | { | 139 | { |
139 | ret = 0; | 140 | case GNUNET_SCALARPRODUCT_STATUS_SUCCESS: |
140 | fprintf (stdout, | 141 | if (0 == (rc = gcry_mpi_aprint(GCRYMPI_FMT_HEX, &buf, NULL, result))) |
141 | "%s\n", | 142 | { |
142 | buf); | 143 | ret = 0; |
143 | fflush (stdout); | 144 | fprintf(stdout, |
145 | "%s\n", | ||
146 | buf); | ||
147 | fflush(stdout); | ||
148 | } | ||
149 | else | ||
150 | LOG_GCRY(GNUNET_ERROR_TYPE_ERROR, | ||
151 | "gcry_mpi_aprint", | ||
152 | rc); | ||
153 | break; | ||
154 | |||
155 | case GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE: | ||
156 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
157 | "Session %s with peer %s failed: invalid response received\n", | ||
158 | GNUNET_h2s(&session_key), | ||
159 | GNUNET_i2s(&peer_id)); | ||
160 | break; | ||
161 | |||
162 | case GNUNET_SCALARPRODUCT_STATUS_FAILURE: | ||
163 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
164 | "Session %s with peer %s failed: API failure\n", | ||
165 | GNUNET_h2s(&session_key), | ||
166 | GNUNET_i2s(&peer_id)); | ||
167 | break; | ||
168 | |||
169 | case GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED: | ||
170 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
171 | "Session %s with peer %s was disconnected from service.\n", | ||
172 | GNUNET_h2s(&session_key), | ||
173 | GNUNET_i2s(&peer_id)); | ||
174 | break; | ||
175 | |||
176 | default: | ||
177 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
178 | "Session %s with peer %s failed: return code %d\n", | ||
179 | GNUNET_h2s(&session_key), | ||
180 | GNUNET_i2s(&peer_id), | ||
181 | status); | ||
144 | } | 182 | } |
145 | else | ||
146 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, | ||
147 | "gcry_mpi_aprint", | ||
148 | rc); | ||
149 | break; | ||
150 | case GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE: | ||
151 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
152 | "Session %s with peer %s failed: invalid response received\n", | ||
153 | GNUNET_h2s (&session_key), | ||
154 | GNUNET_i2s (&peer_id)); | ||
155 | break; | ||
156 | case GNUNET_SCALARPRODUCT_STATUS_FAILURE: | ||
157 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
158 | "Session %s with peer %s failed: API failure\n", | ||
159 | GNUNET_h2s (&session_key), | ||
160 | GNUNET_i2s (&peer_id)); | ||
161 | break; | ||
162 | case GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED: | ||
163 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
164 | "Session %s with peer %s was disconnected from service.\n", | ||
165 | GNUNET_h2s (&session_key), | ||
166 | GNUNET_i2s (&peer_id)); | ||
167 | break; | ||
168 | default: | ||
169 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
170 | "Session %s with peer %s failed: return code %d\n", | ||
171 | GNUNET_h2s (&session_key), | ||
172 | GNUNET_i2s (&peer_id), | ||
173 | status); | ||
174 | } | ||
175 | computation = NULL; | 183 | computation = NULL; |
176 | GNUNET_SCHEDULER_shutdown (); | 184 | GNUNET_SCHEDULER_shutdown(); |
177 | } | 185 | } |
178 | 186 | ||
179 | 187 | ||
@@ -184,13 +192,13 @@ requester_callback (void *cls, | |||
184 | * @param tc unused | 192 | * @param tc unused |
185 | */ | 193 | */ |
186 | static void | 194 | static void |
187 | shutdown_task (void *cls) | 195 | shutdown_task(void *cls) |
188 | { | 196 | { |
189 | if (NULL != computation) | 197 | if (NULL != computation) |
190 | { | 198 | { |
191 | GNUNET_SCALARPRODUCT_cancel (computation); | 199 | GNUNET_SCALARPRODUCT_cancel(computation); |
192 | ret = 1; /* aborted */ | 200 | ret = 1; /* aborted */ |
193 | } | 201 | } |
194 | } | 202 | } |
195 | 203 | ||
196 | 204 | ||
@@ -203,10 +211,10 @@ shutdown_task (void *cls) | |||
203 | * @param cfg configuration | 211 | * @param cfg configuration |
204 | */ | 212 | */ |
205 | static void | 213 | static void |
206 | run (void *cls, | 214 | run(void *cls, |
207 | char *const *args, | 215 | char *const *args, |
208 | const char *cfgfile, | 216 | const char *cfgfile, |
209 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 217 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
210 | { | 218 | { |
211 | char *begin = input_elements; | 219 | char *begin = input_elements; |
212 | char *end; | 220 | char *end; |
@@ -215,120 +223,120 @@ run (void *cls, | |||
215 | uint32_t element_count = 0; | 223 | uint32_t element_count = 0; |
216 | 224 | ||
217 | if (NULL == input_elements) | 225 | if (NULL == input_elements) |
218 | { | 226 | { |
219 | LOG (GNUNET_ERROR_TYPE_ERROR, | 227 | LOG(GNUNET_ERROR_TYPE_ERROR, |
220 | _("You must specify at least one message ID to check!\n")); | 228 | _("You must specify at least one message ID to check!\n")); |
221 | return; | 229 | return; |
222 | } | 230 | } |
223 | if ( (NULL == input_session_key) || | 231 | if ((NULL == input_session_key) || |
224 | (0 == strlen (input_session_key)) ) | 232 | (0 == strlen(input_session_key))) |
225 | { | 233 | { |
226 | LOG (GNUNET_ERROR_TYPE_ERROR, | 234 | LOG(GNUNET_ERROR_TYPE_ERROR, |
227 | _("This program needs a session identifier for comparing vectors.\n")); | 235 | _("This program needs a session identifier for comparing vectors.\n")); |
228 | return; | 236 | return; |
229 | } | 237 | } |
230 | GNUNET_CRYPTO_hash (input_session_key, | 238 | GNUNET_CRYPTO_hash(input_session_key, |
231 | strlen (input_session_key), | 239 | strlen(input_session_key), |
232 | &session_key); | 240 | &session_key); |
233 | if ( (NULL != input_peer_id) && | 241 | if ((NULL != input_peer_id) && |
234 | (GNUNET_OK != | 242 | (GNUNET_OK != |
235 | GNUNET_CRYPTO_eddsa_public_key_from_string (input_peer_id, | 243 | GNUNET_CRYPTO_eddsa_public_key_from_string(input_peer_id, |
236 | strlen (input_peer_id), | 244 | strlen(input_peer_id), |
237 | &peer_id.public_key)) ) | 245 | &peer_id.public_key))) |
238 | { | 246 | { |
239 | LOG (GNUNET_ERROR_TYPE_ERROR, | 247 | LOG(GNUNET_ERROR_TYPE_ERROR, |
240 | _("Tried to set initiator mode, as peer ID was given. " | 248 | _("Tried to set initiator mode, as peer ID was given. " |
241 | "However, `%s' is not a valid peer identifier.\n"), | 249 | "However, `%s' is not a valid peer identifier.\n"), |
242 | input_peer_id); | 250 | input_peer_id); |
243 | return; | 251 | return; |
244 | } | 252 | } |
245 | if ( ('\'' == *begin) && | 253 | if (('\'' == *begin) && |
246 | ('\'' == begin[strlen(begin)-1]) ) | 254 | ('\'' == begin[strlen(begin) - 1])) |
247 | { | 255 | { |
248 | begin[strlen(begin)-1] = '\0'; | 256 | begin[strlen(begin) - 1] = '\0'; |
249 | if (strlen (begin) > 0) | 257 | if (strlen(begin) > 0) |
250 | begin++; | 258 | begin++; |
251 | } | 259 | } |
252 | for (end = begin; 0 != *end; end++) | 260 | for (end = begin; 0 != *end; end++) |
253 | if (*end == ';') | 261 | if (*end == ';') |
254 | element_count++; | 262 | element_count++; |
255 | if (0 == element_count) | 263 | if (0 == element_count) |
256 | { | ||
257 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
258 | _("Need elements to compute the scalarproduct, got none.\n")); | ||
259 | return; | ||
260 | } | ||
261 | |||
262 | elements = GNUNET_malloc (sizeof(struct GNUNET_SCALARPRODUCT_Element) * element_count); | ||
263 | |||
264 | for (i = 0; i < element_count;i++) | ||
265 | { | ||
266 | struct GNUNET_SCALARPRODUCT_Element element; | ||
267 | char* separator = NULL; | ||
268 | |||
269 | /* get the length of the current key,value; tupel */ | ||
270 | for (end = begin; *end != ';'; end++) | ||
271 | if (*end == ',') | ||
272 | separator = end; | ||
273 | |||
274 | /* final element */ | ||
275 | if ( (NULL == separator) || | ||
276 | (begin == separator) || | ||
277 | (separator == end - 1) ) | ||
278 | { | 264 | { |
279 | LOG (GNUNET_ERROR_TYPE_ERROR, | 265 | LOG(GNUNET_ERROR_TYPE_ERROR, |
280 | _("Malformed input, could not parse `%s'\n"), | 266 | _("Need elements to compute the scalarproduct, got none.\n")); |
281 | begin); | ||
282 | GNUNET_free (elements); | ||
283 | return; | 267 | return; |
284 | } | 268 | } |
285 | *separator = 0; | 269 | |
286 | /* read the element's key */ | 270 | elements = GNUNET_malloc(sizeof(struct GNUNET_SCALARPRODUCT_Element) * element_count); |
287 | GNUNET_CRYPTO_hash (begin, | 271 | |
288 | strlen (begin), | 272 | for (i = 0; i < element_count; i++) |
289 | &element.key); | ||
290 | |||
291 | /* read the element's value */ | ||
292 | if (1 != | ||
293 | sscanf (separator + 1, | ||
294 | "%" SCNd64 ";", | ||
295 | &element.value) ) | ||
296 | { | 273 | { |
297 | LOG (GNUNET_ERROR_TYPE_ERROR, | 274 | struct GNUNET_SCALARPRODUCT_Element element; |
298 | _("Could not convert `%s' to int64_t.\n"), | 275 | char* separator = NULL; |
299 | begin); | 276 | |
300 | GNUNET_free (elements); | 277 | /* get the length of the current key,value; tupel */ |
301 | return; | 278 | for (end = begin; *end != ';'; end++) |
279 | if (*end == ',') | ||
280 | separator = end; | ||
281 | |||
282 | /* final element */ | ||
283 | if ((NULL == separator) || | ||
284 | (begin == separator) || | ||
285 | (separator == end - 1)) | ||
286 | { | ||
287 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
288 | _("Malformed input, could not parse `%s'\n"), | ||
289 | begin); | ||
290 | GNUNET_free(elements); | ||
291 | return; | ||
292 | } | ||
293 | *separator = 0; | ||
294 | /* read the element's key */ | ||
295 | GNUNET_CRYPTO_hash(begin, | ||
296 | strlen(begin), | ||
297 | &element.key); | ||
298 | |||
299 | /* read the element's value */ | ||
300 | if (1 != | ||
301 | sscanf(separator + 1, | ||
302 | "%" SCNd64 ";", | ||
303 | &element.value)) | ||
304 | { | ||
305 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
306 | _("Could not convert `%s' to int64_t.\n"), | ||
307 | begin); | ||
308 | GNUNET_free(elements); | ||
309 | return; | ||
310 | } | ||
311 | element.value = GNUNET_htonll(element.value); | ||
312 | elements[i] = element; | ||
313 | begin = end + 1; | ||
302 | } | 314 | } |
303 | element.value = GNUNET_htonll (element.value); | 315 | |
304 | elements[i] = element; | 316 | if (((NULL != input_peer_id) && |
305 | begin = end + 1; | 317 | (NULL == (computation |
306 | } | 318 | = GNUNET_SCALARPRODUCT_start_computation(cfg, |
307 | 319 | &session_key, | |
308 | if ( ( (NULL != input_peer_id) && | 320 | &peer_id, |
309 | (NULL == (computation | 321 | elements, element_count, |
310 | = GNUNET_SCALARPRODUCT_start_computation (cfg, | 322 | &requester_callback, |
323 | NULL)))) || | ||
324 | ((NULL == input_peer_id) && | ||
325 | (NULL == (computation | ||
326 | = GNUNET_SCALARPRODUCT_accept_computation(cfg, | ||
311 | &session_key, | 327 | &session_key, |
312 | &peer_id, | ||
313 | elements, element_count, | 328 | elements, element_count, |
314 | &requester_callback, | 329 | &responder_callback, |
315 | NULL))) ) || | 330 | NULL))))) |
316 | ( (NULL == input_peer_id) && | 331 | { |
317 | (NULL == (computation | 332 | fprintf(stderr, |
318 | = GNUNET_SCALARPRODUCT_accept_computation (cfg, | 333 | _("Failed to initiate computation, were all keys unique?\n")); |
319 | &session_key, | 334 | GNUNET_free(elements); |
320 | elements, element_count, | 335 | return; |
321 | &responder_callback, | 336 | } |
322 | NULL))) ) ) | 337 | GNUNET_free(elements); |
323 | { | 338 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, |
324 | fprintf (stderr, | 339 | NULL); |
325 | _("Failed to initiate computation, were all keys unique?\n")); | ||
326 | GNUNET_free (elements); | ||
327 | return; | ||
328 | } | ||
329 | GNUNET_free (elements); | ||
330 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
331 | NULL); | ||
332 | ret = 0; | 340 | ret = 0; |
333 | } | 341 | } |
334 | 342 | ||
@@ -341,43 +349,42 @@ run (void *cls, | |||
341 | * @return 0 ok, 1 on error | 349 | * @return 0 ok, 1 on error |
342 | */ | 350 | */ |
343 | int | 351 | int |
344 | main (int argc, char *const *argv) | 352 | main(int argc, char *const *argv) |
345 | { | 353 | { |
346 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 354 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
347 | 355 | GNUNET_GETOPT_option_string('e', | |
348 | GNUNET_GETOPT_option_string ('e', | 356 | "elements", |
349 | "elements", | 357 | "\"key1,val1;key2,val2;...,keyn,valn;\"", |
350 | "\"key1,val1;key2,val2;...,keyn,valn;\"", | 358 | gettext_noop("A comma separated list of elements to compare as vector with our remote peer."), |
351 | gettext_noop ("A comma separated list of elements to compare as vector with our remote peer."), | 359 | &input_elements), |
352 | &input_elements), | 360 | |
353 | 361 | GNUNET_GETOPT_option_string('e', | |
354 | GNUNET_GETOPT_option_string ('e', | 362 | "elements", |
355 | "elements", | 363 | "\"key1,val1;key2,val2;...,keyn,valn;\"", |
356 | "\"key1,val1;key2,val2;...,keyn,valn;\"", | 364 | gettext_noop("A comma separated list of elements to compare as vector with our remote peer."), |
357 | gettext_noop ("A comma separated list of elements to compare as vector with our remote peer."), | 365 | &input_elements), |
358 | &input_elements), | 366 | |
359 | 367 | GNUNET_GETOPT_option_string('p', | |
360 | GNUNET_GETOPT_option_string ('p', | 368 | "peer", |
361 | "peer", | 369 | "PEERID", |
362 | "PEERID", | 370 | gettext_noop("[Optional] peer to calculate our scalarproduct with. If this parameter is not given, the service will wait for a remote peer to compute the request."), |
363 | gettext_noop ("[Optional] peer to calculate our scalarproduct with. If this parameter is not given, the service will wait for a remote peer to compute the request."), | 371 | &input_peer_id), |
364 | &input_peer_id), | 372 | |
365 | 373 | GNUNET_GETOPT_option_string('k', | |
366 | GNUNET_GETOPT_option_string ('k', | 374 | "key", |
367 | "key", | 375 | "TRANSACTION_ID", |
368 | "TRANSACTION_ID", | 376 | gettext_noop("Transaction ID shared with peer."), |
369 | gettext_noop ("Transaction ID shared with peer."), | 377 | &input_session_key), |
370 | &input_session_key), | ||
371 | 378 | ||
372 | GNUNET_GETOPT_OPTION_END | 379 | GNUNET_GETOPT_OPTION_END |
373 | }; | 380 | }; |
374 | 381 | ||
375 | return (GNUNET_OK == | 382 | return (GNUNET_OK == |
376 | GNUNET_PROGRAM_run (argc, | 383 | GNUNET_PROGRAM_run(argc, |
377 | argv, | 384 | argv, |
378 | "gnunet-scalarproduct", | 385 | "gnunet-scalarproduct", |
379 | gettext_noop ("Calculate the Vectorproduct with a GNUnet peer."), | 386 | gettext_noop("Calculate the Vectorproduct with a GNUnet peer."), |
380 | options, &run, NULL)) ? ret : 1; | 387 | options, &run, NULL)) ? ret : 1; |
381 | } | 388 | } |
382 | 389 | ||
383 | /* end of gnunet-scalarproduct.c */ | 390 | /* end of gnunet-scalarproduct.c */ |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc.h b/src/scalarproduct/gnunet-service-scalarproduct-ecc.h index 0c40eb0c3..8dbf042b9 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc.h +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -37,8 +37,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
37 | * send a `struct AliceCryptodataMessage *`. Bob is not expected | 37 | * send a `struct AliceCryptodataMessage *`. Bob is not expected |
38 | * to respond via CADET in the meantime. | 38 | * to respond via CADET in the meantime. |
39 | */ | 39 | */ |
40 | struct EccServiceRequestMessage | 40 | struct EccServiceRequestMessage { |
41 | { | ||
42 | /** | 41 | /** |
43 | * Type is #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION | 42 | * Type is #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION |
44 | */ | 43 | */ |
@@ -53,7 +52,6 @@ struct EccServiceRequestMessage | |||
53 | * The transaction/session key used to identify a session | 52 | * The transaction/session key used to identify a session |
54 | */ | 53 | */ |
55 | struct GNUNET_HashCode session_id; | 54 | struct GNUNET_HashCode session_id; |
56 | |||
57 | }; | 55 | }; |
58 | 56 | ||
59 | 57 | ||
@@ -62,8 +60,7 @@ struct EccServiceRequestMessage | |||
62 | * (after set intersection). Alice may send messages of this | 60 | * (after set intersection). Alice may send messages of this |
63 | * type repeatedly to transmit all values. | 61 | * type repeatedly to transmit all values. |
64 | */ | 62 | */ |
65 | struct EccAliceCryptodataMessage | 63 | struct EccAliceCryptodataMessage { |
66 | { | ||
67 | /** | 64 | /** |
68 | * Type is #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA | 65 | * Type is #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA |
69 | */ | 66 | */ |
@@ -87,8 +84,7 @@ struct EccAliceCryptodataMessage | |||
87 | * conversation may be continued with `struct BobCryptodataMultipartMessage` | 84 | * conversation may be continued with `struct BobCryptodataMultipartMessage` |
88 | * messages afterwards. | 85 | * messages afterwards. |
89 | */ | 86 | */ |
90 | struct EccBobCryptodataMessage | 87 | struct EccBobCryptodataMessage { |
91 | { | ||
92 | /** | 88 | /** |
93 | * GNUNET message header with type | 89 | * GNUNET message header with type |
94 | * #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA. | 90 | * #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA. |
@@ -110,7 +106,6 @@ struct EccBobCryptodataMessage | |||
110 | * The product of the h_i^{b_i} values. | 106 | * The product of the h_i^{b_i} values. |
111 | */ | 107 | */ |
112 | struct GNUNET_CRYPTO_EccPoint prod_h_i_b_i; | 108 | struct GNUNET_CRYPTO_EccPoint prod_h_i_b_i; |
113 | |||
114 | }; | 109 | }; |
115 | 110 | ||
116 | 111 | ||
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c index dc2763943..9671c46f6 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #include "gnunet-service-scalarproduct-ecc.h" | 37 | #include "gnunet-service-scalarproduct-ecc.h" |
38 | 38 | ||
39 | #define LOG(kind, ...) \ | 39 | #define LOG(kind, ...) \ |
40 | GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) | 40 | GNUNET_log_from(kind, "scalarproduct-alice", __VA_ARGS__) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Maximum allowed result value for the scalarproduct computation. | 43 | * Maximum allowed result value for the scalarproduct computation. |
@@ -57,8 +57,7 @@ | |||
57 | /** | 57 | /** |
58 | * An encrypted element key-value pair. | 58 | * An encrypted element key-value pair. |
59 | */ | 59 | */ |
60 | struct MpiElement | 60 | struct MpiElement { |
61 | { | ||
62 | /** | 61 | /** |
63 | * Key used to identify matching pairs of values to multiply. | 62 | * Key used to identify matching pairs of values to multiply. |
64 | * Points into an existing data structure, to avoid copying | 63 | * Points into an existing data structure, to avoid copying |
@@ -77,9 +76,7 @@ struct MpiElement | |||
77 | * A scalarproduct session which tracks | 76 | * A scalarproduct session which tracks |
78 | * a request form the client to our final response. | 77 | * a request form the client to our final response. |
79 | */ | 78 | */ |
80 | struct AliceServiceSession | 79 | struct AliceServiceSession { |
81 | { | ||
82 | |||
83 | /** | 80 | /** |
84 | * (hopefully) unique transaction ID | 81 | * (hopefully) unique transaction ID |
85 | */ | 82 | */ |
@@ -213,11 +210,11 @@ static struct GNUNET_CADET_Handle *my_cadet; | |||
213 | * @return #GNUNET_OK (continue to iterate) | 210 | * @return #GNUNET_OK (continue to iterate) |
214 | */ | 211 | */ |
215 | static int | 212 | static int |
216 | free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | 213 | free_element_cb(void *cls, const struct GNUNET_HashCode *key, void *value) |
217 | { | 214 | { |
218 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 215 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
219 | 216 | ||
220 | GNUNET_free (e); | 217 | GNUNET_free(e); |
221 | return GNUNET_OK; | 218 | return GNUNET_OK; |
222 | } | 219 | } |
223 | 220 | ||
@@ -228,7 +225,7 @@ free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
228 | * @param s the session to free elements from | 225 | * @param s the session to free elements from |
229 | */ | 226 | */ |
230 | static void | 227 | static void |
231 | destroy_service_session (struct AliceServiceSession *s) | 228 | destroy_service_session(struct AliceServiceSession *s) |
232 | { | 229 | { |
233 | unsigned int i; | 230 | unsigned int i; |
234 | 231 | ||
@@ -236,54 +233,54 @@ destroy_service_session (struct AliceServiceSession *s) | |||
236 | return; | 233 | return; |
237 | s->in_destroy = GNUNET_YES; | 234 | s->in_destroy = GNUNET_YES; |
238 | if (NULL != s->client) | 235 | if (NULL != s->client) |
239 | { | 236 | { |
240 | struct GNUNET_SERVICE_Client *c = s->client; | 237 | struct GNUNET_SERVICE_Client *c = s->client; |
241 | 238 | ||
242 | s->client = NULL; | 239 | s->client = NULL; |
243 | GNUNET_SERVICE_client_drop (c); | 240 | GNUNET_SERVICE_client_drop(c); |
244 | } | 241 | } |
245 | if (NULL != s->channel) | 242 | if (NULL != s->channel) |
246 | { | 243 | { |
247 | GNUNET_CADET_channel_destroy (s->channel); | 244 | GNUNET_CADET_channel_destroy(s->channel); |
248 | s->channel = NULL; | 245 | s->channel = NULL; |
249 | } | 246 | } |
250 | if (NULL != s->intersected_elements) | 247 | if (NULL != s->intersected_elements) |
251 | { | 248 | { |
252 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 249 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, |
253 | &free_element_cb, | 250 | &free_element_cb, |
254 | s); | 251 | s); |
255 | GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements); | 252 | GNUNET_CONTAINER_multihashmap_destroy(s->intersected_elements); |
256 | s->intersected_elements = NULL; | 253 | s->intersected_elements = NULL; |
257 | } | 254 | } |
258 | if (NULL != s->intersection_listen) | 255 | if (NULL != s->intersection_listen) |
259 | { | 256 | { |
260 | GNUNET_SET_listen_cancel (s->intersection_listen); | 257 | GNUNET_SET_listen_cancel(s->intersection_listen); |
261 | s->intersection_listen = NULL; | 258 | s->intersection_listen = NULL; |
262 | } | 259 | } |
263 | if (NULL != s->intersection_op) | 260 | if (NULL != s->intersection_op) |
264 | { | 261 | { |
265 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection, op still ongoing!\n"); | 262 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Set intersection, op still ongoing!\n"); |
266 | GNUNET_SET_operation_cancel (s->intersection_op); | 263 | GNUNET_SET_operation_cancel(s->intersection_op); |
267 | s->intersection_op = NULL; | 264 | s->intersection_op = NULL; |
268 | } | 265 | } |
269 | if (NULL != s->intersection_set) | 266 | if (NULL != s->intersection_set) |
270 | { | 267 | { |
271 | GNUNET_SET_destroy (s->intersection_set); | 268 | GNUNET_SET_destroy(s->intersection_set); |
272 | s->intersection_set = NULL; | 269 | s->intersection_set = NULL; |
273 | } | 270 | } |
274 | if (NULL != s->sorted_elements) | 271 | if (NULL != s->sorted_elements) |
275 | { | 272 | { |
276 | for (i = 0; i < s->used_element_count; i++) | 273 | for (i = 0; i < s->used_element_count; i++) |
277 | gcry_mpi_release (s->sorted_elements[i].value); | 274 | gcry_mpi_release(s->sorted_elements[i].value); |
278 | GNUNET_free (s->sorted_elements); | 275 | GNUNET_free(s->sorted_elements); |
279 | s->sorted_elements = NULL; | 276 | s->sorted_elements = NULL; |
280 | } | 277 | } |
281 | if (NULL != s->product) | 278 | if (NULL != s->product) |
282 | { | 279 | { |
283 | gcry_mpi_release (s->product); | 280 | gcry_mpi_release(s->product); |
284 | s->product = NULL; | 281 | s->product = NULL; |
285 | } | 282 | } |
286 | GNUNET_free (s); | 283 | GNUNET_free(s); |
287 | } | 284 | } |
288 | 285 | ||
289 | 286 | ||
@@ -294,22 +291,22 @@ destroy_service_session (struct AliceServiceSession *s) | |||
294 | * @param session the associated client session to fail or succeed | 291 | * @param session the associated client session to fail or succeed |
295 | */ | 292 | */ |
296 | static void | 293 | static void |
297 | prepare_client_end_notification (struct AliceServiceSession *session) | 294 | prepare_client_end_notification(struct AliceServiceSession *session) |
298 | { | 295 | { |
299 | struct ClientResponseMessage *msg; | 296 | struct ClientResponseMessage *msg; |
300 | struct GNUNET_MQ_Envelope *e; | 297 | struct GNUNET_MQ_Envelope *e; |
301 | 298 | ||
302 | if (NULL == session->client_mq) | 299 | if (NULL == session->client_mq) |
303 | return; /* no client left to be notified */ | 300 | return; /* no client left to be notified */ |
304 | GNUNET_log ( | 301 | GNUNET_log( |
305 | GNUNET_ERROR_TYPE_DEBUG, | 302 | GNUNET_ERROR_TYPE_DEBUG, |
306 | "Sending session-end notification with status %d to client for session %s\n", | 303 | "Sending session-end notification with status %d to client for session %s\n", |
307 | session->status, | 304 | session->status, |
308 | GNUNET_h2s (&session->session_id)); | 305 | GNUNET_h2s(&session->session_id)); |
309 | e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 306 | e = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
310 | msg->product_length = htonl (0); | 307 | msg->product_length = htonl(0); |
311 | msg->status = htonl (session->status); | 308 | msg->status = htonl(session->status); |
312 | GNUNET_MQ_send (session->client_mq, e); | 309 | GNUNET_MQ_send(session->client_mq, e); |
313 | } | 310 | } |
314 | 311 | ||
315 | 312 | ||
@@ -320,7 +317,7 @@ prepare_client_end_notification (struct AliceServiceSession *session) | |||
320 | * @param s the session associated with our client. | 317 | * @param s the session associated with our client. |
321 | */ | 318 | */ |
322 | static void | 319 | static void |
323 | transmit_client_response (struct AliceServiceSession *s) | 320 | transmit_client_response(struct AliceServiceSession *s) |
324 | { | 321 | { |
325 | struct ClientResponseMessage *msg; | 322 | struct ClientResponseMessage *msg; |
326 | struct GNUNET_MQ_Envelope *e; | 323 | struct GNUNET_MQ_Envelope *e; |
@@ -332,56 +329,56 @@ transmit_client_response (struct AliceServiceSession *s) | |||
332 | gcry_mpi_t value; | 329 | gcry_mpi_t value; |
333 | 330 | ||
334 | if (NULL == s->product) | 331 | if (NULL == s->product) |
335 | { | 332 | { |
336 | GNUNET_break (0); | 333 | GNUNET_break(0); |
337 | prepare_client_end_notification (s); | 334 | prepare_client_end_notification(s); |
338 | return; | 335 | return; |
339 | } | 336 | } |
340 | value = gcry_mpi_new (0); | 337 | value = gcry_mpi_new(0); |
341 | sign = gcry_mpi_cmp_ui (s->product, 0); | 338 | sign = gcry_mpi_cmp_ui(s->product, 0); |
342 | if (0 > sign) | 339 | if (0 > sign) |
343 | { | 340 | { |
344 | range = -1; | 341 | range = -1; |
345 | gcry_mpi_sub (value, value, s->product); | 342 | gcry_mpi_sub(value, value, s->product); |
346 | } | 343 | } |
347 | else if (0 < sign) | 344 | else if (0 < sign) |
348 | { | 345 | { |
349 | range = 1; | 346 | range = 1; |
350 | gcry_mpi_add (value, value, s->product); | 347 | gcry_mpi_add(value, value, s->product); |
351 | } | 348 | } |
352 | else | 349 | else |
353 | { | 350 | { |
354 | /* result is exactly zero */ | 351 | /* result is exactly zero */ |
355 | range = 0; | 352 | range = 0; |
356 | } | 353 | } |
357 | gcry_mpi_release (s->product); | 354 | gcry_mpi_release(s->product); |
358 | s->product = NULL; | 355 | s->product = NULL; |
359 | 356 | ||
360 | if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, | 357 | if ((0 != range) && (0 != (rc = gcry_mpi_aprint(GCRYMPI_FMT_STD, |
361 | &product_exported, | 358 | &product_exported, |
362 | &product_length, | 359 | &product_length, |
363 | value)))) | 360 | value)))) |
364 | { | 361 | { |
365 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 362 | LOG_GCRY(GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
366 | prepare_client_end_notification (s); | 363 | prepare_client_end_notification(s); |
367 | return; | 364 | return; |
368 | } | 365 | } |
369 | gcry_mpi_release (value); | 366 | gcry_mpi_release(value); |
370 | e = GNUNET_MQ_msg_extra (msg, | 367 | e = GNUNET_MQ_msg_extra(msg, |
371 | product_length, | 368 | product_length, |
372 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 369 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
373 | msg->status = htonl (GNUNET_SCALARPRODUCT_STATUS_SUCCESS); | 370 | msg->status = htonl(GNUNET_SCALARPRODUCT_STATUS_SUCCESS); |
374 | msg->range = htonl (range); | 371 | msg->range = htonl(range); |
375 | msg->product_length = htonl (product_length); | 372 | msg->product_length = htonl(product_length); |
376 | if (NULL != product_exported) | 373 | if (NULL != product_exported) |
377 | { | 374 | { |
378 | GNUNET_memcpy (&msg[1], product_exported, product_length); | 375 | GNUNET_memcpy(&msg[1], product_exported, product_length); |
379 | GNUNET_free (product_exported); | 376 | GNUNET_free(product_exported); |
380 | } | 377 | } |
381 | GNUNET_MQ_send (s->client_mq, e); | 378 | GNUNET_MQ_send(s->client_mq, e); |
382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 379 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
383 | "Sent result to client, session %s has ended!\n", | 380 | "Sent result to client, session %s has ended!\n", |
384 | GNUNET_h2s (&s->session_id)); | 381 | GNUNET_h2s(&s->session_id)); |
385 | } | 382 | } |
386 | 383 | ||
387 | 384 | ||
@@ -395,21 +392,21 @@ transmit_client_response (struct AliceServiceSession *s) | |||
395 | * @param channel connection to the other end (henceforth invalid) | 392 | * @param channel connection to the other end (henceforth invalid) |
396 | */ | 393 | */ |
397 | static void | 394 | static void |
398 | cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) | 395 | cb_channel_destruction(void *cls, const struct GNUNET_CADET_Channel *channel) |
399 | { | 396 | { |
400 | struct AliceServiceSession *s = cls; | 397 | struct AliceServiceSession *s = cls; |
401 | 398 | ||
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 399 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
403 | "Peer disconnected, terminating session %s with peer %s\n", | 400 | "Peer disconnected, terminating session %s with peer %s\n", |
404 | GNUNET_h2s (&s->session_id), | 401 | GNUNET_h2s(&s->session_id), |
405 | GNUNET_i2s (&s->peer)); | 402 | GNUNET_i2s(&s->peer)); |
406 | s->channel = NULL; | 403 | s->channel = NULL; |
407 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) | 404 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) |
408 | { | 405 | { |
409 | /* We didn't get an answer yet, fail with error */ | 406 | /* We didn't get an answer yet, fail with error */ |
410 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 407 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
411 | prepare_client_end_notification (s); | 408 | prepare_client_end_notification(s); |
412 | } | 409 | } |
413 | } | 410 | } |
414 | 411 | ||
415 | 412 | ||
@@ -422,9 +419,9 @@ cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) | |||
422 | * @return product as MPI, never NULL | 419 | * @return product as MPI, never NULL |
423 | */ | 420 | */ |
424 | static gcry_mpi_t | 421 | static gcry_mpi_t |
425 | compute_scalar_product (struct AliceServiceSession *session, | 422 | compute_scalar_product(struct AliceServiceSession *session, |
426 | gcry_mpi_point_t prod_g_i_b_i, | 423 | gcry_mpi_point_t prod_g_i_b_i, |
427 | gcry_mpi_point_t prod_h_i_b_i) | 424 | gcry_mpi_point_t prod_h_i_b_i) |
428 | { | 425 | { |
429 | gcry_mpi_point_t g_i_b_i_a_inv; | 426 | gcry_mpi_point_t g_i_b_i_a_inv; |
430 | gcry_mpi_point_t g_ai_bi; | 427 | gcry_mpi_point_t g_ai_bi; |
@@ -432,28 +429,28 @@ compute_scalar_product (struct AliceServiceSession *session, | |||
432 | gcry_mpi_t ret; | 429 | gcry_mpi_t ret; |
433 | 430 | ||
434 | g_i_b_i_a_inv = | 431 | g_i_b_i_a_inv = |
435 | GNUNET_CRYPTO_ecc_pmul_mpi (edc, prod_g_i_b_i, my_privkey_inv); | 432 | GNUNET_CRYPTO_ecc_pmul_mpi(edc, prod_g_i_b_i, my_privkey_inv); |
436 | g_ai_bi = GNUNET_CRYPTO_ecc_add (edc, g_i_b_i_a_inv, prod_h_i_b_i); | 433 | g_ai_bi = GNUNET_CRYPTO_ecc_add(edc, g_i_b_i_a_inv, prod_h_i_b_i); |
437 | gcry_mpi_point_release (g_i_b_i_a_inv); | 434 | gcry_mpi_point_release(g_i_b_i_a_inv); |
438 | ai_bi = GNUNET_CRYPTO_ecc_dlog (edc, g_ai_bi); | 435 | ai_bi = GNUNET_CRYPTO_ecc_dlog(edc, g_ai_bi); |
439 | gcry_mpi_point_release (g_ai_bi); | 436 | gcry_mpi_point_release(g_ai_bi); |
440 | if (INT_MAX == ai_bi) | 437 | if (INT_MAX == ai_bi) |
441 | { | 438 | { |
442 | /* result too big */ | 439 | /* result too big */ |
443 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 440 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
444 | "Scalar product result out of range\n"); | 441 | "Scalar product result out of range\n"); |
445 | return NULL; | 442 | return NULL; |
446 | } | 443 | } |
447 | ret = gcry_mpi_new (0); | 444 | ret = gcry_mpi_new(0); |
448 | if (ai_bi > 0) | 445 | if (ai_bi > 0) |
449 | { | 446 | { |
450 | gcry_mpi_set_ui (ret, ai_bi); | 447 | gcry_mpi_set_ui(ret, ai_bi); |
451 | } | 448 | } |
452 | else | 449 | else |
453 | { | 450 | { |
454 | gcry_mpi_set_ui (ret, -ai_bi); | 451 | gcry_mpi_set_ui(ret, -ai_bi); |
455 | gcry_mpi_neg (ret, ret); | 452 | gcry_mpi_neg(ret, ret); |
456 | } | 453 | } |
457 | return ret; | 454 | return ret; |
458 | } | 455 | } |
459 | 456 | ||
@@ -466,46 +463,46 @@ compute_scalar_product (struct AliceServiceSession *session, | |||
466 | * @param msg the actual message | 463 | * @param msg the actual message |
467 | */ | 464 | */ |
468 | static void | 465 | static void |
469 | handle_bobs_cryptodata_message (void *cls, | 466 | handle_bobs_cryptodata_message(void *cls, |
470 | const struct EccBobCryptodataMessage *msg) | 467 | const struct EccBobCryptodataMessage *msg) |
471 | { | 468 | { |
472 | struct AliceServiceSession *s = cls; | 469 | struct AliceServiceSession *s = cls; |
473 | gcry_mpi_point_t prod_g_i_b_i; | 470 | gcry_mpi_point_t prod_g_i_b_i; |
474 | gcry_mpi_point_t prod_h_i_b_i; | 471 | gcry_mpi_point_t prod_h_i_b_i; |
475 | uint32_t contained; | 472 | uint32_t contained; |
476 | 473 | ||
477 | contained = ntohl (msg->contained_element_count); | 474 | contained = ntohl(msg->contained_element_count); |
478 | if (2 != contained) | 475 | if (2 != contained) |
479 | { | 476 | { |
480 | GNUNET_break_op (0); | 477 | GNUNET_break_op(0); |
481 | destroy_service_session (s); | 478 | destroy_service_session(s); |
482 | return; | 479 | return; |
483 | } | 480 | } |
484 | if (NULL == s->sorted_elements) | 481 | if (NULL == s->sorted_elements) |
485 | { | 482 | { |
486 | /* we're not ready yet, how can Bob be? */ | 483 | /* we're not ready yet, how can Bob be? */ |
487 | GNUNET_break_op (0); | 484 | GNUNET_break_op(0); |
488 | destroy_service_session (s); | 485 | destroy_service_session(s); |
489 | return; | 486 | return; |
490 | } | 487 | } |
491 | if (s->total != s->client_received_element_count) | 488 | if (s->total != s->client_received_element_count) |
492 | { | 489 | { |
493 | /* we're not ready yet, how can Bob be? */ | 490 | /* we're not ready yet, how can Bob be? */ |
494 | GNUNET_break_op (0); | 491 | GNUNET_break_op(0); |
495 | destroy_service_session (s); | 492 | destroy_service_session(s); |
496 | return; | 493 | return; |
497 | } | 494 | } |
498 | 495 | ||
499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 496 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
500 | "Received %u crypto values from Bob\n", | 497 | "Received %u crypto values from Bob\n", |
501 | (unsigned int) contained); | 498 | (unsigned int)contained); |
502 | GNUNET_CADET_receive_done (s->channel); | 499 | GNUNET_CADET_receive_done(s->channel); |
503 | prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_g_i_b_i); | 500 | prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point(edc, &msg->prod_g_i_b_i); |
504 | prod_h_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_h_i_b_i); | 501 | prod_h_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point(edc, &msg->prod_h_i_b_i); |
505 | s->product = compute_scalar_product (s, prod_g_i_b_i, prod_h_i_b_i); | 502 | s->product = compute_scalar_product(s, prod_g_i_b_i, prod_h_i_b_i); |
506 | gcry_mpi_point_release (prod_g_i_b_i); | 503 | gcry_mpi_point_release(prod_g_i_b_i); |
507 | gcry_mpi_point_release (prod_h_i_b_i); | 504 | gcry_mpi_point_release(prod_h_i_b_i); |
508 | transmit_client_response (s); | 505 | transmit_client_response(s); |
509 | } | 506 | } |
510 | 507 | ||
511 | 508 | ||
@@ -518,19 +515,19 @@ handle_bobs_cryptodata_message (void *cls, | |||
518 | * @param value the `struct GNUNET_SCALARPRODUCT_Element *` | 515 | * @param value the `struct GNUNET_SCALARPRODUCT_Element *` |
519 | */ | 516 | */ |
520 | static int | 517 | static int |
521 | copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | 518 | copy_element_cb(void *cls, const struct GNUNET_HashCode *key, void *value) |
522 | { | 519 | { |
523 | struct AliceServiceSession *s = cls; | 520 | struct AliceServiceSession *s = cls; |
524 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 521 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
525 | gcry_mpi_t mval; | 522 | gcry_mpi_t mval; |
526 | int64_t val; | 523 | int64_t val; |
527 | 524 | ||
528 | mval = gcry_mpi_new (0); | 525 | mval = gcry_mpi_new(0); |
529 | val = (int64_t) GNUNET_ntohll (e->value); | 526 | val = (int64_t)GNUNET_ntohll(e->value); |
530 | if (0 > val) | 527 | if (0 > val) |
531 | gcry_mpi_sub_ui (mval, mval, -val); | 528 | gcry_mpi_sub_ui(mval, mval, -val); |
532 | else | 529 | else |
533 | gcry_mpi_add_ui (mval, mval, val); | 530 | gcry_mpi_add_ui(mval, mval, val); |
534 | s->sorted_elements[s->used_element_count].value = mval; | 531 | s->sorted_elements[s->used_element_count].value = mval; |
535 | s->sorted_elements[s->used_element_count].key = &e->key; | 532 | s->sorted_elements[s->used_element_count].key = &e->key; |
536 | s->used_element_count++; | 533 | s->used_element_count++; |
@@ -546,12 +543,12 @@ copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
546 | * @return -1 for a < b, 0 for a=b, 1 for a > b. | 543 | * @return -1 for a < b, 0 for a=b, 1 for a > b. |
547 | */ | 544 | */ |
548 | static int | 545 | static int |
549 | element_cmp (const void *a, const void *b) | 546 | element_cmp(const void *a, const void *b) |
550 | { | 547 | { |
551 | const struct MpiElement *ma = a; | 548 | const struct MpiElement *ma = a; |
552 | const struct MpiElement *mb = b; | 549 | const struct MpiElement *mb = b; |
553 | 550 | ||
554 | return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key); | 551 | return GNUNET_CRYPTO_hash_cmp(ma->key, mb->key); |
555 | } | 552 | } |
556 | 553 | ||
557 | 554 | ||
@@ -561,8 +558,8 @@ element_cmp (const void *a, const void *b) | |||
561 | */ | 558 | */ |
562 | #define ELEMENT_CAPACITY \ | 559 | #define ELEMENT_CAPACITY \ |
563 | ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \ | 560 | ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \ |
564 | sizeof (struct EccAliceCryptodataMessage)) / \ | 561 | sizeof(struct EccAliceCryptodataMessage)) / \ |
565 | sizeof (struct GNUNET_CRYPTO_EccPoint)) | 562 | sizeof(struct GNUNET_CRYPTO_EccPoint)) |
566 | 563 | ||
567 | 564 | ||
568 | /** | 565 | /** |
@@ -572,7 +569,7 @@ element_cmp (const void *a, const void *b) | |||
572 | * @param s the associated service session | 569 | * @param s the associated service session |
573 | */ | 570 | */ |
574 | static void | 571 | static void |
575 | send_alices_cryptodata_message (struct AliceServiceSession *s) | 572 | send_alices_cryptodata_message(struct AliceServiceSession *s) |
576 | { | 573 | { |
577 | struct EccAliceCryptodataMessage *msg; | 574 | struct EccAliceCryptodataMessage *msg; |
578 | struct GNUNET_MQ_Envelope *e; | 575 | struct GNUNET_MQ_Envelope *e; |
@@ -583,64 +580,64 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
583 | unsigned int off; | 580 | unsigned int off; |
584 | unsigned int todo_count; | 581 | unsigned int todo_count; |
585 | 582 | ||
586 | s->sorted_elements = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size ( | 583 | s->sorted_elements = GNUNET_new_array(GNUNET_CONTAINER_multihashmap_size( |
587 | s->intersected_elements), | 584 | s->intersected_elements), |
588 | struct MpiElement); | 585 | struct MpiElement); |
589 | s->used_element_count = 0; | 586 | s->used_element_count = 0; |
590 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 587 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, |
591 | ©_element_cb, | 588 | ©_element_cb, |
592 | s); | 589 | s); |
593 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 590 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
594 | "Finished intersection, %d items remain\n", | 591 | "Finished intersection, %d items remain\n", |
595 | s->used_element_count); | 592 | s->used_element_count); |
596 | qsort (s->sorted_elements, | 593 | qsort(s->sorted_elements, |
597 | s->used_element_count, | 594 | s->used_element_count, |
598 | sizeof (struct MpiElement), | 595 | sizeof(struct MpiElement), |
599 | &element_cmp); | 596 | &element_cmp); |
600 | off = 0; | 597 | off = 0; |
601 | while (off < s->used_element_count) | 598 | while (off < s->used_element_count) |
602 | { | ||
603 | todo_count = s->used_element_count - off; | ||
604 | if (todo_count > ELEMENT_CAPACITY) | ||
605 | todo_count = ELEMENT_CAPACITY; | ||
606 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
607 | "Sending %u/%u crypto values to Bob\n", | ||
608 | (unsigned int) todo_count, | ||
609 | (unsigned int) s->used_element_count); | ||
610 | |||
611 | e = | ||
612 | GNUNET_MQ_msg_extra (msg, | ||
613 | todo_count * 2 * | ||
614 | sizeof (struct GNUNET_CRYPTO_EccPoint), | ||
615 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA); | ||
616 | msg->contained_element_count = htonl (todo_count); | ||
617 | payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1]; | ||
618 | r_ia = gcry_mpi_new (0); | ||
619 | r_ia_ai = gcry_mpi_new (0); | ||
620 | for (i = off; i < off + todo_count; i++) | ||
621 | { | 599 | { |
622 | gcry_mpi_t r_i; | 600 | todo_count = s->used_element_count - off; |
623 | gcry_mpi_point_t g_i; | 601 | if (todo_count > ELEMENT_CAPACITY) |
624 | gcry_mpi_point_t h_i; | 602 | todo_count = ELEMENT_CAPACITY; |
625 | 603 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | |
626 | r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc); | 604 | "Sending %u/%u crypto values to Bob\n", |
627 | g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_i); | 605 | (unsigned int)todo_count, |
628 | /* r_ia = r_i * a */ | 606 | (unsigned int)s->used_element_count); |
629 | gcry_mpi_mul (r_ia, r_i, my_privkey); | 607 | |
630 | gcry_mpi_release (r_i); | 608 | e = |
631 | /* r_ia_ai = r_ia + a_i */ | 609 | GNUNET_MQ_msg_extra(msg, |
632 | gcry_mpi_add (r_ia_ai, r_ia, s->sorted_elements[i].value); | 610 | todo_count * 2 * |
633 | h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_ia_ai); | 611 | sizeof(struct GNUNET_CRYPTO_EccPoint), |
634 | GNUNET_CRYPTO_ecc_point_to_bin (edc, g_i, &payload[(i - off) * 2]); | 612 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA); |
635 | GNUNET_CRYPTO_ecc_point_to_bin (edc, h_i, &payload[(i - off) * 2 + 1]); | 613 | msg->contained_element_count = htonl(todo_count); |
636 | gcry_mpi_point_release (g_i); | 614 | payload = (struct GNUNET_CRYPTO_EccPoint *)&msg[1]; |
637 | gcry_mpi_point_release (h_i); | 615 | r_ia = gcry_mpi_new(0); |
616 | r_ia_ai = gcry_mpi_new(0); | ||
617 | for (i = off; i < off + todo_count; i++) | ||
618 | { | ||
619 | gcry_mpi_t r_i; | ||
620 | gcry_mpi_point_t g_i; | ||
621 | gcry_mpi_point_t h_i; | ||
622 | |||
623 | r_i = GNUNET_CRYPTO_ecc_random_mod_n(edc); | ||
624 | g_i = GNUNET_CRYPTO_ecc_dexp_mpi(edc, r_i); | ||
625 | /* r_ia = r_i * a */ | ||
626 | gcry_mpi_mul(r_ia, r_i, my_privkey); | ||
627 | gcry_mpi_release(r_i); | ||
628 | /* r_ia_ai = r_ia + a_i */ | ||
629 | gcry_mpi_add(r_ia_ai, r_ia, s->sorted_elements[i].value); | ||
630 | h_i = GNUNET_CRYPTO_ecc_dexp_mpi(edc, r_ia_ai); | ||
631 | GNUNET_CRYPTO_ecc_point_to_bin(edc, g_i, &payload[(i - off) * 2]); | ||
632 | GNUNET_CRYPTO_ecc_point_to_bin(edc, h_i, &payload[(i - off) * 2 + 1]); | ||
633 | gcry_mpi_point_release(g_i); | ||
634 | gcry_mpi_point_release(h_i); | ||
635 | } | ||
636 | gcry_mpi_release(r_ia); | ||
637 | gcry_mpi_release(r_ia_ai); | ||
638 | off += todo_count; | ||
639 | GNUNET_MQ_send(s->cadet_mq, e); | ||
638 | } | 640 | } |
639 | gcry_mpi_release (r_ia); | ||
640 | gcry_mpi_release (r_ia_ai); | ||
641 | off += todo_count; | ||
642 | GNUNET_MQ_send (s->cadet_mq, e); | ||
643 | } | ||
644 | } | 641 | } |
645 | 642 | ||
646 | 643 | ||
@@ -655,66 +652,70 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
655 | * @param status what has happened with the set intersection? | 652 | * @param status what has happened with the set intersection? |
656 | */ | 653 | */ |
657 | static void | 654 | static void |
658 | cb_intersection_element_removed (void *cls, | 655 | cb_intersection_element_removed(void *cls, |
659 | const struct GNUNET_SET_Element *element, | 656 | const struct GNUNET_SET_Element *element, |
660 | uint64_t current_size, | 657 | uint64_t current_size, |
661 | enum GNUNET_SET_Status status) | 658 | enum GNUNET_SET_Status status) |
662 | { | 659 | { |
663 | struct AliceServiceSession *s = cls; | 660 | struct AliceServiceSession *s = cls; |
664 | struct GNUNET_SCALARPRODUCT_Element *se; | 661 | struct GNUNET_SCALARPRODUCT_Element *se; |
665 | 662 | ||
666 | switch (status) | 663 | switch (status) |
667 | { | ||
668 | case GNUNET_SET_STATUS_OK: | ||
669 | /* this element has been removed from the set */ | ||
670 | se = GNUNET_CONTAINER_multihashmap_get (s->intersected_elements, | ||
671 | element->data); | ||
672 | GNUNET_assert (NULL != se); | ||
673 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
674 | "Intersection removed element with key %s and value %lld\n", | ||
675 | GNUNET_h2s (&se->key), | ||
676 | (long long) GNUNET_ntohll (se->value)); | ||
677 | GNUNET_assert ( | ||
678 | GNUNET_YES == | ||
679 | GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, | ||
680 | element->data, | ||
681 | se)); | ||
682 | GNUNET_free (se); | ||
683 | return; | ||
684 | case GNUNET_SET_STATUS_DONE: | ||
685 | s->intersection_op = NULL; | ||
686 | if (NULL != s->intersection_set) | ||
687 | { | 664 | { |
688 | GNUNET_SET_destroy (s->intersection_set); | 665 | case GNUNET_SET_STATUS_OK: |
689 | s->intersection_set = NULL; | 666 | /* this element has been removed from the set */ |
667 | se = GNUNET_CONTAINER_multihashmap_get(s->intersected_elements, | ||
668 | element->data); | ||
669 | GNUNET_assert(NULL != se); | ||
670 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
671 | "Intersection removed element with key %s and value %lld\n", | ||
672 | GNUNET_h2s(&se->key), | ||
673 | (long long)GNUNET_ntohll(se->value)); | ||
674 | GNUNET_assert( | ||
675 | GNUNET_YES == | ||
676 | GNUNET_CONTAINER_multihashmap_remove(s->intersected_elements, | ||
677 | element->data, | ||
678 | se)); | ||
679 | GNUNET_free(se); | ||
680 | return; | ||
681 | |||
682 | case GNUNET_SET_STATUS_DONE: | ||
683 | s->intersection_op = NULL; | ||
684 | if (NULL != s->intersection_set) | ||
685 | { | ||
686 | GNUNET_SET_destroy(s->intersection_set); | ||
687 | s->intersection_set = NULL; | ||
688 | } | ||
689 | send_alices_cryptodata_message(s); | ||
690 | return; | ||
691 | |||
692 | case GNUNET_SET_STATUS_HALF_DONE: | ||
693 | /* unexpected for intersection */ | ||
694 | GNUNET_break(0); | ||
695 | return; | ||
696 | |||
697 | case GNUNET_SET_STATUS_FAILURE: | ||
698 | /* unhandled status code */ | ||
699 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n"); | ||
700 | if (NULL != s->intersection_listen) | ||
701 | { | ||
702 | GNUNET_SET_listen_cancel(s->intersection_listen); | ||
703 | s->intersection_listen = NULL; | ||
704 | } | ||
705 | s->intersection_op = NULL; | ||
706 | if (NULL != s->intersection_set) | ||
707 | { | ||
708 | GNUNET_SET_destroy(s->intersection_set); | ||
709 | s->intersection_set = NULL; | ||
710 | } | ||
711 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
712 | prepare_client_end_notification(s); | ||
713 | return; | ||
714 | |||
715 | default: | ||
716 | GNUNET_break(0); | ||
717 | return; | ||
690 | } | 718 | } |
691 | send_alices_cryptodata_message (s); | ||
692 | return; | ||
693 | case GNUNET_SET_STATUS_HALF_DONE: | ||
694 | /* unexpected for intersection */ | ||
695 | GNUNET_break (0); | ||
696 | return; | ||
697 | case GNUNET_SET_STATUS_FAILURE: | ||
698 | /* unhandled status code */ | ||
699 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n"); | ||
700 | if (NULL != s->intersection_listen) | ||
701 | { | ||
702 | GNUNET_SET_listen_cancel (s->intersection_listen); | ||
703 | s->intersection_listen = NULL; | ||
704 | } | ||
705 | s->intersection_op = NULL; | ||
706 | if (NULL != s->intersection_set) | ||
707 | { | ||
708 | GNUNET_SET_destroy (s->intersection_set); | ||
709 | s->intersection_set = NULL; | ||
710 | } | ||
711 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
712 | prepare_client_end_notification (s); | ||
713 | return; | ||
714 | default: | ||
715 | GNUNET_break (0); | ||
716 | return; | ||
717 | } | ||
718 | } | 719 | } |
719 | 720 | ||
720 | 721 | ||
@@ -734,40 +735,40 @@ cb_intersection_element_removed (void *cls, | |||
734 | * message. It's necessary to specify the timeout. | 735 | * message. It's necessary to specify the timeout. |
735 | */ | 736 | */ |
736 | static void | 737 | static void |
737 | cb_intersection_request_alice (void *cls, | 738 | cb_intersection_request_alice(void *cls, |
738 | const struct GNUNET_PeerIdentity *other_peer, | 739 | const struct GNUNET_PeerIdentity *other_peer, |
739 | const struct GNUNET_MessageHeader *context_msg, | 740 | const struct GNUNET_MessageHeader *context_msg, |
740 | struct GNUNET_SET_Request *request) | 741 | struct GNUNET_SET_Request *request) |
741 | { | 742 | { |
742 | struct AliceServiceSession *s = cls; | 743 | struct AliceServiceSession *s = cls; |
743 | 744 | ||
744 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 745 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
745 | "Received intersection request from %s!\n", | 746 | "Received intersection request from %s!\n", |
746 | GNUNET_i2s (other_peer)); | 747 | GNUNET_i2s(other_peer)); |
747 | if (0 != GNUNET_memcmp (other_peer, &s->peer)) | 748 | if (0 != GNUNET_memcmp(other_peer, &s->peer)) |
748 | { | 749 | { |
749 | GNUNET_break_op (0); | 750 | GNUNET_break_op(0); |
750 | return; | 751 | return; |
751 | } | 752 | } |
752 | s->intersection_op = GNUNET_SET_accept (request, | 753 | s->intersection_op = GNUNET_SET_accept(request, |
753 | GNUNET_SET_RESULT_REMOVED, | 754 | GNUNET_SET_RESULT_REMOVED, |
754 | (struct GNUNET_SET_Option[]){{0}}, | 755 | (struct GNUNET_SET_Option[]){ { 0 } }, |
755 | &cb_intersection_element_removed, | 756 | &cb_intersection_element_removed, |
756 | s); | 757 | s); |
757 | if (NULL == s->intersection_op) | 758 | if (NULL == s->intersection_op) |
758 | { | 759 | { |
759 | GNUNET_break (0); | 760 | GNUNET_break(0); |
760 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 761 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
761 | prepare_client_end_notification (s); | 762 | prepare_client_end_notification(s); |
762 | return; | 763 | return; |
763 | } | 764 | } |
764 | if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set)) | 765 | if (GNUNET_OK != GNUNET_SET_commit(s->intersection_op, s->intersection_set)) |
765 | { | 766 | { |
766 | GNUNET_break (0); | 767 | GNUNET_break(0); |
767 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 768 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
768 | prepare_client_end_notification (s); | 769 | prepare_client_end_notification(s); |
769 | return; | 770 | return; |
770 | } | 771 | } |
771 | } | 772 | } |
772 | 773 | ||
773 | 774 | ||
@@ -777,58 +778,58 @@ cb_intersection_request_alice (void *cls, | |||
777 | * @param session the service session context | 778 | * @param session the service session context |
778 | */ | 779 | */ |
779 | static void | 780 | static void |
780 | client_request_complete_alice (struct AliceServiceSession *s) | 781 | client_request_complete_alice(struct AliceServiceSession *s) |
781 | { | 782 | { |
782 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 783 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
783 | {GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, | 784 | { GNUNET_MQ_hd_fixed_size(bobs_cryptodata_message, |
784 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, | 785 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, |
785 | struct EccBobCryptodataMessage, | 786 | struct EccBobCryptodataMessage, |
786 | s), | 787 | s), |
787 | GNUNET_MQ_handler_end ()}; | 788 | GNUNET_MQ_handler_end() }; |
788 | struct EccServiceRequestMessage *msg; | 789 | struct EccServiceRequestMessage *msg; |
789 | struct GNUNET_MQ_Envelope *e; | 790 | struct GNUNET_MQ_Envelope *e; |
790 | struct GNUNET_HashCode set_sid; | 791 | struct GNUNET_HashCode set_sid; |
791 | 792 | ||
792 | GNUNET_CRYPTO_hash (&s->session_id, | 793 | GNUNET_CRYPTO_hash(&s->session_id, |
793 | sizeof (struct GNUNET_HashCode), | 794 | sizeof(struct GNUNET_HashCode), |
794 | &set_sid); | 795 | &set_sid); |
795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 796 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
796 | "Creating new channel for session with key %s.\n", | 797 | "Creating new channel for session with key %s.\n", |
797 | GNUNET_h2s (&s->session_id)); | 798 | GNUNET_h2s(&s->session_id)); |
798 | s->channel = GNUNET_CADET_channel_create (my_cadet, | 799 | s->channel = GNUNET_CADET_channel_create(my_cadet, |
799 | s, | 800 | s, |
800 | &s->peer, | 801 | &s->peer, |
801 | &s->session_id, | 802 | &s->session_id, |
802 | NULL, | 803 | NULL, |
803 | &cb_channel_destruction, | 804 | &cb_channel_destruction, |
804 | cadet_handlers); | 805 | cadet_handlers); |
805 | if (NULL == s->channel) | 806 | if (NULL == s->channel) |
806 | { | 807 | { |
807 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 808 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
808 | prepare_client_end_notification (s); | 809 | prepare_client_end_notification(s); |
809 | return; | 810 | return; |
810 | } | 811 | } |
811 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); | 812 | s->cadet_mq = GNUNET_CADET_get_mq(s->channel); |
812 | s->intersection_listen = GNUNET_SET_listen (cfg, | 813 | s->intersection_listen = GNUNET_SET_listen(cfg, |
813 | GNUNET_SET_OPERATION_INTERSECTION, | 814 | GNUNET_SET_OPERATION_INTERSECTION, |
814 | &set_sid, | 815 | &set_sid, |
815 | &cb_intersection_request_alice, | 816 | &cb_intersection_request_alice, |
816 | s); | 817 | s); |
817 | if (NULL == s->intersection_listen) | 818 | if (NULL == s->intersection_listen) |
818 | { | 819 | { |
819 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 820 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
820 | GNUNET_CADET_channel_destroy (s->channel); | 821 | GNUNET_CADET_channel_destroy(s->channel); |
821 | s->channel = NULL; | 822 | s->channel = NULL; |
822 | prepare_client_end_notification (s); | 823 | prepare_client_end_notification(s); |
823 | return; | 824 | return; |
824 | } | 825 | } |
825 | 826 | ||
826 | e = | 827 | e = |
827 | GNUNET_MQ_msg (msg, | 828 | GNUNET_MQ_msg(msg, |
828 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION); | 829 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION); |
829 | GNUNET_MQ_env_set_options (e, GNUNET_MQ_PRIO_CRITICAL_CONTROL); | 830 | GNUNET_MQ_env_set_options(e, GNUNET_MQ_PRIO_CRITICAL_CONTROL); |
830 | msg->session_id = s->session_id; | 831 | msg->session_id = s->session_id; |
831 | GNUNET_MQ_send (s->cadet_mq, e); | 832 | GNUNET_MQ_send(s->cadet_mq, e); |
832 | } | 833 | } |
833 | 834 | ||
834 | 835 | ||
@@ -841,7 +842,7 @@ client_request_complete_alice (struct AliceServiceSession *s) | |||
841 | * @return #GNUNET_OK if @a msg is well-formed | 842 | * @return #GNUNET_OK if @a msg is well-formed |
842 | */ | 843 | */ |
843 | static int | 844 | static int |
844 | check_alice_client_message_multipart ( | 845 | check_alice_client_message_multipart( |
845 | void *cls, | 846 | void *cls, |
846 | const struct ComputationBobCryptodataMultipartMessage *msg) | 847 | const struct ComputationBobCryptodataMultipartMessage *msg) |
847 | { | 848 | { |
@@ -849,18 +850,18 @@ check_alice_client_message_multipart ( | |||
849 | uint32_t contained_count; | 850 | uint32_t contained_count; |
850 | uint16_t msize; | 851 | uint16_t msize; |
851 | 852 | ||
852 | msize = ntohs (msg->header.size); | 853 | msize = ntohs(msg->header.size); |
853 | contained_count = ntohl (msg->element_count_contained); | 854 | contained_count = ntohl(msg->element_count_contained); |
854 | if ((msize != | 855 | if ((msize != |
855 | (sizeof (struct ComputationBobCryptodataMultipartMessage) + | 856 | (sizeof(struct ComputationBobCryptodataMultipartMessage) + |
856 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || | 857 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element))) || |
857 | (0 == contained_count) || | 858 | (0 == contained_count) || |
858 | (s->total == s->client_received_element_count) || | 859 | (s->total == s->client_received_element_count) || |
859 | (s->total < s->client_received_element_count + contained_count)) | 860 | (s->total < s->client_received_element_count + contained_count)) |
860 | { | 861 | { |
861 | GNUNET_break_op (0); | 862 | GNUNET_break_op(0); |
862 | return GNUNET_SYSERR; | 863 | return GNUNET_SYSERR; |
863 | } | 864 | } |
864 | return GNUNET_OK; | 865 | return GNUNET_OK; |
865 | } | 866 | } |
866 | 867 | ||
@@ -873,7 +874,7 @@ check_alice_client_message_multipart ( | |||
873 | * @param msg the actual message | 874 | * @param msg the actual message |
874 | */ | 875 | */ |
875 | static void | 876 | static void |
876 | handle_alice_client_message_multipart ( | 877 | handle_alice_client_message_multipart( |
877 | void *cls, | 878 | void *cls, |
878 | const struct ComputationBobCryptodataMultipartMessage *msg) | 879 | const struct ComputationBobCryptodataMultipartMessage *msg) |
879 | { | 880 | { |
@@ -883,41 +884,41 @@ handle_alice_client_message_multipart ( | |||
883 | struct GNUNET_SET_Element set_elem; | 884 | struct GNUNET_SET_Element set_elem; |
884 | struct GNUNET_SCALARPRODUCT_Element *elem; | 885 | struct GNUNET_SCALARPRODUCT_Element *elem; |
885 | 886 | ||
886 | contained_count = ntohl (msg->element_count_contained); | 887 | contained_count = ntohl(msg->element_count_contained); |
887 | s->client_received_element_count += contained_count; | 888 | s->client_received_element_count += contained_count; |
888 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 889 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; |
889 | for (uint32_t i = 0; i < contained_count; i++) | 890 | for (uint32_t i = 0; i < contained_count; i++) |
890 | { | ||
891 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
892 | GNUNET_memcpy (elem, | ||
893 | &elements[i], | ||
894 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | ||
895 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( | ||
896 | s->intersected_elements, | ||
897 | &elem->key, | ||
898 | elem, | ||
899 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
900 | { | 891 | { |
901 | GNUNET_break (0); | 892 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); |
902 | GNUNET_free (elem); | 893 | GNUNET_memcpy(elem, |
903 | continue; | 894 | &elements[i], |
895 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
896 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put( | ||
897 | s->intersected_elements, | ||
898 | &elem->key, | ||
899 | elem, | ||
900 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
901 | { | ||
902 | GNUNET_break(0); | ||
903 | GNUNET_free(elem); | ||
904 | continue; | ||
905 | } | ||
906 | set_elem.data = &elem->key; | ||
907 | set_elem.size = sizeof(elem->key); | ||
908 | set_elem.element_type = 0; | ||
909 | GNUNET_SET_add_element(s->intersection_set, &set_elem, NULL, NULL); | ||
910 | s->used_element_count++; | ||
904 | } | 911 | } |
905 | set_elem.data = &elem->key; | 912 | GNUNET_SERVICE_client_continue(s->client); |
906 | set_elem.size = sizeof (elem->key); | ||
907 | set_elem.element_type = 0; | ||
908 | GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); | ||
909 | s->used_element_count++; | ||
910 | } | ||
911 | GNUNET_SERVICE_client_continue (s->client); | ||
912 | if (s->total != s->client_received_element_count) | 913 | if (s->total != s->client_received_element_count) |
913 | { | 914 | { |
914 | /* more to come */ | 915 | /* more to come */ |
915 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 916 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
916 | "Received client multipart data, waiting for more!\n"); | 917 | "Received client multipart data, waiting for more!\n"); |
917 | return; | 918 | return; |
918 | } | 919 | } |
919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); | 920 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); |
920 | client_request_complete_alice (s); | 921 | client_request_complete_alice(s); |
921 | } | 922 | } |
922 | 923 | ||
923 | 924 | ||
@@ -930,8 +931,8 @@ handle_alice_client_message_multipart ( | |||
930 | * @return #GNUNET_OK if @a msg is well-formed | 931 | * @return #GNUNET_OK if @a msg is well-formed |
931 | */ | 932 | */ |
932 | static int | 933 | static int |
933 | check_alice_client_message (void *cls, | 934 | check_alice_client_message(void *cls, |
934 | const struct AliceComputationMessage *msg) | 935 | const struct AliceComputationMessage *msg) |
935 | { | 936 | { |
936 | struct AliceServiceSession *s = cls; | 937 | struct AliceServiceSession *s = cls; |
937 | uint16_t msize; | 938 | uint16_t msize; |
@@ -939,23 +940,23 @@ check_alice_client_message (void *cls, | |||
939 | uint32_t contained_count; | 940 | uint32_t contained_count; |
940 | 941 | ||
941 | if (NULL != s->intersected_elements) | 942 | if (NULL != s->intersected_elements) |
942 | { | 943 | { |
943 | /* only one concurrent session per client connection allowed, | 944 | /* only one concurrent session per client connection allowed, |
944 | simplifies logic a lot... */ | 945 | simplifies logic a lot... */ |
945 | GNUNET_break (0); | 946 | GNUNET_break(0); |
946 | return GNUNET_SYSERR; | 947 | return GNUNET_SYSERR; |
947 | } | 948 | } |
948 | msize = ntohs (msg->header.size); | 949 | msize = ntohs(msg->header.size); |
949 | total_count = ntohl (msg->element_count_total); | 950 | total_count = ntohl(msg->element_count_total); |
950 | contained_count = ntohl (msg->element_count_contained); | 951 | contained_count = ntohl(msg->element_count_contained); |
951 | if ((0 == total_count) || (0 == contained_count) || | 952 | if ((0 == total_count) || (0 == contained_count) || |
952 | (msize != | 953 | (msize != |
953 | (sizeof (struct AliceComputationMessage) + | 954 | (sizeof(struct AliceComputationMessage) + |
954 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element)))) | 955 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element)))) |
955 | { | 956 | { |
956 | GNUNET_break_op (0); | 957 | GNUNET_break_op(0); |
957 | return GNUNET_SYSERR; | 958 | return GNUNET_SYSERR; |
958 | } | 959 | } |
959 | return GNUNET_OK; | 960 | return GNUNET_OK; |
960 | } | 961 | } |
961 | 962 | ||
@@ -968,8 +969,8 @@ check_alice_client_message (void *cls, | |||
968 | * @param msg the actual message | 969 | * @param msg the actual message |
969 | */ | 970 | */ |
970 | static void | 971 | static void |
971 | handle_alice_client_message (void *cls, | 972 | handle_alice_client_message(void *cls, |
972 | const struct AliceComputationMessage *msg) | 973 | const struct AliceComputationMessage *msg) |
973 | { | 974 | { |
974 | struct AliceServiceSession *s = cls; | 975 | struct AliceServiceSession *s = cls; |
975 | uint32_t contained_count; | 976 | uint32_t contained_count; |
@@ -978,53 +979,53 @@ handle_alice_client_message (void *cls, | |||
978 | struct GNUNET_SET_Element set_elem; | 979 | struct GNUNET_SET_Element set_elem; |
979 | struct GNUNET_SCALARPRODUCT_Element *elem; | 980 | struct GNUNET_SCALARPRODUCT_Element *elem; |
980 | 981 | ||
981 | total_count = ntohl (msg->element_count_total); | 982 | total_count = ntohl(msg->element_count_total); |
982 | contained_count = ntohl (msg->element_count_contained); | 983 | contained_count = ntohl(msg->element_count_contained); |
983 | s->peer = msg->peer; | 984 | s->peer = msg->peer; |
984 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; | 985 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; |
985 | s->total = total_count; | 986 | s->total = total_count; |
986 | s->client_received_element_count = contained_count; | 987 | s->client_received_element_count = contained_count; |
987 | s->session_id = msg->session_key; | 988 | s->session_id = msg->session_key; |
988 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 989 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; |
989 | s->intersected_elements = | 990 | s->intersected_elements = |
990 | GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES); | 991 | GNUNET_CONTAINER_multihashmap_create(s->total, GNUNET_YES); |
991 | s->intersection_set = | 992 | s->intersection_set = |
992 | GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); | 993 | GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_INTERSECTION); |
993 | for (uint32_t i = 0; i < contained_count; i++) | 994 | for (uint32_t i = 0; i < contained_count; i++) |
994 | { | ||
995 | if (0 == GNUNET_ntohll (elements[i].value)) | ||
996 | continue; | ||
997 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
998 | GNUNET_memcpy (elem, | ||
999 | &elements[i], | ||
1000 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | ||
1001 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( | ||
1002 | s->intersected_elements, | ||
1003 | &elem->key, | ||
1004 | elem, | ||
1005 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1006 | { | 995 | { |
1007 | /* element with same key encountered twice! */ | 996 | if (0 == GNUNET_ntohll(elements[i].value)) |
1008 | GNUNET_break (0); | 997 | continue; |
1009 | GNUNET_free (elem); | 998 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); |
1010 | continue; | 999 | GNUNET_memcpy(elem, |
1000 | &elements[i], | ||
1001 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
1002 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put( | ||
1003 | s->intersected_elements, | ||
1004 | &elem->key, | ||
1005 | elem, | ||
1006 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1007 | { | ||
1008 | /* element with same key encountered twice! */ | ||
1009 | GNUNET_break(0); | ||
1010 | GNUNET_free(elem); | ||
1011 | continue; | ||
1012 | } | ||
1013 | set_elem.data = &elem->key; | ||
1014 | set_elem.size = sizeof(elem->key); | ||
1015 | set_elem.element_type = 0; | ||
1016 | GNUNET_SET_add_element(s->intersection_set, &set_elem, NULL, NULL); | ||
1017 | s->used_element_count++; | ||
1011 | } | 1018 | } |
1012 | set_elem.data = &elem->key; | 1019 | GNUNET_SERVICE_client_continue(s->client); |
1013 | set_elem.size = sizeof (elem->key); | ||
1014 | set_elem.element_type = 0; | ||
1015 | GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); | ||
1016 | s->used_element_count++; | ||
1017 | } | ||
1018 | GNUNET_SERVICE_client_continue (s->client); | ||
1019 | if (s->total != s->client_received_element_count) | 1020 | if (s->total != s->client_received_element_count) |
1020 | { | 1021 | { |
1021 | /* wait for multipart msg */ | 1022 | /* wait for multipart msg */ |
1022 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1023 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1023 | "Received partial client request, waiting for more!\n"); | 1024 | "Received partial client request, waiting for more!\n"); |
1024 | return; | 1025 | return; |
1025 | } | 1026 | } |
1026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); | 1027 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); |
1027 | client_request_complete_alice (s); | 1028 | client_request_complete_alice(s); |
1028 | } | 1029 | } |
1029 | 1030 | ||
1030 | 1031 | ||
@@ -1035,20 +1036,20 @@ handle_alice_client_message (void *cls, | |||
1035 | * @param tc unused | 1036 | * @param tc unused |
1036 | */ | 1037 | */ |
1037 | static void | 1038 | static void |
1038 | shutdown_task (void *cls) | 1039 | shutdown_task(void *cls) |
1039 | { | 1040 | { |
1040 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n"); | 1041 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n"); |
1041 | // FIXME: we have to cut our connections to CADET first! | 1042 | // FIXME: we have to cut our connections to CADET first! |
1042 | if (NULL != my_cadet) | 1043 | if (NULL != my_cadet) |
1043 | { | 1044 | { |
1044 | GNUNET_CADET_disconnect (my_cadet); | 1045 | GNUNET_CADET_disconnect(my_cadet); |
1045 | my_cadet = NULL; | 1046 | my_cadet = NULL; |
1046 | } | 1047 | } |
1047 | if (NULL != edc) | 1048 | if (NULL != edc) |
1048 | { | 1049 | { |
1049 | GNUNET_CRYPTO_ecc_dlog_release (edc); | 1050 | GNUNET_CRYPTO_ecc_dlog_release(edc); |
1050 | edc = NULL; | 1051 | edc = NULL; |
1051 | } | 1052 | } |
1052 | } | 1053 | } |
1053 | 1054 | ||
1054 | 1055 | ||
@@ -1063,13 +1064,13 @@ shutdown_task (void *cls) | |||
1063 | * @return our `struct AliceServiceSession` | 1064 | * @return our `struct AliceServiceSession` |
1064 | */ | 1065 | */ |
1065 | static void * | 1066 | static void * |
1066 | client_connect_cb (void *cls, | 1067 | client_connect_cb(void *cls, |
1067 | struct GNUNET_SERVICE_Client *client, | 1068 | struct GNUNET_SERVICE_Client *client, |
1068 | struct GNUNET_MQ_Handle *mq) | 1069 | struct GNUNET_MQ_Handle *mq) |
1069 | { | 1070 | { |
1070 | struct AliceServiceSession *s; | 1071 | struct AliceServiceSession *s; |
1071 | 1072 | ||
1072 | s = GNUNET_new (struct AliceServiceSession); | 1073 | s = GNUNET_new(struct AliceServiceSession); |
1073 | s->client = client; | 1074 | s->client = client; |
1074 | s->client_mq = mq; | 1075 | s->client_mq = mq; |
1075 | return s; | 1076 | return s; |
@@ -1087,18 +1088,18 @@ client_connect_cb (void *cls, | |||
1087 | * @param app_cls our `struct AliceServiceSession` | 1088 | * @param app_cls our `struct AliceServiceSession` |
1088 | */ | 1089 | */ |
1089 | static void | 1090 | static void |
1090 | client_disconnect_cb (void *cls, | 1091 | client_disconnect_cb(void *cls, |
1091 | struct GNUNET_SERVICE_Client *client, | 1092 | struct GNUNET_SERVICE_Client *client, |
1092 | void *app_cls) | 1093 | void *app_cls) |
1093 | { | 1094 | { |
1094 | struct AliceServiceSession *s = app_cls; | 1095 | struct AliceServiceSession *s = app_cls; |
1095 | 1096 | ||
1096 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1097 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1097 | "Client %p disconnected from us.\n", | 1098 | "Client %p disconnected from us.\n", |
1098 | client); | 1099 | client); |
1099 | s->client = NULL; | 1100 | s->client = NULL; |
1100 | s->client_mq = NULL; | 1101 | s->client_mq = NULL; |
1101 | destroy_service_session (s); | 1102 | destroy_service_session(s); |
1102 | } | 1103 | } |
1103 | 1104 | ||
1104 | 1105 | ||
@@ -1110,45 +1111,45 @@ client_disconnect_cb (void *cls, | |||
1110 | * @param service the initialized service | 1111 | * @param service the initialized service |
1111 | */ | 1112 | */ |
1112 | static void | 1113 | static void |
1113 | run (void *cls, | 1114 | run(void *cls, |
1114 | const struct GNUNET_CONFIGURATION_Handle *c, | 1115 | const struct GNUNET_CONFIGURATION_Handle *c, |
1115 | struct GNUNET_SERVICE_Handle *service) | 1116 | struct GNUNET_SERVICE_Handle *service) |
1116 | { | 1117 | { |
1117 | cfg = c; | 1118 | cfg = c; |
1118 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, MAX_RAM); | 1119 | edc = GNUNET_CRYPTO_ecc_dlog_prepare(MAX_RESULT, MAX_RAM); |
1119 | /* Select a random 'a' value for Alice */ | 1120 | /* Select a random 'a' value for Alice */ |
1120 | GNUNET_CRYPTO_ecc_rnd_mpi (edc, &my_privkey, &my_privkey_inv); | 1121 | GNUNET_CRYPTO_ecc_rnd_mpi(edc, &my_privkey, &my_privkey_inv); |
1121 | my_cadet = GNUNET_CADET_connect (cfg); | 1122 | my_cadet = GNUNET_CADET_connect(cfg); |
1122 | if (NULL == my_cadet) | 1123 | if (NULL == my_cadet) |
1123 | { | 1124 | { |
1124 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n")); | 1125 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Connect to CADET failed\n")); |
1125 | GNUNET_SCHEDULER_shutdown (); | 1126 | GNUNET_SCHEDULER_shutdown(); |
1126 | return; | 1127 | return; |
1127 | } | 1128 | } |
1128 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1129 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
1129 | } | 1130 | } |
1130 | 1131 | ||
1131 | 1132 | ||
1132 | /** | 1133 | /** |
1133 | * Define "main" method using service macro. | 1134 | * Define "main" method using service macro. |
1134 | */ | 1135 | */ |
1135 | GNUNET_SERVICE_MAIN ( | 1136 | GNUNET_SERVICE_MAIN( |
1136 | "scalarproduct-alice", | 1137 | "scalarproduct-alice", |
1137 | GNUNET_SERVICE_OPTION_NONE, | 1138 | GNUNET_SERVICE_OPTION_NONE, |
1138 | &run, | 1139 | &run, |
1139 | &client_connect_cb, | 1140 | &client_connect_cb, |
1140 | &client_disconnect_cb, | 1141 | &client_disconnect_cb, |
1141 | NULL, | 1142 | NULL, |
1142 | GNUNET_MQ_hd_var_size (alice_client_message, | 1143 | GNUNET_MQ_hd_var_size(alice_client_message, |
1143 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, | 1144 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, |
1144 | struct AliceComputationMessage, | 1145 | struct AliceComputationMessage, |
1145 | NULL), | 1146 | NULL), |
1146 | GNUNET_MQ_hd_var_size ( | 1147 | GNUNET_MQ_hd_var_size( |
1147 | alice_client_message_multipart, | 1148 | alice_client_message_multipart, |
1148 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, | 1149 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, |
1149 | struct ComputationBobCryptodataMultipartMessage, | 1150 | struct ComputationBobCryptodataMultipartMessage, |
1150 | NULL), | 1151 | NULL), |
1151 | GNUNET_MQ_handler_end ()); | 1152 | GNUNET_MQ_handler_end()); |
1152 | 1153 | ||
1153 | 1154 | ||
1154 | /* end of gnunet-service-scalarproduct-ecc_alice.c */ | 1155 | /* end of gnunet-service-scalarproduct-ecc_alice.c */ |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c index eb39943f8..fc2d1d8c5 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_bob.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -36,14 +36,13 @@ | |||
36 | #include "scalarproduct.h" | 36 | #include "scalarproduct.h" |
37 | #include "gnunet-service-scalarproduct-ecc.h" | 37 | #include "gnunet-service-scalarproduct-ecc.h" |
38 | 38 | ||
39 | #define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-bob", __VA_ARGS__) | 39 | #define LOG(kind, ...) GNUNET_log_from(kind, "scalarproduct-bob", __VA_ARGS__) |
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * An encrypted element key-value pair. | 43 | * An encrypted element key-value pair. |
44 | */ | 44 | */ |
45 | struct MpiElement | 45 | struct MpiElement { |
46 | { | ||
47 | /** | 46 | /** |
48 | * Key used to identify matching pairs of values to multiply. | 47 | * Key used to identify matching pairs of values to multiply. |
49 | * Points into an existing data structure, to avoid copying | 48 | * Points into an existing data structure, to avoid copying |
@@ -62,9 +61,7 @@ struct MpiElement | |||
62 | * A scalarproduct session which tracks an offer for a | 61 | * A scalarproduct session which tracks an offer for a |
63 | * multiplication service by a local client. | 62 | * multiplication service by a local client. |
64 | */ | 63 | */ |
65 | struct BobServiceSession | 64 | struct BobServiceSession { |
66 | { | ||
67 | |||
68 | /** | 65 | /** |
69 | * The client this request is related to. | 66 | * The client this request is related to. |
70 | */ | 67 | */ |
@@ -168,7 +165,6 @@ struct BobServiceSession | |||
168 | * The message queue for this channel. | 165 | * The message queue for this channel. |
169 | */ | 166 | */ |
170 | struct GNUNET_MQ_Handle *cadet_mq; | 167 | struct GNUNET_MQ_Handle *cadet_mq; |
171 | |||
172 | }; | 168 | }; |
173 | 169 | ||
174 | 170 | ||
@@ -196,13 +192,13 @@ static struct GNUNET_CRYPTO_EccDlogContext *edc; | |||
196 | * @param value the value to free | 192 | * @param value the value to free |
197 | */ | 193 | */ |
198 | static int | 194 | static int |
199 | free_element_cb (void *cls, | 195 | free_element_cb(void *cls, |
200 | const struct GNUNET_HashCode *key, | 196 | const struct GNUNET_HashCode *key, |
201 | void *value) | 197 | void *value) |
202 | { | 198 | { |
203 | struct GNUNET_SCALARPRODUCT_Element *element = value; | 199 | struct GNUNET_SCALARPRODUCT_Element *element = value; |
204 | 200 | ||
205 | GNUNET_free (element); | 201 | GNUNET_free(element); |
206 | return GNUNET_OK; | 202 | return GNUNET_OK; |
207 | } | 203 | } |
208 | 204 | ||
@@ -213,7 +209,7 @@ free_element_cb (void *cls, | |||
213 | * @param session the session to free elements from | 209 | * @param session the session to free elements from |
214 | */ | 210 | */ |
215 | static void | 211 | static void |
216 | destroy_service_session (struct BobServiceSession *s) | 212 | destroy_service_session(struct BobServiceSession *s) |
217 | { | 213 | { |
218 | unsigned int i; | 214 | unsigned int i; |
219 | 215 | ||
@@ -221,58 +217,58 @@ destroy_service_session (struct BobServiceSession *s) | |||
221 | return; | 217 | return; |
222 | s->in_destroy = GNUNET_YES; | 218 | s->in_destroy = GNUNET_YES; |
223 | if (NULL != s->client) | 219 | if (NULL != s->client) |
224 | { | 220 | { |
225 | struct GNUNET_SERVICE_Client *c = s->client; | 221 | struct GNUNET_SERVICE_Client *c = s->client; |
226 | 222 | ||
227 | s->client = NULL; | 223 | s->client = NULL; |
228 | GNUNET_SERVICE_client_drop (c); | 224 | GNUNET_SERVICE_client_drop(c); |
229 | } | 225 | } |
230 | if (NULL != s->intersected_elements) | 226 | if (NULL != s->intersected_elements) |
231 | { | 227 | { |
232 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 228 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, |
233 | &free_element_cb, | 229 | &free_element_cb, |
234 | NULL); | 230 | NULL); |
235 | GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements); | 231 | GNUNET_CONTAINER_multihashmap_destroy(s->intersected_elements); |
236 | s->intersected_elements = NULL; | 232 | s->intersected_elements = NULL; |
237 | } | 233 | } |
238 | if (NULL != s->intersection_op) | 234 | if (NULL != s->intersection_op) |
239 | { | 235 | { |
240 | GNUNET_SET_operation_cancel (s->intersection_op); | 236 | GNUNET_SET_operation_cancel(s->intersection_op); |
241 | s->intersection_op = NULL; | 237 | s->intersection_op = NULL; |
242 | } | 238 | } |
243 | if (NULL != s->intersection_set) | 239 | if (NULL != s->intersection_set) |
244 | { | 240 | { |
245 | GNUNET_SET_destroy (s->intersection_set); | 241 | GNUNET_SET_destroy(s->intersection_set); |
246 | s->intersection_set = NULL; | 242 | s->intersection_set = NULL; |
247 | } | 243 | } |
248 | if (NULL != s->sorted_elements) | 244 | if (NULL != s->sorted_elements) |
249 | { | 245 | { |
250 | for (i=0;i<s->used_element_count;i++) | 246 | for (i = 0; i < s->used_element_count; i++) |
251 | gcry_mpi_release (s->sorted_elements[i].value); | 247 | gcry_mpi_release(s->sorted_elements[i].value); |
252 | GNUNET_free (s->sorted_elements); | 248 | GNUNET_free(s->sorted_elements); |
253 | s->sorted_elements = NULL; | 249 | s->sorted_elements = NULL; |
254 | } | 250 | } |
255 | if (NULL != s->prod_g_i_b_i) | 251 | if (NULL != s->prod_g_i_b_i) |
256 | { | 252 | { |
257 | gcry_mpi_point_release (s->prod_g_i_b_i); | 253 | gcry_mpi_point_release(s->prod_g_i_b_i); |
258 | s->prod_g_i_b_i = NULL; | 254 | s->prod_g_i_b_i = NULL; |
259 | } | 255 | } |
260 | if (NULL != s->prod_h_i_b_i) | 256 | if (NULL != s->prod_h_i_b_i) |
261 | { | 257 | { |
262 | gcry_mpi_point_release (s->prod_h_i_b_i); | 258 | gcry_mpi_point_release(s->prod_h_i_b_i); |
263 | s->prod_h_i_b_i = NULL; | 259 | s->prod_h_i_b_i = NULL; |
264 | } | 260 | } |
265 | if (NULL != s->port) | 261 | if (NULL != s->port) |
266 | { | 262 | { |
267 | GNUNET_CADET_close_port (s->port); | 263 | GNUNET_CADET_close_port(s->port); |
268 | s->port = NULL; | 264 | s->port = NULL; |
269 | } | 265 | } |
270 | if (NULL != s->channel) | 266 | if (NULL != s->channel) |
271 | { | 267 | { |
272 | GNUNET_CADET_channel_destroy (s->channel); | 268 | GNUNET_CADET_channel_destroy(s->channel); |
273 | s->channel = NULL; | 269 | s->channel = NULL; |
274 | } | 270 | } |
275 | GNUNET_free (s); | 271 | GNUNET_free(s); |
276 | } | 272 | } |
277 | 273 | ||
278 | 274 | ||
@@ -284,24 +280,24 @@ destroy_service_session (struct BobServiceSession *s) | |||
284 | * @param session the associated client session to fail or succeed | 280 | * @param session the associated client session to fail or succeed |
285 | */ | 281 | */ |
286 | static void | 282 | static void |
287 | prepare_client_end_notification (struct BobServiceSession *session) | 283 | prepare_client_end_notification(struct BobServiceSession *session) |
288 | { | 284 | { |
289 | struct ClientResponseMessage *msg; | 285 | struct ClientResponseMessage *msg; |
290 | struct GNUNET_MQ_Envelope *e; | 286 | struct GNUNET_MQ_Envelope *e; |
291 | 287 | ||
292 | if (NULL == session->client_mq) | 288 | if (NULL == session->client_mq) |
293 | return; /* no client left to be notified */ | 289 | return; /* no client left to be notified */ |
294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 290 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
295 | "Sending session-end notification with status %d to client for session %s\n", | 291 | "Sending session-end notification with status %d to client for session %s\n", |
296 | session->status, | 292 | session->status, |
297 | GNUNET_h2s (&session->session_id)); | 293 | GNUNET_h2s(&session->session_id)); |
298 | e = GNUNET_MQ_msg (msg, | 294 | e = GNUNET_MQ_msg(msg, |
299 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 295 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
300 | msg->range = 0; | 296 | msg->range = 0; |
301 | msg->product_length = htonl (0); | 297 | msg->product_length = htonl(0); |
302 | msg->status = htonl (session->status); | 298 | msg->status = htonl(session->status); |
303 | GNUNET_MQ_send (session->client_mq, | 299 | GNUNET_MQ_send(session->client_mq, |
304 | e); | 300 | e); |
305 | } | 301 | } |
306 | 302 | ||
307 | 303 | ||
@@ -317,22 +313,22 @@ prepare_client_end_notification (struct BobServiceSession *session) | |||
317 | * with the channel is stored | 313 | * with the channel is stored |
318 | */ | 314 | */ |
319 | static void | 315 | static void |
320 | cb_channel_destruction (void *cls, | 316 | cb_channel_destruction(void *cls, |
321 | const struct GNUNET_CADET_Channel *channel) | 317 | const struct GNUNET_CADET_Channel *channel) |
322 | { | 318 | { |
323 | struct BobServiceSession *s = cls; | 319 | struct BobServiceSession *s = cls; |
324 | 320 | ||
325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 321 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
326 | "Peer disconnected, terminating session %s with peer %s\n", | 322 | "Peer disconnected, terminating session %s with peer %s\n", |
327 | GNUNET_h2s (&s->session_id), | 323 | GNUNET_h2s(&s->session_id), |
328 | GNUNET_i2s (&s->peer)); | 324 | GNUNET_i2s(&s->peer)); |
329 | s->channel = NULL; | 325 | s->channel = NULL; |
330 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) | 326 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) |
331 | { | 327 | { |
332 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 328 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
333 | prepare_client_end_notification (s); | 329 | prepare_client_end_notification(s); |
334 | } | 330 | } |
335 | destroy_service_session (s); | 331 | destroy_service_session(s); |
336 | } | 332 | } |
337 | 333 | ||
338 | 334 | ||
@@ -341,12 +337,12 @@ cb_channel_destruction (void *cls, | |||
341 | * the client that we are finished. | 337 | * the client that we are finished. |
342 | */ | 338 | */ |
343 | static void | 339 | static void |
344 | bob_cadet_done_cb (void *cls) | 340 | bob_cadet_done_cb(void *cls) |
345 | { | 341 | { |
346 | struct BobServiceSession *session = cls; | 342 | struct BobServiceSession *session = cls; |
347 | 343 | ||
348 | session->status = GNUNET_SCALARPRODUCT_STATUS_SUCCESS; | 344 | session->status = GNUNET_SCALARPRODUCT_STATUS_SUCCESS; |
349 | prepare_client_end_notification (session); | 345 | prepare_client_end_notification(session); |
350 | } | 346 | } |
351 | 347 | ||
352 | 348 | ||
@@ -356,29 +352,29 @@ bob_cadet_done_cb (void *cls) | |||
356 | * @param s the associated requesting session with Alice | 352 | * @param s the associated requesting session with Alice |
357 | */ | 353 | */ |
358 | static void | 354 | static void |
359 | transmit_bobs_cryptodata_message (struct BobServiceSession *s) | 355 | transmit_bobs_cryptodata_message(struct BobServiceSession *s) |
360 | { | 356 | { |
361 | struct EccBobCryptodataMessage *msg; | 357 | struct EccBobCryptodataMessage *msg; |
362 | struct GNUNET_MQ_Envelope *e; | 358 | struct GNUNET_MQ_Envelope *e; |
363 | 359 | ||
364 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 360 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
365 | "Sending response to Alice\n"); | 361 | "Sending response to Alice\n"); |
366 | e = GNUNET_MQ_msg (msg, | 362 | e = GNUNET_MQ_msg(msg, |
367 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA); | 363 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA); |
368 | msg->contained_element_count = htonl (2); | 364 | msg->contained_element_count = htonl(2); |
369 | if (NULL != s->prod_g_i_b_i) | 365 | if (NULL != s->prod_g_i_b_i) |
370 | GNUNET_CRYPTO_ecc_point_to_bin (edc, | 366 | GNUNET_CRYPTO_ecc_point_to_bin(edc, |
371 | s->prod_g_i_b_i, | 367 | s->prod_g_i_b_i, |
372 | &msg->prod_g_i_b_i); | 368 | &msg->prod_g_i_b_i); |
373 | if (NULL != s->prod_h_i_b_i) | 369 | if (NULL != s->prod_h_i_b_i) |
374 | GNUNET_CRYPTO_ecc_point_to_bin (edc, | 370 | GNUNET_CRYPTO_ecc_point_to_bin(edc, |
375 | s->prod_h_i_b_i, | 371 | s->prod_h_i_b_i, |
376 | &msg->prod_h_i_b_i); | 372 | &msg->prod_h_i_b_i); |
377 | GNUNET_MQ_notify_sent (e, | 373 | GNUNET_MQ_notify_sent(e, |
378 | &bob_cadet_done_cb, | 374 | &bob_cadet_done_cb, |
379 | s); | 375 | s); |
380 | GNUNET_MQ_send (s->cadet_mq, | 376 | GNUNET_MQ_send(s->cadet_mq, |
381 | e); | 377 | e); |
382 | } | 378 | } |
383 | 379 | ||
384 | 380 | ||
@@ -392,21 +388,21 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) | |||
392 | * TODO: code duplication with Alice! | 388 | * TODO: code duplication with Alice! |
393 | */ | 389 | */ |
394 | static int | 390 | static int |
395 | copy_element_cb (void *cls, | 391 | copy_element_cb(void *cls, |
396 | const struct GNUNET_HashCode *key, | 392 | const struct GNUNET_HashCode *key, |
397 | void *value) | 393 | void *value) |
398 | { | 394 | { |
399 | struct BobServiceSession *s = cls; | 395 | struct BobServiceSession *s = cls; |
400 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 396 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
401 | gcry_mpi_t mval; | 397 | gcry_mpi_t mval; |
402 | int64_t val; | 398 | int64_t val; |
403 | 399 | ||
404 | mval = gcry_mpi_new (0); | 400 | mval = gcry_mpi_new(0); |
405 | val = (int64_t) GNUNET_ntohll (e->value); | 401 | val = (int64_t)GNUNET_ntohll(e->value); |
406 | if (0 > val) | 402 | if (0 > val) |
407 | gcry_mpi_sub_ui (mval, mval, -val); | 403 | gcry_mpi_sub_ui(mval, mval, -val); |
408 | else | 404 | else |
409 | gcry_mpi_add_ui (mval, mval, val); | 405 | gcry_mpi_add_ui(mval, mval, val); |
410 | s->sorted_elements [s->used_element_count].value = mval; | 406 | s->sorted_elements [s->used_element_count].value = mval; |
411 | s->sorted_elements [s->used_element_count].key = &e->key; | 407 | s->sorted_elements [s->used_element_count].key = &e->key; |
412 | s->used_element_count++; | 408 | s->used_element_count++; |
@@ -423,14 +419,14 @@ copy_element_cb (void *cls, | |||
423 | * TODO: code duplication with Alice! | 419 | * TODO: code duplication with Alice! |
424 | */ | 420 | */ |
425 | static int | 421 | static int |
426 | element_cmp (const void *a, | 422 | element_cmp(const void *a, |
427 | const void *b) | 423 | const void *b) |
428 | { | 424 | { |
429 | const struct MpiElement *ma = a; | 425 | const struct MpiElement *ma = a; |
430 | const struct MpiElement *mb = b; | 426 | const struct MpiElement *mb = b; |
431 | 427 | ||
432 | return GNUNET_CRYPTO_hash_cmp (ma->key, | 428 | return GNUNET_CRYPTO_hash_cmp(ma->key, |
433 | mb->key); | 429 | mb->key); |
434 | } | 430 | } |
435 | 431 | ||
436 | 432 | ||
@@ -444,8 +440,8 @@ element_cmp (const void *a, | |||
444 | * #GNUNET_SYSERR to close it (signal serious error) | 440 | * #GNUNET_SYSERR to close it (signal serious error) |
445 | */ | 441 | */ |
446 | static int | 442 | static int |
447 | check_alices_cryptodata_message (void *cls, | 443 | check_alices_cryptodata_message(void *cls, |
448 | const struct EccAliceCryptodataMessage *msg) | 444 | const struct EccAliceCryptodataMessage *msg) |
449 | { | 445 | { |
450 | struct BobServiceSession *s = cls; | 446 | struct BobServiceSession *s = cls; |
451 | uint32_t contained_elements; | 447 | uint32_t contained_elements; |
@@ -453,26 +449,26 @@ check_alices_cryptodata_message (void *cls, | |||
453 | uint16_t msize; | 449 | uint16_t msize; |
454 | unsigned int max; | 450 | unsigned int max; |
455 | 451 | ||
456 | msize = ntohs (msg->header.size); | 452 | msize = ntohs(msg->header.size); |
457 | if (msize <= sizeof (struct EccAliceCryptodataMessage)) | 453 | if (msize <= sizeof(struct EccAliceCryptodataMessage)) |
458 | { | 454 | { |
459 | GNUNET_break_op (0); | 455 | GNUNET_break_op(0); |
460 | return GNUNET_SYSERR; | 456 | return GNUNET_SYSERR; |
461 | } | 457 | } |
462 | contained_elements = ntohl (msg->contained_element_count); | 458 | contained_elements = ntohl(msg->contained_element_count); |
463 | /* Our intersection may still be ongoing, but this is nevertheless | 459 | /* Our intersection may still be ongoing, but this is nevertheless |
464 | an upper bound on the required array size */ | 460 | an upper bound on the required array size */ |
465 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); | 461 | max = GNUNET_CONTAINER_multihashmap_size(s->intersected_elements); |
466 | msg_length = sizeof (struct EccAliceCryptodataMessage) | 462 | msg_length = sizeof(struct EccAliceCryptodataMessage) |
467 | + contained_elements * sizeof (struct GNUNET_CRYPTO_EccPoint) * 2; | 463 | + contained_elements * sizeof(struct GNUNET_CRYPTO_EccPoint) * 2; |
468 | if ( (msize != msg_length) || | 464 | if ((msize != msg_length) || |
469 | (0 == contained_elements) || | 465 | (0 == contained_elements) || |
470 | (contained_elements > UINT16_MAX) || | 466 | (contained_elements > UINT16_MAX) || |
471 | (max < contained_elements + s->cadet_received_element_count) ) | 467 | (max < contained_elements + s->cadet_received_element_count)) |
472 | { | 468 | { |
473 | GNUNET_break_op (0); | 469 | GNUNET_break_op(0); |
474 | return GNUNET_SYSERR; | 470 | return GNUNET_SYSERR; |
475 | } | 471 | } |
476 | return GNUNET_OK; | 472 | return GNUNET_OK; |
477 | } | 473 | } |
478 | 474 | ||
@@ -485,8 +481,8 @@ check_alices_cryptodata_message (void *cls, | |||
485 | * @param msg the actual message | 481 | * @param msg the actual message |
486 | */ | 482 | */ |
487 | static void | 483 | static void |
488 | handle_alices_cryptodata_message (void *cls, | 484 | handle_alices_cryptodata_message(void *cls, |
489 | const struct EccAliceCryptodataMessage *msg) | 485 | const struct EccAliceCryptodataMessage *msg) |
490 | { | 486 | { |
491 | struct BobServiceSession *s = cls; | 487 | struct BobServiceSession *s = cls; |
492 | const struct GNUNET_CRYPTO_EccPoint *payload; | 488 | const struct GNUNET_CRYPTO_EccPoint *payload; |
@@ -500,77 +496,77 @@ handle_alices_cryptodata_message (void *cls, | |||
500 | gcry_mpi_point_t g_i_b_i; | 496 | gcry_mpi_point_t g_i_b_i; |
501 | gcry_mpi_point_t h_i_b_i; | 497 | gcry_mpi_point_t h_i_b_i; |
502 | 498 | ||
503 | contained_elements = ntohl (msg->contained_element_count); | 499 | contained_elements = ntohl(msg->contained_element_count); |
504 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); | 500 | max = GNUNET_CONTAINER_multihashmap_size(s->intersected_elements); |
505 | /* sort our vector for the computation */ | 501 | /* sort our vector for the computation */ |
506 | if (NULL == s->sorted_elements) | 502 | if (NULL == s->sorted_elements) |
507 | { | ||
508 | s->sorted_elements | ||
509 | = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements), | ||
510 | struct MpiElement); | ||
511 | s->used_element_count = 0; | ||
512 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | ||
513 | ©_element_cb, | ||
514 | s); | ||
515 | qsort (s->sorted_elements, | ||
516 | s->used_element_count, | ||
517 | sizeof (struct MpiElement), | ||
518 | &element_cmp); | ||
519 | } | ||
520 | |||
521 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
522 | "Received %u crypto values from Alice\n", | ||
523 | (unsigned int) contained_elements); | ||
524 | payload = (const struct GNUNET_CRYPTO_EccPoint *) &msg[1]; | ||
525 | |||
526 | for (i=0;i<contained_elements;i++) | ||
527 | { | ||
528 | b_i = &s->sorted_elements[i + s->cadet_received_element_count]; | ||
529 | g_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, | ||
530 | &payload[i * 2]); | ||
531 | g_i_b_i = GNUNET_CRYPTO_ecc_pmul_mpi (edc, | ||
532 | g_i, | ||
533 | b_i->value); | ||
534 | gcry_mpi_point_release (g_i); | ||
535 | h_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, | ||
536 | &payload[i * 2 + 1]); | ||
537 | h_i_b_i = GNUNET_CRYPTO_ecc_pmul_mpi (edc, | ||
538 | h_i, | ||
539 | b_i->value); | ||
540 | gcry_mpi_point_release (h_i); | ||
541 | if (0 == i + s->cadet_received_element_count) | ||
542 | { | 503 | { |
543 | /* first iteration, nothing to add */ | 504 | s->sorted_elements |
544 | s->prod_g_i_b_i = g_i_b_i; | 505 | = GNUNET_new_array(GNUNET_CONTAINER_multihashmap_size(s->intersected_elements), |
545 | s->prod_h_i_b_i = h_i_b_i; | 506 | struct MpiElement); |
507 | s->used_element_count = 0; | ||
508 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, | ||
509 | ©_element_cb, | ||
510 | s); | ||
511 | qsort(s->sorted_elements, | ||
512 | s->used_element_count, | ||
513 | sizeof(struct MpiElement), | ||
514 | &element_cmp); | ||
546 | } | 515 | } |
547 | else | 516 | |
517 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
518 | "Received %u crypto values from Alice\n", | ||
519 | (unsigned int)contained_elements); | ||
520 | payload = (const struct GNUNET_CRYPTO_EccPoint *)&msg[1]; | ||
521 | |||
522 | for (i = 0; i < contained_elements; i++) | ||
548 | { | 523 | { |
549 | /* further iterations, cummulate resulting value */ | 524 | b_i = &s->sorted_elements[i + s->cadet_received_element_count]; |
550 | tmp = GNUNET_CRYPTO_ecc_add (edc, | 525 | g_i = GNUNET_CRYPTO_ecc_bin_to_point(edc, |
551 | s->prod_g_i_b_i, | 526 | &payload[i * 2]); |
552 | g_i_b_i); | 527 | g_i_b_i = GNUNET_CRYPTO_ecc_pmul_mpi(edc, |
553 | gcry_mpi_point_release (s->prod_g_i_b_i); | 528 | g_i, |
554 | gcry_mpi_point_release (g_i_b_i); | 529 | b_i->value); |
555 | s->prod_g_i_b_i = tmp; | 530 | gcry_mpi_point_release(g_i); |
556 | tmp = GNUNET_CRYPTO_ecc_add (edc, | 531 | h_i = GNUNET_CRYPTO_ecc_bin_to_point(edc, |
557 | s->prod_h_i_b_i, | 532 | &payload[i * 2 + 1]); |
558 | h_i_b_i); | 533 | h_i_b_i = GNUNET_CRYPTO_ecc_pmul_mpi(edc, |
559 | gcry_mpi_point_release (s->prod_h_i_b_i); | 534 | h_i, |
560 | gcry_mpi_point_release (h_i_b_i); | 535 | b_i->value); |
561 | s->prod_h_i_b_i = tmp; | 536 | gcry_mpi_point_release(h_i); |
537 | if (0 == i + s->cadet_received_element_count) | ||
538 | { | ||
539 | /* first iteration, nothing to add */ | ||
540 | s->prod_g_i_b_i = g_i_b_i; | ||
541 | s->prod_h_i_b_i = h_i_b_i; | ||
542 | } | ||
543 | else | ||
544 | { | ||
545 | /* further iterations, cummulate resulting value */ | ||
546 | tmp = GNUNET_CRYPTO_ecc_add(edc, | ||
547 | s->prod_g_i_b_i, | ||
548 | g_i_b_i); | ||
549 | gcry_mpi_point_release(s->prod_g_i_b_i); | ||
550 | gcry_mpi_point_release(g_i_b_i); | ||
551 | s->prod_g_i_b_i = tmp; | ||
552 | tmp = GNUNET_CRYPTO_ecc_add(edc, | ||
553 | s->prod_h_i_b_i, | ||
554 | h_i_b_i); | ||
555 | gcry_mpi_point_release(s->prod_h_i_b_i); | ||
556 | gcry_mpi_point_release(h_i_b_i); | ||
557 | s->prod_h_i_b_i = tmp; | ||
558 | } | ||
562 | } | 559 | } |
563 | } | ||
564 | s->cadet_received_element_count += contained_elements; | 560 | s->cadet_received_element_count += contained_elements; |
565 | if ( (s->cadet_received_element_count == max) && | 561 | if ((s->cadet_received_element_count == max) && |
566 | (NULL == s->intersection_op) ) | 562 | (NULL == s->intersection_op)) |
567 | { | 563 | { |
568 | /* intersection has finished also on our side, and | 564 | /* intersection has finished also on our side, and |
569 | we got the full set, so we can proceed with the | 565 | we got the full set, so we can proceed with the |
570 | CADET response(s) */ | 566 | CADET response(s) */ |
571 | transmit_bobs_cryptodata_message (s); | 567 | transmit_bobs_cryptodata_message(s); |
572 | } | 568 | } |
573 | GNUNET_CADET_receive_done (s->channel); | 569 | GNUNET_CADET_receive_done(s->channel); |
574 | } | 570 | } |
575 | 571 | ||
576 | 572 | ||
@@ -584,67 +580,71 @@ handle_alices_cryptodata_message (void *cls, | |||
584 | * @param status what has happened with the set intersection? | 580 | * @param status what has happened with the set intersection? |
585 | */ | 581 | */ |
586 | static void | 582 | static void |
587 | cb_intersection_element_removed (void *cls, | 583 | cb_intersection_element_removed(void *cls, |
588 | const struct GNUNET_SET_Element *element, | 584 | const struct GNUNET_SET_Element *element, |
589 | uint64_t current_size, | 585 | uint64_t current_size, |
590 | enum GNUNET_SET_Status status) | 586 | enum GNUNET_SET_Status status) |
591 | { | 587 | { |
592 | struct BobServiceSession *s = cls; | 588 | struct BobServiceSession *s = cls; |
593 | struct GNUNET_SCALARPRODUCT_Element *se; | 589 | struct GNUNET_SCALARPRODUCT_Element *se; |
594 | 590 | ||
595 | switch (status) | 591 | switch (status) |
596 | { | 592 | { |
597 | case GNUNET_SET_STATUS_OK: | 593 | case GNUNET_SET_STATUS_OK: |
598 | /* this element has been removed from the set */ | 594 | /* this element has been removed from the set */ |
599 | se = GNUNET_CONTAINER_multihashmap_get (s->intersected_elements, | 595 | se = GNUNET_CONTAINER_multihashmap_get(s->intersected_elements, |
600 | element->data); | 596 | element->data); |
601 | GNUNET_assert (NULL != se); | 597 | GNUNET_assert(NULL != se); |
602 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 598 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
603 | "Removed element with key %s and value %lld\n", | 599 | "Removed element with key %s and value %lld\n", |
604 | GNUNET_h2s (&se->key), | 600 | GNUNET_h2s(&se->key), |
605 | (long long) GNUNET_ntohll (se->value)); | 601 | (long long)GNUNET_ntohll(se->value)); |
606 | GNUNET_assert (GNUNET_YES == | 602 | GNUNET_assert(GNUNET_YES == |
607 | GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, | 603 | GNUNET_CONTAINER_multihashmap_remove(s->intersected_elements, |
608 | element->data, | 604 | element->data, |
609 | se)); | 605 | se)); |
610 | GNUNET_free (se); | 606 | GNUNET_free(se); |
611 | return; | 607 | return; |
612 | case GNUNET_SET_STATUS_DONE: | 608 | |
613 | s->intersection_op = NULL; | 609 | case GNUNET_SET_STATUS_DONE: |
614 | GNUNET_break (NULL == s->intersection_set); | 610 | s->intersection_op = NULL; |
615 | GNUNET_CADET_receive_done (s->channel); | 611 | GNUNET_break(NULL == s->intersection_set); |
616 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 612 | GNUNET_CADET_receive_done(s->channel); |
617 | "Finished intersection, %d items remain\n", | 613 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
618 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); | 614 | "Finished intersection, %d items remain\n", |
619 | if (s->client_received_element_count == | 615 | GNUNET_CONTAINER_multihashmap_size(s->intersected_elements)); |
620 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)) | 616 | if (s->client_received_element_count == |
621 | { | 617 | GNUNET_CONTAINER_multihashmap_size(s->intersected_elements)) |
622 | /* CADET transmission from Alice is also already done, | 618 | { |
623 | start with our own reply */ | 619 | /* CADET transmission from Alice is also already done, |
624 | transmit_bobs_cryptodata_message (s); | 620 | start with our own reply */ |
625 | } | 621 | transmit_bobs_cryptodata_message(s); |
626 | return; | 622 | } |
627 | case GNUNET_SET_STATUS_HALF_DONE: | 623 | return; |
628 | /* unexpected for intersection */ | 624 | |
629 | GNUNET_break (0); | 625 | case GNUNET_SET_STATUS_HALF_DONE: |
630 | return; | 626 | /* unexpected for intersection */ |
631 | case GNUNET_SET_STATUS_FAILURE: | 627 | GNUNET_break(0); |
632 | /* unhandled status code */ | 628 | return; |
633 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 629 | |
634 | "Set intersection failed!\n"); | 630 | case GNUNET_SET_STATUS_FAILURE: |
635 | s->intersection_op = NULL; | 631 | /* unhandled status code */ |
636 | if (NULL != s->intersection_set) | 632 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
637 | { | 633 | "Set intersection failed!\n"); |
638 | GNUNET_SET_destroy (s->intersection_set); | 634 | s->intersection_op = NULL; |
639 | s->intersection_set = NULL; | 635 | if (NULL != s->intersection_set) |
636 | { | ||
637 | GNUNET_SET_destroy(s->intersection_set); | ||
638 | s->intersection_set = NULL; | ||
639 | } | ||
640 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
641 | prepare_client_end_notification(s); | ||
642 | return; | ||
643 | |||
644 | default: | ||
645 | GNUNET_break(0); | ||
646 | return; | ||
640 | } | 647 | } |
641 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
642 | prepare_client_end_notification (s); | ||
643 | return; | ||
644 | default: | ||
645 | GNUNET_break (0); | ||
646 | return; | ||
647 | } | ||
648 | } | 648 | } |
649 | 649 | ||
650 | 650 | ||
@@ -655,36 +655,36 @@ cb_intersection_element_removed (void *cls, | |||
655 | * @param s client session to start intersection for | 655 | * @param s client session to start intersection for |
656 | */ | 656 | */ |
657 | static void | 657 | static void |
658 | start_intersection (struct BobServiceSession *s) | 658 | start_intersection(struct BobServiceSession *s) |
659 | { | 659 | { |
660 | struct GNUNET_HashCode set_sid; | 660 | struct GNUNET_HashCode set_sid; |
661 | 661 | ||
662 | GNUNET_CRYPTO_hash (&s->session_id, | 662 | GNUNET_CRYPTO_hash(&s->session_id, |
663 | sizeof (struct GNUNET_HashCode), | 663 | sizeof(struct GNUNET_HashCode), |
664 | &set_sid); | 664 | &set_sid); |
665 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 665 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
666 | "Got session with key %s and %u elements, starting intersection.\n", | 666 | "Got session with key %s and %u elements, starting intersection.\n", |
667 | GNUNET_h2s (&s->session_id), | 667 | GNUNET_h2s(&s->session_id), |
668 | (unsigned int) s->total); | 668 | (unsigned int)s->total); |
669 | 669 | ||
670 | s->intersection_op | 670 | s->intersection_op |
671 | = GNUNET_SET_prepare (&s->peer, | 671 | = GNUNET_SET_prepare(&s->peer, |
672 | &set_sid, | 672 | &set_sid, |
673 | NULL, | 673 | NULL, |
674 | GNUNET_SET_RESULT_REMOVED, | 674 | GNUNET_SET_RESULT_REMOVED, |
675 | (struct GNUNET_SET_Option[]) {{ 0 }}, | 675 | (struct GNUNET_SET_Option[]) { { 0 } }, |
676 | &cb_intersection_element_removed, | 676 | &cb_intersection_element_removed, |
677 | s); | 677 | s); |
678 | if (GNUNET_OK != | 678 | if (GNUNET_OK != |
679 | GNUNET_SET_commit (s->intersection_op, | 679 | GNUNET_SET_commit(s->intersection_op, |
680 | s->intersection_set)) | 680 | s->intersection_set)) |
681 | { | 681 | { |
682 | GNUNET_break (0); | 682 | GNUNET_break(0); |
683 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 683 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
684 | prepare_client_end_notification (s); | 684 | prepare_client_end_notification(s); |
685 | return; | 685 | return; |
686 | } | 686 | } |
687 | GNUNET_SET_destroy (s->intersection_set); | 687 | GNUNET_SET_destroy(s->intersection_set); |
688 | s->intersection_set = NULL; | 688 | s->intersection_set = NULL; |
689 | } | 689 | } |
690 | 690 | ||
@@ -696,21 +696,21 @@ start_intersection (struct BobServiceSession *s) | |||
696 | * @param msg the actual message | 696 | * @param msg the actual message |
697 | */ | 697 | */ |
698 | static void | 698 | static void |
699 | handle_alices_computation_request (void *cls, | 699 | handle_alices_computation_request(void *cls, |
700 | const struct EccServiceRequestMessage *msg) | 700 | const struct EccServiceRequestMessage *msg) |
701 | { | 701 | { |
702 | struct BobServiceSession *s = cls; | 702 | struct BobServiceSession *s = cls; |
703 | 703 | ||
704 | s->session_id = msg->session_id; // ?? | 704 | s->session_id = msg->session_id; // ?? |
705 | if (s->client_received_element_count < s->total) | 705 | if (s->client_received_element_count < s->total) |
706 | { | 706 | { |
707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 707 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
708 | "Alice ready, still waiting for Bob client data!\n"); | 708 | "Alice ready, still waiting for Bob client data!\n"); |
709 | return; | 709 | return; |
710 | } | 710 | } |
711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 711 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
712 | "Both ready, launching intersection!\n"); | 712 | "Both ready, launching intersection!\n"); |
713 | start_intersection (s); | 713 | start_intersection(s); |
714 | } | 714 | } |
715 | 715 | ||
716 | 716 | ||
@@ -725,20 +725,20 @@ handle_alices_computation_request (void *cls, | |||
725 | * @return session associated with the channel | 725 | * @return session associated with the channel |
726 | */ | 726 | */ |
727 | static void * | 727 | static void * |
728 | cb_channel_incoming (void *cls, | 728 | cb_channel_incoming(void *cls, |
729 | struct GNUNET_CADET_Channel *channel, | 729 | struct GNUNET_CADET_Channel *channel, |
730 | const struct GNUNET_PeerIdentity *initiator) | 730 | const struct GNUNET_PeerIdentity *initiator) |
731 | { | 731 | { |
732 | struct BobServiceSession *s = cls; | 732 | struct BobServiceSession *s = cls; |
733 | 733 | ||
734 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 734 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
735 | "New incoming channel from peer %s.\n", | 735 | "New incoming channel from peer %s.\n", |
736 | GNUNET_i2s (initiator)); | 736 | GNUNET_i2s(initiator)); |
737 | GNUNET_CADET_close_port (s->port); | 737 | GNUNET_CADET_close_port(s->port); |
738 | s->port = NULL; | 738 | s->port = NULL; |
739 | s->peer = *initiator; | 739 | s->peer = *initiator; |
740 | s->channel = channel; | 740 | s->channel = channel; |
741 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); | 741 | s->cadet_mq = GNUNET_CADET_get_mq(s->channel); |
742 | return s; | 742 | return s; |
743 | } | 743 | } |
744 | 744 | ||
@@ -751,25 +751,25 @@ cb_channel_incoming (void *cls, | |||
751 | * @return #GNUNET_OK if @a msg is well-formed | 751 | * @return #GNUNET_OK if @a msg is well-formed |
752 | */ | 752 | */ |
753 | static int | 753 | static int |
754 | check_bob_client_message_multipart (void *cls, | 754 | check_bob_client_message_multipart(void *cls, |
755 | const struct ComputationBobCryptodataMultipartMessage *msg) | 755 | const struct ComputationBobCryptodataMultipartMessage *msg) |
756 | { | 756 | { |
757 | struct BobServiceSession *s = cls; | 757 | struct BobServiceSession *s = cls; |
758 | uint32_t contained_count; | 758 | uint32_t contained_count; |
759 | uint16_t msize; | 759 | uint16_t msize; |
760 | 760 | ||
761 | msize = ntohs (msg->header.size); | 761 | msize = ntohs(msg->header.size); |
762 | contained_count = ntohl (msg->element_count_contained); | 762 | contained_count = ntohl(msg->element_count_contained); |
763 | if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + | 763 | if ((msize != (sizeof(struct ComputationBobCryptodataMultipartMessage) + |
764 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || | 764 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element))) || |
765 | (0 == contained_count) || | 765 | (0 == contained_count) || |
766 | (UINT16_MAX < contained_count) || | 766 | (UINT16_MAX < contained_count) || |
767 | (s->total == s->client_received_element_count) || | 767 | (s->total == s->client_received_element_count) || |
768 | (s->total < s->client_received_element_count + contained_count) ) | 768 | (s->total < s->client_received_element_count + contained_count)) |
769 | { | 769 | { |
770 | GNUNET_break (0); | 770 | GNUNET_break(0); |
771 | return GNUNET_SYSERR; | 771 | return GNUNET_SYSERR; |
772 | } | 772 | } |
773 | return GNUNET_OK; | 773 | return GNUNET_OK; |
774 | } | 774 | } |
775 | 775 | ||
@@ -782,8 +782,8 @@ check_bob_client_message_multipart (void *cls, | |||
782 | * @param msg the actual message | 782 | * @param msg the actual message |
783 | */ | 783 | */ |
784 | static void | 784 | static void |
785 | handle_bob_client_message_multipart (void *cls, | 785 | handle_bob_client_message_multipart(void *cls, |
786 | const struct ComputationBobCryptodataMultipartMessage *msg) | 786 | const struct ComputationBobCryptodataMultipartMessage *msg) |
787 | { | 787 | { |
788 | struct BobServiceSession *s = cls; | 788 | struct BobServiceSession *s = cls; |
789 | uint32_t contained_count; | 789 | uint32_t contained_count; |
@@ -791,50 +791,50 @@ handle_bob_client_message_multipart (void *cls, | |||
791 | struct GNUNET_SET_Element set_elem; | 791 | struct GNUNET_SET_Element set_elem; |
792 | struct GNUNET_SCALARPRODUCT_Element *elem; | 792 | struct GNUNET_SCALARPRODUCT_Element *elem; |
793 | 793 | ||
794 | contained_count = ntohl (msg->element_count_contained); | 794 | contained_count = ntohl(msg->element_count_contained); |
795 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 795 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; |
796 | for (uint32_t i = 0; i < contained_count; i++) | 796 | for (uint32_t i = 0; i < contained_count; i++) |
797 | { | ||
798 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
799 | GNUNET_memcpy (elem, | ||
800 | &elements[i], | ||
801 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | ||
802 | if (GNUNET_SYSERR == | ||
803 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, | ||
804 | &elem->key, | ||
805 | elem, | ||
806 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
807 | { | 797 | { |
808 | GNUNET_break (0); | 798 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); |
809 | GNUNET_free (elem); | 799 | GNUNET_memcpy(elem, |
810 | continue; | 800 | &elements[i], |
801 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
802 | if (GNUNET_SYSERR == | ||
803 | GNUNET_CONTAINER_multihashmap_put(s->intersected_elements, | ||
804 | &elem->key, | ||
805 | elem, | ||
806 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
807 | { | ||
808 | GNUNET_break(0); | ||
809 | GNUNET_free(elem); | ||
810 | continue; | ||
811 | } | ||
812 | set_elem.data = &elem->key; | ||
813 | set_elem.size = sizeof(elem->key); | ||
814 | set_elem.element_type = 0; | ||
815 | GNUNET_SET_add_element(s->intersection_set, | ||
816 | &set_elem, | ||
817 | NULL, NULL); | ||
811 | } | 818 | } |
812 | set_elem.data = &elem->key; | ||
813 | set_elem.size = sizeof (elem->key); | ||
814 | set_elem.element_type = 0; | ||
815 | GNUNET_SET_add_element (s->intersection_set, | ||
816 | &set_elem, | ||
817 | NULL, NULL); | ||
818 | } | ||
819 | s->client_received_element_count += contained_count; | 819 | s->client_received_element_count += contained_count; |
820 | GNUNET_SERVICE_client_continue (s->client); | 820 | GNUNET_SERVICE_client_continue(s->client); |
821 | if (s->total != s->client_received_element_count) | 821 | if (s->total != s->client_received_element_count) |
822 | { | 822 | { |
823 | /* more to come */ | 823 | /* more to come */ |
824 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 824 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
825 | "Request still partial, waiting for more client data!\n"); | 825 | "Request still partial, waiting for more client data!\n"); |
826 | return; | 826 | return; |
827 | } | 827 | } |
828 | if (NULL == s->channel) | 828 | if (NULL == s->channel) |
829 | { | 829 | { |
830 | /* no Alice waiting for this request, wait for Alice */ | 830 | /* no Alice waiting for this request, wait for Alice */ |
831 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 831 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
832 | "Client ready, still waiting for Alice!\n"); | 832 | "Client ready, still waiting for Alice!\n"); |
833 | return; | 833 | return; |
834 | } | 834 | } |
835 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 835 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
836 | "Both ready, launching intersection!\n"); | 836 | "Both ready, launching intersection!\n"); |
837 | start_intersection (s); | 837 | start_intersection(s); |
838 | } | 838 | } |
839 | 839 | ||
840 | 840 | ||
@@ -847,8 +847,8 @@ handle_bob_client_message_multipart (void *cls, | |||
847 | * @return #GNUNET_OK if @a msg is well-formed | 847 | * @return #GNUNET_OK if @a msg is well-formed |
848 | */ | 848 | */ |
849 | static int | 849 | static int |
850 | check_bob_client_message (void *cls, | 850 | check_bob_client_message(void *cls, |
851 | const struct BobComputationMessage *msg) | 851 | const struct BobComputationMessage *msg) |
852 | { | 852 | { |
853 | struct BobServiceSession *s = cls; | 853 | struct BobServiceSession *s = cls; |
854 | uint32_t contained_count; | 854 | uint32_t contained_count; |
@@ -856,22 +856,22 @@ check_bob_client_message (void *cls, | |||
856 | uint16_t msize; | 856 | uint16_t msize; |
857 | 857 | ||
858 | if (GNUNET_SCALARPRODUCT_STATUS_INIT != s->status) | 858 | if (GNUNET_SCALARPRODUCT_STATUS_INIT != s->status) |
859 | { | 859 | { |
860 | GNUNET_break (0); | 860 | GNUNET_break(0); |
861 | return GNUNET_SYSERR; | 861 | return GNUNET_SYSERR; |
862 | } | 862 | } |
863 | msize = ntohs (msg->header.size); | 863 | msize = ntohs(msg->header.size); |
864 | total_count = ntohl (msg->element_count_total); | 864 | total_count = ntohl(msg->element_count_total); |
865 | contained_count = ntohl (msg->element_count_contained); | 865 | contained_count = ntohl(msg->element_count_contained); |
866 | if ( (0 == total_count) || | 866 | if ((0 == total_count) || |
867 | (0 == contained_count) || | 867 | (0 == contained_count) || |
868 | (UINT16_MAX < contained_count) || | 868 | (UINT16_MAX < contained_count) || |
869 | (msize != (sizeof (struct BobComputationMessage) + | 869 | (msize != (sizeof(struct BobComputationMessage) + |
870 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) | 870 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element)))) |
871 | { | 871 | { |
872 | GNUNET_break_op (0); | 872 | GNUNET_break_op(0); |
873 | return GNUNET_SYSERR; | 873 | return GNUNET_SYSERR; |
874 | } | 874 | } |
875 | return GNUNET_OK; | 875 | return GNUNET_OK; |
876 | } | 876 | } |
877 | 877 | ||
@@ -885,20 +885,20 @@ check_bob_client_message (void *cls, | |||
885 | * @param msg the actual message | 885 | * @param msg the actual message |
886 | */ | 886 | */ |
887 | static void | 887 | static void |
888 | handle_bob_client_message (void *cls, | 888 | handle_bob_client_message(void *cls, |
889 | const struct BobComputationMessage *msg) | 889 | const struct BobComputationMessage *msg) |
890 | { | 890 | { |
891 | struct BobServiceSession *s = cls; | 891 | struct BobServiceSession *s = cls; |
892 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 892 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
893 | GNUNET_MQ_hd_fixed_size (alices_computation_request, | 893 | GNUNET_MQ_hd_fixed_size(alices_computation_request, |
894 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION, | 894 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION, |
895 | struct EccServiceRequestMessage, | 895 | struct EccServiceRequestMessage, |
896 | s), | 896 | s), |
897 | GNUNET_MQ_hd_var_size (alices_cryptodata_message, | 897 | GNUNET_MQ_hd_var_size(alices_cryptodata_message, |
898 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA, | 898 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA, |
899 | struct EccAliceCryptodataMessage, | 899 | struct EccAliceCryptodataMessage, |
900 | s), | 900 | s), |
901 | GNUNET_MQ_handler_end () | 901 | GNUNET_MQ_handler_end() |
902 | }; | 902 | }; |
903 | uint32_t contained_count; | 903 | uint32_t contained_count; |
904 | uint32_t total_count; | 904 | uint32_t total_count; |
@@ -906,63 +906,63 @@ handle_bob_client_message (void *cls, | |||
906 | struct GNUNET_SET_Element set_elem; | 906 | struct GNUNET_SET_Element set_elem; |
907 | struct GNUNET_SCALARPRODUCT_Element *elem; | 907 | struct GNUNET_SCALARPRODUCT_Element *elem; |
908 | 908 | ||
909 | total_count = ntohl (msg->element_count_total); | 909 | total_count = ntohl(msg->element_count_total); |
910 | contained_count = ntohl (msg->element_count_contained); | 910 | contained_count = ntohl(msg->element_count_contained); |
911 | 911 | ||
912 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; | 912 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; |
913 | s->total = total_count; | 913 | s->total = total_count; |
914 | s->client_received_element_count = contained_count; | 914 | s->client_received_element_count = contained_count; |
915 | s->session_id = msg->session_key; | 915 | s->session_id = msg->session_key; |
916 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 916 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; |
917 | s->intersected_elements | 917 | s->intersected_elements |
918 | = GNUNET_CONTAINER_multihashmap_create (s->total, | 918 | = GNUNET_CONTAINER_multihashmap_create(s->total, |
919 | GNUNET_YES); | 919 | GNUNET_YES); |
920 | s->intersection_set | 920 | s->intersection_set |
921 | = GNUNET_SET_create (cfg, | 921 | = GNUNET_SET_create(cfg, |
922 | GNUNET_SET_OPERATION_INTERSECTION); | 922 | GNUNET_SET_OPERATION_INTERSECTION); |
923 | for (uint32_t i = 0; i < contained_count; i++) | 923 | for (uint32_t i = 0; i < contained_count; i++) |
924 | { | ||
925 | if (0 == GNUNET_ntohll (elements[i].value)) | ||
926 | continue; | ||
927 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
928 | GNUNET_memcpy (elem, | ||
929 | &elements[i], | ||
930 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | ||
931 | if (GNUNET_SYSERR == | ||
932 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, | ||
933 | &elem->key, | ||
934 | elem, | ||
935 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
936 | { | 924 | { |
937 | GNUNET_break (0); | 925 | if (0 == GNUNET_ntohll(elements[i].value)) |
938 | GNUNET_free (elem); | 926 | continue; |
939 | continue; | 927 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); |
928 | GNUNET_memcpy(elem, | ||
929 | &elements[i], | ||
930 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
931 | if (GNUNET_SYSERR == | ||
932 | GNUNET_CONTAINER_multihashmap_put(s->intersected_elements, | ||
933 | &elem->key, | ||
934 | elem, | ||
935 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
936 | { | ||
937 | GNUNET_break(0); | ||
938 | GNUNET_free(elem); | ||
939 | continue; | ||
940 | } | ||
941 | set_elem.data = &elem->key; | ||
942 | set_elem.size = sizeof(elem->key); | ||
943 | set_elem.element_type = 0; | ||
944 | GNUNET_SET_add_element(s->intersection_set, | ||
945 | &set_elem, | ||
946 | NULL, NULL); | ||
947 | s->used_element_count++; | ||
940 | } | 948 | } |
941 | set_elem.data = &elem->key; | 949 | GNUNET_SERVICE_client_continue(s->client); |
942 | set_elem.size = sizeof (elem->key); | 950 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
943 | set_elem.element_type = 0; | 951 | "Received client request, opening port %s!\n", |
944 | GNUNET_SET_add_element (s->intersection_set, | 952 | GNUNET_h2s(&msg->session_key)); |
945 | &set_elem, | 953 | s->port = GNUNET_CADET_open_port(my_cadet, |
946 | NULL, NULL); | 954 | &msg->session_key, |
947 | s->used_element_count++; | 955 | &cb_channel_incoming, |
948 | } | 956 | s, |
949 | GNUNET_SERVICE_client_continue (s->client); | 957 | NULL, |
950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 958 | &cb_channel_destruction, |
951 | "Received client request, opening port %s!\n", | 959 | cadet_handlers); |
952 | GNUNET_h2s (&msg->session_key)); | ||
953 | s->port = GNUNET_CADET_open_port (my_cadet, | ||
954 | &msg->session_key, | ||
955 | &cb_channel_incoming, | ||
956 | s, | ||
957 | NULL, | ||
958 | &cb_channel_destruction, | ||
959 | cadet_handlers); | ||
960 | if (NULL == s->port) | 960 | if (NULL == s->port) |
961 | { | 961 | { |
962 | GNUNET_break (0); | 962 | GNUNET_break(0); |
963 | GNUNET_SERVICE_client_drop (s->client); | 963 | GNUNET_SERVICE_client_drop(s->client); |
964 | return; | 964 | return; |
965 | } | 965 | } |
966 | } | 966 | } |
967 | 967 | ||
968 | 968 | ||
@@ -972,21 +972,21 @@ handle_bob_client_message (void *cls, | |||
972 | * @param cls unused | 972 | * @param cls unused |
973 | */ | 973 | */ |
974 | static void | 974 | static void |
975 | shutdown_task (void *cls) | 975 | shutdown_task(void *cls) |
976 | { | 976 | { |
977 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 977 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
978 | "Shutting down, initiating cleanup.\n"); | 978 | "Shutting down, initiating cleanup.\n"); |
979 | // FIXME: we have to cut our connections to CADET first! | 979 | // FIXME: we have to cut our connections to CADET first! |
980 | if (NULL != my_cadet) | 980 | if (NULL != my_cadet) |
981 | { | 981 | { |
982 | GNUNET_CADET_disconnect (my_cadet); | 982 | GNUNET_CADET_disconnect(my_cadet); |
983 | my_cadet = NULL; | 983 | my_cadet = NULL; |
984 | } | 984 | } |
985 | if (NULL != edc) | 985 | if (NULL != edc) |
986 | { | 986 | { |
987 | GNUNET_CRYPTO_ecc_dlog_release (edc); | 987 | GNUNET_CRYPTO_ecc_dlog_release(edc); |
988 | edc = NULL; | 988 | edc = NULL; |
989 | } | 989 | } |
990 | } | 990 | } |
991 | 991 | ||
992 | 992 | ||
@@ -1001,13 +1001,13 @@ shutdown_task (void *cls) | |||
1001 | * @return our `struct BobServiceSession` | 1001 | * @return our `struct BobServiceSession` |
1002 | */ | 1002 | */ |
1003 | static void * | 1003 | static void * |
1004 | client_connect_cb (void *cls, | 1004 | client_connect_cb(void *cls, |
1005 | struct GNUNET_SERVICE_Client *client, | 1005 | struct GNUNET_SERVICE_Client *client, |
1006 | struct GNUNET_MQ_Handle *mq) | 1006 | struct GNUNET_MQ_Handle *mq) |
1007 | { | 1007 | { |
1008 | struct BobServiceSession *s; | 1008 | struct BobServiceSession *s; |
1009 | 1009 | ||
1010 | s = GNUNET_new (struct BobServiceSession); | 1010 | s = GNUNET_new(struct BobServiceSession); |
1011 | s->client = client; | 1011 | s->client = client; |
1012 | s->client_mq = mq; | 1012 | s->client_mq = mq; |
1013 | return s; | 1013 | return s; |
@@ -1025,16 +1025,16 @@ client_connect_cb (void *cls, | |||
1025 | * @param app_cls our `struct BobServiceSession` | 1025 | * @param app_cls our `struct BobServiceSession` |
1026 | */ | 1026 | */ |
1027 | static void | 1027 | static void |
1028 | client_disconnect_cb (void *cls, | 1028 | client_disconnect_cb(void *cls, |
1029 | struct GNUNET_SERVICE_Client *client, | 1029 | struct GNUNET_SERVICE_Client *client, |
1030 | void *app_cls) | 1030 | void *app_cls) |
1031 | { | 1031 | { |
1032 | struct BobServiceSession *s = app_cls; | 1032 | struct BobServiceSession *s = app_cls; |
1033 | 1033 | ||
1034 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1034 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1035 | "Client disconnected from us.\n"); | 1035 | "Client disconnected from us.\n"); |
1036 | s->client = NULL; | 1036 | s->client = NULL; |
1037 | destroy_service_session (s); | 1037 | destroy_service_session(s); |
1038 | } | 1038 | } |
1039 | 1039 | ||
1040 | 1040 | ||
@@ -1046,24 +1046,24 @@ client_disconnect_cb (void *cls, | |||
1046 | * @param service the initialized service | 1046 | * @param service the initialized service |
1047 | */ | 1047 | */ |
1048 | static void | 1048 | static void |
1049 | run (void *cls, | 1049 | run(void *cls, |
1050 | const struct GNUNET_CONFIGURATION_Handle *c, | 1050 | const struct GNUNET_CONFIGURATION_Handle *c, |
1051 | struct GNUNET_SERVICE_Handle *service) | 1051 | struct GNUNET_SERVICE_Handle *service) |
1052 | { | 1052 | { |
1053 | cfg = c; | 1053 | cfg = c; |
1054 | /* We don't really do DLOG, so we can setup with very minimal resources */ | 1054 | /* We don't really do DLOG, so we can setup with very minimal resources */ |
1055 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (4 /* max value */, | 1055 | edc = GNUNET_CRYPTO_ecc_dlog_prepare(4 /* max value */, |
1056 | 2 /* RAM */); | 1056 | 2 /* RAM */); |
1057 | my_cadet = GNUNET_CADET_connect (cfg); | 1057 | my_cadet = GNUNET_CADET_connect(cfg); |
1058 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 1058 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, |
1059 | NULL); | 1059 | NULL); |
1060 | if (NULL == my_cadet) | 1060 | if (NULL == my_cadet) |
1061 | { | 1061 | { |
1062 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1062 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1063 | _("Connect to CADET failed\n")); | 1063 | _("Connect to CADET failed\n")); |
1064 | GNUNET_SCHEDULER_shutdown (); | 1064 | GNUNET_SCHEDULER_shutdown(); |
1065 | return; | 1065 | return; |
1066 | } | 1066 | } |
1067 | } | 1067 | } |
1068 | 1068 | ||
1069 | 1069 | ||
@@ -1071,21 +1071,21 @@ run (void *cls, | |||
1071 | * Define "main" method using service macro. | 1071 | * Define "main" method using service macro. |
1072 | */ | 1072 | */ |
1073 | GNUNET_SERVICE_MAIN | 1073 | GNUNET_SERVICE_MAIN |
1074 | ("scalarproduct-bob", | 1074 | ("scalarproduct-bob", |
1075 | GNUNET_SERVICE_OPTION_NONE, | 1075 | GNUNET_SERVICE_OPTION_NONE, |
1076 | &run, | 1076 | &run, |
1077 | &client_connect_cb, | 1077 | &client_connect_cb, |
1078 | &client_disconnect_cb, | 1078 | &client_disconnect_cb, |
1079 | NULL, | 1079 | NULL, |
1080 | GNUNET_MQ_hd_var_size (bob_client_message, | 1080 | GNUNET_MQ_hd_var_size(bob_client_message, |
1081 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, | 1081 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, |
1082 | struct BobComputationMessage, | 1082 | struct BobComputationMessage, |
1083 | NULL), | 1083 | NULL), |
1084 | GNUNET_MQ_hd_var_size (bob_client_message_multipart, | 1084 | GNUNET_MQ_hd_var_size(bob_client_message_multipart, |
1085 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, | 1085 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, |
1086 | struct ComputationBobCryptodataMultipartMessage, | 1086 | struct ComputationBobCryptodataMultipartMessage, |
1087 | NULL), | 1087 | NULL), |
1088 | GNUNET_MQ_handler_end ()); | 1088 | GNUNET_MQ_handler_end()); |
1089 | 1089 | ||
1090 | 1090 | ||
1091 | /* end of gnunet-service-scalarproduct-ecc_bob.c */ | 1091 | /* end of gnunet-service-scalarproduct-ecc_bob.c */ |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.h b/src/scalarproduct/gnunet-service-scalarproduct.h index 668f6441c..d795badf1 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.h +++ b/src/scalarproduct/gnunet-service-scalarproduct.h | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -37,8 +37,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
37 | * send a `struct AliceCryptodataMessage *`. Bob is not expected | 37 | * send a `struct AliceCryptodataMessage *`. Bob is not expected |
38 | * to respond via CADET in the meantime. | 38 | * to respond via CADET in the meantime. |
39 | */ | 39 | */ |
40 | struct ServiceRequestMessage | 40 | struct ServiceRequestMessage { |
41 | { | ||
42 | /** | 41 | /** |
43 | * Type is #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION | 42 | * Type is #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION |
44 | */ | 43 | */ |
@@ -58,7 +57,6 @@ struct ServiceRequestMessage | |||
58 | * Alice's public key | 57 | * Alice's public key |
59 | */ | 58 | */ |
60 | struct GNUNET_CRYPTO_PaillierPublicKey public_key; | 59 | struct GNUNET_CRYPTO_PaillierPublicKey public_key; |
61 | |||
62 | }; | 60 | }; |
63 | 61 | ||
64 | 62 | ||
@@ -67,8 +65,7 @@ struct ServiceRequestMessage | |||
67 | * (after set intersection). Alice may send messages of this | 65 | * (after set intersection). Alice may send messages of this |
68 | * type repeatedly to transmit all values. | 66 | * type repeatedly to transmit all values. |
69 | */ | 67 | */ |
70 | struct AliceCryptodataMessage | 68 | struct AliceCryptodataMessage { |
71 | { | ||
72 | /** | 69 | /** |
73 | * Type is #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA | 70 | * Type is #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA |
74 | */ | 71 | */ |
@@ -92,8 +89,7 @@ struct AliceCryptodataMessage | |||
92 | * conversation may be continued with `struct BobCryptodataMultipartMessage` | 89 | * conversation may be continued with `struct BobCryptodataMultipartMessage` |
93 | * messages afterwards. | 90 | * messages afterwards. |
94 | */ | 91 | */ |
95 | struct BobCryptodataMessage | 92 | struct BobCryptodataMessage { |
96 | { | ||
97 | /** | 93 | /** |
98 | * GNUNET message header with type | 94 | * GNUNET message header with type |
99 | * #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA. | 95 | * #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA. |
@@ -118,8 +114,7 @@ struct BobCryptodataMessage | |||
118 | * Once all k-values have been transmitted, Bob is finished and | 114 | * Once all k-values have been transmitted, Bob is finished and |
119 | * Alice can transmit the final result to the client. | 115 | * Alice can transmit the final result to the client. |
120 | */ | 116 | */ |
121 | struct BobCryptodataMultipartMessage | 117 | struct BobCryptodataMultipartMessage { |
122 | { | ||
123 | /** | 118 | /** |
124 | * GNUNET message header | 119 | * GNUNET message header |
125 | */ | 120 | */ |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c index e138876f5..6e823dca4 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c | |||
@@ -37,13 +37,12 @@ | |||
37 | #include "gnunet-service-scalarproduct.h" | 37 | #include "gnunet-service-scalarproduct.h" |
38 | 38 | ||
39 | #define LOG(kind, ...) \ | 39 | #define LOG(kind, ...) \ |
40 | GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) | 40 | GNUNET_log_from(kind, "scalarproduct-alice", __VA_ARGS__) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * An encrypted element key-value pair. | 43 | * An encrypted element key-value pair. |
44 | */ | 44 | */ |
45 | struct MpiElement | 45 | struct MpiElement { |
46 | { | ||
47 | /** | 46 | /** |
48 | * Key used to identify matching pairs of values to multiply. | 47 | * Key used to identify matching pairs of values to multiply. |
49 | * Points into an existing data structure, to avoid copying | 48 | * Points into an existing data structure, to avoid copying |
@@ -62,9 +61,7 @@ struct MpiElement | |||
62 | * A scalarproduct session which tracks | 61 | * A scalarproduct session which tracks |
63 | * a request form the client to our final response. | 62 | * a request form the client to our final response. |
64 | */ | 63 | */ |
65 | struct AliceServiceSession | 64 | struct AliceServiceSession { |
66 | { | ||
67 | |||
68 | /** | 65 | /** |
69 | * (hopefully) unique transaction ID | 66 | * (hopefully) unique transaction ID |
70 | */ | 67 | */ |
@@ -224,11 +221,11 @@ static struct GNUNET_CADET_Handle *my_cadet; | |||
224 | * @return #GNUNET_OK (continue to iterate) | 221 | * @return #GNUNET_OK (continue to iterate) |
225 | */ | 222 | */ |
226 | static int | 223 | static int |
227 | free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | 224 | free_element_cb(void *cls, const struct GNUNET_HashCode *key, void *value) |
228 | { | 225 | { |
229 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 226 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
230 | 227 | ||
231 | GNUNET_free (e); | 228 | GNUNET_free(e); |
232 | return GNUNET_OK; | 229 | return GNUNET_OK; |
233 | } | 230 | } |
234 | 231 | ||
@@ -239,69 +236,69 @@ free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
239 | * @param s the session to free elements from | 236 | * @param s the session to free elements from |
240 | */ | 237 | */ |
241 | static void | 238 | static void |
242 | destroy_service_session (struct AliceServiceSession *s) | 239 | destroy_service_session(struct AliceServiceSession *s) |
243 | { | 240 | { |
244 | if (GNUNET_YES == s->in_destroy) | 241 | if (GNUNET_YES == s->in_destroy) |
245 | return; | 242 | return; |
246 | s->in_destroy = GNUNET_YES; | 243 | s->in_destroy = GNUNET_YES; |
247 | if (NULL != s->client) | 244 | if (NULL != s->client) |
248 | { | 245 | { |
249 | struct GNUNET_SERVICE_Client *c = s->client; | 246 | struct GNUNET_SERVICE_Client *c = s->client; |
250 | 247 | ||
251 | s->client = NULL; | 248 | s->client = NULL; |
252 | GNUNET_SERVICE_client_drop (c); | 249 | GNUNET_SERVICE_client_drop(c); |
253 | } | 250 | } |
254 | if (NULL != s->channel) | 251 | if (NULL != s->channel) |
255 | { | 252 | { |
256 | GNUNET_CADET_channel_destroy (s->channel); | 253 | GNUNET_CADET_channel_destroy(s->channel); |
257 | s->channel = NULL; | 254 | s->channel = NULL; |
258 | } | 255 | } |
259 | if (NULL != s->intersected_elements) | 256 | if (NULL != s->intersected_elements) |
260 | { | 257 | { |
261 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 258 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, |
262 | &free_element_cb, | 259 | &free_element_cb, |
263 | s); | 260 | s); |
264 | GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements); | 261 | GNUNET_CONTAINER_multihashmap_destroy(s->intersected_elements); |
265 | s->intersected_elements = NULL; | 262 | s->intersected_elements = NULL; |
266 | } | 263 | } |
267 | if (NULL != s->intersection_listen) | 264 | if (NULL != s->intersection_listen) |
268 | { | 265 | { |
269 | GNUNET_SET_listen_cancel (s->intersection_listen); | 266 | GNUNET_SET_listen_cancel(s->intersection_listen); |
270 | s->intersection_listen = NULL; | 267 | s->intersection_listen = NULL; |
271 | } | 268 | } |
272 | if (NULL != s->intersection_op) | 269 | if (NULL != s->intersection_op) |
273 | { | 270 | { |
274 | GNUNET_SET_operation_cancel (s->intersection_op); | 271 | GNUNET_SET_operation_cancel(s->intersection_op); |
275 | s->intersection_op = NULL; | 272 | s->intersection_op = NULL; |
276 | } | 273 | } |
277 | if (NULL != s->intersection_set) | 274 | if (NULL != s->intersection_set) |
278 | { | 275 | { |
279 | GNUNET_SET_destroy (s->intersection_set); | 276 | GNUNET_SET_destroy(s->intersection_set); |
280 | s->intersection_set = NULL; | 277 | s->intersection_set = NULL; |
281 | } | 278 | } |
282 | if (NULL != s->sorted_elements) | 279 | if (NULL != s->sorted_elements) |
283 | { | 280 | { |
284 | for (unsigned int i = 0; i < s->used_element_count; i++) | 281 | for (unsigned int i = 0; i < s->used_element_count; i++) |
285 | gcry_mpi_release (s->sorted_elements[i].value); | 282 | gcry_mpi_release(s->sorted_elements[i].value); |
286 | GNUNET_free (s->sorted_elements); | 283 | GNUNET_free(s->sorted_elements); |
287 | s->sorted_elements = NULL; | 284 | s->sorted_elements = NULL; |
288 | } | 285 | } |
289 | if (NULL != s->r) | 286 | if (NULL != s->r) |
290 | { | 287 | { |
291 | GNUNET_free (s->r); | 288 | GNUNET_free(s->r); |
292 | s->r = NULL; | 289 | s->r = NULL; |
293 | } | 290 | } |
294 | if (NULL != s->r_prime) | 291 | if (NULL != s->r_prime) |
295 | { | 292 | { |
296 | GNUNET_free (s->r_prime); | 293 | GNUNET_free(s->r_prime); |
297 | s->r_prime = NULL; | 294 | s->r_prime = NULL; |
298 | } | 295 | } |
299 | if (NULL != s->product) | 296 | if (NULL != s->product) |
300 | { | 297 | { |
301 | gcry_mpi_release (s->product); | 298 | gcry_mpi_release(s->product); |
302 | s->product = NULL; | 299 | s->product = NULL; |
303 | } | 300 | } |
304 | GNUNET_free (s); | 301 | GNUNET_free(s); |
305 | } | 302 | } |
306 | 303 | ||
307 | 304 | ||
@@ -312,22 +309,22 @@ destroy_service_session (struct AliceServiceSession *s) | |||
312 | * @param session the associated client session to fail or succeed | 309 | * @param session the associated client session to fail or succeed |
313 | */ | 310 | */ |
314 | static void | 311 | static void |
315 | prepare_client_end_notification (struct AliceServiceSession *session) | 312 | prepare_client_end_notification(struct AliceServiceSession *session) |
316 | { | 313 | { |
317 | struct ClientResponseMessage *msg; | 314 | struct ClientResponseMessage *msg; |
318 | struct GNUNET_MQ_Envelope *e; | 315 | struct GNUNET_MQ_Envelope *e; |
319 | 316 | ||
320 | if (NULL == session->client_mq) | 317 | if (NULL == session->client_mq) |
321 | return; /* no client left to be notified */ | 318 | return; /* no client left to be notified */ |
322 | GNUNET_log ( | 319 | GNUNET_log( |
323 | GNUNET_ERROR_TYPE_DEBUG, | 320 | GNUNET_ERROR_TYPE_DEBUG, |
324 | "Sending session-end notification with status %d to client for session %s\n", | 321 | "Sending session-end notification with status %d to client for session %s\n", |
325 | session->status, | 322 | session->status, |
326 | GNUNET_h2s (&session->session_id)); | 323 | GNUNET_h2s(&session->session_id)); |
327 | e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 324 | e = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
328 | msg->product_length = htonl (0); | 325 | msg->product_length = htonl(0); |
329 | msg->status = htonl (session->status); | 326 | msg->status = htonl(session->status); |
330 | GNUNET_MQ_send (session->client_mq, e); | 327 | GNUNET_MQ_send(session->client_mq, e); |
331 | } | 328 | } |
332 | 329 | ||
333 | 330 | ||
@@ -338,7 +335,7 @@ prepare_client_end_notification (struct AliceServiceSession *session) | |||
338 | * @param s the session associated with our client. | 335 | * @param s the session associated with our client. |
339 | */ | 336 | */ |
340 | static void | 337 | static void |
341 | transmit_client_response (struct AliceServiceSession *s) | 338 | transmit_client_response(struct AliceServiceSession *s) |
342 | { | 339 | { |
343 | struct ClientResponseMessage *msg; | 340 | struct ClientResponseMessage *msg; |
344 | struct GNUNET_MQ_Envelope *e; | 341 | struct GNUNET_MQ_Envelope *e; |
@@ -350,56 +347,56 @@ transmit_client_response (struct AliceServiceSession *s) | |||
350 | gcry_mpi_t value; | 347 | gcry_mpi_t value; |
351 | 348 | ||
352 | if (NULL == s->product) | 349 | if (NULL == s->product) |
353 | { | 350 | { |
354 | GNUNET_break (0); | 351 | GNUNET_break(0); |
355 | prepare_client_end_notification (s); | 352 | prepare_client_end_notification(s); |
356 | return; | 353 | return; |
357 | } | 354 | } |
358 | value = gcry_mpi_new (0); | 355 | value = gcry_mpi_new(0); |
359 | sign = gcry_mpi_cmp_ui (s->product, 0); | 356 | sign = gcry_mpi_cmp_ui(s->product, 0); |
360 | if (0 > sign) | 357 | if (0 > sign) |
361 | { | 358 | { |
362 | range = -1; | 359 | range = -1; |
363 | gcry_mpi_sub (value, value, s->product); | 360 | gcry_mpi_sub(value, value, s->product); |
364 | } | 361 | } |
365 | else if (0 < sign) | 362 | else if (0 < sign) |
366 | { | 363 | { |
367 | range = 1; | 364 | range = 1; |
368 | gcry_mpi_add (value, value, s->product); | 365 | gcry_mpi_add(value, value, s->product); |
369 | } | 366 | } |
370 | else | 367 | else |
371 | { | 368 | { |
372 | /* result is exactly zero */ | 369 | /* result is exactly zero */ |
373 | range = 0; | 370 | range = 0; |
374 | } | 371 | } |
375 | gcry_mpi_release (s->product); | 372 | gcry_mpi_release(s->product); |
376 | s->product = NULL; | 373 | s->product = NULL; |
377 | 374 | ||
378 | if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, | 375 | if ((0 != range) && (0 != (rc = gcry_mpi_aprint(GCRYMPI_FMT_STD, |
379 | &product_exported, | 376 | &product_exported, |
380 | &product_length, | 377 | &product_length, |
381 | value)))) | 378 | value)))) |
382 | { | 379 | { |
383 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 380 | LOG_GCRY(GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
384 | prepare_client_end_notification (s); | 381 | prepare_client_end_notification(s); |
385 | return; | 382 | return; |
386 | } | 383 | } |
387 | gcry_mpi_release (value); | 384 | gcry_mpi_release(value); |
388 | e = GNUNET_MQ_msg_extra (msg, | 385 | e = GNUNET_MQ_msg_extra(msg, |
389 | product_length, | 386 | product_length, |
390 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 387 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
391 | msg->status = htonl (GNUNET_SCALARPRODUCT_STATUS_SUCCESS); | 388 | msg->status = htonl(GNUNET_SCALARPRODUCT_STATUS_SUCCESS); |
392 | msg->range = htonl (range); | 389 | msg->range = htonl(range); |
393 | msg->product_length = htonl (product_length); | 390 | msg->product_length = htonl(product_length); |
394 | if (NULL != product_exported) | 391 | if (NULL != product_exported) |
395 | { | 392 | { |
396 | GNUNET_memcpy (&msg[1], product_exported, product_length); | 393 | GNUNET_memcpy(&msg[1], product_exported, product_length); |
397 | GNUNET_free (product_exported); | 394 | GNUNET_free(product_exported); |
398 | } | 395 | } |
399 | GNUNET_MQ_send (s->client_mq, e); | 396 | GNUNET_MQ_send(s->client_mq, e); |
400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 397 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
401 | "Sent result to client, session %s has ended!\n", | 398 | "Sent result to client, session %s has ended!\n", |
402 | GNUNET_h2s (&s->session_id)); | 399 | GNUNET_h2s(&s->session_id)); |
403 | } | 400 | } |
404 | 401 | ||
405 | 402 | ||
@@ -413,20 +410,20 @@ transmit_client_response (struct AliceServiceSession *s) | |||
413 | * @param channel connection to the other end (henceforth invalid) | 410 | * @param channel connection to the other end (henceforth invalid) |
414 | */ | 411 | */ |
415 | static void | 412 | static void |
416 | cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) | 413 | cb_channel_destruction(void *cls, const struct GNUNET_CADET_Channel *channel) |
417 | { | 414 | { |
418 | struct AliceServiceSession *s = cls; | 415 | struct AliceServiceSession *s = cls; |
419 | 416 | ||
420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 417 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
421 | "Peer disconnected, terminating session %s with peer %s\n", | 418 | "Peer disconnected, terminating session %s with peer %s\n", |
422 | GNUNET_h2s (&s->session_id), | 419 | GNUNET_h2s(&s->session_id), |
423 | GNUNET_i2s (&s->peer)); | 420 | GNUNET_i2s(&s->peer)); |
424 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) | 421 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) |
425 | { | 422 | { |
426 | /* We didn't get an answer yet, fail with error */ | 423 | /* We didn't get an answer yet, fail with error */ |
427 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 424 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
428 | prepare_client_end_notification (s); | 425 | prepare_client_end_notification(s); |
429 | } | 426 | } |
430 | s->channel = NULL; | 427 | s->channel = NULL; |
431 | } | 428 | } |
432 | 429 | ||
@@ -439,21 +436,21 @@ cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) | |||
439 | * @return an MPI value containing the calculated sum, never NULL | 436 | * @return an MPI value containing the calculated sum, never NULL |
440 | */ | 437 | */ |
441 | static gcry_mpi_t | 438 | static gcry_mpi_t |
442 | compute_square_sum_mpi_elements (const struct MpiElement *vector, | 439 | compute_square_sum_mpi_elements(const struct MpiElement *vector, |
443 | uint32_t length) | 440 | uint32_t length) |
444 | { | 441 | { |
445 | gcry_mpi_t elem; | 442 | gcry_mpi_t elem; |
446 | gcry_mpi_t sum; | 443 | gcry_mpi_t sum; |
447 | uint32_t i; | 444 | uint32_t i; |
448 | 445 | ||
449 | GNUNET_assert (NULL != (sum = gcry_mpi_new (0))); | 446 | GNUNET_assert(NULL != (sum = gcry_mpi_new(0))); |
450 | GNUNET_assert (NULL != (elem = gcry_mpi_new (0))); | 447 | GNUNET_assert(NULL != (elem = gcry_mpi_new(0))); |
451 | for (i = 0; i < length; i++) | 448 | for (i = 0; i < length; i++) |
452 | { | 449 | { |
453 | gcry_mpi_mul (elem, vector[i].value, vector[i].value); | 450 | gcry_mpi_mul(elem, vector[i].value, vector[i].value); |
454 | gcry_mpi_add (sum, sum, elem); | 451 | gcry_mpi_add(sum, sum, elem); |
455 | } | 452 | } |
456 | gcry_mpi_release (elem); | 453 | gcry_mpi_release(elem); |
457 | return sum; | 454 | return sum; |
458 | } | 455 | } |
459 | 456 | ||
@@ -466,20 +463,20 @@ compute_square_sum_mpi_elements (const struct MpiElement *vector, | |||
466 | * @return an MPI value containing the calculated sum, never NULL | 463 | * @return an MPI value containing the calculated sum, never NULL |
467 | */ | 464 | */ |
468 | static gcry_mpi_t | 465 | static gcry_mpi_t |
469 | compute_square_sum (const gcry_mpi_t *vector, uint32_t length) | 466 | compute_square_sum(const gcry_mpi_t *vector, uint32_t length) |
470 | { | 467 | { |
471 | gcry_mpi_t elem; | 468 | gcry_mpi_t elem; |
472 | gcry_mpi_t sum; | 469 | gcry_mpi_t sum; |
473 | uint32_t i; | 470 | uint32_t i; |
474 | 471 | ||
475 | GNUNET_assert (NULL != (sum = gcry_mpi_new (0))); | 472 | GNUNET_assert(NULL != (sum = gcry_mpi_new(0))); |
476 | GNUNET_assert (NULL != (elem = gcry_mpi_new (0))); | 473 | GNUNET_assert(NULL != (elem = gcry_mpi_new(0))); |
477 | for (i = 0; i < length; i++) | 474 | for (i = 0; i < length; i++) |
478 | { | 475 | { |
479 | gcry_mpi_mul (elem, vector[i], vector[i]); | 476 | gcry_mpi_mul(elem, vector[i], vector[i]); |
480 | gcry_mpi_add (sum, sum, elem); | 477 | gcry_mpi_add(sum, sum, elem); |
481 | } | 478 | } |
482 | gcry_mpi_release (elem); | 479 | gcry_mpi_release(elem); |
483 | return sum; | 480 | return sum; |
484 | } | 481 | } |
485 | 482 | ||
@@ -491,7 +488,7 @@ compute_square_sum (const gcry_mpi_t *vector, uint32_t length) | |||
491 | * @return product as MPI, never NULL | 488 | * @return product as MPI, never NULL |
492 | */ | 489 | */ |
493 | static gcry_mpi_t | 490 | static gcry_mpi_t |
494 | compute_scalar_product (struct AliceServiceSession *session) | 491 | compute_scalar_product(struct AliceServiceSession *session) |
495 | { | 492 | { |
496 | uint32_t count; | 493 | uint32_t count; |
497 | gcry_mpi_t t; | 494 | gcry_mpi_t t; |
@@ -511,80 +508,80 @@ compute_scalar_product (struct AliceServiceSession *session) | |||
511 | // from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each, | 508 | // from the E(a_pi)(+)E(-b_pi-r_pi) and E(a_qi)(+)E(-r_qi) twice each, |
512 | // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) | 509 | // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) |
513 | for (i = 0; i < count; i++) | 510 | for (i = 0; i < count; i++) |
514 | { | 511 | { |
515 | r[i] = gcry_mpi_new (0); | 512 | r[i] = gcry_mpi_new(0); |
516 | GNUNET_CRYPTO_paillier_decrypt (&my_privkey, | 513 | GNUNET_CRYPTO_paillier_decrypt(&my_privkey, |
517 | &my_pubkey, | 514 | &my_pubkey, |
518 | &session->r[i], | 515 | &session->r[i], |
519 | r[i]); | 516 | r[i]); |
520 | gcry_mpi_sub (r[i], r[i], my_offset); | 517 | gcry_mpi_sub(r[i], r[i], my_offset); |
521 | gcry_mpi_sub (r[i], r[i], my_offset); | 518 | gcry_mpi_sub(r[i], r[i], my_offset); |
522 | r_prime[i] = gcry_mpi_new (0); | 519 | r_prime[i] = gcry_mpi_new(0); |
523 | GNUNET_CRYPTO_paillier_decrypt (&my_privkey, | 520 | GNUNET_CRYPTO_paillier_decrypt(&my_privkey, |
524 | &my_pubkey, | 521 | &my_pubkey, |
525 | &session->r_prime[i], | 522 | &session->r_prime[i], |
526 | r_prime[i]); | 523 | r_prime[i]); |
527 | gcry_mpi_sub (r_prime[i], r_prime[i], my_offset); | 524 | gcry_mpi_sub(r_prime[i], r_prime[i], my_offset); |
528 | gcry_mpi_sub (r_prime[i], r_prime[i], my_offset); | 525 | gcry_mpi_sub(r_prime[i], r_prime[i], my_offset); |
529 | } | 526 | } |
530 | 527 | ||
531 | // calculate t = sum(ai) | 528 | // calculate t = sum(ai) |
532 | t = compute_square_sum_mpi_elements (session->sorted_elements, count); | 529 | t = compute_square_sum_mpi_elements(session->sorted_elements, count); |
533 | // calculate U | 530 | // calculate U |
534 | u = gcry_mpi_new (0); | 531 | u = gcry_mpi_new(0); |
535 | tmp = compute_square_sum (r, count); | 532 | tmp = compute_square_sum(r, count); |
536 | gcry_mpi_sub (u, u, tmp); | 533 | gcry_mpi_sub(u, u, tmp); |
537 | gcry_mpi_release (tmp); | 534 | gcry_mpi_release(tmp); |
538 | 535 | ||
539 | //calculate U' | 536 | //calculate U' |
540 | u_prime = gcry_mpi_new (0); | 537 | u_prime = gcry_mpi_new(0); |
541 | tmp = compute_square_sum (r_prime, count); | 538 | tmp = compute_square_sum(r_prime, count); |
542 | gcry_mpi_sub (u_prime, u_prime, tmp); | 539 | gcry_mpi_sub(u_prime, u_prime, tmp); |
543 | 540 | ||
544 | GNUNET_assert (p = gcry_mpi_new (0)); | 541 | GNUNET_assert(p = gcry_mpi_new(0)); |
545 | GNUNET_assert (p_prime = gcry_mpi_new (0)); | 542 | GNUNET_assert(p_prime = gcry_mpi_new(0)); |
546 | GNUNET_assert (s = gcry_mpi_new (0)); | 543 | GNUNET_assert(s = gcry_mpi_new(0)); |
547 | GNUNET_assert (s_prime = gcry_mpi_new (0)); | 544 | GNUNET_assert(s_prime = gcry_mpi_new(0)); |
548 | 545 | ||
549 | // compute P | 546 | // compute P |
550 | GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, &session->s, s); | 547 | GNUNET_CRYPTO_paillier_decrypt(&my_privkey, &my_pubkey, &session->s, s); |
551 | GNUNET_CRYPTO_paillier_decrypt (&my_privkey, | 548 | GNUNET_CRYPTO_paillier_decrypt(&my_privkey, |
552 | &my_pubkey, | 549 | &my_pubkey, |
553 | &session->s_prime, | 550 | &session->s_prime, |
554 | s_prime); | 551 | s_prime); |
555 | 552 | ||
556 | // compute P | 553 | // compute P |
557 | gcry_mpi_add (p, s, t); | 554 | gcry_mpi_add(p, s, t); |
558 | gcry_mpi_add (p, p, u); | 555 | gcry_mpi_add(p, p, u); |
559 | 556 | ||
560 | // compute P' | 557 | // compute P' |
561 | gcry_mpi_add (p_prime, s_prime, t); | 558 | gcry_mpi_add(p_prime, s_prime, t); |
562 | gcry_mpi_add (p_prime, p_prime, u_prime); | 559 | gcry_mpi_add(p_prime, p_prime, u_prime); |
563 | 560 | ||
564 | gcry_mpi_release (t); | 561 | gcry_mpi_release(t); |
565 | gcry_mpi_release (u); | 562 | gcry_mpi_release(u); |
566 | gcry_mpi_release (u_prime); | 563 | gcry_mpi_release(u_prime); |
567 | gcry_mpi_release (s); | 564 | gcry_mpi_release(s); |
568 | gcry_mpi_release (s_prime); | 565 | gcry_mpi_release(s_prime); |
569 | 566 | ||
570 | // compute product | 567 | // compute product |
571 | gcry_mpi_sub (p, p, p_prime); | 568 | gcry_mpi_sub(p, p, p_prime); |
572 | gcry_mpi_release (p_prime); | 569 | gcry_mpi_release(p_prime); |
573 | tmp = gcry_mpi_set_ui (tmp, 2); | 570 | tmp = gcry_mpi_set_ui(tmp, 2); |
574 | gcry_mpi_div (p, NULL, p, tmp, 0); | 571 | gcry_mpi_div(p, NULL, p, tmp, 0); |
575 | 572 | ||
576 | gcry_mpi_release (tmp); | 573 | gcry_mpi_release(tmp); |
577 | for (i = 0; i < count; i++) | 574 | for (i = 0; i < count; i++) |
578 | { | 575 | { |
579 | gcry_mpi_release (session->sorted_elements[i].value); | 576 | gcry_mpi_release(session->sorted_elements[i].value); |
580 | gcry_mpi_release (r[i]); | 577 | gcry_mpi_release(r[i]); |
581 | gcry_mpi_release (r_prime[i]); | 578 | gcry_mpi_release(r_prime[i]); |
582 | } | 579 | } |
583 | GNUNET_free (session->sorted_elements); | 580 | GNUNET_free(session->sorted_elements); |
584 | session->sorted_elements = NULL; | 581 | session->sorted_elements = NULL; |
585 | GNUNET_free (session->r); | 582 | GNUNET_free(session->r); |
586 | session->r = NULL; | 583 | session->r = NULL; |
587 | GNUNET_free (session->r_prime); | 584 | GNUNET_free(session->r_prime); |
588 | session->r_prime = NULL; | 585 | session->r_prime = NULL; |
589 | 586 | ||
590 | return p; | 587 | return p; |
@@ -601,7 +598,7 @@ compute_scalar_product (struct AliceServiceSession *session) | |||
601 | * #GNUNET_SYSERR to close it (signal serious error) | 598 | * #GNUNET_SYSERR to close it (signal serious error) |
602 | */ | 599 | */ |
603 | static int | 600 | static int |
604 | check_bobs_cryptodata_multipart ( | 601 | check_bobs_cryptodata_multipart( |
605 | void *cls, | 602 | void *cls, |
606 | const struct BobCryptodataMultipartMessage *msg) | 603 | const struct BobCryptodataMultipartMessage *msg) |
607 | { | 604 | { |
@@ -610,17 +607,17 @@ check_bobs_cryptodata_multipart ( | |||
610 | size_t msg_size; | 607 | size_t msg_size; |
611 | size_t required_size; | 608 | size_t required_size; |
612 | 609 | ||
613 | msg_size = ntohs (msg->header.size); | 610 | msg_size = ntohs(msg->header.size); |
614 | contained = ntohl (msg->contained_element_count); | 611 | contained = ntohl(msg->contained_element_count); |
615 | required_size = | 612 | required_size = |
616 | sizeof (struct BobCryptodataMultipartMessage) + | 613 | sizeof(struct BobCryptodataMultipartMessage) + |
617 | 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 614 | 2 * contained * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext); |
618 | if ((required_size != msg_size) || | 615 | if ((required_size != msg_size) || |
619 | (s->cadet_received_element_count + contained > s->used_element_count)) | 616 | (s->cadet_received_element_count + contained > s->used_element_count)) |
620 | { | 617 | { |
621 | GNUNET_break (0); | 618 | GNUNET_break(0); |
622 | return GNUNET_SYSERR; | 619 | return GNUNET_SYSERR; |
623 | } | 620 | } |
624 | return GNUNET_OK; | 621 | return GNUNET_OK; |
625 | } | 622 | } |
626 | 623 | ||
@@ -632,7 +629,7 @@ check_bobs_cryptodata_multipart ( | |||
632 | * @param msg the actual message | 629 | * @param msg the actual message |
633 | */ | 630 | */ |
634 | static void | 631 | static void |
635 | handle_bobs_cryptodata_multipart ( | 632 | handle_bobs_cryptodata_multipart( |
636 | void *cls, | 633 | void *cls, |
637 | const struct BobCryptodataMultipartMessage *msg) | 634 | const struct BobCryptodataMultipartMessage *msg) |
638 | { | 635 | { |
@@ -641,29 +638,29 @@ handle_bobs_cryptodata_multipart ( | |||
641 | size_t i; | 638 | size_t i; |
642 | uint32_t contained; | 639 | uint32_t contained; |
643 | 640 | ||
644 | contained = ntohl (msg->contained_element_count); | 641 | contained = ntohl(msg->contained_element_count); |
645 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 642 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
646 | "Received %u additional crypto values from Bob\n", | 643 | "Received %u additional crypto values from Bob\n", |
647 | (unsigned int) contained); | 644 | (unsigned int)contained); |
648 | 645 | ||
649 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 646 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1]; |
650 | /* Convert each k[][perm] to its MPI_value */ | 647 | /* Convert each k[][perm] to its MPI_value */ |
651 | for (i = 0; i < contained; i++) | 648 | for (i = 0; i < contained; i++) |
652 | { | 649 | { |
653 | GNUNET_memcpy (&s->r[s->cadet_received_element_count + i], | 650 | GNUNET_memcpy(&s->r[s->cadet_received_element_count + i], |
654 | &payload[2 * i], | 651 | &payload[2 * i], |
655 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 652 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
656 | GNUNET_memcpy (&s->r_prime[s->cadet_received_element_count + i], | 653 | GNUNET_memcpy(&s->r_prime[s->cadet_received_element_count + i], |
657 | &payload[2 * i], | 654 | &payload[2 * i], |
658 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 655 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
659 | } | 656 | } |
660 | s->cadet_received_element_count += contained; | 657 | s->cadet_received_element_count += contained; |
661 | GNUNET_CADET_receive_done (s->channel); | 658 | GNUNET_CADET_receive_done(s->channel); |
662 | if (s->cadet_received_element_count != s->used_element_count) | 659 | if (s->cadet_received_element_count != s->used_element_count) |
663 | return; /* more to come */ | 660 | return; /* more to come */ |
664 | 661 | ||
665 | s->product = compute_scalar_product (s); | 662 | s->product = compute_scalar_product(s); |
666 | transmit_client_response (s); | 663 | transmit_client_response(s); |
667 | } | 664 | } |
668 | 665 | ||
669 | 666 | ||
@@ -677,38 +674,38 @@ handle_bobs_cryptodata_multipart ( | |||
677 | * #GNUNET_SYSERR to close it (we are done) | 674 | * #GNUNET_SYSERR to close it (we are done) |
678 | */ | 675 | */ |
679 | static int | 676 | static int |
680 | check_bobs_cryptodata_message (void *cls, | 677 | check_bobs_cryptodata_message(void *cls, |
681 | const struct BobCryptodataMessage *msg) | 678 | const struct BobCryptodataMessage *msg) |
682 | { | 679 | { |
683 | struct AliceServiceSession *s = cls; | 680 | struct AliceServiceSession *s = cls; |
684 | uint32_t contained; | 681 | uint32_t contained; |
685 | uint16_t msg_size; | 682 | uint16_t msg_size; |
686 | size_t required_size; | 683 | size_t required_size; |
687 | 684 | ||
688 | msg_size = ntohs (msg->header.size); | 685 | msg_size = ntohs(msg->header.size); |
689 | contained = ntohl (msg->contained_element_count); | 686 | contained = ntohl(msg->contained_element_count); |
690 | required_size = | 687 | required_size = |
691 | sizeof (struct BobCryptodataMessage) + | 688 | sizeof(struct BobCryptodataMessage) + |
692 | 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) + | 689 | 2 * contained * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) + |
693 | 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 690 | 2 * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext); |
694 | if ((msg_size != required_size) || (contained > UINT16_MAX) || | 691 | if ((msg_size != required_size) || (contained > UINT16_MAX) || |
695 | (s->used_element_count < contained)) | 692 | (s->used_element_count < contained)) |
696 | { | 693 | { |
697 | GNUNET_break_op (0); | 694 | GNUNET_break_op(0); |
698 | return GNUNET_SYSERR; | 695 | return GNUNET_SYSERR; |
699 | } | 696 | } |
700 | if (NULL == s->sorted_elements) | 697 | if (NULL == s->sorted_elements) |
701 | { | 698 | { |
702 | /* we're not ready yet, how can Bob be? */ | 699 | /* we're not ready yet, how can Bob be? */ |
703 | GNUNET_break_op (0); | 700 | GNUNET_break_op(0); |
704 | return GNUNET_SYSERR; | 701 | return GNUNET_SYSERR; |
705 | } | 702 | } |
706 | if (s->total != s->client_received_element_count) | 703 | if (s->total != s->client_received_element_count) |
707 | { | 704 | { |
708 | /* we're not ready yet, how can Bob be? */ | 705 | /* we're not ready yet, how can Bob be? */ |
709 | GNUNET_break_op (0); | 706 | GNUNET_break_op(0); |
710 | return GNUNET_SYSERR; | 707 | return GNUNET_SYSERR; |
711 | } | 708 | } |
712 | return GNUNET_OK; | 709 | return GNUNET_OK; |
713 | } | 710 | } |
714 | 711 | ||
@@ -721,50 +718,50 @@ check_bobs_cryptodata_message (void *cls, | |||
721 | * @param msg the actual message | 718 | * @param msg the actual message |
722 | */ | 719 | */ |
723 | static void | 720 | static void |
724 | handle_bobs_cryptodata_message (void *cls, | 721 | handle_bobs_cryptodata_message(void *cls, |
725 | const struct BobCryptodataMessage *msg) | 722 | const struct BobCryptodataMessage *msg) |
726 | { | 723 | { |
727 | struct AliceServiceSession *s = cls; | 724 | struct AliceServiceSession *s = cls; |
728 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; | 725 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; |
729 | uint32_t i; | 726 | uint32_t i; |
730 | uint32_t contained; | 727 | uint32_t contained; |
731 | 728 | ||
732 | contained = ntohl (msg->contained_element_count); | 729 | contained = ntohl(msg->contained_element_count); |
733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 730 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
734 | "Received %u crypto values from Bob\n", | 731 | "Received %u crypto values from Bob\n", |
735 | (unsigned int) contained); | 732 | (unsigned int)contained); |
736 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 733 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1]; |
737 | GNUNET_memcpy (&s->s, | 734 | GNUNET_memcpy(&s->s, |
738 | &payload[0], | 735 | &payload[0], |
739 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 736 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
740 | GNUNET_memcpy (&s->s_prime, | 737 | GNUNET_memcpy(&s->s_prime, |
741 | &payload[1], | 738 | &payload[1], |
742 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 739 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
743 | payload = &payload[2]; | 740 | payload = &payload[2]; |
744 | 741 | ||
745 | s->r = GNUNET_new_array (s->used_element_count, | 742 | s->r = GNUNET_new_array(s->used_element_count, |
746 | struct GNUNET_CRYPTO_PaillierCiphertext); | 743 | struct GNUNET_CRYPTO_PaillierCiphertext); |
747 | s->r_prime = GNUNET_new_array (s->used_element_count, | 744 | s->r_prime = GNUNET_new_array(s->used_element_count, |
748 | struct GNUNET_CRYPTO_PaillierCiphertext); | 745 | struct GNUNET_CRYPTO_PaillierCiphertext); |
749 | for (i = 0; i < contained; i++) | 746 | for (i = 0; i < contained; i++) |
750 | { | 747 | { |
751 | GNUNET_memcpy (&s->r[i], | 748 | GNUNET_memcpy(&s->r[i], |
752 | &payload[2 * i], | 749 | &payload[2 * i], |
753 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 750 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
754 | GNUNET_memcpy (&s->r_prime[i], | 751 | GNUNET_memcpy(&s->r_prime[i], |
755 | &payload[2 * i + 1], | 752 | &payload[2 * i + 1], |
756 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 753 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
757 | } | 754 | } |
758 | s->cadet_received_element_count = contained; | 755 | s->cadet_received_element_count = contained; |
759 | GNUNET_CADET_receive_done (s->channel); | 756 | GNUNET_CADET_receive_done(s->channel); |
760 | 757 | ||
761 | if (s->cadet_received_element_count != s->used_element_count) | 758 | if (s->cadet_received_element_count != s->used_element_count) |
762 | { | 759 | { |
763 | /* More to come */ | 760 | /* More to come */ |
764 | return; | 761 | return; |
765 | } | 762 | } |
766 | s->product = compute_scalar_product (s); | 763 | s->product = compute_scalar_product(s); |
767 | transmit_client_response (s); | 764 | transmit_client_response(s); |
768 | } | 765 | } |
769 | 766 | ||
770 | 767 | ||
@@ -777,19 +774,19 @@ handle_bobs_cryptodata_message (void *cls, | |||
777 | * @param value the `struct GNUNET_SCALARPRODUCT_Element *` | 774 | * @param value the `struct GNUNET_SCALARPRODUCT_Element *` |
778 | */ | 775 | */ |
779 | static int | 776 | static int |
780 | copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | 777 | copy_element_cb(void *cls, const struct GNUNET_HashCode *key, void *value) |
781 | { | 778 | { |
782 | struct AliceServiceSession *s = cls; | 779 | struct AliceServiceSession *s = cls; |
783 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 780 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
784 | gcry_mpi_t mval; | 781 | gcry_mpi_t mval; |
785 | int64_t val; | 782 | int64_t val; |
786 | 783 | ||
787 | mval = gcry_mpi_new (0); | 784 | mval = gcry_mpi_new(0); |
788 | val = (int64_t) GNUNET_ntohll (e->value); | 785 | val = (int64_t)GNUNET_ntohll(e->value); |
789 | if (0 > val) | 786 | if (0 > val) |
790 | gcry_mpi_sub_ui (mval, mval, -val); | 787 | gcry_mpi_sub_ui(mval, mval, -val); |
791 | else | 788 | else |
792 | gcry_mpi_add_ui (mval, mval, val); | 789 | gcry_mpi_add_ui(mval, mval, val); |
793 | s->sorted_elements[s->used_element_count].value = mval; | 790 | s->sorted_elements[s->used_element_count].value = mval; |
794 | s->sorted_elements[s->used_element_count].key = &e->key; | 791 | s->sorted_elements[s->used_element_count].key = &e->key; |
795 | s->used_element_count++; | 792 | s->used_element_count++; |
@@ -805,12 +802,12 @@ copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
805 | * @return -1 for a < b, 0 for a=b, 1 for a > b. | 802 | * @return -1 for a < b, 0 for a=b, 1 for a > b. |
806 | */ | 803 | */ |
807 | static int | 804 | static int |
808 | element_cmp (const void *a, const void *b) | 805 | element_cmp(const void *a, const void *b) |
809 | { | 806 | { |
810 | const struct MpiElement *ma = a; | 807 | const struct MpiElement *ma = a; |
811 | const struct MpiElement *mb = b; | 808 | const struct MpiElement *mb = b; |
812 | 809 | ||
813 | return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key); | 810 | return GNUNET_CRYPTO_hash_cmp(ma->key, mb->key); |
814 | } | 811 | } |
815 | 812 | ||
816 | 813 | ||
@@ -820,8 +817,8 @@ element_cmp (const void *a, const void *b) | |||
820 | */ | 817 | */ |
821 | #define ELEMENT_CAPACITY \ | 818 | #define ELEMENT_CAPACITY \ |
822 | ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \ | 819 | ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \ |
823 | sizeof (struct AliceCryptodataMessage)) / \ | 820 | sizeof(struct AliceCryptodataMessage)) / \ |
824 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) | 821 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)) |
825 | 822 | ||
826 | 823 | ||
827 | /** | 824 | /** |
@@ -831,7 +828,7 @@ element_cmp (const void *a, const void *b) | |||
831 | * @param s the associated service session | 828 | * @param s the associated service session |
832 | */ | 829 | */ |
833 | static void | 830 | static void |
834 | send_alices_cryptodata_message (struct AliceServiceSession *s) | 831 | send_alices_cryptodata_message(struct AliceServiceSession *s) |
835 | { | 832 | { |
836 | struct AliceCryptodataMessage *msg; | 833 | struct AliceCryptodataMessage *msg; |
837 | struct GNUNET_MQ_Envelope *e; | 834 | struct GNUNET_MQ_Envelope *e; |
@@ -841,50 +838,50 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
841 | gcry_mpi_t a; | 838 | gcry_mpi_t a; |
842 | uint32_t off; | 839 | uint32_t off; |
843 | 840 | ||
844 | s->sorted_elements = GNUNET_malloc ( | 841 | s->sorted_elements = GNUNET_malloc( |
845 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * | 842 | GNUNET_CONTAINER_multihashmap_size(s->intersected_elements) * |
846 | sizeof (struct MpiElement)); | 843 | sizeof(struct MpiElement)); |
847 | s->used_element_count = 0; | 844 | s->used_element_count = 0; |
848 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 845 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, |
849 | ©_element_cb, | 846 | ©_element_cb, |
850 | s); | 847 | s); |
851 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 848 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
852 | "Finished intersection, %d items remain\n", | 849 | "Finished intersection, %d items remain\n", |
853 | s->used_element_count); | 850 | s->used_element_count); |
854 | qsort (s->sorted_elements, | 851 | qsort(s->sorted_elements, |
855 | s->used_element_count, | 852 | s->used_element_count, |
856 | sizeof (struct MpiElement), | 853 | sizeof(struct MpiElement), |
857 | &element_cmp); | 854 | &element_cmp); |
858 | off = 0; | 855 | off = 0; |
859 | while (off < s->used_element_count) | 856 | while (off < s->used_element_count) |
860 | { | ||
861 | todo_count = s->used_element_count - off; | ||
862 | if (todo_count > ELEMENT_CAPACITY) | ||
863 | todo_count = ELEMENT_CAPACITY; | ||
864 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
865 | "Sending %u/%u crypto values to Bob\n", | ||
866 | (unsigned int) todo_count, | ||
867 | (unsigned int) s->used_element_count); | ||
868 | |||
869 | e = | ||
870 | GNUNET_MQ_msg_extra (msg, | ||
871 | todo_count * | ||
872 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), | ||
873 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); | ||
874 | msg->contained_element_count = htonl (todo_count); | ||
875 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | ||
876 | a = gcry_mpi_new (0); | ||
877 | for (i = off; i < off + todo_count; i++) | ||
878 | { | 857 | { |
879 | gcry_mpi_add (a, s->sorted_elements[i].value, my_offset); | 858 | todo_count = s->used_element_count - off; |
880 | GNUNET_assert ( | 859 | if (todo_count > ELEMENT_CAPACITY) |
881 | 3 == | 860 | todo_count = ELEMENT_CAPACITY; |
882 | GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - off])); | 861 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
862 | "Sending %u/%u crypto values to Bob\n", | ||
863 | (unsigned int)todo_count, | ||
864 | (unsigned int)s->used_element_count); | ||
865 | |||
866 | e = | ||
867 | GNUNET_MQ_msg_extra(msg, | ||
868 | todo_count * | ||
869 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext), | ||
870 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); | ||
871 | msg->contained_element_count = htonl(todo_count); | ||
872 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1]; | ||
873 | a = gcry_mpi_new(0); | ||
874 | for (i = off; i < off + todo_count; i++) | ||
875 | { | ||
876 | gcry_mpi_add(a, s->sorted_elements[i].value, my_offset); | ||
877 | GNUNET_assert( | ||
878 | 3 == | ||
879 | GNUNET_CRYPTO_paillier_encrypt(&my_pubkey, a, 3, &payload[i - off])); | ||
880 | } | ||
881 | gcry_mpi_release(a); | ||
882 | off += todo_count; | ||
883 | GNUNET_MQ_send(s->cadet_mq, e); | ||
883 | } | 884 | } |
884 | gcry_mpi_release (a); | ||
885 | off += todo_count; | ||
886 | GNUNET_MQ_send (s->cadet_mq, e); | ||
887 | } | ||
888 | } | 885 | } |
889 | 886 | ||
890 | 887 | ||
@@ -899,66 +896,70 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
899 | * @param status what has happened with the set intersection? | 896 | * @param status what has happened with the set intersection? |
900 | */ | 897 | */ |
901 | static void | 898 | static void |
902 | cb_intersection_element_removed (void *cls, | 899 | cb_intersection_element_removed(void *cls, |
903 | const struct GNUNET_SET_Element *element, | 900 | const struct GNUNET_SET_Element *element, |
904 | uint64_t current_size, | 901 | uint64_t current_size, |
905 | enum GNUNET_SET_Status status) | 902 | enum GNUNET_SET_Status status) |
906 | { | 903 | { |
907 | struct AliceServiceSession *s = cls; | 904 | struct AliceServiceSession *s = cls; |
908 | struct GNUNET_SCALARPRODUCT_Element *se; | 905 | struct GNUNET_SCALARPRODUCT_Element *se; |
909 | 906 | ||
910 | switch (status) | 907 | switch (status) |
911 | { | ||
912 | case GNUNET_SET_STATUS_OK: | ||
913 | /* this element has been removed from the set */ | ||
914 | se = GNUNET_CONTAINER_multihashmap_get (s->intersected_elements, | ||
915 | element->data); | ||
916 | GNUNET_assert (NULL != se); | ||
917 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
918 | "Intersection removed element with key %s and value %lld\n", | ||
919 | GNUNET_h2s (&se->key), | ||
920 | (long long) GNUNET_ntohll (se->value)); | ||
921 | GNUNET_assert ( | ||
922 | GNUNET_YES == | ||
923 | GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, | ||
924 | element->data, | ||
925 | se)); | ||
926 | GNUNET_free (se); | ||
927 | return; | ||
928 | case GNUNET_SET_STATUS_DONE: | ||
929 | s->intersection_op = NULL; | ||
930 | if (NULL != s->intersection_set) | ||
931 | { | 908 | { |
932 | GNUNET_SET_destroy (s->intersection_set); | 909 | case GNUNET_SET_STATUS_OK: |
933 | s->intersection_set = NULL; | 910 | /* this element has been removed from the set */ |
911 | se = GNUNET_CONTAINER_multihashmap_get(s->intersected_elements, | ||
912 | element->data); | ||
913 | GNUNET_assert(NULL != se); | ||
914 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
915 | "Intersection removed element with key %s and value %lld\n", | ||
916 | GNUNET_h2s(&se->key), | ||
917 | (long long)GNUNET_ntohll(se->value)); | ||
918 | GNUNET_assert( | ||
919 | GNUNET_YES == | ||
920 | GNUNET_CONTAINER_multihashmap_remove(s->intersected_elements, | ||
921 | element->data, | ||
922 | se)); | ||
923 | GNUNET_free(se); | ||
924 | return; | ||
925 | |||
926 | case GNUNET_SET_STATUS_DONE: | ||
927 | s->intersection_op = NULL; | ||
928 | if (NULL != s->intersection_set) | ||
929 | { | ||
930 | GNUNET_SET_destroy(s->intersection_set); | ||
931 | s->intersection_set = NULL; | ||
932 | } | ||
933 | send_alices_cryptodata_message(s); | ||
934 | return; | ||
935 | |||
936 | case GNUNET_SET_STATUS_HALF_DONE: | ||
937 | /* unexpected for intersection */ | ||
938 | GNUNET_break(0); | ||
939 | return; | ||
940 | |||
941 | case GNUNET_SET_STATUS_FAILURE: | ||
942 | /* unhandled status code */ | ||
943 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n"); | ||
944 | if (NULL != s->intersection_listen) | ||
945 | { | ||
946 | GNUNET_SET_listen_cancel(s->intersection_listen); | ||
947 | s->intersection_listen = NULL; | ||
948 | } | ||
949 | s->intersection_op = NULL; | ||
950 | if (NULL != s->intersection_set) | ||
951 | { | ||
952 | GNUNET_SET_destroy(s->intersection_set); | ||
953 | s->intersection_set = NULL; | ||
954 | } | ||
955 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
956 | prepare_client_end_notification(s); | ||
957 | return; | ||
958 | |||
959 | default: | ||
960 | GNUNET_break(0); | ||
961 | return; | ||
934 | } | 962 | } |
935 | send_alices_cryptodata_message (s); | ||
936 | return; | ||
937 | case GNUNET_SET_STATUS_HALF_DONE: | ||
938 | /* unexpected for intersection */ | ||
939 | GNUNET_break (0); | ||
940 | return; | ||
941 | case GNUNET_SET_STATUS_FAILURE: | ||
942 | /* unhandled status code */ | ||
943 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n"); | ||
944 | if (NULL != s->intersection_listen) | ||
945 | { | ||
946 | GNUNET_SET_listen_cancel (s->intersection_listen); | ||
947 | s->intersection_listen = NULL; | ||
948 | } | ||
949 | s->intersection_op = NULL; | ||
950 | if (NULL != s->intersection_set) | ||
951 | { | ||
952 | GNUNET_SET_destroy (s->intersection_set); | ||
953 | s->intersection_set = NULL; | ||
954 | } | ||
955 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
956 | prepare_client_end_notification (s); | ||
957 | return; | ||
958 | default: | ||
959 | GNUNET_break (0); | ||
960 | return; | ||
961 | } | ||
962 | } | 963 | } |
963 | 964 | ||
964 | 965 | ||
@@ -978,37 +979,37 @@ cb_intersection_element_removed (void *cls, | |||
978 | * message. It's necessary to specify the timeout. | 979 | * message. It's necessary to specify the timeout. |
979 | */ | 980 | */ |
980 | static void | 981 | static void |
981 | cb_intersection_request_alice (void *cls, | 982 | cb_intersection_request_alice(void *cls, |
982 | const struct GNUNET_PeerIdentity *other_peer, | 983 | const struct GNUNET_PeerIdentity *other_peer, |
983 | const struct GNUNET_MessageHeader *context_msg, | 984 | const struct GNUNET_MessageHeader *context_msg, |
984 | struct GNUNET_SET_Request *request) | 985 | struct GNUNET_SET_Request *request) |
985 | { | 986 | { |
986 | struct AliceServiceSession *s = cls; | 987 | struct AliceServiceSession *s = cls; |
987 | 988 | ||
988 | if (0 != GNUNET_memcmp (other_peer, &s->peer)) | 989 | if (0 != GNUNET_memcmp(other_peer, &s->peer)) |
989 | { | 990 | { |
990 | GNUNET_break_op (0); | 991 | GNUNET_break_op(0); |
991 | return; | 992 | return; |
992 | } | 993 | } |
993 | s->intersection_op = GNUNET_SET_accept (request, | 994 | s->intersection_op = GNUNET_SET_accept(request, |
994 | GNUNET_SET_RESULT_REMOVED, | 995 | GNUNET_SET_RESULT_REMOVED, |
995 | (struct GNUNET_SET_Option[]){{0}}, | 996 | (struct GNUNET_SET_Option[]){ { 0 } }, |
996 | &cb_intersection_element_removed, | 997 | &cb_intersection_element_removed, |
997 | s); | 998 | s); |
998 | if (NULL == s->intersection_op) | 999 | if (NULL == s->intersection_op) |
999 | { | 1000 | { |
1000 | GNUNET_break (0); | 1001 | GNUNET_break(0); |
1001 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 1002 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
1002 | prepare_client_end_notification (s); | 1003 | prepare_client_end_notification(s); |
1003 | return; | 1004 | return; |
1004 | } | 1005 | } |
1005 | if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set)) | 1006 | if (GNUNET_OK != GNUNET_SET_commit(s->intersection_op, s->intersection_set)) |
1006 | { | 1007 | { |
1007 | GNUNET_break (0); | 1008 | GNUNET_break(0); |
1008 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 1009 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
1009 | prepare_client_end_notification (s); | 1010 | prepare_client_end_notification(s); |
1010 | return; | 1011 | return; |
1011 | } | 1012 | } |
1012 | } | 1013 | } |
1013 | 1014 | ||
1014 | 1015 | ||
@@ -1018,58 +1019,58 @@ cb_intersection_request_alice (void *cls, | |||
1018 | * @param session the service session context | 1019 | * @param session the service session context |
1019 | */ | 1020 | */ |
1020 | static void | 1021 | static void |
1021 | client_request_complete_alice (struct AliceServiceSession *s) | 1022 | client_request_complete_alice(struct AliceServiceSession *s) |
1022 | { | 1023 | { |
1023 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 1024 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
1024 | {GNUNET_MQ_hd_var_size (bobs_cryptodata_message, | 1025 | { GNUNET_MQ_hd_var_size(bobs_cryptodata_message, |
1025 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, | 1026 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, |
1026 | struct BobCryptodataMessage, | 1027 | struct BobCryptodataMessage, |
1027 | s), | 1028 | s), |
1028 | GNUNET_MQ_hd_var_size ( | 1029 | GNUNET_MQ_hd_var_size( |
1029 | bobs_cryptodata_multipart, | 1030 | bobs_cryptodata_multipart, |
1030 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, | 1031 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, |
1031 | struct BobCryptodataMultipartMessage, | 1032 | struct BobCryptodataMultipartMessage, |
1032 | s), | 1033 | s), |
1033 | GNUNET_MQ_handler_end ()}; | 1034 | GNUNET_MQ_handler_end() }; |
1034 | struct ServiceRequestMessage *msg; | 1035 | struct ServiceRequestMessage *msg; |
1035 | struct GNUNET_MQ_Envelope *e; | 1036 | struct GNUNET_MQ_Envelope *e; |
1036 | 1037 | ||
1037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1038 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1038 | "Creating new channel for session with key %s.\n", | 1039 | "Creating new channel for session with key %s.\n", |
1039 | GNUNET_h2s (&s->session_id)); | 1040 | GNUNET_h2s(&s->session_id)); |
1040 | s->channel = GNUNET_CADET_channel_create (my_cadet, | 1041 | s->channel = GNUNET_CADET_channel_create(my_cadet, |
1041 | s, | 1042 | s, |
1042 | &s->peer, | 1043 | &s->peer, |
1043 | &s->session_id, | 1044 | &s->session_id, |
1044 | NULL, | 1045 | NULL, |
1045 | &cb_channel_destruction, | 1046 | &cb_channel_destruction, |
1046 | cadet_handlers); | 1047 | cadet_handlers); |
1047 | if (NULL == s->channel) | 1048 | if (NULL == s->channel) |
1048 | { | 1049 | { |
1049 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 1050 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
1050 | prepare_client_end_notification (s); | 1051 | prepare_client_end_notification(s); |
1051 | return; | 1052 | return; |
1052 | } | 1053 | } |
1053 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); | 1054 | s->cadet_mq = GNUNET_CADET_get_mq(s->channel); |
1054 | s->intersection_listen = GNUNET_SET_listen (cfg, | 1055 | s->intersection_listen = GNUNET_SET_listen(cfg, |
1055 | GNUNET_SET_OPERATION_INTERSECTION, | 1056 | GNUNET_SET_OPERATION_INTERSECTION, |
1056 | &s->session_id, | 1057 | &s->session_id, |
1057 | &cb_intersection_request_alice, | 1058 | &cb_intersection_request_alice, |
1058 | s); | 1059 | s); |
1059 | if (NULL == s->intersection_listen) | 1060 | if (NULL == s->intersection_listen) |
1060 | { | 1061 | { |
1061 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 1062 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
1062 | GNUNET_CADET_channel_destroy (s->channel); | 1063 | GNUNET_CADET_channel_destroy(s->channel); |
1063 | s->channel = NULL; | 1064 | s->channel = NULL; |
1064 | prepare_client_end_notification (s); | 1065 | prepare_client_end_notification(s); |
1065 | return; | 1066 | return; |
1066 | } | 1067 | } |
1067 | 1068 | ||
1068 | e = GNUNET_MQ_msg (msg, | 1069 | e = GNUNET_MQ_msg(msg, |
1069 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION); | 1070 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION); |
1070 | msg->session_id = s->session_id; | 1071 | msg->session_id = s->session_id; |
1071 | msg->public_key = my_pubkey; | 1072 | msg->public_key = my_pubkey; |
1072 | GNUNET_MQ_send (s->cadet_mq, e); | 1073 | GNUNET_MQ_send(s->cadet_mq, e); |
1073 | } | 1074 | } |
1074 | 1075 | ||
1075 | 1076 | ||
@@ -1082,7 +1083,7 @@ client_request_complete_alice (struct AliceServiceSession *s) | |||
1082 | * @return #GNUNET_OK if @a msg is well-formed | 1083 | * @return #GNUNET_OK if @a msg is well-formed |
1083 | */ | 1084 | */ |
1084 | static int | 1085 | static int |
1085 | check_alice_client_message_multipart ( | 1086 | check_alice_client_message_multipart( |
1086 | void *cls, | 1087 | void *cls, |
1087 | const struct ComputationBobCryptodataMultipartMessage *msg) | 1088 | const struct ComputationBobCryptodataMultipartMessage *msg) |
1088 | { | 1089 | { |
@@ -1090,18 +1091,18 @@ check_alice_client_message_multipart ( | |||
1090 | uint32_t contained_count; | 1091 | uint32_t contained_count; |
1091 | uint16_t msize; | 1092 | uint16_t msize; |
1092 | 1093 | ||
1093 | msize = ntohs (msg->header.size); | 1094 | msize = ntohs(msg->header.size); |
1094 | contained_count = ntohl (msg->element_count_contained); | 1095 | contained_count = ntohl(msg->element_count_contained); |
1095 | if ((msize != | 1096 | if ((msize != |
1096 | (sizeof (struct ComputationBobCryptodataMultipartMessage) + | 1097 | (sizeof(struct ComputationBobCryptodataMultipartMessage) + |
1097 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || | 1098 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element))) || |
1098 | (0 == contained_count) || | 1099 | (0 == contained_count) || |
1099 | (s->total == s->client_received_element_count) || | 1100 | (s->total == s->client_received_element_count) || |
1100 | (s->total < s->client_received_element_count + contained_count)) | 1101 | (s->total < s->client_received_element_count + contained_count)) |
1101 | { | 1102 | { |
1102 | GNUNET_break_op (0); | 1103 | GNUNET_break_op(0); |
1103 | return GNUNET_SYSERR; | 1104 | return GNUNET_SYSERR; |
1104 | } | 1105 | } |
1105 | return GNUNET_OK; | 1106 | return GNUNET_OK; |
1106 | } | 1107 | } |
1107 | 1108 | ||
@@ -1114,7 +1115,7 @@ check_alice_client_message_multipart ( | |||
1114 | * @param msg the actual message | 1115 | * @param msg the actual message |
1115 | */ | 1116 | */ |
1116 | static void | 1117 | static void |
1117 | handle_alice_client_message_multipart ( | 1118 | handle_alice_client_message_multipart( |
1118 | void *cls, | 1119 | void *cls, |
1119 | const struct ComputationBobCryptodataMultipartMessage *msg) | 1120 | const struct ComputationBobCryptodataMultipartMessage *msg) |
1120 | { | 1121 | { |
@@ -1124,38 +1125,38 @@ handle_alice_client_message_multipart ( | |||
1124 | struct GNUNET_SET_Element set_elem; | 1125 | struct GNUNET_SET_Element set_elem; |
1125 | struct GNUNET_SCALARPRODUCT_Element *elem; | 1126 | struct GNUNET_SCALARPRODUCT_Element *elem; |
1126 | 1127 | ||
1127 | contained_count = ntohl (msg->element_count_contained); | 1128 | contained_count = ntohl(msg->element_count_contained); |
1128 | s->client_received_element_count += contained_count; | 1129 | s->client_received_element_count += contained_count; |
1129 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 1130 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; |
1130 | for (uint32_t i = 0; i < contained_count; i++) | 1131 | for (uint32_t i = 0; i < contained_count; i++) |
1131 | { | ||
1132 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
1133 | GNUNET_memcpy (elem, | ||
1134 | &elements[i], | ||
1135 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | ||
1136 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( | ||
1137 | s->intersected_elements, | ||
1138 | &elem->key, | ||
1139 | elem, | ||
1140 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1141 | { | 1132 | { |
1142 | GNUNET_break (0); | 1133 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); |
1143 | GNUNET_free (elem); | 1134 | GNUNET_memcpy(elem, |
1144 | continue; | 1135 | &elements[i], |
1136 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
1137 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put( | ||
1138 | s->intersected_elements, | ||
1139 | &elem->key, | ||
1140 | elem, | ||
1141 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1142 | { | ||
1143 | GNUNET_break(0); | ||
1144 | GNUNET_free(elem); | ||
1145 | continue; | ||
1146 | } | ||
1147 | set_elem.data = &elem->key; | ||
1148 | set_elem.size = sizeof(elem->key); | ||
1149 | set_elem.element_type = 0; | ||
1150 | GNUNET_SET_add_element(s->intersection_set, &set_elem, NULL, NULL); | ||
1151 | s->used_element_count++; | ||
1145 | } | 1152 | } |
1146 | set_elem.data = &elem->key; | 1153 | GNUNET_SERVICE_client_continue(s->client); |
1147 | set_elem.size = sizeof (elem->key); | ||
1148 | set_elem.element_type = 0; | ||
1149 | GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); | ||
1150 | s->used_element_count++; | ||
1151 | } | ||
1152 | GNUNET_SERVICE_client_continue (s->client); | ||
1153 | if (s->total != s->client_received_element_count) | 1154 | if (s->total != s->client_received_element_count) |
1154 | { | 1155 | { |
1155 | /* more to come */ | 1156 | /* more to come */ |
1156 | return; | 1157 | return; |
1157 | } | 1158 | } |
1158 | client_request_complete_alice (s); | 1159 | client_request_complete_alice(s); |
1159 | } | 1160 | } |
1160 | 1161 | ||
1161 | 1162 | ||
@@ -1168,8 +1169,8 @@ handle_alice_client_message_multipart ( | |||
1168 | * @return #GNUNET_OK if @a msg is well-formed | 1169 | * @return #GNUNET_OK if @a msg is well-formed |
1169 | */ | 1170 | */ |
1170 | static int | 1171 | static int |
1171 | check_alice_client_message (void *cls, | 1172 | check_alice_client_message(void *cls, |
1172 | const struct AliceComputationMessage *msg) | 1173 | const struct AliceComputationMessage *msg) |
1173 | { | 1174 | { |
1174 | struct AliceServiceSession *s = cls; | 1175 | struct AliceServiceSession *s = cls; |
1175 | uint16_t msize; | 1176 | uint16_t msize; |
@@ -1177,23 +1178,23 @@ check_alice_client_message (void *cls, | |||
1177 | uint32_t contained_count; | 1178 | uint32_t contained_count; |
1178 | 1179 | ||
1179 | if (NULL != s->intersected_elements) | 1180 | if (NULL != s->intersected_elements) |
1180 | { | 1181 | { |
1181 | /* only one concurrent session per client connection allowed, | 1182 | /* only one concurrent session per client connection allowed, |
1182 | simplifies logic a lot... */ | 1183 | simplifies logic a lot... */ |
1183 | GNUNET_break (0); | 1184 | GNUNET_break(0); |
1184 | return GNUNET_SYSERR; | 1185 | return GNUNET_SYSERR; |
1185 | } | 1186 | } |
1186 | msize = ntohs (msg->header.size); | 1187 | msize = ntohs(msg->header.size); |
1187 | total_count = ntohl (msg->element_count_total); | 1188 | total_count = ntohl(msg->element_count_total); |
1188 | contained_count = ntohl (msg->element_count_contained); | 1189 | contained_count = ntohl(msg->element_count_contained); |
1189 | if ((0 == total_count) || (0 == contained_count) || | 1190 | if ((0 == total_count) || (0 == contained_count) || |
1190 | (msize != | 1191 | (msize != |
1191 | (sizeof (struct AliceComputationMessage) + | 1192 | (sizeof(struct AliceComputationMessage) + |
1192 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element)))) | 1193 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element)))) |
1193 | { | 1194 | { |
1194 | GNUNET_break_op (0); | 1195 | GNUNET_break_op(0); |
1195 | return GNUNET_SYSERR; | 1196 | return GNUNET_SYSERR; |
1196 | } | 1197 | } |
1197 | return GNUNET_OK; | 1198 | return GNUNET_OK; |
1198 | } | 1199 | } |
1199 | 1200 | ||
@@ -1206,8 +1207,8 @@ check_alice_client_message (void *cls, | |||
1206 | * @param msg the actual message | 1207 | * @param msg the actual message |
1207 | */ | 1208 | */ |
1208 | static void | 1209 | static void |
1209 | handle_alice_client_message (void *cls, | 1210 | handle_alice_client_message(void *cls, |
1210 | const struct AliceComputationMessage *msg) | 1211 | const struct AliceComputationMessage *msg) |
1211 | { | 1212 | { |
1212 | struct AliceServiceSession *s = cls; | 1213 | struct AliceServiceSession *s = cls; |
1213 | uint32_t contained_count; | 1214 | uint32_t contained_count; |
@@ -1216,51 +1217,51 @@ handle_alice_client_message (void *cls, | |||
1216 | struct GNUNET_SET_Element set_elem; | 1217 | struct GNUNET_SET_Element set_elem; |
1217 | struct GNUNET_SCALARPRODUCT_Element *elem; | 1218 | struct GNUNET_SCALARPRODUCT_Element *elem; |
1218 | 1219 | ||
1219 | total_count = ntohl (msg->element_count_total); | 1220 | total_count = ntohl(msg->element_count_total); |
1220 | contained_count = ntohl (msg->element_count_contained); | 1221 | contained_count = ntohl(msg->element_count_contained); |
1221 | s->peer = msg->peer; | 1222 | s->peer = msg->peer; |
1222 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; | 1223 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; |
1223 | s->total = total_count; | 1224 | s->total = total_count; |
1224 | s->client_received_element_count = contained_count; | 1225 | s->client_received_element_count = contained_count; |
1225 | s->session_id = msg->session_key; | 1226 | s->session_id = msg->session_key; |
1226 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 1227 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; |
1227 | s->intersected_elements = | 1228 | s->intersected_elements = |
1228 | GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES); | 1229 | GNUNET_CONTAINER_multihashmap_create(s->total, GNUNET_YES); |
1229 | s->intersection_set = | 1230 | s->intersection_set = |
1230 | GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); | 1231 | GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_INTERSECTION); |
1231 | 1232 | ||
1232 | for (uint32_t i = 0; i < contained_count; i++) | 1233 | for (uint32_t i = 0; i < contained_count; i++) |
1233 | { | ||
1234 | if (0 == GNUNET_ntohll (elements[i].value)) | ||
1235 | continue; | ||
1236 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
1237 | GNUNET_memcpy (elem, | ||
1238 | &elements[i], | ||
1239 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | ||
1240 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( | ||
1241 | s->intersected_elements, | ||
1242 | &elem->key, | ||
1243 | elem, | ||
1244 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1245 | { | 1234 | { |
1246 | /* element with same key encountered twice! */ | 1235 | if (0 == GNUNET_ntohll(elements[i].value)) |
1247 | GNUNET_break (0); | 1236 | continue; |
1248 | GNUNET_free (elem); | 1237 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); |
1249 | continue; | 1238 | GNUNET_memcpy(elem, |
1239 | &elements[i], | ||
1240 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
1241 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put( | ||
1242 | s->intersected_elements, | ||
1243 | &elem->key, | ||
1244 | elem, | ||
1245 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1246 | { | ||
1247 | /* element with same key encountered twice! */ | ||
1248 | GNUNET_break(0); | ||
1249 | GNUNET_free(elem); | ||
1250 | continue; | ||
1251 | } | ||
1252 | set_elem.data = &elem->key; | ||
1253 | set_elem.size = sizeof(elem->key); | ||
1254 | set_elem.element_type = 0; | ||
1255 | GNUNET_SET_add_element(s->intersection_set, &set_elem, NULL, NULL); | ||
1256 | s->used_element_count++; | ||
1250 | } | 1257 | } |
1251 | set_elem.data = &elem->key; | 1258 | GNUNET_SERVICE_client_continue(s->client); |
1252 | set_elem.size = sizeof (elem->key); | ||
1253 | set_elem.element_type = 0; | ||
1254 | GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); | ||
1255 | s->used_element_count++; | ||
1256 | } | ||
1257 | GNUNET_SERVICE_client_continue (s->client); | ||
1258 | if (s->total != s->client_received_element_count) | 1259 | if (s->total != s->client_received_element_count) |
1259 | { | 1260 | { |
1260 | /* wait for multipart msg */ | 1261 | /* wait for multipart msg */ |
1261 | return; | 1262 | return; |
1262 | } | 1263 | } |
1263 | client_request_complete_alice (s); | 1264 | client_request_complete_alice(s); |
1264 | } | 1265 | } |
1265 | 1266 | ||
1266 | 1267 | ||
@@ -1270,15 +1271,15 @@ handle_alice_client_message (void *cls, | |||
1270 | * @param cls unused | 1271 | * @param cls unused |
1271 | */ | 1272 | */ |
1272 | static void | 1273 | static void |
1273 | shutdown_task (void *cls) | 1274 | shutdown_task(void *cls) |
1274 | { | 1275 | { |
1275 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n"); | 1276 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n"); |
1276 | // FIXME: we have to cut our connections to CADET first! | 1277 | // FIXME: we have to cut our connections to CADET first! |
1277 | if (NULL != my_cadet) | 1278 | if (NULL != my_cadet) |
1278 | { | 1279 | { |
1279 | GNUNET_CADET_disconnect (my_cadet); | 1280 | GNUNET_CADET_disconnect(my_cadet); |
1280 | my_cadet = NULL; | 1281 | my_cadet = NULL; |
1281 | } | 1282 | } |
1282 | } | 1283 | } |
1283 | 1284 | ||
1284 | 1285 | ||
@@ -1293,13 +1294,13 @@ shutdown_task (void *cls) | |||
1293 | * @return our `struct AliceServiceSession` | 1294 | * @return our `struct AliceServiceSession` |
1294 | */ | 1295 | */ |
1295 | static void * | 1296 | static void * |
1296 | client_connect_cb (void *cls, | 1297 | client_connect_cb(void *cls, |
1297 | struct GNUNET_SERVICE_Client *client, | 1298 | struct GNUNET_SERVICE_Client *client, |
1298 | struct GNUNET_MQ_Handle *mq) | 1299 | struct GNUNET_MQ_Handle *mq) |
1299 | { | 1300 | { |
1300 | struct AliceServiceSession *s; | 1301 | struct AliceServiceSession *s; |
1301 | 1302 | ||
1302 | s = GNUNET_new (struct AliceServiceSession); | 1303 | s = GNUNET_new(struct AliceServiceSession); |
1303 | s->client = client; | 1304 | s->client = client; |
1304 | s->client_mq = mq; | 1305 | s->client_mq = mq; |
1305 | return s; | 1306 | return s; |
@@ -1317,18 +1318,18 @@ client_connect_cb (void *cls, | |||
1317 | * @param app_cls our `struct AliceServiceSession` | 1318 | * @param app_cls our `struct AliceServiceSession` |
1318 | */ | 1319 | */ |
1319 | static void | 1320 | static void |
1320 | client_disconnect_cb (void *cls, | 1321 | client_disconnect_cb(void *cls, |
1321 | struct GNUNET_SERVICE_Client *client, | 1322 | struct GNUNET_SERVICE_Client *client, |
1322 | void *app_cls) | 1323 | void *app_cls) |
1323 | { | 1324 | { |
1324 | struct AliceServiceSession *s = app_cls; | 1325 | struct AliceServiceSession *s = app_cls; |
1325 | 1326 | ||
1326 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1327 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1327 | "Client %p disconnected from us.\n", | 1328 | "Client %p disconnected from us.\n", |
1328 | client); | 1329 | client); |
1329 | s->client = NULL; | 1330 | s->client = NULL; |
1330 | s->client_mq = NULL; | 1331 | s->client_mq = NULL; |
1331 | destroy_service_session (s); | 1332 | destroy_service_session(s); |
1332 | } | 1333 | } |
1333 | 1334 | ||
1334 | 1335 | ||
@@ -1340,49 +1341,49 @@ client_disconnect_cb (void *cls, | |||
1340 | * @param service the initialized service | 1341 | * @param service the initialized service |
1341 | */ | 1342 | */ |
1342 | static void | 1343 | static void |
1343 | run (void *cls, | 1344 | run(void *cls, |
1344 | const struct GNUNET_CONFIGURATION_Handle *c, | 1345 | const struct GNUNET_CONFIGURATION_Handle *c, |
1345 | struct GNUNET_SERVICE_Handle *service) | 1346 | struct GNUNET_SERVICE_Handle *service) |
1346 | { | 1347 | { |
1347 | cfg = c; | 1348 | cfg = c; |
1348 | /* | 1349 | /* |
1349 | offset has to be sufficiently small to allow computation of: | 1350 | offset has to be sufficiently small to allow computation of: |
1350 | m1+m2 mod n == (S + a) + (S + b) mod n, | 1351 | m1+m2 mod n == (S + a) + (S + b) mod n, |
1351 | if we have more complex operations, this factor needs to be lowered */ | 1352 | if we have more complex operations, this factor needs to be lowered */ |
1352 | my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); | 1353 | my_offset = gcry_mpi_new(GNUNET_CRYPTO_PAILLIER_BITS / 3); |
1353 | gcry_mpi_set_bit (my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3); | 1354 | gcry_mpi_set_bit(my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3); |
1354 | GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey); | 1355 | GNUNET_CRYPTO_paillier_create(&my_pubkey, &my_privkey); |
1355 | my_cadet = GNUNET_CADET_connect (cfg); | 1356 | my_cadet = GNUNET_CADET_connect(cfg); |
1356 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1357 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
1357 | if (NULL == my_cadet) | 1358 | if (NULL == my_cadet) |
1358 | { | 1359 | { |
1359 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n")); | 1360 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Connect to CADET failed\n")); |
1360 | GNUNET_SCHEDULER_shutdown (); | 1361 | GNUNET_SCHEDULER_shutdown(); |
1361 | return; | 1362 | return; |
1362 | } | 1363 | } |
1363 | } | 1364 | } |
1364 | 1365 | ||
1365 | 1366 | ||
1366 | /** | 1367 | /** |
1367 | * Define "main" method using service macro. | 1368 | * Define "main" method using service macro. |
1368 | */ | 1369 | */ |
1369 | GNUNET_SERVICE_MAIN ( | 1370 | GNUNET_SERVICE_MAIN( |
1370 | "scalarproduct-alice", | 1371 | "scalarproduct-alice", |
1371 | GNUNET_SERVICE_OPTION_NONE, | 1372 | GNUNET_SERVICE_OPTION_NONE, |
1372 | &run, | 1373 | &run, |
1373 | &client_connect_cb, | 1374 | &client_connect_cb, |
1374 | &client_disconnect_cb, | 1375 | &client_disconnect_cb, |
1375 | NULL, | 1376 | NULL, |
1376 | GNUNET_MQ_hd_var_size (alice_client_message, | 1377 | GNUNET_MQ_hd_var_size(alice_client_message, |
1377 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, | 1378 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, |
1378 | struct AliceComputationMessage, | 1379 | struct AliceComputationMessage, |
1379 | NULL), | 1380 | NULL), |
1380 | GNUNET_MQ_hd_var_size ( | 1381 | GNUNET_MQ_hd_var_size( |
1381 | alice_client_message_multipart, | 1382 | alice_client_message_multipart, |
1382 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, | 1383 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, |
1383 | struct ComputationBobCryptodataMultipartMessage, | 1384 | struct ComputationBobCryptodataMultipartMessage, |
1384 | NULL), | 1385 | NULL), |
1385 | GNUNET_MQ_handler_end ()); | 1386 | GNUNET_MQ_handler_end()); |
1386 | 1387 | ||
1387 | 1388 | ||
1388 | /* end of gnunet-service-scalarproduct_alice.c */ | 1389 | /* end of gnunet-service-scalarproduct_alice.c */ |
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c index 0b95f3a00..f787cdd2e 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -36,14 +36,13 @@ | |||
36 | #include "scalarproduct.h" | 36 | #include "scalarproduct.h" |
37 | #include "gnunet-service-scalarproduct.h" | 37 | #include "gnunet-service-scalarproduct.h" |
38 | 38 | ||
39 | #define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-bob", __VA_ARGS__) | 39 | #define LOG(kind, ...) GNUNET_log_from(kind, "scalarproduct-bob", __VA_ARGS__) |
40 | 40 | ||
41 | 41 | ||
42 | /** | 42 | /** |
43 | * An encrypted element key-value pair. | 43 | * An encrypted element key-value pair. |
44 | */ | 44 | */ |
45 | struct MpiElement | 45 | struct MpiElement { |
46 | { | ||
47 | /** | 46 | /** |
48 | * Key used to identify matching pairs of values to multiply. | 47 | * Key used to identify matching pairs of values to multiply. |
49 | * Points into an existing data structure, to avoid copying | 48 | * Points into an existing data structure, to avoid copying |
@@ -62,9 +61,7 @@ struct MpiElement | |||
62 | * A scalarproduct session which tracks an offer for a | 61 | * A scalarproduct session which tracks an offer for a |
63 | * multiplication service by a local client. | 62 | * multiplication service by a local client. |
64 | */ | 63 | */ |
65 | struct BobServiceSession | 64 | struct BobServiceSession { |
66 | { | ||
67 | |||
68 | /** | 65 | /** |
69 | * (hopefully) unique transaction ID | 66 | * (hopefully) unique transaction ID |
70 | */ | 67 | */ |
@@ -200,7 +197,6 @@ struct BobServiceSession | |||
200 | * The message queue for this channel. | 197 | * The message queue for this channel. |
201 | */ | 198 | */ |
202 | struct GNUNET_MQ_Handle *cadet_mq; | 199 | struct GNUNET_MQ_Handle *cadet_mq; |
203 | |||
204 | }; | 200 | }; |
205 | 201 | ||
206 | 202 | ||
@@ -239,13 +235,13 @@ static struct GNUNET_CADET_Handle *my_cadet; | |||
239 | * @param value the value to free | 235 | * @param value the value to free |
240 | */ | 236 | */ |
241 | static int | 237 | static int |
242 | free_element_cb (void *cls, | 238 | free_element_cb(void *cls, |
243 | const struct GNUNET_HashCode *key, | 239 | const struct GNUNET_HashCode *key, |
244 | void *value) | 240 | void *value) |
245 | { | 241 | { |
246 | struct GNUNET_SCALARPRODUCT_Element *element = value; | 242 | struct GNUNET_SCALARPRODUCT_Element *element = value; |
247 | 243 | ||
248 | GNUNET_free (element); | 244 | GNUNET_free(element); |
249 | return GNUNET_OK; | 245 | return GNUNET_OK; |
250 | } | 246 | } |
251 | 247 | ||
@@ -256,7 +252,7 @@ free_element_cb (void *cls, | |||
256 | * @param session the session to free elements from | 252 | * @param session the session to free elements from |
257 | */ | 253 | */ |
258 | static void | 254 | static void |
259 | destroy_service_session (struct BobServiceSession *s) | 255 | destroy_service_session(struct BobServiceSession *s) |
260 | { | 256 | { |
261 | unsigned int i; | 257 | unsigned int i; |
262 | 258 | ||
@@ -264,63 +260,63 @@ destroy_service_session (struct BobServiceSession *s) | |||
264 | return; | 260 | return; |
265 | s->in_destroy = GNUNET_YES; | 261 | s->in_destroy = GNUNET_YES; |
266 | if (NULL != s->client) | 262 | if (NULL != s->client) |
267 | { | 263 | { |
268 | struct GNUNET_SERVICE_Client *c = s->client; | 264 | struct GNUNET_SERVICE_Client *c = s->client; |
269 | 265 | ||
270 | s->client = NULL; | 266 | s->client = NULL; |
271 | GNUNET_SERVICE_client_drop (c); | 267 | GNUNET_SERVICE_client_drop(c); |
272 | } | 268 | } |
273 | if (NULL != s->intersected_elements) | 269 | if (NULL != s->intersected_elements) |
274 | { | 270 | { |
275 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 271 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, |
276 | &free_element_cb, | 272 | &free_element_cb, |
277 | NULL); | 273 | NULL); |
278 | GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements); | 274 | GNUNET_CONTAINER_multihashmap_destroy(s->intersected_elements); |
279 | s->intersected_elements = NULL; | 275 | s->intersected_elements = NULL; |
280 | } | 276 | } |
281 | if (NULL != s->intersection_op) | 277 | if (NULL != s->intersection_op) |
282 | { | 278 | { |
283 | GNUNET_SET_operation_cancel (s->intersection_op); | 279 | GNUNET_SET_operation_cancel(s->intersection_op); |
284 | s->intersection_op = NULL; | 280 | s->intersection_op = NULL; |
285 | } | 281 | } |
286 | if (NULL != s->intersection_set) | 282 | if (NULL != s->intersection_set) |
287 | { | 283 | { |
288 | GNUNET_SET_destroy (s->intersection_set); | 284 | GNUNET_SET_destroy(s->intersection_set); |
289 | s->intersection_set = NULL; | 285 | s->intersection_set = NULL; |
290 | } | 286 | } |
291 | if (NULL != s->e_a) | 287 | if (NULL != s->e_a) |
292 | { | 288 | { |
293 | GNUNET_free (s->e_a); | 289 | GNUNET_free(s->e_a); |
294 | s->e_a = NULL; | 290 | s->e_a = NULL; |
295 | } | 291 | } |
296 | if (NULL != s->sorted_elements) | 292 | if (NULL != s->sorted_elements) |
297 | { | 293 | { |
298 | for (i=0;i<s->used_element_count;i++) | 294 | for (i = 0; i < s->used_element_count; i++) |
299 | gcry_mpi_release (s->sorted_elements[i].value); | 295 | gcry_mpi_release(s->sorted_elements[i].value); |
300 | GNUNET_free (s->sorted_elements); | 296 | GNUNET_free(s->sorted_elements); |
301 | s->sorted_elements = NULL; | 297 | s->sorted_elements = NULL; |
302 | } | 298 | } |
303 | if (NULL != s->r) | 299 | if (NULL != s->r) |
304 | { | 300 | { |
305 | GNUNET_free (s->r); | 301 | GNUNET_free(s->r); |
306 | s->r = NULL; | 302 | s->r = NULL; |
307 | } | 303 | } |
308 | if (NULL != s->r_prime) | 304 | if (NULL != s->r_prime) |
309 | { | 305 | { |
310 | GNUNET_free (s->r_prime); | 306 | GNUNET_free(s->r_prime); |
311 | s->r_prime = NULL; | 307 | s->r_prime = NULL; |
312 | } | 308 | } |
313 | if (NULL != s->port) | 309 | if (NULL != s->port) |
314 | { | 310 | { |
315 | GNUNET_CADET_close_port (s->port); | 311 | GNUNET_CADET_close_port(s->port); |
316 | s->port = NULL; | 312 | s->port = NULL; |
317 | } | 313 | } |
318 | if (NULL != s->channel) | 314 | if (NULL != s->channel) |
319 | { | 315 | { |
320 | GNUNET_CADET_channel_destroy (s->channel); | 316 | GNUNET_CADET_channel_destroy(s->channel); |
321 | s->channel = NULL; | 317 | s->channel = NULL; |
322 | } | 318 | } |
323 | GNUNET_free (s); | 319 | GNUNET_free(s); |
324 | } | 320 | } |
325 | 321 | ||
326 | 322 | ||
@@ -332,24 +328,24 @@ destroy_service_session (struct BobServiceSession *s) | |||
332 | * @param session the associated client session to fail or succeed | 328 | * @param session the associated client session to fail or succeed |
333 | */ | 329 | */ |
334 | static void | 330 | static void |
335 | prepare_client_end_notification (struct BobServiceSession *session) | 331 | prepare_client_end_notification(struct BobServiceSession *session) |
336 | { | 332 | { |
337 | struct ClientResponseMessage *msg; | 333 | struct ClientResponseMessage *msg; |
338 | struct GNUNET_MQ_Envelope *e; | 334 | struct GNUNET_MQ_Envelope *e; |
339 | 335 | ||
340 | if (NULL == session->client_mq) | 336 | if (NULL == session->client_mq) |
341 | return; /* no client left to be notified */ | 337 | return; /* no client left to be notified */ |
342 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 338 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
343 | "Sending session-end notification with status %d to client for session %s\n", | 339 | "Sending session-end notification with status %d to client for session %s\n", |
344 | session->status, | 340 | session->status, |
345 | GNUNET_h2s (&session->session_id)); | 341 | GNUNET_h2s(&session->session_id)); |
346 | e = GNUNET_MQ_msg (msg, | 342 | e = GNUNET_MQ_msg(msg, |
347 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 343 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
348 | msg->range = 0; | 344 | msg->range = 0; |
349 | msg->product_length = htonl (0); | 345 | msg->product_length = htonl(0); |
350 | msg->status = htonl (session->status); | 346 | msg->status = htonl(session->status); |
351 | GNUNET_MQ_send (session->client_mq, | 347 | GNUNET_MQ_send(session->client_mq, |
352 | e); | 348 | e); |
353 | } | 349 | } |
354 | 350 | ||
355 | 351 | ||
@@ -363,22 +359,22 @@ prepare_client_end_notification (struct BobServiceSession *session) | |||
363 | * @param channel connection to the other end (henceforth invalid) | 359 | * @param channel connection to the other end (henceforth invalid) |
364 | */ | 360 | */ |
365 | static void | 361 | static void |
366 | cb_channel_destruction (void *cls, | 362 | cb_channel_destruction(void *cls, |
367 | const struct GNUNET_CADET_Channel *channel) | 363 | const struct GNUNET_CADET_Channel *channel) |
368 | { | 364 | { |
369 | struct BobServiceSession *s = cls; | 365 | struct BobServiceSession *s = cls; |
370 | 366 | ||
371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 367 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
372 | "Peer disconnected, terminating session %s with peer %s\n", | 368 | "Peer disconnected, terminating session %s with peer %s\n", |
373 | GNUNET_h2s (&s->session_id), | 369 | GNUNET_h2s(&s->session_id), |
374 | GNUNET_i2s (&s->peer)); | 370 | GNUNET_i2s(&s->peer)); |
375 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) | 371 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) |
376 | { | 372 | { |
377 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 373 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
378 | prepare_client_end_notification (s); | 374 | prepare_client_end_notification(s); |
379 | } | 375 | } |
380 | s->channel = NULL; | 376 | s->channel = NULL; |
381 | destroy_service_session (s); | 377 | destroy_service_session(s); |
382 | } | 378 | } |
383 | 379 | ||
384 | 380 | ||
@@ -387,19 +383,19 @@ cb_channel_destruction (void *cls, | |||
387 | * the client that we are finished. | 383 | * the client that we are finished. |
388 | */ | 384 | */ |
389 | static void | 385 | static void |
390 | bob_cadet_done_cb (void *cls) | 386 | bob_cadet_done_cb(void *cls) |
391 | { | 387 | { |
392 | struct BobServiceSession *session = cls; | 388 | struct BobServiceSession *session = cls; |
393 | 389 | ||
394 | session->status = GNUNET_SCALARPRODUCT_STATUS_SUCCESS; | 390 | session->status = GNUNET_SCALARPRODUCT_STATUS_SUCCESS; |
395 | prepare_client_end_notification (session); | 391 | prepare_client_end_notification(session); |
396 | } | 392 | } |
397 | 393 | ||
398 | 394 | ||
399 | /** | 395 | /** |
400 | * Maximum count of elements we can put into a multipart message | 396 | * Maximum count of elements we can put into a multipart message |
401 | */ | 397 | */ |
402 | #define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct BobCryptodataMultipartMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) | 398 | #define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof(struct BobCryptodataMultipartMessage)) / sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)) |
403 | 399 | ||
404 | 400 | ||
405 | /** | 401 | /** |
@@ -409,7 +405,7 @@ bob_cadet_done_cb (void *cls) | |||
409 | * @param s the associated service session | 405 | * @param s the associated service session |
410 | */ | 406 | */ |
411 | static void | 407 | static void |
412 | transmit_bobs_cryptodata_message_multipart (struct BobServiceSession *s) | 408 | transmit_bobs_cryptodata_message_multipart(struct BobServiceSession *s) |
413 | { | 409 | { |
414 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; | 410 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; |
415 | struct BobCryptodataMultipartMessage *msg; | 411 | struct BobCryptodataMultipartMessage *msg; |
@@ -419,39 +415,39 @@ transmit_bobs_cryptodata_message_multipart (struct BobServiceSession *s) | |||
419 | uint32_t todo_count; | 415 | uint32_t todo_count; |
420 | 416 | ||
421 | while (s->cadet_transmitted_element_count != s->used_element_count) | 417 | while (s->cadet_transmitted_element_count != s->used_element_count) |
422 | { | ||
423 | todo_count = s->used_element_count - s->cadet_transmitted_element_count; | ||
424 | if (todo_count > ELEMENT_CAPACITY / 2) | ||
425 | todo_count = ELEMENT_CAPACITY / 2; | ||
426 | |||
427 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
428 | "Sending %u additional crypto values to Alice\n", | ||
429 | (unsigned int) todo_count); | ||
430 | e = GNUNET_MQ_msg_extra (msg, | ||
431 | todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * 2, | ||
432 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART); | ||
433 | msg->contained_element_count = htonl (todo_count); | ||
434 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | ||
435 | for (i = s->cadet_transmitted_element_count, j = 0; i < s->cadet_transmitted_element_count + todo_count; i++) | ||
436 | { | 418 | { |
437 | //r[i][p] and r[i][q] | 419 | todo_count = s->used_element_count - s->cadet_transmitted_element_count; |
438 | GNUNET_memcpy (&payload[j++], | 420 | if (todo_count > ELEMENT_CAPACITY / 2) |
439 | &s->r[i], | 421 | todo_count = ELEMENT_CAPACITY / 2; |
440 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 422 | |
441 | GNUNET_memcpy (&payload[j++], | 423 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
442 | &s->r_prime[i], | 424 | "Sending %u additional crypto values to Alice\n", |
443 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 425 | (unsigned int)todo_count); |
426 | e = GNUNET_MQ_msg_extra(msg, | ||
427 | todo_count * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) * 2, | ||
428 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART); | ||
429 | msg->contained_element_count = htonl(todo_count); | ||
430 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1]; | ||
431 | for (i = s->cadet_transmitted_element_count, j = 0; i < s->cadet_transmitted_element_count + todo_count; i++) | ||
432 | { | ||
433 | //r[i][p] and r[i][q] | ||
434 | GNUNET_memcpy(&payload[j++], | ||
435 | &s->r[i], | ||
436 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); | ||
437 | GNUNET_memcpy(&payload[j++], | ||
438 | &s->r_prime[i], | ||
439 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); | ||
440 | } | ||
441 | s->cadet_transmitted_element_count += todo_count; | ||
442 | if (s->cadet_transmitted_element_count == s->used_element_count) | ||
443 | GNUNET_MQ_notify_sent(e, | ||
444 | &bob_cadet_done_cb, | ||
445 | s); | ||
446 | GNUNET_MQ_send(s->cadet_mq, | ||
447 | e); | ||
444 | } | 448 | } |
445 | s->cadet_transmitted_element_count += todo_count; | 449 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
446 | if (s->cadet_transmitted_element_count == s->used_element_count) | 450 | "All values queued for Alice, Bob is done\n"); |
447 | GNUNET_MQ_notify_sent (e, | ||
448 | &bob_cadet_done_cb, | ||
449 | s); | ||
450 | GNUNET_MQ_send (s->cadet_mq, | ||
451 | e); | ||
452 | } | ||
453 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
454 | "All values queued for Alice, Bob is done\n"); | ||
455 | } | 451 | } |
456 | 452 | ||
457 | 453 | ||
@@ -467,7 +463,7 @@ transmit_bobs_cryptodata_message_multipart (struct BobServiceSession *s) | |||
467 | * @param s the associated requesting session with Alice | 463 | * @param s the associated requesting session with Alice |
468 | */ | 464 | */ |
469 | static void | 465 | static void |
470 | transmit_bobs_cryptodata_message (struct BobServiceSession *s) | 466 | transmit_bobs_cryptodata_message(struct BobServiceSession *s) |
471 | { | 467 | { |
472 | struct BobCryptodataMessage *msg; | 468 | struct BobCryptodataMessage *msg; |
473 | struct GNUNET_MQ_Envelope *e; | 469 | struct GNUNET_MQ_Envelope *e; |
@@ -475,49 +471,49 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) | |||
475 | unsigned int i; | 471 | unsigned int i; |
476 | 472 | ||
477 | s->cadet_transmitted_element_count | 473 | s->cadet_transmitted_element_count |
478 | = ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct BobCryptodataMessage)) | 474 | = ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof(struct BobCryptodataMessage)) |
479 | / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) / 2) - 1; | 475 | / sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) / 2) - 1; |
480 | if (s->cadet_transmitted_element_count > s->used_element_count) | 476 | if (s->cadet_transmitted_element_count > s->used_element_count) |
481 | s->cadet_transmitted_element_count = s->used_element_count; | 477 | s->cadet_transmitted_element_count = s->used_element_count; |
482 | 478 | ||
483 | e = GNUNET_MQ_msg_extra (msg, | 479 | e = GNUNET_MQ_msg_extra(msg, |
484 | (2 + s->cadet_transmitted_element_count * 2) | 480 | (2 + s->cadet_transmitted_element_count * 2) |
485 | * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), | 481 | * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext), |
486 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); | 482 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); |
487 | msg->contained_element_count = htonl (s->cadet_transmitted_element_count); | 483 | msg->contained_element_count = htonl(s->cadet_transmitted_element_count); |
488 | 484 | ||
489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 485 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
490 | "Sending %u/%u crypto values to Alice\n", | 486 | "Sending %u/%u crypto values to Alice\n", |
491 | (unsigned int) s->cadet_transmitted_element_count, | 487 | (unsigned int)s->cadet_transmitted_element_count, |
492 | (unsigned int) s->used_element_count); | 488 | (unsigned int)s->used_element_count); |
493 | 489 | ||
494 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 490 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1]; |
495 | GNUNET_memcpy (&payload[0], | 491 | GNUNET_memcpy(&payload[0], |
496 | &s->s, | 492 | &s->s, |
497 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 493 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
498 | GNUNET_memcpy (&payload[1], | 494 | GNUNET_memcpy(&payload[1], |
499 | &s->s_prime, | 495 | &s->s_prime, |
500 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 496 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
501 | 497 | ||
502 | payload = &payload[2]; | 498 | payload = &payload[2]; |
503 | // convert k[][] | 499 | // convert k[][] |
504 | for (i = 0; i < s->cadet_transmitted_element_count; i++) | 500 | for (i = 0; i < s->cadet_transmitted_element_count; i++) |
505 | { | 501 | { |
506 | //k[i][p] and k[i][q] | 502 | //k[i][p] and k[i][q] |
507 | GNUNET_memcpy (&payload[i * 2], | 503 | GNUNET_memcpy(&payload[i * 2], |
508 | &s->r[i], | 504 | &s->r[i], |
509 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 505 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
510 | GNUNET_memcpy (&payload[i * 2 + 1], | 506 | GNUNET_memcpy(&payload[i * 2 + 1], |
511 | &s->r_prime[i], | 507 | &s->r_prime[i], |
512 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); | 508 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
513 | } | 509 | } |
514 | if (s->cadet_transmitted_element_count == s->used_element_count) | 510 | if (s->cadet_transmitted_element_count == s->used_element_count) |
515 | GNUNET_MQ_notify_sent (e, | 511 | GNUNET_MQ_notify_sent(e, |
516 | &bob_cadet_done_cb, | 512 | &bob_cadet_done_cb, |
517 | s); | 513 | s); |
518 | GNUNET_MQ_send (s->cadet_mq, | 514 | GNUNET_MQ_send(s->cadet_mq, |
519 | e); | 515 | e); |
520 | transmit_bobs_cryptodata_message_multipart (s); | 516 | transmit_bobs_cryptodata_message_multipart(s); |
521 | } | 517 | } |
522 | #undef ELEMENT_CAPACITY | 518 | #undef ELEMENT_CAPACITY |
523 | 519 | ||
@@ -531,21 +527,21 @@ transmit_bobs_cryptodata_message (struct BobServiceSession *s) | |||
531 | * TODO: code duplication with Alice! | 527 | * TODO: code duplication with Alice! |
532 | */ | 528 | */ |
533 | static gcry_mpi_t | 529 | static gcry_mpi_t |
534 | compute_square_sum (const gcry_mpi_t *vector, | 530 | compute_square_sum(const gcry_mpi_t *vector, |
535 | uint32_t length) | 531 | uint32_t length) |
536 | { | 532 | { |
537 | gcry_mpi_t elem; | 533 | gcry_mpi_t elem; |
538 | gcry_mpi_t sum; | 534 | gcry_mpi_t sum; |
539 | uint32_t i; | 535 | uint32_t i; |
540 | 536 | ||
541 | GNUNET_assert (NULL != (sum = gcry_mpi_new (0))); | 537 | GNUNET_assert(NULL != (sum = gcry_mpi_new(0))); |
542 | GNUNET_assert (NULL != (elem = gcry_mpi_new (0))); | 538 | GNUNET_assert(NULL != (elem = gcry_mpi_new(0))); |
543 | for (i = 0; i < length; i++) | 539 | for (i = 0; i < length; i++) |
544 | { | 540 | { |
545 | gcry_mpi_mul (elem, vector[i], vector[i]); | 541 | gcry_mpi_mul(elem, vector[i], vector[i]); |
546 | gcry_mpi_add (sum, sum, elem); | 542 | gcry_mpi_add(sum, sum, elem); |
547 | } | 543 | } |
548 | gcry_mpi_release (elem); | 544 | gcry_mpi_release(elem); |
549 | return sum; | 545 | return sum; |
550 | } | 546 | } |
551 | 547 | ||
@@ -561,7 +557,7 @@ compute_square_sum (const gcry_mpi_t *vector, | |||
561 | * @return #GNUNET_OK on success | 557 | * @return #GNUNET_OK on success |
562 | */ | 558 | */ |
563 | static int | 559 | static int |
564 | compute_service_response (struct BobServiceSession *session) | 560 | compute_service_response(struct BobServiceSession *session) |
565 | { | 561 | { |
566 | uint32_t i; | 562 | uint32_t i; |
567 | unsigned int *p; | 563 | unsigned int *p; |
@@ -577,125 +573,125 @@ compute_service_response (struct BobServiceSession *session) | |||
577 | count = session->used_element_count; | 573 | count = session->used_element_count; |
578 | a = session->e_a; | 574 | a = session->e_a; |
579 | b = session->sorted_elements; | 575 | b = session->sorted_elements; |
580 | q = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | 576 | q = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, |
581 | count); | 577 | count); |
582 | p = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | 578 | p = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, |
583 | count); | 579 | count); |
584 | rand = GNUNET_malloc (sizeof (gcry_mpi_t) * count); | 580 | rand = GNUNET_malloc(sizeof(gcry_mpi_t) * count); |
585 | for (i = 0; i < count; i++) | 581 | for (i = 0; i < count; i++) |
586 | GNUNET_assert (NULL != (rand[i] = gcry_mpi_new (0))); | 582 | GNUNET_assert(NULL != (rand[i] = gcry_mpi_new(0))); |
587 | r = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * count); | 583 | r = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) * count); |
588 | r_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * count); | 584 | r_prime = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) * count); |
589 | 585 | ||
590 | for (i = 0; i < count; i++) | 586 | for (i = 0; i < count; i++) |
591 | { | 587 | { |
592 | int32_t svalue; | 588 | int32_t svalue; |
593 | 589 | ||
594 | svalue = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 590 | svalue = (int32_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
595 | UINT32_MAX); | 591 | UINT32_MAX); |
596 | // long to gcry_mpi_t | 592 | // long to gcry_mpi_t |
597 | if (svalue < 0) | 593 | if (svalue < 0) |
598 | gcry_mpi_sub_ui (rand[i], | 594 | gcry_mpi_sub_ui(rand[i], |
599 | rand[i], | 595 | rand[i], |
600 | - svalue); | 596 | -svalue); |
601 | else | 597 | else |
602 | rand[i] = gcry_mpi_set_ui (rand[i], svalue); | 598 | rand[i] = gcry_mpi_set_ui(rand[i], svalue); |
603 | } | 599 | } |
604 | 600 | ||
605 | tmp = gcry_mpi_new (0); | 601 | tmp = gcry_mpi_new(0); |
606 | // encrypt the element | 602 | // encrypt the element |
607 | // for the sake of readability I decided to have dedicated permutation | 603 | // for the sake of readability I decided to have dedicated permutation |
608 | // vectors, which get rid of all the lookups in p/q. | 604 | // vectors, which get rid of all the lookups in p/q. |
609 | // however, ap/aq are not absolutely necessary but are just abstraction | 605 | // however, ap/aq are not absolutely necessary but are just abstraction |
610 | // Calculate Kp = E(S + a_pi) (+) E(S - r_pi - b_pi) | 606 | // Calculate Kp = E(S + a_pi) (+) E(S - r_pi - b_pi) |
611 | for (i = 0; i < count; i++) | 607 | for (i = 0; i < count; i++) |
612 | { | 608 | { |
613 | // E(S - r_pi - b_pi) | 609 | // E(S - r_pi - b_pi) |
614 | gcry_mpi_sub (tmp, my_offset, rand[p[i]]); | 610 | gcry_mpi_sub(tmp, my_offset, rand[p[i]]); |
615 | gcry_mpi_sub (tmp, tmp, b[p[i]].value); | 611 | gcry_mpi_sub(tmp, tmp, b[p[i]].value); |
616 | GNUNET_assert (2 == | 612 | GNUNET_assert(2 == |
617 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, | 613 | GNUNET_CRYPTO_paillier_encrypt(&session->remote_pubkey, |
618 | tmp, | 614 | tmp, |
619 | 2, | 615 | 2, |
620 | &r[i])); | 616 | &r[i])); |
621 | 617 | ||
622 | // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b) | 618 | // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b) |
623 | if (GNUNET_OK != | 619 | if (GNUNET_OK != |
624 | GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey, | 620 | GNUNET_CRYPTO_paillier_hom_add(&session->remote_pubkey, |
625 | &r[i], | 621 | &r[i], |
626 | &a[p[i]], | 622 | &a[p[i]], |
627 | &r[i])) | 623 | &r[i])) |
628 | { | 624 | { |
629 | GNUNET_break_op (0); | 625 | GNUNET_break_op(0); |
630 | goto error_cleanup; | 626 | goto error_cleanup; |
627 | } | ||
631 | } | 628 | } |
632 | } | ||
633 | 629 | ||
634 | // Calculate Kq = E(S + a_qi) (+) E(S - r_qi) | 630 | // Calculate Kq = E(S + a_qi) (+) E(S - r_qi) |
635 | for (i = 0; i < count; i++) | 631 | for (i = 0; i < count; i++) |
636 | { | 632 | { |
637 | // E(S - r_qi) | 633 | // E(S - r_qi) |
638 | gcry_mpi_sub (tmp, my_offset, rand[q[i]]); | 634 | gcry_mpi_sub(tmp, my_offset, rand[q[i]]); |
639 | GNUNET_assert (2 == | 635 | GNUNET_assert(2 == |
640 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, | 636 | GNUNET_CRYPTO_paillier_encrypt(&session->remote_pubkey, |
641 | tmp, | 637 | tmp, |
642 | 2, | 638 | 2, |
643 | &r_prime[i])); | 639 | &r_prime[i])); |
644 | 640 | ||
645 | // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi) | 641 | // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi) |
646 | if (GNUNET_OK != | 642 | if (GNUNET_OK != |
647 | GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey, | 643 | GNUNET_CRYPTO_paillier_hom_add(&session->remote_pubkey, |
648 | &r_prime[i], | 644 | &r_prime[i], |
649 | &a[q[i]], | 645 | &a[q[i]], |
650 | &r_prime[i])) | 646 | &r_prime[i])) |
651 | { | 647 | { |
652 | GNUNET_break_op (0); | 648 | GNUNET_break_op(0); |
653 | goto error_cleanup; | 649 | goto error_cleanup; |
650 | } | ||
654 | } | 651 | } |
655 | } | 652 | gcry_mpi_release(tmp); |
656 | gcry_mpi_release (tmp); | ||
657 | 653 | ||
658 | // Calculate S' = E(SUM( r_i^2 )) | 654 | // Calculate S' = E(SUM( r_i^2 )) |
659 | tmp = compute_square_sum (rand, count); | 655 | tmp = compute_square_sum(rand, count); |
660 | GNUNET_assert (1 == | 656 | GNUNET_assert(1 == |
661 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, | 657 | GNUNET_CRYPTO_paillier_encrypt(&session->remote_pubkey, |
662 | tmp, | 658 | tmp, |
663 | 1, | 659 | 1, |
664 | &session->s_prime)); | 660 | &session->s_prime)); |
665 | gcry_mpi_release (tmp); | 661 | gcry_mpi_release(tmp); |
666 | 662 | ||
667 | // Calculate S = E(SUM( (r_i + b_i)^2 )) | 663 | // Calculate S = E(SUM( (r_i + b_i)^2 )) |
668 | for (i = 0; i < count; i++) | 664 | for (i = 0; i < count; i++) |
669 | gcry_mpi_add (rand[i], rand[i], b[i].value); | 665 | gcry_mpi_add(rand[i], rand[i], b[i].value); |
670 | tmp = compute_square_sum (rand, count); | 666 | tmp = compute_square_sum(rand, count); |
671 | GNUNET_assert (1 == | 667 | GNUNET_assert(1 == |
672 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, | 668 | GNUNET_CRYPTO_paillier_encrypt(&session->remote_pubkey, |
673 | tmp, | 669 | tmp, |
674 | 1, | 670 | 1, |
675 | &session->s)); | 671 | &session->s)); |
676 | gcry_mpi_release (tmp); | 672 | gcry_mpi_release(tmp); |
677 | 673 | ||
678 | session->r = r; | 674 | session->r = r; |
679 | session->r_prime = r_prime; | 675 | session->r_prime = r_prime; |
680 | 676 | ||
681 | for (i = 0; i < count; i++) | 677 | for (i = 0; i < count; i++) |
682 | gcry_mpi_release (rand[i]); | 678 | gcry_mpi_release(rand[i]); |
683 | GNUNET_free (session->e_a); | 679 | GNUNET_free(session->e_a); |
684 | session->e_a = NULL; | 680 | session->e_a = NULL; |
685 | GNUNET_free (p); | 681 | GNUNET_free(p); |
686 | GNUNET_free (q); | 682 | GNUNET_free(q); |
687 | GNUNET_free (rand); | 683 | GNUNET_free(rand); |
688 | return GNUNET_OK; | 684 | return GNUNET_OK; |
689 | 685 | ||
690 | error_cleanup: | 686 | error_cleanup: |
691 | GNUNET_free (r); | 687 | GNUNET_free(r); |
692 | GNUNET_free (r_prime); | 688 | GNUNET_free(r_prime); |
693 | gcry_mpi_release (tmp); | 689 | gcry_mpi_release(tmp); |
694 | GNUNET_free (p); | 690 | GNUNET_free(p); |
695 | GNUNET_free (q); | 691 | GNUNET_free(q); |
696 | for (i = 0; i < count; i++) | 692 | for (i = 0; i < count; i++) |
697 | gcry_mpi_release (rand[i]); | 693 | gcry_mpi_release(rand[i]); |
698 | GNUNET_free (rand); | 694 | GNUNET_free(rand); |
699 | return GNUNET_SYSERR; | 695 | return GNUNET_SYSERR; |
700 | } | 696 | } |
701 | 697 | ||
@@ -710,21 +706,21 @@ compute_service_response (struct BobServiceSession *session) | |||
710 | * TODO: code duplication with Alice! | 706 | * TODO: code duplication with Alice! |
711 | */ | 707 | */ |
712 | static int | 708 | static int |
713 | copy_element_cb (void *cls, | 709 | copy_element_cb(void *cls, |
714 | const struct GNUNET_HashCode *key, | 710 | const struct GNUNET_HashCode *key, |
715 | void *value) | 711 | void *value) |
716 | { | 712 | { |
717 | struct BobServiceSession *s = cls; | 713 | struct BobServiceSession *s = cls; |
718 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 714 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
719 | gcry_mpi_t mval; | 715 | gcry_mpi_t mval; |
720 | int64_t val; | 716 | int64_t val; |
721 | 717 | ||
722 | mval = gcry_mpi_new (0); | 718 | mval = gcry_mpi_new(0); |
723 | val = (int64_t) GNUNET_ntohll (e->value); | 719 | val = (int64_t)GNUNET_ntohll(e->value); |
724 | if (0 > val) | 720 | if (0 > val) |
725 | gcry_mpi_sub_ui (mval, mval, -val); | 721 | gcry_mpi_sub_ui(mval, mval, -val); |
726 | else | 722 | else |
727 | gcry_mpi_add_ui (mval, mval, val); | 723 | gcry_mpi_add_ui(mval, mval, val); |
728 | s->sorted_elements [s->used_element_count].value = mval; | 724 | s->sorted_elements [s->used_element_count].value = mval; |
729 | s->sorted_elements [s->used_element_count].key = &e->key; | 725 | s->sorted_elements [s->used_element_count].key = &e->key; |
730 | s->used_element_count++; | 726 | s->used_element_count++; |
@@ -741,14 +737,14 @@ copy_element_cb (void *cls, | |||
741 | * TODO: code duplication with Alice! | 737 | * TODO: code duplication with Alice! |
742 | */ | 738 | */ |
743 | static int | 739 | static int |
744 | element_cmp (const void *a, | 740 | element_cmp(const void *a, |
745 | const void *b) | 741 | const void *b) |
746 | { | 742 | { |
747 | const struct MpiElement *ma = a; | 743 | const struct MpiElement *ma = a; |
748 | const struct MpiElement *mb = b; | 744 | const struct MpiElement *mb = b; |
749 | 745 | ||
750 | return GNUNET_CRYPTO_hash_cmp (ma->key, | 746 | return GNUNET_CRYPTO_hash_cmp(ma->key, |
751 | mb->key); | 747 | mb->key); |
752 | } | 748 | } |
753 | 749 | ||
754 | 750 | ||
@@ -760,33 +756,33 @@ element_cmp (const void *a, | |||
760 | * @param s session to transmit reply for. | 756 | * @param s session to transmit reply for. |
761 | */ | 757 | */ |
762 | static void | 758 | static void |
763 | transmit_cryptographic_reply (struct BobServiceSession *s) | 759 | transmit_cryptographic_reply(struct BobServiceSession *s) |
764 | { | 760 | { |
765 | struct GNUNET_CADET_Channel *channel; | 761 | struct GNUNET_CADET_Channel *channel; |
766 | 762 | ||
767 | /* TODO: code duplication with Alice! */ | 763 | /* TODO: code duplication with Alice! */ |
768 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 764 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
769 | "Received everything, building reply for Alice\n"); | 765 | "Received everything, building reply for Alice\n"); |
770 | s->sorted_elements | 766 | s->sorted_elements |
771 | = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * | 767 | = GNUNET_malloc(GNUNET_CONTAINER_multihashmap_size(s->intersected_elements) * |
772 | sizeof (struct MpiElement)); | 768 | sizeof(struct MpiElement)); |
773 | s->used_element_count = 0; | 769 | s->used_element_count = 0; |
774 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 770 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, |
775 | ©_element_cb, | 771 | ©_element_cb, |
776 | s); | 772 | s); |
777 | qsort (s->sorted_elements, | 773 | qsort(s->sorted_elements, |
778 | s->used_element_count, | 774 | s->used_element_count, |
779 | sizeof (struct MpiElement), | 775 | sizeof(struct MpiElement), |
780 | &element_cmp); | 776 | &element_cmp); |
781 | if (GNUNET_OK != | 777 | if (GNUNET_OK != |
782 | compute_service_response (s)) | 778 | compute_service_response(s)) |
783 | { | 779 | { |
784 | channel = s->channel; | 780 | channel = s->channel; |
785 | s->channel = NULL; | 781 | s->channel = NULL; |
786 | GNUNET_CADET_channel_destroy (channel); | 782 | GNUNET_CADET_channel_destroy(channel); |
787 | return; | 783 | return; |
788 | } | 784 | } |
789 | transmit_bobs_cryptodata_message (s); | 785 | transmit_bobs_cryptodata_message(s); |
790 | } | 786 | } |
791 | 787 | ||
792 | 788 | ||
@@ -800,8 +796,8 @@ transmit_cryptographic_reply (struct BobServiceSession *s) | |||
800 | * #GNUNET_SYSERR to close it (signal serious error) | 796 | * #GNUNET_SYSERR to close it (signal serious error) |
801 | */ | 797 | */ |
802 | static int | 798 | static int |
803 | check_alices_cryptodata_message (void *cls, | 799 | check_alices_cryptodata_message(void *cls, |
804 | const struct AliceCryptodataMessage *msg) | 800 | const struct AliceCryptodataMessage *msg) |
805 | { | 801 | { |
806 | struct BobServiceSession *s = cls; | 802 | struct BobServiceSession *s = cls; |
807 | uint32_t contained_elements; | 803 | uint32_t contained_elements; |
@@ -809,21 +805,21 @@ check_alices_cryptodata_message (void *cls, | |||
809 | uint16_t msize; | 805 | uint16_t msize; |
810 | unsigned int max; | 806 | unsigned int max; |
811 | 807 | ||
812 | msize = ntohs (msg->header.size); | 808 | msize = ntohs(msg->header.size); |
813 | contained_elements = ntohl (msg->contained_element_count); | 809 | contained_elements = ntohl(msg->contained_element_count); |
814 | /* Our intersection may still be ongoing, but this is nevertheless | 810 | /* Our intersection may still be ongoing, but this is nevertheless |
815 | an upper bound on the required array size */ | 811 | an upper bound on the required array size */ |
816 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); | 812 | max = GNUNET_CONTAINER_multihashmap_size(s->intersected_elements); |
817 | msg_length = sizeof (struct AliceCryptodataMessage) | 813 | msg_length = sizeof(struct AliceCryptodataMessage) |
818 | + contained_elements * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); | 814 | + contained_elements * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext); |
819 | if ( (msize != msg_length) || | 815 | if ((msize != msg_length) || |
820 | (0 == contained_elements) || | 816 | (0 == contained_elements) || |
821 | (contained_elements > UINT16_MAX) || | 817 | (contained_elements > UINT16_MAX) || |
822 | (max < contained_elements + s->cadet_received_element_count) ) | 818 | (max < contained_elements + s->cadet_received_element_count)) |
823 | { | 819 | { |
824 | GNUNET_break_op (0); | 820 | GNUNET_break_op(0); |
825 | return GNUNET_SYSERR; | 821 | return GNUNET_SYSERR; |
826 | } | 822 | } |
827 | return GNUNET_OK; | 823 | return GNUNET_OK; |
828 | } | 824 | } |
829 | 825 | ||
@@ -836,40 +832,40 @@ check_alices_cryptodata_message (void *cls, | |||
836 | * @param msg the actual message | 832 | * @param msg the actual message |
837 | */ | 833 | */ |
838 | static void | 834 | static void |
839 | handle_alices_cryptodata_message (void *cls, | 835 | handle_alices_cryptodata_message(void *cls, |
840 | const struct AliceCryptodataMessage *msg) | 836 | const struct AliceCryptodataMessage *msg) |
841 | { | 837 | { |
842 | struct BobServiceSession *s = cls; | 838 | struct BobServiceSession *s = cls; |
843 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; | 839 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; |
844 | uint32_t contained_elements; | 840 | uint32_t contained_elements; |
845 | unsigned int max; | 841 | unsigned int max; |
846 | 842 | ||
847 | contained_elements = ntohl (msg->contained_element_count); | 843 | contained_elements = ntohl(msg->contained_element_count); |
848 | /* Our intersection may still be ongoing, but this is nevertheless | 844 | /* Our intersection may still be ongoing, but this is nevertheless |
849 | an upper bound on the required array size */ | 845 | an upper bound on the required array size */ |
850 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); | 846 | max = GNUNET_CONTAINER_multihashmap_size(s->intersected_elements); |
851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 847 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
852 | "Received %u crypto values from Alice\n", | 848 | "Received %u crypto values from Alice\n", |
853 | (unsigned int) contained_elements); | 849 | (unsigned int)contained_elements); |
854 | 850 | ||
855 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | 851 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1]; |
856 | if (NULL == s->e_a) | 852 | if (NULL == s->e_a) |
857 | s->e_a = GNUNET_new_array (max, | 853 | s->e_a = GNUNET_new_array(max, |
858 | struct GNUNET_CRYPTO_PaillierCiphertext); | 854 | struct GNUNET_CRYPTO_PaillierCiphertext); |
859 | GNUNET_memcpy (&s->e_a[s->cadet_received_element_count], | 855 | GNUNET_memcpy(&s->e_a[s->cadet_received_element_count], |
860 | payload, | 856 | payload, |
861 | sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); | 857 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); |
862 | s->cadet_received_element_count += contained_elements; | 858 | s->cadet_received_element_count += contained_elements; |
863 | 859 | ||
864 | if ( (s->cadet_received_element_count == max) && | 860 | if ((s->cadet_received_element_count == max) && |
865 | (NULL == s->intersection_op) ) | 861 | (NULL == s->intersection_op)) |
866 | { | 862 | { |
867 | /* intersection has finished also on our side, and | 863 | /* intersection has finished also on our side, and |
868 | we got the full set, so we can proceed with the | 864 | we got the full set, so we can proceed with the |
869 | CADET response(s) */ | 865 | CADET response(s) */ |
870 | transmit_cryptographic_reply (s); | 866 | transmit_cryptographic_reply(s); |
871 | } | 867 | } |
872 | GNUNET_CADET_receive_done (s->channel); | 868 | GNUNET_CADET_receive_done(s->channel); |
873 | } | 869 | } |
874 | 870 | ||
875 | 871 | ||
@@ -883,67 +879,71 @@ handle_alices_cryptodata_message (void *cls, | |||
883 | * @param status what has happened with the set intersection? | 879 | * @param status what has happened with the set intersection? |
884 | */ | 880 | */ |
885 | static void | 881 | static void |
886 | cb_intersection_element_removed (void *cls, | 882 | cb_intersection_element_removed(void *cls, |
887 | const struct GNUNET_SET_Element *element, | 883 | const struct GNUNET_SET_Element *element, |
888 | uint64_t current_size, | 884 | uint64_t current_size, |
889 | enum GNUNET_SET_Status status) | 885 | enum GNUNET_SET_Status status) |
890 | { | 886 | { |
891 | struct BobServiceSession *s = cls; | 887 | struct BobServiceSession *s = cls; |
892 | struct GNUNET_SCALARPRODUCT_Element *se; | 888 | struct GNUNET_SCALARPRODUCT_Element *se; |
893 | 889 | ||
894 | switch (status) | 890 | switch (status) |
895 | { | 891 | { |
896 | case GNUNET_SET_STATUS_OK: | 892 | case GNUNET_SET_STATUS_OK: |
897 | /* this element has been removed from the set */ | 893 | /* this element has been removed from the set */ |
898 | se = GNUNET_CONTAINER_multihashmap_get (s->intersected_elements, | 894 | se = GNUNET_CONTAINER_multihashmap_get(s->intersected_elements, |
899 | element->data); | 895 | element->data); |
900 | GNUNET_assert (NULL != se); | 896 | GNUNET_assert(NULL != se); |
901 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 897 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
902 | "Removed element with key %s and value %lld\n", | 898 | "Removed element with key %s and value %lld\n", |
903 | GNUNET_h2s (&se->key), | 899 | GNUNET_h2s(&se->key), |
904 | (long long) GNUNET_ntohll (se->value)); | 900 | (long long)GNUNET_ntohll(se->value)); |
905 | GNUNET_assert (GNUNET_YES == | 901 | GNUNET_assert(GNUNET_YES == |
906 | GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, | 902 | GNUNET_CONTAINER_multihashmap_remove(s->intersected_elements, |
907 | element->data, | 903 | element->data, |
908 | se)); | 904 | se)); |
909 | GNUNET_free (se); | 905 | GNUNET_free(se); |
910 | return; | 906 | return; |
911 | case GNUNET_SET_STATUS_DONE: | 907 | |
912 | s->intersection_op = NULL; | 908 | case GNUNET_SET_STATUS_DONE: |
913 | GNUNET_break (NULL == s->intersection_set); | 909 | s->intersection_op = NULL; |
914 | GNUNET_CADET_receive_done (s->channel); | 910 | GNUNET_break(NULL == s->intersection_set); |
915 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 911 | GNUNET_CADET_receive_done(s->channel); |
916 | "Finished intersection, %d items remain\n", | 912 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
917 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); | 913 | "Finished intersection, %d items remain\n", |
918 | if (s->client_received_element_count == | 914 | GNUNET_CONTAINER_multihashmap_size(s->intersected_elements)); |
919 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)) | 915 | if (s->client_received_element_count == |
920 | { | 916 | GNUNET_CONTAINER_multihashmap_size(s->intersected_elements)) |
921 | /* CADET transmission from Alice is also already done, | 917 | { |
922 | start with our own reply */ | 918 | /* CADET transmission from Alice is also already done, |
923 | transmit_cryptographic_reply (s); | 919 | start with our own reply */ |
920 | transmit_cryptographic_reply(s); | ||
921 | } | ||
922 | return; | ||
923 | |||
924 | case GNUNET_SET_STATUS_HALF_DONE: | ||
925 | /* unexpected for intersection */ | ||
926 | GNUNET_break(0); | ||
927 | return; | ||
928 | |||
929 | case GNUNET_SET_STATUS_FAILURE: | ||
930 | /* unhandled status code */ | ||
931 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
932 | "Set intersection failed!\n"); | ||
933 | s->intersection_op = NULL; | ||
934 | if (NULL != s->intersection_set) | ||
935 | { | ||
936 | GNUNET_SET_destroy(s->intersection_set); | ||
937 | s->intersection_set = NULL; | ||
938 | } | ||
939 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
940 | prepare_client_end_notification(s); | ||
941 | return; | ||
942 | |||
943 | default: | ||
944 | GNUNET_break(0); | ||
945 | return; | ||
924 | } | 946 | } |
925 | return; | ||
926 | case GNUNET_SET_STATUS_HALF_DONE: | ||
927 | /* unexpected for intersection */ | ||
928 | GNUNET_break (0); | ||
929 | return; | ||
930 | case GNUNET_SET_STATUS_FAILURE: | ||
931 | /* unhandled status code */ | ||
932 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
933 | "Set intersection failed!\n"); | ||
934 | s->intersection_op = NULL; | ||
935 | if (NULL != s->intersection_set) | ||
936 | { | ||
937 | GNUNET_SET_destroy (s->intersection_set); | ||
938 | s->intersection_set = NULL; | ||
939 | } | ||
940 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
941 | prepare_client_end_notification (s); | ||
942 | return; | ||
943 | default: | ||
944 | GNUNET_break (0); | ||
945 | return; | ||
946 | } | ||
947 | } | 947 | } |
948 | 948 | ||
949 | 949 | ||
@@ -954,31 +954,31 @@ cb_intersection_element_removed (void *cls, | |||
954 | * @param s client session to start intersection for | 954 | * @param s client session to start intersection for |
955 | */ | 955 | */ |
956 | static void | 956 | static void |
957 | start_intersection (struct BobServiceSession *s) | 957 | start_intersection(struct BobServiceSession *s) |
958 | { | 958 | { |
959 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 959 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
960 | "Got session with key %s and %u elements, starting intersection.\n", | 960 | "Got session with key %s and %u elements, starting intersection.\n", |
961 | GNUNET_h2s (&s->session_id), | 961 | GNUNET_h2s(&s->session_id), |
962 | (unsigned int) s->total); | 962 | (unsigned int)s->total); |
963 | 963 | ||
964 | s->intersection_op | 964 | s->intersection_op |
965 | = GNUNET_SET_prepare (&s->peer, | 965 | = GNUNET_SET_prepare(&s->peer, |
966 | &s->session_id, | 966 | &s->session_id, |
967 | NULL, | 967 | NULL, |
968 | GNUNET_SET_RESULT_REMOVED, | 968 | GNUNET_SET_RESULT_REMOVED, |
969 | (struct GNUNET_SET_Option[]) {{ 0 }}, | 969 | (struct GNUNET_SET_Option[]) { { 0 } }, |
970 | &cb_intersection_element_removed, | 970 | &cb_intersection_element_removed, |
971 | s); | 971 | s); |
972 | if (GNUNET_OK != | 972 | if (GNUNET_OK != |
973 | GNUNET_SET_commit (s->intersection_op, | 973 | GNUNET_SET_commit(s->intersection_op, |
974 | s->intersection_set)) | 974 | s->intersection_set)) |
975 | { | 975 | { |
976 | GNUNET_break (0); | 976 | GNUNET_break(0); |
977 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 977 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
978 | prepare_client_end_notification (s); | 978 | prepare_client_end_notification(s); |
979 | return; | 979 | return; |
980 | } | 980 | } |
981 | GNUNET_SET_destroy (s->intersection_set); | 981 | GNUNET_SET_destroy(s->intersection_set); |
982 | s->intersection_set = NULL; | 982 | s->intersection_set = NULL; |
983 | } | 983 | } |
984 | 984 | ||
@@ -990,15 +990,15 @@ start_intersection (struct BobServiceSession *s) | |||
990 | * @param msg the actual message | 990 | * @param msg the actual message |
991 | */ | 991 | */ |
992 | static void | 992 | static void |
993 | handle_alices_computation_request (void *cls, | 993 | handle_alices_computation_request(void *cls, |
994 | const struct ServiceRequestMessage *msg) | 994 | const struct ServiceRequestMessage *msg) |
995 | { | 995 | { |
996 | struct BobServiceSession *s = cls; | 996 | struct BobServiceSession *s = cls; |
997 | 997 | ||
998 | s->session_id = msg->session_id; // ?? | 998 | s->session_id = msg->session_id; // ?? |
999 | s->remote_pubkey = msg->public_key; | 999 | s->remote_pubkey = msg->public_key; |
1000 | if (s->client_received_element_count == s->total) | 1000 | if (s->client_received_element_count == s->total) |
1001 | start_intersection (s); | 1001 | start_intersection(s); |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | 1004 | ||
@@ -1013,20 +1013,20 @@ handle_alices_computation_request (void *cls, | |||
1013 | * @return session associated with the channel | 1013 | * @return session associated with the channel |
1014 | */ | 1014 | */ |
1015 | static void * | 1015 | static void * |
1016 | cb_channel_incoming (void *cls, | 1016 | cb_channel_incoming(void *cls, |
1017 | struct GNUNET_CADET_Channel *channel, | 1017 | struct GNUNET_CADET_Channel *channel, |
1018 | const struct GNUNET_PeerIdentity *initiator) | 1018 | const struct GNUNET_PeerIdentity *initiator) |
1019 | { | 1019 | { |
1020 | struct BobServiceSession *s = cls; | 1020 | struct BobServiceSession *s = cls; |
1021 | 1021 | ||
1022 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1022 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1023 | "New incoming channel from peer %s.\n", | 1023 | "New incoming channel from peer %s.\n", |
1024 | GNUNET_i2s (initiator)); | 1024 | GNUNET_i2s(initiator)); |
1025 | GNUNET_CADET_close_port (s->port); | 1025 | GNUNET_CADET_close_port(s->port); |
1026 | s->port = NULL; | 1026 | s->port = NULL; |
1027 | s->channel = channel; | 1027 | s->channel = channel; |
1028 | s->peer = *initiator; | 1028 | s->peer = *initiator; |
1029 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); | 1029 | s->cadet_mq = GNUNET_CADET_get_mq(s->channel); |
1030 | return s; | 1030 | return s; |
1031 | } | 1031 | } |
1032 | 1032 | ||
@@ -1039,25 +1039,25 @@ cb_channel_incoming (void *cls, | |||
1039 | * @return #GNUNET_OK if @a msg is well-formed | 1039 | * @return #GNUNET_OK if @a msg is well-formed |
1040 | */ | 1040 | */ |
1041 | static int | 1041 | static int |
1042 | check_bob_client_message_multipart (void *cls, | 1042 | check_bob_client_message_multipart(void *cls, |
1043 | const struct ComputationBobCryptodataMultipartMessage *msg) | 1043 | const struct ComputationBobCryptodataMultipartMessage *msg) |
1044 | { | 1044 | { |
1045 | struct BobServiceSession *s = cls; | 1045 | struct BobServiceSession *s = cls; |
1046 | uint32_t contained_count; | 1046 | uint32_t contained_count; |
1047 | uint16_t msize; | 1047 | uint16_t msize; |
1048 | 1048 | ||
1049 | msize = ntohs (msg->header.size); | 1049 | msize = ntohs(msg->header.size); |
1050 | contained_count = ntohl (msg->element_count_contained); | 1050 | contained_count = ntohl(msg->element_count_contained); |
1051 | if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + | 1051 | if ((msize != (sizeof(struct ComputationBobCryptodataMultipartMessage) + |
1052 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || | 1052 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element))) || |
1053 | (0 == contained_count) || | 1053 | (0 == contained_count) || |
1054 | (UINT16_MAX < contained_count) || | 1054 | (UINT16_MAX < contained_count) || |
1055 | (s->total == s->client_received_element_count) || | 1055 | (s->total == s->client_received_element_count) || |
1056 | (s->total < s->client_received_element_count + contained_count) ) | 1056 | (s->total < s->client_received_element_count + contained_count)) |
1057 | { | 1057 | { |
1058 | GNUNET_break (0); | 1058 | GNUNET_break(0); |
1059 | return GNUNET_SYSERR; | 1059 | return GNUNET_SYSERR; |
1060 | } | 1060 | } |
1061 | return GNUNET_OK; | 1061 | return GNUNET_OK; |
1062 | } | 1062 | } |
1063 | 1063 | ||
@@ -1070,8 +1070,8 @@ check_bob_client_message_multipart (void *cls, | |||
1070 | * @param msg the actual message | 1070 | * @param msg the actual message |
1071 | */ | 1071 | */ |
1072 | static void | 1072 | static void |
1073 | handle_bob_client_message_multipart (void *cls, | 1073 | handle_bob_client_message_multipart(void *cls, |
1074 | const struct ComputationBobCryptodataMultipartMessage *msg) | 1074 | const struct ComputationBobCryptodataMultipartMessage *msg) |
1075 | { | 1075 | { |
1076 | struct BobServiceSession *s = cls; | 1076 | struct BobServiceSession *s = cls; |
1077 | uint32_t contained_count; | 1077 | uint32_t contained_count; |
@@ -1079,44 +1079,44 @@ handle_bob_client_message_multipart (void *cls, | |||
1079 | struct GNUNET_SET_Element set_elem; | 1079 | struct GNUNET_SET_Element set_elem; |
1080 | struct GNUNET_SCALARPRODUCT_Element *elem; | 1080 | struct GNUNET_SCALARPRODUCT_Element *elem; |
1081 | 1081 | ||
1082 | contained_count = ntohl (msg->element_count_contained); | 1082 | contained_count = ntohl(msg->element_count_contained); |
1083 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 1083 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; |
1084 | for (uint32_t i = 0; i < contained_count; i++) | 1084 | for (uint32_t i = 0; i < contained_count; i++) |
1085 | { | ||
1086 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
1087 | GNUNET_memcpy (elem, | ||
1088 | &elements[i], | ||
1089 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | ||
1090 | if (GNUNET_SYSERR == | ||
1091 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, | ||
1092 | &elem->key, | ||
1093 | elem, | ||
1094 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1095 | { | 1085 | { |
1096 | GNUNET_break (0); | 1086 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); |
1097 | GNUNET_free (elem); | 1087 | GNUNET_memcpy(elem, |
1098 | continue; | 1088 | &elements[i], |
1089 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
1090 | if (GNUNET_SYSERR == | ||
1091 | GNUNET_CONTAINER_multihashmap_put(s->intersected_elements, | ||
1092 | &elem->key, | ||
1093 | elem, | ||
1094 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1095 | { | ||
1096 | GNUNET_break(0); | ||
1097 | GNUNET_free(elem); | ||
1098 | continue; | ||
1099 | } | ||
1100 | set_elem.data = &elem->key; | ||
1101 | set_elem.size = sizeof(elem->key); | ||
1102 | set_elem.element_type = 0; | ||
1103 | GNUNET_SET_add_element(s->intersection_set, | ||
1104 | &set_elem, | ||
1105 | NULL, NULL); | ||
1099 | } | 1106 | } |
1100 | set_elem.data = &elem->key; | ||
1101 | set_elem.size = sizeof (elem->key); | ||
1102 | set_elem.element_type = 0; | ||
1103 | GNUNET_SET_add_element (s->intersection_set, | ||
1104 | &set_elem, | ||
1105 | NULL, NULL); | ||
1106 | } | ||
1107 | s->client_received_element_count += contained_count; | 1107 | s->client_received_element_count += contained_count; |
1108 | GNUNET_SERVICE_client_continue (s->client); | 1108 | GNUNET_SERVICE_client_continue(s->client); |
1109 | if (s->total != s->client_received_element_count) | 1109 | if (s->total != s->client_received_element_count) |
1110 | { | 1110 | { |
1111 | /* more to come */ | 1111 | /* more to come */ |
1112 | return; | 1112 | return; |
1113 | } | 1113 | } |
1114 | if (NULL == s->channel) | 1114 | if (NULL == s->channel) |
1115 | { | 1115 | { |
1116 | /* no Alice waiting for this request, wait for Alice */ | 1116 | /* no Alice waiting for this request, wait for Alice */ |
1117 | return; | 1117 | return; |
1118 | } | 1118 | } |
1119 | start_intersection (s); | 1119 | start_intersection(s); |
1120 | } | 1120 | } |
1121 | 1121 | ||
1122 | 1122 | ||
@@ -1129,8 +1129,8 @@ handle_bob_client_message_multipart (void *cls, | |||
1129 | * @return #GNUNET_OK if @a msg is well-formed | 1129 | * @return #GNUNET_OK if @a msg is well-formed |
1130 | */ | 1130 | */ |
1131 | static int | 1131 | static int |
1132 | check_bob_client_message (void *cls, | 1132 | check_bob_client_message(void *cls, |
1133 | const struct BobComputationMessage *msg) | 1133 | const struct BobComputationMessage *msg) |
1134 | { | 1134 | { |
1135 | struct BobServiceSession *s = cls; | 1135 | struct BobServiceSession *s = cls; |
1136 | uint32_t contained_count; | 1136 | uint32_t contained_count; |
@@ -1138,22 +1138,22 @@ check_bob_client_message (void *cls, | |||
1138 | uint16_t msize; | 1138 | uint16_t msize; |
1139 | 1139 | ||
1140 | if (GNUNET_SCALARPRODUCT_STATUS_INIT != s->status) | 1140 | if (GNUNET_SCALARPRODUCT_STATUS_INIT != s->status) |
1141 | { | 1141 | { |
1142 | GNUNET_break (0); | 1142 | GNUNET_break(0); |
1143 | return GNUNET_SYSERR; | 1143 | return GNUNET_SYSERR; |
1144 | } | 1144 | } |
1145 | msize = ntohs (msg->header.size); | 1145 | msize = ntohs(msg->header.size); |
1146 | total_count = ntohl (msg->element_count_total); | 1146 | total_count = ntohl(msg->element_count_total); |
1147 | contained_count = ntohl (msg->element_count_contained); | 1147 | contained_count = ntohl(msg->element_count_contained); |
1148 | if ( (0 == total_count) || | 1148 | if ((0 == total_count) || |
1149 | (0 == contained_count) || | 1149 | (0 == contained_count) || |
1150 | (UINT16_MAX < contained_count) || | 1150 | (UINT16_MAX < contained_count) || |
1151 | (msize != (sizeof (struct BobComputationMessage) + | 1151 | (msize != (sizeof(struct BobComputationMessage) + |
1152 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) | 1152 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element)))) |
1153 | { | 1153 | { |
1154 | GNUNET_break_op (0); | 1154 | GNUNET_break_op(0); |
1155 | return GNUNET_SYSERR; | 1155 | return GNUNET_SYSERR; |
1156 | } | 1156 | } |
1157 | return GNUNET_OK; | 1157 | return GNUNET_OK; |
1158 | } | 1158 | } |
1159 | 1159 | ||
@@ -1167,20 +1167,20 @@ check_bob_client_message (void *cls, | |||
1167 | * @param msg the actual message | 1167 | * @param msg the actual message |
1168 | */ | 1168 | */ |
1169 | static void | 1169 | static void |
1170 | handle_bob_client_message (void *cls, | 1170 | handle_bob_client_message(void *cls, |
1171 | const struct BobComputationMessage *msg) | 1171 | const struct BobComputationMessage *msg) |
1172 | { | 1172 | { |
1173 | struct BobServiceSession *s = cls; | 1173 | struct BobServiceSession *s = cls; |
1174 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 1174 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
1175 | GNUNET_MQ_hd_fixed_size (alices_computation_request, | 1175 | GNUNET_MQ_hd_fixed_size(alices_computation_request, |
1176 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION, | 1176 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION, |
1177 | struct ServiceRequestMessage, | 1177 | struct ServiceRequestMessage, |
1178 | NULL), | 1178 | NULL), |
1179 | GNUNET_MQ_hd_var_size (alices_cryptodata_message, | 1179 | GNUNET_MQ_hd_var_size(alices_cryptodata_message, |
1180 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA, | 1180 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA, |
1181 | struct AliceCryptodataMessage, | 1181 | struct AliceCryptodataMessage, |
1182 | NULL), | 1182 | NULL), |
1183 | GNUNET_MQ_handler_end () | 1183 | GNUNET_MQ_handler_end() |
1184 | }; | 1184 | }; |
1185 | uint32_t contained_count; | 1185 | uint32_t contained_count; |
1186 | uint32_t total_count; | 1186 | uint32_t total_count; |
@@ -1188,61 +1188,61 @@ handle_bob_client_message (void *cls, | |||
1188 | struct GNUNET_SET_Element set_elem; | 1188 | struct GNUNET_SET_Element set_elem; |
1189 | struct GNUNET_SCALARPRODUCT_Element *elem; | 1189 | struct GNUNET_SCALARPRODUCT_Element *elem; |
1190 | 1190 | ||
1191 | total_count = ntohl (msg->element_count_total); | 1191 | total_count = ntohl(msg->element_count_total); |
1192 | contained_count = ntohl (msg->element_count_contained); | 1192 | contained_count = ntohl(msg->element_count_contained); |
1193 | 1193 | ||
1194 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; | 1194 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; |
1195 | s->total = total_count; | 1195 | s->total = total_count; |
1196 | s->client_received_element_count = contained_count; | 1196 | s->client_received_element_count = contained_count; |
1197 | s->session_id = msg->session_key; | 1197 | s->session_id = msg->session_key; |
1198 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 1198 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; |
1199 | s->intersected_elements | 1199 | s->intersected_elements |
1200 | = GNUNET_CONTAINER_multihashmap_create (s->total, | 1200 | = GNUNET_CONTAINER_multihashmap_create(s->total, |
1201 | GNUNET_YES); | 1201 | GNUNET_YES); |
1202 | s->intersection_set | 1202 | s->intersection_set |
1203 | = GNUNET_SET_create (cfg, | 1203 | = GNUNET_SET_create(cfg, |
1204 | GNUNET_SET_OPERATION_INTERSECTION); | 1204 | GNUNET_SET_OPERATION_INTERSECTION); |
1205 | for (uint32_t i = 0; i < contained_count; i++) | 1205 | for (uint32_t i = 0; i < contained_count; i++) |
1206 | { | ||
1207 | if (0 == GNUNET_ntohll (elements[i].value)) | ||
1208 | continue; | ||
1209 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
1210 | GNUNET_memcpy (elem, | ||
1211 | &elements[i], | ||
1212 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | ||
1213 | if (GNUNET_SYSERR == | ||
1214 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, | ||
1215 | &elem->key, | ||
1216 | elem, | ||
1217 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1218 | { | 1206 | { |
1219 | GNUNET_break (0); | 1207 | if (0 == GNUNET_ntohll(elements[i].value)) |
1220 | GNUNET_free (elem); | 1208 | continue; |
1221 | continue; | 1209 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); |
1210 | GNUNET_memcpy(elem, | ||
1211 | &elements[i], | ||
1212 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
1213 | if (GNUNET_SYSERR == | ||
1214 | GNUNET_CONTAINER_multihashmap_put(s->intersected_elements, | ||
1215 | &elem->key, | ||
1216 | elem, | ||
1217 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1218 | { | ||
1219 | GNUNET_break(0); | ||
1220 | GNUNET_free(elem); | ||
1221 | continue; | ||
1222 | } | ||
1223 | set_elem.data = &elem->key; | ||
1224 | set_elem.size = sizeof(elem->key); | ||
1225 | set_elem.element_type = 0; | ||
1226 | GNUNET_SET_add_element(s->intersection_set, | ||
1227 | &set_elem, | ||
1228 | NULL, NULL); | ||
1229 | s->used_element_count++; | ||
1222 | } | 1230 | } |
1223 | set_elem.data = &elem->key; | 1231 | GNUNET_SERVICE_client_continue(s->client); |
1224 | set_elem.size = sizeof (elem->key); | ||
1225 | set_elem.element_type = 0; | ||
1226 | GNUNET_SET_add_element (s->intersection_set, | ||
1227 | &set_elem, | ||
1228 | NULL, NULL); | ||
1229 | s->used_element_count++; | ||
1230 | } | ||
1231 | GNUNET_SERVICE_client_continue (s->client); | ||
1232 | /* We're ready, open the port */ | 1232 | /* We're ready, open the port */ |
1233 | s->port = GNUNET_CADET_open_port (my_cadet, | 1233 | s->port = GNUNET_CADET_open_port(my_cadet, |
1234 | &msg->session_key, | 1234 | &msg->session_key, |
1235 | &cb_channel_incoming, | 1235 | &cb_channel_incoming, |
1236 | s, | 1236 | s, |
1237 | NULL, | 1237 | NULL, |
1238 | &cb_channel_destruction, | 1238 | &cb_channel_destruction, |
1239 | cadet_handlers); | 1239 | cadet_handlers); |
1240 | if (NULL == s->port) | 1240 | if (NULL == s->port) |
1241 | { | 1241 | { |
1242 | GNUNET_break (0); | 1242 | GNUNET_break(0); |
1243 | GNUNET_SERVICE_client_drop (s->client); | 1243 | GNUNET_SERVICE_client_drop(s->client); |
1244 | return; | 1244 | return; |
1245 | } | 1245 | } |
1246 | } | 1246 | } |
1247 | 1247 | ||
1248 | 1248 | ||
@@ -1252,16 +1252,16 @@ handle_bob_client_message (void *cls, | |||
1252 | * @param cls unused | 1252 | * @param cls unused |
1253 | */ | 1253 | */ |
1254 | static void | 1254 | static void |
1255 | shutdown_task (void *cls) | 1255 | shutdown_task(void *cls) |
1256 | { | 1256 | { |
1257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1257 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1258 | "Shutting down, initiating cleanup.\n"); | 1258 | "Shutting down, initiating cleanup.\n"); |
1259 | // FIXME: we have to cut our connections to CADET first! | 1259 | // FIXME: we have to cut our connections to CADET first! |
1260 | if (NULL != my_cadet) | 1260 | if (NULL != my_cadet) |
1261 | { | 1261 | { |
1262 | GNUNET_CADET_disconnect (my_cadet); | 1262 | GNUNET_CADET_disconnect(my_cadet); |
1263 | my_cadet = NULL; | 1263 | my_cadet = NULL; |
1264 | } | 1264 | } |
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | 1267 | ||
@@ -1276,13 +1276,13 @@ shutdown_task (void *cls) | |||
1276 | * @return our `struct BobServiceSession` | 1276 | * @return our `struct BobServiceSession` |
1277 | */ | 1277 | */ |
1278 | static void * | 1278 | static void * |
1279 | client_connect_cb (void *cls, | 1279 | client_connect_cb(void *cls, |
1280 | struct GNUNET_SERVICE_Client *client, | 1280 | struct GNUNET_SERVICE_Client *client, |
1281 | struct GNUNET_MQ_Handle *mq) | 1281 | struct GNUNET_MQ_Handle *mq) |
1282 | { | 1282 | { |
1283 | struct BobServiceSession *s; | 1283 | struct BobServiceSession *s; |
1284 | 1284 | ||
1285 | s = GNUNET_new (struct BobServiceSession); | 1285 | s = GNUNET_new(struct BobServiceSession); |
1286 | s->client = client; | 1286 | s->client = client; |
1287 | s->client_mq = mq; | 1287 | s->client_mq = mq; |
1288 | return s; | 1288 | return s; |
@@ -1300,16 +1300,16 @@ client_connect_cb (void *cls, | |||
1300 | * @param app_cls our `struct BobServiceSession` | 1300 | * @param app_cls our `struct BobServiceSession` |
1301 | */ | 1301 | */ |
1302 | static void | 1302 | static void |
1303 | client_disconnect_cb (void *cls, | 1303 | client_disconnect_cb(void *cls, |
1304 | struct GNUNET_SERVICE_Client *client, | 1304 | struct GNUNET_SERVICE_Client *client, |
1305 | void *app_cls) | 1305 | void *app_cls) |
1306 | { | 1306 | { |
1307 | struct BobServiceSession *s = app_cls; | 1307 | struct BobServiceSession *s = app_cls; |
1308 | 1308 | ||
1309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1309 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1310 | "Client disconnected from us.\n"); | 1310 | "Client disconnected from us.\n"); |
1311 | s->client = NULL; | 1311 | s->client = NULL; |
1312 | destroy_service_session (s); | 1312 | destroy_service_session(s); |
1313 | } | 1313 | } |
1314 | 1314 | ||
1315 | 1315 | ||
@@ -1321,31 +1321,31 @@ client_disconnect_cb (void *cls, | |||
1321 | * @param service the initialized service | 1321 | * @param service the initialized service |
1322 | */ | 1322 | */ |
1323 | static void | 1323 | static void |
1324 | run (void *cls, | 1324 | run(void *cls, |
1325 | const struct GNUNET_CONFIGURATION_Handle *c, | 1325 | const struct GNUNET_CONFIGURATION_Handle *c, |
1326 | struct GNUNET_SERVICE_Handle *service) | 1326 | struct GNUNET_SERVICE_Handle *service) |
1327 | { | 1327 | { |
1328 | cfg = c; | 1328 | cfg = c; |
1329 | /* | 1329 | /* |
1330 | offset has to be sufficiently small to allow computation of: | 1330 | offset has to be sufficiently small to allow computation of: |
1331 | m1+m2 mod n == (S + a) + (S + b) mod n, | 1331 | m1+m2 mod n == (S + a) + (S + b) mod n, |
1332 | if we have more complex operations, this factor needs to be lowered */ | 1332 | if we have more complex operations, this factor needs to be lowered */ |
1333 | my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); | 1333 | my_offset = gcry_mpi_new(GNUNET_CRYPTO_PAILLIER_BITS / 3); |
1334 | gcry_mpi_set_bit (my_offset, | 1334 | gcry_mpi_set_bit(my_offset, |
1335 | GNUNET_CRYPTO_PAILLIER_BITS / 3); | 1335 | GNUNET_CRYPTO_PAILLIER_BITS / 3); |
1336 | 1336 | ||
1337 | GNUNET_CRYPTO_paillier_create (&my_pubkey, | 1337 | GNUNET_CRYPTO_paillier_create(&my_pubkey, |
1338 | &my_privkey); | 1338 | &my_privkey); |
1339 | my_cadet = GNUNET_CADET_connect (cfg); | 1339 | my_cadet = GNUNET_CADET_connect(cfg); |
1340 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 1340 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, |
1341 | NULL); | 1341 | NULL); |
1342 | if (NULL == my_cadet) | 1342 | if (NULL == my_cadet) |
1343 | { | 1343 | { |
1344 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1344 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1345 | _("Connect to CADET failed\n")); | 1345 | _("Connect to CADET failed\n")); |
1346 | GNUNET_SCHEDULER_shutdown (); | 1346 | GNUNET_SCHEDULER_shutdown(); |
1347 | return; | 1347 | return; |
1348 | } | 1348 | } |
1349 | } | 1349 | } |
1350 | 1350 | ||
1351 | 1351 | ||
@@ -1353,21 +1353,21 @@ run (void *cls, | |||
1353 | * Define "main" method using service macro. | 1353 | * Define "main" method using service macro. |
1354 | */ | 1354 | */ |
1355 | GNUNET_SERVICE_MAIN | 1355 | GNUNET_SERVICE_MAIN |
1356 | ("scalarproduct-bob", | 1356 | ("scalarproduct-bob", |
1357 | GNUNET_SERVICE_OPTION_NONE, | 1357 | GNUNET_SERVICE_OPTION_NONE, |
1358 | &run, | 1358 | &run, |
1359 | &client_connect_cb, | 1359 | &client_connect_cb, |
1360 | &client_disconnect_cb, | 1360 | &client_disconnect_cb, |
1361 | NULL, | 1361 | NULL, |
1362 | GNUNET_MQ_hd_var_size (bob_client_message, | 1362 | GNUNET_MQ_hd_var_size(bob_client_message, |
1363 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, | 1363 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, |
1364 | struct BobComputationMessage, | 1364 | struct BobComputationMessage, |
1365 | NULL), | 1365 | NULL), |
1366 | GNUNET_MQ_hd_var_size (bob_client_message_multipart, | 1366 | GNUNET_MQ_hd_var_size(bob_client_message_multipart, |
1367 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, | 1367 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, |
1368 | struct ComputationBobCryptodataMultipartMessage, | 1368 | struct ComputationBobCryptodataMultipartMessage, |
1369 | NULL), | 1369 | NULL), |
1370 | GNUNET_MQ_handler_end ()); | 1370 | GNUNET_MQ_handler_end()); |
1371 | 1371 | ||
1372 | 1372 | ||
1373 | /* end of gnunet-service-scalarproduct_bob.c */ | 1373 | /* end of gnunet-service-scalarproduct_bob.c */ |
diff --git a/src/scalarproduct/scalarproduct.h b/src/scalarproduct/scalarproduct.h index 2a6a5c76c..a3154e587 100644 --- a/src/scalarproduct/scalarproduct.h +++ b/src/scalarproduct/scalarproduct.h | |||
@@ -11,19 +11,19 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file scalarproduct.h | 21 | * @file scalarproduct.h |
22 | * @brief Scalar Product API Message Types | 22 | * @brief Scalar Product API Message Types |
23 | * @author Christian M. Fuchs | 23 | * @author Christian M. Fuchs |
24 | */ | 24 | */ |
25 | #ifndef SCALARPRODUCT_H | 25 | #ifndef SCALARPRODUCT_H |
26 | #define SCALARPRODUCT_H | 26 | #define SCALARPRODUCT_H |
27 | 27 | ||
28 | GNUNET_NETWORK_STRUCT_BEGIN | 28 | GNUNET_NETWORK_STRUCT_BEGIN |
29 | 29 | ||
@@ -32,15 +32,14 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
32 | * a failure of the command 'cmd' with the message given | 32 | * a failure of the command 'cmd' with the message given |
33 | * by gcry_strerror(rc). | 33 | * by gcry_strerror(rc). |
34 | */ | 34 | */ |
35 | #define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while(0) | 35 | #define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while (0) |
36 | 36 | ||
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Message type passed from client to service | 39 | * Message type passed from client to service |
40 | * to initiate a request or responder role | 40 | * to initiate a request or responder role |
41 | */ | 41 | */ |
42 | struct AliceComputationMessage | 42 | struct AliceComputationMessage { |
43 | { | ||
44 | /** | 43 | /** |
45 | * GNUNET message header with type | 44 | * GNUNET message header with type |
46 | * #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE | 45 | * #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE |
@@ -82,8 +81,7 @@ struct AliceComputationMessage | |||
82 | * Message type passed from client to service | 81 | * Message type passed from client to service |
83 | * to initiate a request or responder role | 82 | * to initiate a request or responder role |
84 | */ | 83 | */ |
85 | struct BobComputationMessage | 84 | struct BobComputationMessage { |
86 | { | ||
87 | /** | 85 | /** |
88 | * GNUNET message header with type | 86 | * GNUNET message header with type |
89 | * #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB | 87 | * #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB |
@@ -119,8 +117,7 @@ struct BobComputationMessage | |||
119 | /** | 117 | /** |
120 | * multipart messages following `struct ComputationMessage` | 118 | * multipart messages following `struct ComputationMessage` |
121 | */ | 119 | */ |
122 | struct ComputationBobCryptodataMultipartMessage | 120 | struct ComputationBobCryptodataMultipartMessage { |
123 | { | ||
124 | /** | 121 | /** |
125 | * GNUNET message header | 122 | * GNUNET message header |
126 | */ | 123 | */ |
@@ -141,8 +138,7 @@ struct ComputationBobCryptodataMultipartMessage | |||
141 | * Message type passed from service client | 138 | * Message type passed from service client |
142 | * to finalize a session as requester or responder | 139 | * to finalize a session as requester or responder |
143 | */ | 140 | */ |
144 | struct ClientResponseMessage | 141 | struct ClientResponseMessage { |
145 | { | ||
146 | /** | 142 | /** |
147 | * GNUNET message header | 143 | * GNUNET message header |
148 | */ | 144 | */ |
@@ -171,4 +167,4 @@ struct ClientResponseMessage | |||
171 | 167 | ||
172 | GNUNET_NETWORK_STRUCT_END | 168 | GNUNET_NETWORK_STRUCT_END |
173 | 169 | ||
174 | #endif /* SCALARPRODUCT_H */ | 170 | #endif /* SCALARPRODUCT_H */ |
diff --git a/src/scalarproduct/scalarproduct_api.c b/src/scalarproduct/scalarproduct_api.c index 89aec14bc..5fd810317 100644 --- a/src/scalarproduct/scalarproduct_api.c +++ b/src/scalarproduct/scalarproduct_api.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -31,7 +31,7 @@ | |||
31 | #include "gnunet_protocols.h" | 31 | #include "gnunet_protocols.h" |
32 | #include "scalarproduct.h" | 32 | #include "scalarproduct.h" |
33 | 33 | ||
34 | #define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-api",__VA_ARGS__) | 34 | #define LOG(kind, ...) GNUNET_log_from(kind, "scalarproduct-api", __VA_ARGS__) |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
@@ -50,8 +50,7 @@ typedef void | |||
50 | /** | 50 | /** |
51 | * A handle returned for each computation | 51 | * A handle returned for each computation |
52 | */ | 52 | */ |
53 | struct GNUNET_SCALARPRODUCT_ComputationHandle | 53 | struct GNUNET_SCALARPRODUCT_ComputationHandle { |
54 | { | ||
55 | /** | 54 | /** |
56 | * Our configuration. | 55 | * Our configuration. |
57 | */ | 56 | */ |
@@ -87,7 +86,6 @@ struct GNUNET_SCALARPRODUCT_ComputationHandle | |||
87 | * The shared session key identifying this computation | 86 | * The shared session key identifying this computation |
88 | */ | 87 | */ |
89 | struct GNUNET_HashCode key; | 88 | struct GNUNET_HashCode key; |
90 | |||
91 | }; | 89 | }; |
92 | 90 | ||
93 | 91 | ||
@@ -100,15 +98,15 @@ struct GNUNET_SCALARPRODUCT_ComputationHandle | |||
100 | * @return #GNUNET_OK if @a message is well-formed | 98 | * @return #GNUNET_OK if @a message is well-formed |
101 | */ | 99 | */ |
102 | static int | 100 | static int |
103 | check_response (void *cls, | 101 | check_response(void *cls, |
104 | const struct ClientResponseMessage *message) | 102 | const struct ClientResponseMessage *message) |
105 | { | 103 | { |
106 | if (ntohs (message->header.size) != | 104 | if (ntohs(message->header.size) != |
107 | ntohl (message->product_length) + sizeof (struct ClientResponseMessage)) | 105 | ntohl(message->product_length) + sizeof(struct ClientResponseMessage)) |
108 | { | 106 | { |
109 | GNUNET_break (0); | 107 | GNUNET_break(0); |
110 | return GNUNET_SYSERR; | 108 | return GNUNET_SYSERR; |
111 | } | 109 | } |
112 | return GNUNET_OK; | 110 | return GNUNET_OK; |
113 | } | 111 | } |
114 | 112 | ||
@@ -123,14 +121,14 @@ check_response (void *cls, | |||
123 | * @param status the condition the request was terminated with (eg: disconnect) | 121 | * @param status the condition the request was terminated with (eg: disconnect) |
124 | */ | 122 | */ |
125 | static void | 123 | static void |
126 | process_status_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h, | 124 | process_status_message(struct GNUNET_SCALARPRODUCT_ComputationHandle *h, |
127 | const struct ClientResponseMessage *msg, | 125 | const struct ClientResponseMessage *msg, |
128 | enum GNUNET_SCALARPRODUCT_ResponseStatus status) | 126 | enum GNUNET_SCALARPRODUCT_ResponseStatus status) |
129 | { | 127 | { |
130 | if (NULL != h->cont_status) | 128 | if (NULL != h->cont_status) |
131 | h->cont_status (h->cont_cls, | 129 | h->cont_status(h->cont_cls, |
132 | status); | 130 | status); |
133 | GNUNET_SCALARPRODUCT_cancel (h); | 131 | GNUNET_SCALARPRODUCT_cancel(h); |
134 | } | 132 | } |
135 | 133 | ||
136 | 134 | ||
@@ -143,16 +141,16 @@ process_status_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h, | |||
143 | * @param msg Pointer to the data received in response | 141 | * @param msg Pointer to the data received in response |
144 | */ | 142 | */ |
145 | static void | 143 | static void |
146 | handle_response (void *cls, | 144 | handle_response(void *cls, |
147 | const struct ClientResponseMessage *message) | 145 | const struct ClientResponseMessage *message) |
148 | { | 146 | { |
149 | struct GNUNET_SCALARPRODUCT_ComputationHandle *h = cls; | 147 | struct GNUNET_SCALARPRODUCT_ComputationHandle *h = cls; |
150 | enum GNUNET_SCALARPRODUCT_ResponseStatus status; | 148 | enum GNUNET_SCALARPRODUCT_ResponseStatus status; |
151 | 149 | ||
152 | status = (enum GNUNET_SCALARPRODUCT_ResponseStatus) ntohl (message->status); | 150 | status = (enum GNUNET_SCALARPRODUCT_ResponseStatus)ntohl(message->status); |
153 | h->response_proc (h, | 151 | h->response_proc(h, |
154 | message, | 152 | message, |
155 | status); | 153 | status); |
156 | } | 154 | } |
157 | 155 | ||
158 | 156 | ||
@@ -164,28 +162,28 @@ handle_response (void *cls, | |||
164 | * @return #GNUNET_OK if all keys are unique | 162 | * @return #GNUNET_OK if all keys are unique |
165 | */ | 163 | */ |
166 | static int | 164 | static int |
167 | check_unique (const struct GNUNET_SCALARPRODUCT_Element *elements, | 165 | check_unique(const struct GNUNET_SCALARPRODUCT_Element *elements, |
168 | uint32_t element_count) | 166 | uint32_t element_count) |
169 | { | 167 | { |
170 | struct GNUNET_CONTAINER_MultiHashMap *map; | 168 | struct GNUNET_CONTAINER_MultiHashMap *map; |
171 | uint32_t i; | 169 | uint32_t i; |
172 | int ok; | 170 | int ok; |
173 | 171 | ||
174 | ok = GNUNET_OK; | 172 | ok = GNUNET_OK; |
175 | map = GNUNET_CONTAINER_multihashmap_create (2 * element_count, | 173 | map = GNUNET_CONTAINER_multihashmap_create(2 * element_count, |
176 | GNUNET_YES); | 174 | GNUNET_YES); |
177 | for (i=0;i<element_count;i++) | 175 | for (i = 0; i < element_count; i++) |
178 | if (GNUNET_OK != | 176 | if (GNUNET_OK != |
179 | GNUNET_CONTAINER_multihashmap_put (map, | 177 | GNUNET_CONTAINER_multihashmap_put(map, |
180 | &elements[i].key, | 178 | &elements[i].key, |
181 | map, | 179 | map, |
182 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 180 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
183 | { | 181 | { |
184 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 182 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
185 | _("Keys given to SCALARPRODUCT not unique!\n")); | 183 | _("Keys given to SCALARPRODUCT not unique!\n")); |
186 | ok = GNUNET_SYSERR; | 184 | ok = GNUNET_SYSERR; |
187 | } | 185 | } |
188 | GNUNET_CONTAINER_multihashmap_destroy (map); | 186 | GNUNET_CONTAINER_multihashmap_destroy(map); |
189 | return ok; | 187 | return ok; |
190 | } | 188 | } |
191 | 189 | ||
@@ -198,16 +196,16 @@ check_unique (const struct GNUNET_SCALARPRODUCT_Element *elements, | |||
198 | * @param error error code | 196 | * @param error error code |
199 | */ | 197 | */ |
200 | static void | 198 | static void |
201 | mq_error_handler (void *cls, | 199 | mq_error_handler(void *cls, |
202 | enum GNUNET_MQ_Error error) | 200 | enum GNUNET_MQ_Error error) |
203 | { | 201 | { |
204 | struct GNUNET_SCALARPRODUCT_ComputationHandle *h = cls; | 202 | struct GNUNET_SCALARPRODUCT_ComputationHandle *h = cls; |
205 | 203 | ||
206 | LOG (GNUNET_ERROR_TYPE_INFO, | 204 | LOG(GNUNET_ERROR_TYPE_INFO, |
207 | "Disconnected from SCALARPRODUCT service.\n"); | 205 | "Disconnected from SCALARPRODUCT service.\n"); |
208 | h->response_proc (h, | 206 | h->response_proc(h, |
209 | NULL, | 207 | NULL, |
210 | GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED); | 208 | GNUNET_SCALARPRODUCT_STATUS_DISCONNECTED); |
211 | } | 209 | } |
212 | 210 | ||
213 | 211 | ||
@@ -223,21 +221,21 @@ mq_error_handler (void *cls, | |||
223 | * @return a new handle for this computation | 221 | * @return a new handle for this computation |
224 | */ | 222 | */ |
225 | struct GNUNET_SCALARPRODUCT_ComputationHandle * | 223 | struct GNUNET_SCALARPRODUCT_ComputationHandle * |
226 | GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handle *cfg, | 224 | GNUNET_SCALARPRODUCT_accept_computation(const struct GNUNET_CONFIGURATION_Handle *cfg, |
227 | const struct GNUNET_HashCode *session_key, | 225 | const struct GNUNET_HashCode *session_key, |
228 | const struct GNUNET_SCALARPRODUCT_Element *elements, | 226 | const struct GNUNET_SCALARPRODUCT_Element *elements, |
229 | uint32_t element_count, | 227 | uint32_t element_count, |
230 | GNUNET_SCALARPRODUCT_ContinuationWithStatus cont, | 228 | GNUNET_SCALARPRODUCT_ContinuationWithStatus cont, |
231 | void *cont_cls) | 229 | void *cont_cls) |
232 | { | 230 | { |
233 | struct GNUNET_SCALARPRODUCT_ComputationHandle *h | 231 | struct GNUNET_SCALARPRODUCT_ComputationHandle *h |
234 | = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle); | 232 | = GNUNET_new(struct GNUNET_SCALARPRODUCT_ComputationHandle); |
235 | struct GNUNET_MQ_MessageHandler handlers[] = { | 233 | struct GNUNET_MQ_MessageHandler handlers[] = { |
236 | GNUNET_MQ_hd_var_size (response, | 234 | GNUNET_MQ_hd_var_size(response, |
237 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, | 235 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, |
238 | struct ClientResponseMessage, | 236 | struct ClientResponseMessage, |
239 | h), | 237 | h), |
240 | GNUNET_MQ_handler_end () | 238 | GNUNET_MQ_handler_end() |
241 | }; | 239 | }; |
242 | struct GNUNET_MQ_Envelope *env; | 240 | struct GNUNET_MQ_Envelope *env; |
243 | struct BobComputationMessage *msg; | 241 | struct BobComputationMessage *msg; |
@@ -248,61 +246,61 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl | |||
248 | uint32_t element_count_transfered; | 246 | uint32_t element_count_transfered; |
249 | 247 | ||
250 | 248 | ||
251 | if (GNUNET_SYSERR == check_unique (elements, | 249 | if (GNUNET_SYSERR == check_unique(elements, |
252 | element_count)) | 250 | element_count)) |
253 | return NULL; | 251 | return NULL; |
254 | h->cont_status = cont; | 252 | h->cont_status = cont; |
255 | h->cont_cls = cont_cls; | 253 | h->cont_cls = cont_cls; |
256 | h->response_proc = &process_status_message; | 254 | h->response_proc = &process_status_message; |
257 | h->cfg = cfg; | 255 | h->cfg = cfg; |
258 | h->key = *session_key; | 256 | h->key = *session_key; |
259 | h->mq = GNUNET_CLIENT_connect (cfg, | 257 | h->mq = GNUNET_CLIENT_connect(cfg, |
260 | "scalarproduct-bob", | 258 | "scalarproduct-bob", |
261 | handlers, | 259 | handlers, |
262 | &mq_error_handler, | 260 | &mq_error_handler, |
263 | h); | 261 | h); |
264 | if (NULL == h->mq) | 262 | if (NULL == h->mq) |
265 | { | 263 | { |
266 | /* scalarproduct configuration error */ | 264 | /* scalarproduct configuration error */ |
267 | GNUNET_break (0); | 265 | GNUNET_break(0); |
268 | GNUNET_free (h); | 266 | GNUNET_free(h); |
269 | return NULL; | 267 | return NULL; |
270 | } | 268 | } |
271 | possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (struct BobComputationMessage)) | 269 | possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(struct BobComputationMessage)) |
272 | / sizeof (struct GNUNET_SCALARPRODUCT_Element); | 270 | / sizeof(struct GNUNET_SCALARPRODUCT_Element); |
273 | todo = GNUNET_MIN (possible, | 271 | todo = GNUNET_MIN(possible, |
274 | element_count); | 272 | element_count); |
275 | size = todo * sizeof (struct GNUNET_SCALARPRODUCT_Element); | 273 | size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element); |
276 | env = GNUNET_MQ_msg_extra (msg, | 274 | env = GNUNET_MQ_msg_extra(msg, |
277 | size, | 275 | size, |
278 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB); | 276 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB); |
279 | msg->element_count_total = htonl (element_count); | 277 | msg->element_count_total = htonl(element_count); |
280 | msg->element_count_contained = htonl (todo); | 278 | msg->element_count_contained = htonl(todo); |
281 | msg->session_key = *session_key; | 279 | msg->session_key = *session_key; |
282 | GNUNET_memcpy (&msg[1], | 280 | GNUNET_memcpy(&msg[1], |
283 | elements, | 281 | elements, |
284 | size); | 282 | size); |
285 | element_count_transfered = todo; | 283 | element_count_transfered = todo; |
286 | GNUNET_MQ_send (h->mq, | 284 | GNUNET_MQ_send(h->mq, |
287 | env); | 285 | env); |
288 | possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (*mmsg)) | 286 | possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*mmsg)) |
289 | / sizeof (struct GNUNET_SCALARPRODUCT_Element); | 287 | / sizeof(struct GNUNET_SCALARPRODUCT_Element); |
290 | while (element_count_transfered < element_count) | 288 | while (element_count_transfered < element_count) |
291 | { | 289 | { |
292 | todo = GNUNET_MIN (possible, | 290 | todo = GNUNET_MIN(possible, |
293 | element_count - element_count_transfered); | 291 | element_count - element_count_transfered); |
294 | size = todo * sizeof (struct GNUNET_SCALARPRODUCT_Element); | 292 | size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element); |
295 | env = GNUNET_MQ_msg_extra (mmsg, | 293 | env = GNUNET_MQ_msg_extra(mmsg, |
296 | size, | 294 | size, |
297 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB); | 295 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB); |
298 | mmsg->element_count_contained = htonl (todo); | 296 | mmsg->element_count_contained = htonl(todo); |
299 | GNUNET_memcpy (&mmsg[1], | 297 | GNUNET_memcpy(&mmsg[1], |
300 | &elements[element_count_transfered], | 298 | &elements[element_count_transfered], |
301 | size); | 299 | size); |
302 | element_count_transfered += todo; | 300 | element_count_transfered += todo; |
303 | GNUNET_MQ_send (h->mq, | 301 | GNUNET_MQ_send(h->mq, |
304 | env); | 302 | env); |
305 | } | 303 | } |
306 | return h; | 304 | return h; |
307 | } | 305 | } |
308 | 306 | ||
@@ -317,9 +315,9 @@ GNUNET_SCALARPRODUCT_accept_computation (const struct GNUNET_CONFIGURATION_Handl | |||
317 | * @param status the condition the request was terminated with (eg: disconnect) | 315 | * @param status the condition the request was terminated with (eg: disconnect) |
318 | */ | 316 | */ |
319 | static void | 317 | static void |
320 | process_result_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h, | 318 | process_result_message(struct GNUNET_SCALARPRODUCT_ComputationHandle *h, |
321 | const struct ClientResponseMessage *msg, | 319 | const struct ClientResponseMessage *msg, |
322 | enum GNUNET_SCALARPRODUCT_ResponseStatus status) | 320 | enum GNUNET_SCALARPRODUCT_ResponseStatus status) |
323 | { | 321 | { |
324 | uint32_t product_len; | 322 | uint32_t product_len; |
325 | gcry_mpi_t result = NULL; | 323 | gcry_mpi_t result = NULL; |
@@ -328,42 +326,42 @@ process_result_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h, | |||
328 | size_t rsize; | 326 | size_t rsize; |
329 | 327 | ||
330 | if (GNUNET_SCALARPRODUCT_STATUS_SUCCESS == status) | 328 | if (GNUNET_SCALARPRODUCT_STATUS_SUCCESS == status) |
331 | { | ||
332 | result = gcry_mpi_new (0); | ||
333 | |||
334 | product_len = ntohl (msg->product_length); | ||
335 | if (0 < product_len) | ||
336 | { | 329 | { |
337 | rsize = 0; | 330 | result = gcry_mpi_new(0); |
338 | if (0 != (rc = gcry_mpi_scan (&num, GCRYMPI_FMT_STD, | 331 | |
339 | &msg[1], | 332 | product_len = ntohl(msg->product_length); |
340 | product_len, | 333 | if (0 < product_len) |
341 | &rsize))) | 334 | { |
342 | { | 335 | rsize = 0; |
343 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, | 336 | if (0 != (rc = gcry_mpi_scan(&num, GCRYMPI_FMT_STD, |
344 | "gcry_mpi_scan", | 337 | &msg[1], |
345 | rc); | 338 | product_len, |
346 | gcry_mpi_release (result); | 339 | &rsize))) |
347 | result = NULL; | 340 | { |
348 | status = GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE; | 341 | LOG_GCRY(GNUNET_ERROR_TYPE_ERROR, |
349 | } | 342 | "gcry_mpi_scan", |
350 | else | 343 | rc); |
351 | { | 344 | gcry_mpi_release(result); |
352 | if (0 < (int32_t) ntohl (msg->range)) | 345 | result = NULL; |
353 | gcry_mpi_add (result, result, num); | 346 | status = GNUNET_SCALARPRODUCT_STATUS_INVALID_RESPONSE; |
354 | else | 347 | } |
355 | gcry_mpi_sub (result, result, num); | 348 | else |
356 | gcry_mpi_release (num); | 349 | { |
357 | } | 350 | if (0 < (int32_t)ntohl(msg->range)) |
351 | gcry_mpi_add(result, result, num); | ||
352 | else | ||
353 | gcry_mpi_sub(result, result, num); | ||
354 | gcry_mpi_release(num); | ||
355 | } | ||
356 | } | ||
358 | } | 357 | } |
359 | } | ||
360 | if (NULL != h->cont_datum) | 358 | if (NULL != h->cont_datum) |
361 | h->cont_datum (h->cont_cls, | 359 | h->cont_datum(h->cont_cls, |
362 | status, | 360 | status, |
363 | result); | 361 | result); |
364 | if (NULL != result) | 362 | if (NULL != result) |
365 | gcry_mpi_release (result); | 363 | gcry_mpi_release(result); |
366 | GNUNET_SCALARPRODUCT_cancel (h); | 364 | GNUNET_SCALARPRODUCT_cancel(h); |
367 | } | 365 | } |
368 | 366 | ||
369 | 367 | ||
@@ -380,22 +378,22 @@ process_result_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h, | |||
380 | * @return a new handle for this computation | 378 | * @return a new handle for this computation |
381 | */ | 379 | */ |
382 | struct GNUNET_SCALARPRODUCT_ComputationHandle * | 380 | struct GNUNET_SCALARPRODUCT_ComputationHandle * |
383 | GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle *cfg, | 381 | GNUNET_SCALARPRODUCT_start_computation(const struct GNUNET_CONFIGURATION_Handle *cfg, |
384 | const struct GNUNET_HashCode *session_key, | 382 | const struct GNUNET_HashCode *session_key, |
385 | const struct GNUNET_PeerIdentity *peer, | 383 | const struct GNUNET_PeerIdentity *peer, |
386 | const struct GNUNET_SCALARPRODUCT_Element *elements, | 384 | const struct GNUNET_SCALARPRODUCT_Element *elements, |
387 | uint32_t element_count, | 385 | uint32_t element_count, |
388 | GNUNET_SCALARPRODUCT_DatumProcessor cont, | 386 | GNUNET_SCALARPRODUCT_DatumProcessor cont, |
389 | void *cont_cls) | 387 | void *cont_cls) |
390 | { | 388 | { |
391 | struct GNUNET_SCALARPRODUCT_ComputationHandle *h | 389 | struct GNUNET_SCALARPRODUCT_ComputationHandle *h |
392 | = GNUNET_new (struct GNUNET_SCALARPRODUCT_ComputationHandle); | 390 | = GNUNET_new(struct GNUNET_SCALARPRODUCT_ComputationHandle); |
393 | struct GNUNET_MQ_MessageHandler handlers[] = { | 391 | struct GNUNET_MQ_MessageHandler handlers[] = { |
394 | GNUNET_MQ_hd_var_size (response, | 392 | GNUNET_MQ_hd_var_size(response, |
395 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, | 393 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT, |
396 | struct ClientResponseMessage, | 394 | struct ClientResponseMessage, |
397 | h), | 395 | h), |
398 | GNUNET_MQ_handler_end () | 396 | GNUNET_MQ_handler_end() |
399 | }; | 397 | }; |
400 | struct GNUNET_MQ_Envelope *env; | 398 | struct GNUNET_MQ_Envelope *env; |
401 | struct AliceComputationMessage *msg; | 399 | struct AliceComputationMessage *msg; |
@@ -405,64 +403,64 @@ GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle | |||
405 | uint16_t todo; | 403 | uint16_t todo; |
406 | uint32_t element_count_transfered; | 404 | uint32_t element_count_transfered; |
407 | 405 | ||
408 | if (GNUNET_SYSERR == check_unique (elements, | 406 | if (GNUNET_SYSERR == check_unique(elements, |
409 | element_count)) | 407 | element_count)) |
410 | return NULL; | 408 | return NULL; |
411 | h->mq = GNUNET_CLIENT_connect (cfg, | 409 | h->mq = GNUNET_CLIENT_connect(cfg, |
412 | "scalarproduct-alice", | 410 | "scalarproduct-alice", |
413 | handlers, | 411 | handlers, |
414 | &mq_error_handler, | 412 | &mq_error_handler, |
415 | h); | 413 | h); |
416 | if (NULL == h->mq) | 414 | if (NULL == h->mq) |
417 | { | 415 | { |
418 | /* missconfigured scalarproduct service */ | 416 | /* missconfigured scalarproduct service */ |
419 | GNUNET_break (0); | 417 | GNUNET_break(0); |
420 | GNUNET_free (h); | 418 | GNUNET_free(h); |
421 | return NULL; | 419 | return NULL; |
422 | } | 420 | } |
423 | h->cont_datum = cont; | 421 | h->cont_datum = cont; |
424 | h->cont_cls = cont_cls; | 422 | h->cont_cls = cont_cls; |
425 | h->response_proc = &process_result_message; | 423 | h->response_proc = &process_result_message; |
426 | h->cfg = cfg; | 424 | h->cfg = cfg; |
427 | h->key = *session_key; | 425 | h->key = *session_key; |
428 | 426 | ||
429 | possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (struct AliceComputationMessage)) | 427 | possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(struct AliceComputationMessage)) |
430 | / sizeof (struct GNUNET_SCALARPRODUCT_Element); | 428 | / sizeof(struct GNUNET_SCALARPRODUCT_Element); |
431 | todo = GNUNET_MIN (possible, | 429 | todo = GNUNET_MIN(possible, |
432 | element_count); | 430 | element_count); |
433 | size = todo * sizeof (struct GNUNET_SCALARPRODUCT_Element); | 431 | size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element); |
434 | env = GNUNET_MQ_msg_extra (msg, | 432 | env = GNUNET_MQ_msg_extra(msg, |
435 | size, | 433 | size, |
436 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE); | 434 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE); |
437 | msg->element_count_total = htonl (element_count); | 435 | msg->element_count_total = htonl(element_count); |
438 | msg->element_count_contained = htonl (todo); | 436 | msg->element_count_contained = htonl(todo); |
439 | msg->reserved = htonl (0); | 437 | msg->reserved = htonl(0); |
440 | msg->peer = *peer; | 438 | msg->peer = *peer; |
441 | msg->session_key = *session_key; | 439 | msg->session_key = *session_key; |
442 | GNUNET_memcpy (&msg[1], | 440 | GNUNET_memcpy(&msg[1], |
443 | elements, | 441 | elements, |
444 | size); | 442 | size); |
445 | GNUNET_MQ_send (h->mq, | 443 | GNUNET_MQ_send(h->mq, |
446 | env); | 444 | env); |
447 | element_count_transfered = todo; | 445 | element_count_transfered = todo; |
448 | possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof (*mmsg)) | 446 | possible = (GNUNET_MAX_MESSAGE_SIZE - 1 - sizeof(*mmsg)) |
449 | / sizeof (struct GNUNET_SCALARPRODUCT_Element); | 447 | / sizeof(struct GNUNET_SCALARPRODUCT_Element); |
450 | while (element_count_transfered < element_count) | 448 | while (element_count_transfered < element_count) |
451 | { | 449 | { |
452 | todo = GNUNET_MIN (possible, | 450 | todo = GNUNET_MIN(possible, |
453 | element_count - element_count_transfered); | 451 | element_count - element_count_transfered); |
454 | size = todo * sizeof (struct GNUNET_SCALARPRODUCT_Element); | 452 | size = todo * sizeof(struct GNUNET_SCALARPRODUCT_Element); |
455 | env = GNUNET_MQ_msg_extra (mmsg, | 453 | env = GNUNET_MQ_msg_extra(mmsg, |
456 | size, | 454 | size, |
457 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE); | 455 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE); |
458 | mmsg->element_count_contained = htonl (todo); | 456 | mmsg->element_count_contained = htonl(todo); |
459 | GNUNET_memcpy (&mmsg[1], | 457 | GNUNET_memcpy(&mmsg[1], |
460 | &elements[element_count_transfered], | 458 | &elements[element_count_transfered], |
461 | size); | 459 | size); |
462 | element_count_transfered += todo; | 460 | element_count_transfered += todo; |
463 | GNUNET_MQ_send (h->mq, | 461 | GNUNET_MQ_send(h->mq, |
464 | env); | 462 | env); |
465 | } | 463 | } |
466 | return h; | 464 | return h; |
467 | } | 465 | } |
468 | 466 | ||
@@ -474,14 +472,14 @@ GNUNET_SCALARPRODUCT_start_computation (const struct GNUNET_CONFIGURATION_Handle | |||
474 | * @param h computation handle to terminate | 472 | * @param h computation handle to terminate |
475 | */ | 473 | */ |
476 | void | 474 | void |
477 | GNUNET_SCALARPRODUCT_cancel (struct GNUNET_SCALARPRODUCT_ComputationHandle *h) | 475 | GNUNET_SCALARPRODUCT_cancel(struct GNUNET_SCALARPRODUCT_ComputationHandle *h) |
478 | { | 476 | { |
479 | if (NULL != h->mq) | 477 | if (NULL != h->mq) |
480 | { | 478 | { |
481 | GNUNET_MQ_destroy (h->mq); | 479 | GNUNET_MQ_destroy(h->mq); |
482 | h->mq = NULL; | 480 | h->mq = NULL; |
483 | } | 481 | } |
484 | GNUNET_free (h); | 482 | GNUNET_free(h); |
485 | } | 483 | } |
486 | 484 | ||
487 | 485 | ||
diff --git a/src/scalarproduct/test_ecc_scalarproduct.c b/src/scalarproduct/test_ecc_scalarproduct.c index f078ab37d..543ac4c7e 100644 --- a/src/scalarproduct/test_ecc_scalarproduct.c +++ b/src/scalarproduct/test_ecc_scalarproduct.c | |||
@@ -11,13 +11,13 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | 19 | ||
20 | */ | 20 | */ |
21 | /** | 21 | /** |
22 | * @file util/test_ecc_scalarproduct.c | 22 | * @file util/test_ecc_scalarproduct.c |
23 | * @brief testcase for math behind ECC SP calculation | 23 | * @brief testcase for math behind ECC SP calculation |
@@ -41,8 +41,8 @@ static struct GNUNET_CRYPTO_EccDlogContext *edc; | |||
41 | * @return avec * bvec | 41 | * @return avec * bvec |
42 | */ | 42 | */ |
43 | static int | 43 | static int |
44 | test_sp (const unsigned int *avec, | 44 | test_sp(const unsigned int *avec, |
45 | const unsigned int *bvec) | 45 | const unsigned int *bvec) |
46 | { | 46 | { |
47 | unsigned int len; | 47 | unsigned int len; |
48 | unsigned int i; | 48 | unsigned int i; |
@@ -61,114 +61,115 @@ test_sp (const unsigned int *avec, | |||
61 | int sp; | 61 | int sp; |
62 | 62 | ||
63 | /* determine length */ | 63 | /* determine length */ |
64 | for (len=0;0 != avec[len];len++) ; | 64 | for (len = 0; 0 != avec[len]; len++) |
65 | ; | ||
65 | if (0 == len) | 66 | if (0 == len) |
66 | return 0; | 67 | return 0; |
67 | 68 | ||
68 | /* Alice */ | 69 | /* Alice */ |
69 | GNUNET_CRYPTO_ecc_rnd_mpi (edc, | 70 | GNUNET_CRYPTO_ecc_rnd_mpi(edc, |
70 | &a, &a_inv); | 71 | &a, &a_inv); |
71 | g = GNUNET_new_array (len, | 72 | g = GNUNET_new_array(len, |
72 | gcry_mpi_point_t); | 73 | gcry_mpi_point_t); |
73 | h = GNUNET_new_array (len, | 74 | h = GNUNET_new_array(len, |
74 | gcry_mpi_point_t); | 75 | gcry_mpi_point_t); |
75 | ria = gcry_mpi_new (0); | 76 | ria = gcry_mpi_new(0); |
76 | tmp = gcry_mpi_new (0); | 77 | tmp = gcry_mpi_new(0); |
77 | for (i=0;i<len;i++) | 78 | for (i = 0; i < len; i++) |
78 | { | 79 | { |
79 | ri = GNUNET_CRYPTO_ecc_random_mod_n (edc); | 80 | ri = GNUNET_CRYPTO_ecc_random_mod_n(edc); |
80 | g[i] = GNUNET_CRYPTO_ecc_dexp_mpi (edc, | 81 | g[i] = GNUNET_CRYPTO_ecc_dexp_mpi(edc, |
81 | ri); | 82 | ri); |
82 | /* ria = ri * a */ | 83 | /* ria = ri * a */ |
83 | gcry_mpi_mul (ria, | 84 | gcry_mpi_mul(ria, |
84 | ri, | 85 | ri, |
85 | a); | 86 | a); |
86 | /* tmp = ria + avec[i] */ | 87 | /* tmp = ria + avec[i] */ |
87 | gcry_mpi_add_ui (tmp, | 88 | gcry_mpi_add_ui(tmp, |
88 | ria, | 89 | ria, |
89 | avec[i]); | 90 | avec[i]); |
90 | h[i] = GNUNET_CRYPTO_ecc_dexp_mpi (edc, | 91 | h[i] = GNUNET_CRYPTO_ecc_dexp_mpi(edc, |
91 | tmp); | 92 | tmp); |
92 | } | 93 | } |
93 | gcry_mpi_release (ria); | 94 | gcry_mpi_release(ria); |
94 | gcry_mpi_release (tmp); | 95 | gcry_mpi_release(tmp); |
95 | 96 | ||
96 | /* Bob */ | 97 | /* Bob */ |
97 | val = gcry_mpi_new (0); | 98 | val = gcry_mpi_new(0); |
98 | gcry_mpi_set_ui (val, bvec[0]); | 99 | gcry_mpi_set_ui(val, bvec[0]); |
99 | pg = GNUNET_CRYPTO_ecc_pmul_mpi (edc, | 100 | pg = GNUNET_CRYPTO_ecc_pmul_mpi(edc, |
100 | g[0], | 101 | g[0], |
101 | val); | 102 | val); |
102 | ph = GNUNET_CRYPTO_ecc_pmul_mpi (edc, | 103 | ph = GNUNET_CRYPTO_ecc_pmul_mpi(edc, |
103 | h[0], | 104 | h[0], |
104 | val); | 105 | val); |
105 | for (i=1;i<len;i++) | 106 | for (i = 1; i < len; i++) |
106 | { | 107 | { |
107 | gcry_mpi_point_t m; | 108 | gcry_mpi_point_t m; |
108 | gcry_mpi_point_t tmp; | 109 | gcry_mpi_point_t tmp; |
109 | 110 | ||
110 | gcry_mpi_set_ui (val, bvec[i]); | 111 | gcry_mpi_set_ui(val, bvec[i]); |
111 | m = GNUNET_CRYPTO_ecc_pmul_mpi (edc, | 112 | m = GNUNET_CRYPTO_ecc_pmul_mpi(edc, |
112 | g[i], | 113 | g[i], |
113 | val); | 114 | val); |
114 | tmp = GNUNET_CRYPTO_ecc_add (edc, | 115 | tmp = GNUNET_CRYPTO_ecc_add(edc, |
115 | m, | 116 | m, |
116 | pg); | 117 | pg); |
117 | gcry_mpi_point_release (m); | 118 | gcry_mpi_point_release(m); |
118 | gcry_mpi_point_release (pg); | 119 | gcry_mpi_point_release(pg); |
119 | gcry_mpi_point_release (g[i]); | 120 | gcry_mpi_point_release(g[i]); |
120 | pg = tmp; | 121 | pg = tmp; |
121 | 122 | ||
122 | m = GNUNET_CRYPTO_ecc_pmul_mpi (edc, | 123 | m = GNUNET_CRYPTO_ecc_pmul_mpi(edc, |
123 | h[i], | 124 | h[i], |
124 | val); | 125 | val); |
125 | tmp = GNUNET_CRYPTO_ecc_add (edc, | 126 | tmp = GNUNET_CRYPTO_ecc_add(edc, |
126 | m, | 127 | m, |
127 | ph); | 128 | ph); |
128 | gcry_mpi_point_release (m); | 129 | gcry_mpi_point_release(m); |
129 | gcry_mpi_point_release (ph); | 130 | gcry_mpi_point_release(ph); |
130 | gcry_mpi_point_release (h[i]); | 131 | gcry_mpi_point_release(h[i]); |
131 | ph = tmp; | 132 | ph = tmp; |
132 | } | 133 | } |
133 | gcry_mpi_release (val); | 134 | gcry_mpi_release(val); |
134 | GNUNET_free (g); | 135 | GNUNET_free(g); |
135 | GNUNET_free (h); | 136 | GNUNET_free(h); |
136 | 137 | ||
137 | /* Alice */ | 138 | /* Alice */ |
138 | pgi = GNUNET_CRYPTO_ecc_pmul_mpi (edc, | 139 | pgi = GNUNET_CRYPTO_ecc_pmul_mpi(edc, |
139 | pg, | 140 | pg, |
140 | a_inv); | 141 | a_inv); |
141 | gsp = GNUNET_CRYPTO_ecc_add (edc, | 142 | gsp = GNUNET_CRYPTO_ecc_add(edc, |
142 | pgi, | 143 | pgi, |
143 | ph); | 144 | ph); |
144 | gcry_mpi_point_release (pgi); | 145 | gcry_mpi_point_release(pgi); |
145 | gcry_mpi_point_release (ph); | 146 | gcry_mpi_point_release(ph); |
146 | sp = GNUNET_CRYPTO_ecc_dlog (edc, | 147 | sp = GNUNET_CRYPTO_ecc_dlog(edc, |
147 | gsp); | 148 | gsp); |
148 | gcry_mpi_point_release (gsp); | 149 | gcry_mpi_point_release(gsp); |
149 | return sp; | 150 | return sp; |
150 | } | 151 | } |
151 | 152 | ||
152 | 153 | ||
153 | int | 154 | int |
154 | main (int argc, char *argv[]) | 155 | main(int argc, char *argv[]) |
155 | { | 156 | { |
156 | static unsigned int v11[] = { 1, 1, 0 }; | 157 | static unsigned int v11[] = { 1, 1, 0 }; |
157 | static unsigned int v22[] = { 2, 2, 0 }; | 158 | static unsigned int v22[] = { 2, 2, 0 }; |
158 | static unsigned int v35[] = { 3, 5, 0 }; | 159 | static unsigned int v35[] = { 3, 5, 0 }; |
159 | static unsigned int v24[] = { 2, 4, 0 }; | 160 | static unsigned int v24[] = { 2, 4, 0 }; |
160 | 161 | ||
161 | GNUNET_log_setup ("test-ecc-scalarproduct", | 162 | GNUNET_log_setup("test-ecc-scalarproduct", |
162 | "WARNING", | 163 | "WARNING", |
163 | NULL); | 164 | NULL); |
164 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (128, 128); | 165 | edc = GNUNET_CRYPTO_ecc_dlog_prepare(128, 128); |
165 | GNUNET_assert ( 2 == test_sp (v11, v11)); | 166 | GNUNET_assert(2 == test_sp(v11, v11)); |
166 | GNUNET_assert ( 4 == test_sp (v22, v11)); | 167 | GNUNET_assert(4 == test_sp(v22, v11)); |
167 | GNUNET_assert ( 8 == test_sp (v35, v11)); | 168 | GNUNET_assert(8 == test_sp(v35, v11)); |
168 | GNUNET_assert (26 == test_sp (v35, v24)); | 169 | GNUNET_assert(26 == test_sp(v35, v24)); |
169 | GNUNET_assert (26 == test_sp (v24, v35)); | 170 | GNUNET_assert(26 == test_sp(v24, v35)); |
170 | GNUNET_assert (16 == test_sp (v22, v35)); | 171 | GNUNET_assert(16 == test_sp(v22, v35)); |
171 | GNUNET_CRYPTO_ecc_dlog_release (edc); | 172 | GNUNET_CRYPTO_ecc_dlog_release(edc); |
172 | return 0; | 173 | return 0; |
173 | } | 174 | } |
174 | 175 | ||