diff options
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct_bob.c')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct_bob.c | 1110 |
1 files changed, 565 insertions, 545 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_bob.c b/src/scalarproduct/gnunet-service-scalarproduct_bob.c index f787cdd2e..23d59a36a 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct_bob.c +++ b/src/scalarproduct/gnunet-service-scalarproduct_bob.c | |||
@@ -36,13 +36,14 @@ | |||
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 | { | ||
46 | /** | 47 | /** |
47 | * Key used to identify matching pairs of values to multiply. | 48 | * Key used to identify matching pairs of values to multiply. |
48 | * Points into an existing data structure, to avoid copying | 49 | * Points into an existing data structure, to avoid copying |
@@ -61,7 +62,8 @@ struct MpiElement { | |||
61 | * A scalarproduct session which tracks an offer for a | 62 | * A scalarproduct session which tracks an offer for a |
62 | * multiplication service by a local client. | 63 | * multiplication service by a local client. |
63 | */ | 64 | */ |
64 | struct BobServiceSession { | 65 | struct BobServiceSession |
66 | { | ||
65 | /** | 67 | /** |
66 | * (hopefully) unique transaction ID | 68 | * (hopefully) unique transaction ID |
67 | */ | 69 | */ |
@@ -235,13 +237,13 @@ static struct GNUNET_CADET_Handle *my_cadet; | |||
235 | * @param value the value to free | 237 | * @param value the value to free |
236 | */ | 238 | */ |
237 | static int | 239 | static int |
238 | free_element_cb(void *cls, | 240 | free_element_cb (void *cls, |
239 | const struct GNUNET_HashCode *key, | 241 | const struct GNUNET_HashCode *key, |
240 | void *value) | 242 | void *value) |
241 | { | 243 | { |
242 | struct GNUNET_SCALARPRODUCT_Element *element = value; | 244 | struct GNUNET_SCALARPRODUCT_Element *element = value; |
243 | 245 | ||
244 | GNUNET_free(element); | 246 | GNUNET_free (element); |
245 | return GNUNET_OK; | 247 | return GNUNET_OK; |
246 | } | 248 | } |
247 | 249 | ||
@@ -252,7 +254,7 @@ free_element_cb(void *cls, | |||
252 | * @param session the session to free elements from | 254 | * @param session the session to free elements from |
253 | */ | 255 | */ |
254 | static void | 256 | static void |
255 | destroy_service_session(struct BobServiceSession *s) | 257 | destroy_service_session (struct BobServiceSession *s) |
256 | { | 258 | { |
257 | unsigned int i; | 259 | unsigned int i; |
258 | 260 | ||
@@ -260,63 +262,63 @@ destroy_service_session(struct BobServiceSession *s) | |||
260 | return; | 262 | return; |
261 | s->in_destroy = GNUNET_YES; | 263 | s->in_destroy = GNUNET_YES; |
262 | if (NULL != s->client) | 264 | if (NULL != s->client) |
263 | { | 265 | { |
264 | struct GNUNET_SERVICE_Client *c = s->client; | 266 | struct GNUNET_SERVICE_Client *c = s->client; |
265 | 267 | ||
266 | s->client = NULL; | 268 | s->client = NULL; |
267 | GNUNET_SERVICE_client_drop(c); | 269 | GNUNET_SERVICE_client_drop (c); |
268 | } | 270 | } |
269 | if (NULL != s->intersected_elements) | 271 | if (NULL != s->intersected_elements) |
270 | { | 272 | { |
271 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, | 273 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, |
272 | &free_element_cb, | 274 | &free_element_cb, |
273 | NULL); | 275 | NULL); |
274 | GNUNET_CONTAINER_multihashmap_destroy(s->intersected_elements); | 276 | GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements); |
275 | s->intersected_elements = NULL; | 277 | s->intersected_elements = NULL; |
276 | } | 278 | } |
277 | if (NULL != s->intersection_op) | 279 | if (NULL != s->intersection_op) |
278 | { | 280 | { |
279 | GNUNET_SET_operation_cancel(s->intersection_op); | 281 | GNUNET_SET_operation_cancel (s->intersection_op); |
280 | s->intersection_op = NULL; | 282 | s->intersection_op = NULL; |
281 | } | 283 | } |
282 | if (NULL != s->intersection_set) | 284 | if (NULL != s->intersection_set) |
283 | { | 285 | { |
284 | GNUNET_SET_destroy(s->intersection_set); | 286 | GNUNET_SET_destroy (s->intersection_set); |
285 | s->intersection_set = NULL; | 287 | s->intersection_set = NULL; |
286 | } | 288 | } |
287 | if (NULL != s->e_a) | 289 | if (NULL != s->e_a) |
288 | { | 290 | { |
289 | GNUNET_free(s->e_a); | 291 | GNUNET_free (s->e_a); |
290 | s->e_a = NULL; | 292 | s->e_a = NULL; |
291 | } | 293 | } |
292 | if (NULL != s->sorted_elements) | 294 | if (NULL != s->sorted_elements) |
293 | { | 295 | { |
294 | for (i = 0; i < s->used_element_count; i++) | 296 | for (i = 0; i < s->used_element_count; i++) |
295 | gcry_mpi_release(s->sorted_elements[i].value); | 297 | gcry_mpi_release (s->sorted_elements[i].value); |
296 | GNUNET_free(s->sorted_elements); | 298 | GNUNET_free (s->sorted_elements); |
297 | s->sorted_elements = NULL; | 299 | s->sorted_elements = NULL; |
298 | } | 300 | } |
299 | if (NULL != s->r) | 301 | if (NULL != s->r) |
300 | { | 302 | { |
301 | GNUNET_free(s->r); | 303 | GNUNET_free (s->r); |
302 | s->r = NULL; | 304 | s->r = NULL; |
303 | } | 305 | } |
304 | if (NULL != s->r_prime) | 306 | if (NULL != s->r_prime) |
305 | { | 307 | { |
306 | GNUNET_free(s->r_prime); | 308 | GNUNET_free (s->r_prime); |
307 | s->r_prime = NULL; | 309 | s->r_prime = NULL; |
308 | } | 310 | } |
309 | if (NULL != s->port) | 311 | if (NULL != s->port) |
310 | { | 312 | { |
311 | GNUNET_CADET_close_port(s->port); | 313 | GNUNET_CADET_close_port (s->port); |
312 | s->port = NULL; | 314 | s->port = NULL; |
313 | } | 315 | } |
314 | if (NULL != s->channel) | 316 | if (NULL != s->channel) |
315 | { | 317 | { |
316 | GNUNET_CADET_channel_destroy(s->channel); | 318 | GNUNET_CADET_channel_destroy (s->channel); |
317 | s->channel = NULL; | 319 | s->channel = NULL; |
318 | } | 320 | } |
319 | GNUNET_free(s); | 321 | GNUNET_free (s); |
320 | } | 322 | } |
321 | 323 | ||
322 | 324 | ||
@@ -328,24 +330,24 @@ destroy_service_session(struct BobServiceSession *s) | |||
328 | * @param session the associated client session to fail or succeed | 330 | * @param session the associated client session to fail or succeed |
329 | */ | 331 | */ |
330 | static void | 332 | static void |
331 | prepare_client_end_notification(struct BobServiceSession *session) | 333 | prepare_client_end_notification (struct BobServiceSession *session) |
332 | { | 334 | { |
333 | struct ClientResponseMessage *msg; | 335 | struct ClientResponseMessage *msg; |
334 | struct GNUNET_MQ_Envelope *e; | 336 | struct GNUNET_MQ_Envelope *e; |
335 | 337 | ||
336 | if (NULL == session->client_mq) | 338 | if (NULL == session->client_mq) |
337 | return; /* no client left to be notified */ | 339 | return; /* no client left to be notified */ |
338 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
339 | "Sending session-end notification with status %d to client for session %s\n", | 341 | "Sending session-end notification with status %d to client for session %s\n", |
340 | session->status, | 342 | session->status, |
341 | GNUNET_h2s(&session->session_id)); | 343 | GNUNET_h2s (&session->session_id)); |
342 | e = GNUNET_MQ_msg(msg, | 344 | e = GNUNET_MQ_msg (msg, |
343 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 345 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
344 | msg->range = 0; | 346 | msg->range = 0; |
345 | msg->product_length = htonl(0); | 347 | msg->product_length = htonl (0); |
346 | msg->status = htonl(session->status); | 348 | msg->status = htonl (session->status); |
347 | GNUNET_MQ_send(session->client_mq, | 349 | GNUNET_MQ_send (session->client_mq, |
348 | e); | 350 | e); |
349 | } | 351 | } |
350 | 352 | ||
351 | 353 | ||
@@ -359,22 +361,22 @@ prepare_client_end_notification(struct BobServiceSession *session) | |||
359 | * @param channel connection to the other end (henceforth invalid) | 361 | * @param channel connection to the other end (henceforth invalid) |
360 | */ | 362 | */ |
361 | static void | 363 | static void |
362 | cb_channel_destruction(void *cls, | 364 | cb_channel_destruction (void *cls, |
363 | const struct GNUNET_CADET_Channel *channel) | 365 | const struct GNUNET_CADET_Channel *channel) |
364 | { | 366 | { |
365 | struct BobServiceSession *s = cls; | 367 | struct BobServiceSession *s = cls; |
366 | 368 | ||
367 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 369 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
368 | "Peer disconnected, terminating session %s with peer %s\n", | 370 | "Peer disconnected, terminating session %s with peer %s\n", |
369 | GNUNET_h2s(&s->session_id), | 371 | GNUNET_h2s (&s->session_id), |
370 | GNUNET_i2s(&s->peer)); | 372 | GNUNET_i2s (&s->peer)); |
371 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) | 373 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) |
372 | { | 374 | { |
373 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 375 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
374 | prepare_client_end_notification(s); | 376 | prepare_client_end_notification (s); |
375 | } | 377 | } |
376 | s->channel = NULL; | 378 | s->channel = NULL; |
377 | destroy_service_session(s); | 379 | destroy_service_session (s); |
378 | } | 380 | } |
379 | 381 | ||
380 | 382 | ||
@@ -383,19 +385,22 @@ cb_channel_destruction(void *cls, | |||
383 | * the client that we are finished. | 385 | * the client that we are finished. |
384 | */ | 386 | */ |
385 | static void | 387 | static void |
386 | bob_cadet_done_cb(void *cls) | 388 | bob_cadet_done_cb (void *cls) |
387 | { | 389 | { |
388 | struct BobServiceSession *session = cls; | 390 | struct BobServiceSession *session = cls; |
389 | 391 | ||
390 | session->status = GNUNET_SCALARPRODUCT_STATUS_SUCCESS; | 392 | session->status = GNUNET_SCALARPRODUCT_STATUS_SUCCESS; |
391 | prepare_client_end_notification(session); | 393 | prepare_client_end_notification (session); |
392 | } | 394 | } |
393 | 395 | ||
394 | 396 | ||
395 | /** | 397 | /** |
396 | * Maximum count of elements we can put into a multipart message | 398 | * Maximum count of elements we can put into a multipart message |
397 | */ | 399 | */ |
398 | #define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof(struct BobCryptodataMultipartMessage)) / sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)) | 400 | #define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 \ |
401 | - sizeof(struct BobCryptodataMultipartMessage)) \ | ||
402 | / sizeof(struct \ | ||
403 | GNUNET_CRYPTO_PaillierCiphertext)) | ||
399 | 404 | ||
400 | 405 | ||
401 | /** | 406 | /** |
@@ -405,7 +410,7 @@ bob_cadet_done_cb(void *cls) | |||
405 | * @param s the associated service session | 410 | * @param s the associated service session |
406 | */ | 411 | */ |
407 | static void | 412 | static void |
408 | transmit_bobs_cryptodata_message_multipart(struct BobServiceSession *s) | 413 | transmit_bobs_cryptodata_message_multipart (struct BobServiceSession *s) |
409 | { | 414 | { |
410 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; | 415 | struct GNUNET_CRYPTO_PaillierCiphertext *payload; |
411 | struct BobCryptodataMultipartMessage *msg; | 416 | struct BobCryptodataMultipartMessage *msg; |
@@ -415,39 +420,42 @@ transmit_bobs_cryptodata_message_multipart(struct BobServiceSession *s) | |||
415 | uint32_t todo_count; | 420 | uint32_t todo_count; |
416 | 421 | ||
417 | while (s->cadet_transmitted_element_count != s->used_element_count) | 422 | while (s->cadet_transmitted_element_count != s->used_element_count) |
423 | { | ||
424 | todo_count = s->used_element_count - s->cadet_transmitted_element_count; | ||
425 | if (todo_count > ELEMENT_CAPACITY / 2) | ||
426 | todo_count = ELEMENT_CAPACITY / 2; | ||
427 | |||
428 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
429 | "Sending %u additional crypto values to Alice\n", | ||
430 | (unsigned int) todo_count); | ||
431 | e = GNUNET_MQ_msg_extra (msg, | ||
432 | todo_count * sizeof(struct | ||
433 | GNUNET_CRYPTO_PaillierCiphertext) | ||
434 | * 2, | ||
435 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART); | ||
436 | msg->contained_element_count = htonl (todo_count); | ||
437 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; | ||
438 | for (i = s->cadet_transmitted_element_count, j = 0; i < | ||
439 | s->cadet_transmitted_element_count + todo_count; i++) | ||
418 | { | 440 | { |
419 | todo_count = s->used_element_count - s->cadet_transmitted_element_count; | 441 | // r[i][p] and r[i][q] |
420 | if (todo_count > ELEMENT_CAPACITY / 2) | 442 | GNUNET_memcpy (&payload[j++], |
421 | todo_count = ELEMENT_CAPACITY / 2; | 443 | &s->r[i], |
422 | 444 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); | |
423 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 445 | GNUNET_memcpy (&payload[j++], |
424 | "Sending %u additional crypto values to Alice\n", | 446 | &s->r_prime[i], |
425 | (unsigned int)todo_count); | 447 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
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); | ||
448 | } | 448 | } |
449 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 449 | s->cadet_transmitted_element_count += todo_count; |
450 | "All values queued for Alice, Bob is done\n"); | 450 | if (s->cadet_transmitted_element_count == s->used_element_count) |
451 | GNUNET_MQ_notify_sent (e, | ||
452 | &bob_cadet_done_cb, | ||
453 | s); | ||
454 | GNUNET_MQ_send (s->cadet_mq, | ||
455 | e); | ||
456 | } | ||
457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
458 | "All values queued for Alice, Bob is done\n"); | ||
451 | } | 459 | } |
452 | 460 | ||
453 | 461 | ||
@@ -463,7 +471,7 @@ transmit_bobs_cryptodata_message_multipart(struct BobServiceSession *s) | |||
463 | * @param s the associated requesting session with Alice | 471 | * @param s the associated requesting session with Alice |
464 | */ | 472 | */ |
465 | static void | 473 | static void |
466 | transmit_bobs_cryptodata_message(struct BobServiceSession *s) | 474 | transmit_bobs_cryptodata_message (struct BobServiceSession *s) |
467 | { | 475 | { |
468 | struct BobCryptodataMessage *msg; | 476 | struct BobCryptodataMessage *msg; |
469 | struct GNUNET_MQ_Envelope *e; | 477 | struct GNUNET_MQ_Envelope *e; |
@@ -471,49 +479,50 @@ transmit_bobs_cryptodata_message(struct BobServiceSession *s) | |||
471 | unsigned int i; | 479 | unsigned int i; |
472 | 480 | ||
473 | s->cadet_transmitted_element_count | 481 | s->cadet_transmitted_element_count |
474 | = ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof(struct BobCryptodataMessage)) | 482 | = ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof(struct |
483 | BobCryptodataMessage)) | ||
475 | / sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) / 2) - 1; | 484 | / sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) / 2) - 1; |
476 | if (s->cadet_transmitted_element_count > s->used_element_count) | 485 | if (s->cadet_transmitted_element_count > s->used_element_count) |
477 | s->cadet_transmitted_element_count = s->used_element_count; | 486 | s->cadet_transmitted_element_count = s->used_element_count; |
478 | 487 | ||
479 | e = GNUNET_MQ_msg_extra(msg, | 488 | e = GNUNET_MQ_msg_extra (msg, |
480 | (2 + s->cadet_transmitted_element_count * 2) | 489 | (2 + s->cadet_transmitted_element_count * 2) |
481 | * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext), | 490 | * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext), |
482 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); | 491 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA); |
483 | msg->contained_element_count = htonl(s->cadet_transmitted_element_count); | 492 | msg->contained_element_count = htonl (s->cadet_transmitted_element_count); |
484 | 493 | ||
485 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
486 | "Sending %u/%u crypto values to Alice\n", | 495 | "Sending %u/%u crypto values to Alice\n", |
487 | (unsigned int)s->cadet_transmitted_element_count, | 496 | (unsigned int) s->cadet_transmitted_element_count, |
488 | (unsigned int)s->used_element_count); | 497 | (unsigned int) s->used_element_count); |
489 | 498 | ||
490 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1]; | 499 | payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
491 | GNUNET_memcpy(&payload[0], | 500 | GNUNET_memcpy (&payload[0], |
492 | &s->s, | 501 | &s->s, |
493 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); | 502 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
494 | GNUNET_memcpy(&payload[1], | 503 | GNUNET_memcpy (&payload[1], |
495 | &s->s_prime, | 504 | &s->s_prime, |
496 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); | 505 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
497 | 506 | ||
498 | payload = &payload[2]; | 507 | payload = &payload[2]; |
499 | // convert k[][] | 508 | // convert k[][] |
500 | for (i = 0; i < s->cadet_transmitted_element_count; i++) | 509 | for (i = 0; i < s->cadet_transmitted_element_count; i++) |
501 | { | 510 | { |
502 | //k[i][p] and k[i][q] | 511 | // k[i][p] and k[i][q] |
503 | GNUNET_memcpy(&payload[i * 2], | 512 | GNUNET_memcpy (&payload[i * 2], |
504 | &s->r[i], | 513 | &s->r[i], |
505 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); | 514 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
506 | GNUNET_memcpy(&payload[i * 2 + 1], | 515 | GNUNET_memcpy (&payload[i * 2 + 1], |
507 | &s->r_prime[i], | 516 | &s->r_prime[i], |
508 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); | 517 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext)); |
509 | } | 518 | } |
510 | if (s->cadet_transmitted_element_count == s->used_element_count) | 519 | if (s->cadet_transmitted_element_count == s->used_element_count) |
511 | GNUNET_MQ_notify_sent(e, | 520 | GNUNET_MQ_notify_sent (e, |
512 | &bob_cadet_done_cb, | 521 | &bob_cadet_done_cb, |
513 | s); | 522 | s); |
514 | GNUNET_MQ_send(s->cadet_mq, | 523 | GNUNET_MQ_send (s->cadet_mq, |
515 | e); | 524 | e); |
516 | transmit_bobs_cryptodata_message_multipart(s); | 525 | transmit_bobs_cryptodata_message_multipart (s); |
517 | } | 526 | } |
518 | #undef ELEMENT_CAPACITY | 527 | #undef ELEMENT_CAPACITY |
519 | 528 | ||
@@ -527,21 +536,21 @@ transmit_bobs_cryptodata_message(struct BobServiceSession *s) | |||
527 | * TODO: code duplication with Alice! | 536 | * TODO: code duplication with Alice! |
528 | */ | 537 | */ |
529 | static gcry_mpi_t | 538 | static gcry_mpi_t |
530 | compute_square_sum(const gcry_mpi_t *vector, | 539 | compute_square_sum (const gcry_mpi_t *vector, |
531 | uint32_t length) | 540 | uint32_t length) |
532 | { | 541 | { |
533 | gcry_mpi_t elem; | 542 | gcry_mpi_t elem; |
534 | gcry_mpi_t sum; | 543 | gcry_mpi_t sum; |
535 | uint32_t i; | 544 | uint32_t i; |
536 | 545 | ||
537 | GNUNET_assert(NULL != (sum = gcry_mpi_new(0))); | 546 | GNUNET_assert (NULL != (sum = gcry_mpi_new (0))); |
538 | GNUNET_assert(NULL != (elem = gcry_mpi_new(0))); | 547 | GNUNET_assert (NULL != (elem = gcry_mpi_new (0))); |
539 | for (i = 0; i < length; i++) | 548 | for (i = 0; i < length; i++) |
540 | { | 549 | { |
541 | gcry_mpi_mul(elem, vector[i], vector[i]); | 550 | gcry_mpi_mul (elem, vector[i], vector[i]); |
542 | gcry_mpi_add(sum, sum, elem); | 551 | gcry_mpi_add (sum, sum, elem); |
543 | } | 552 | } |
544 | gcry_mpi_release(elem); | 553 | gcry_mpi_release (elem); |
545 | return sum; | 554 | return sum; |
546 | } | 555 | } |
547 | 556 | ||
@@ -557,7 +566,7 @@ compute_square_sum(const gcry_mpi_t *vector, | |||
557 | * @return #GNUNET_OK on success | 566 | * @return #GNUNET_OK on success |
558 | */ | 567 | */ |
559 | static int | 568 | static int |
560 | compute_service_response(struct BobServiceSession *session) | 569 | compute_service_response (struct BobServiceSession *session) |
561 | { | 570 | { |
562 | uint32_t i; | 571 | uint32_t i; |
563 | unsigned int *p; | 572 | unsigned int *p; |
@@ -573,125 +582,126 @@ compute_service_response(struct BobServiceSession *session) | |||
573 | count = session->used_element_count; | 582 | count = session->used_element_count; |
574 | a = session->e_a; | 583 | a = session->e_a; |
575 | b = session->sorted_elements; | 584 | b = session->sorted_elements; |
576 | q = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, | 585 | q = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, |
577 | count); | 586 | count); |
578 | p = GNUNET_CRYPTO_random_permute(GNUNET_CRYPTO_QUALITY_WEAK, | 587 | p = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, |
579 | count); | 588 | count); |
580 | rand = GNUNET_malloc(sizeof(gcry_mpi_t) * count); | 589 | rand = GNUNET_malloc (sizeof(gcry_mpi_t) * count); |
581 | for (i = 0; i < count; i++) | 590 | for (i = 0; i < count; i++) |
582 | GNUNET_assert(NULL != (rand[i] = gcry_mpi_new(0))); | 591 | GNUNET_assert (NULL != (rand[i] = gcry_mpi_new (0))); |
583 | r = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) * count); | 592 | r = GNUNET_malloc (sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) * count); |
584 | r_prime = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) * count); | 593 | r_prime = GNUNET_malloc (sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) |
594 | * count); | ||
585 | 595 | ||
586 | for (i = 0; i < count; i++) | 596 | for (i = 0; i < count; i++) |
587 | { | 597 | { |
588 | int32_t svalue; | 598 | int32_t svalue; |
589 | 599 | ||
590 | svalue = (int32_t)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, | 600 | svalue = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
591 | UINT32_MAX); | 601 | UINT32_MAX); |
592 | // long to gcry_mpi_t | 602 | // long to gcry_mpi_t |
593 | if (svalue < 0) | 603 | if (svalue < 0) |
594 | gcry_mpi_sub_ui(rand[i], | 604 | gcry_mpi_sub_ui (rand[i], |
595 | rand[i], | 605 | rand[i], |
596 | -svalue); | 606 | -svalue); |
597 | else | 607 | else |
598 | rand[i] = gcry_mpi_set_ui(rand[i], svalue); | 608 | rand[i] = gcry_mpi_set_ui (rand[i], svalue); |
599 | } | 609 | } |
600 | 610 | ||
601 | tmp = gcry_mpi_new(0); | 611 | tmp = gcry_mpi_new (0); |
602 | // encrypt the element | 612 | // encrypt the element |
603 | // for the sake of readability I decided to have dedicated permutation | 613 | // for the sake of readability I decided to have dedicated permutation |
604 | // vectors, which get rid of all the lookups in p/q. | 614 | // vectors, which get rid of all the lookups in p/q. |
605 | // however, ap/aq are not absolutely necessary but are just abstraction | 615 | // however, ap/aq are not absolutely necessary but are just abstraction |
606 | // Calculate Kp = E(S + a_pi) (+) E(S - r_pi - b_pi) | 616 | // Calculate Kp = E(S + a_pi) (+) E(S - r_pi - b_pi) |
607 | for (i = 0; i < count; i++) | 617 | for (i = 0; i < count; i++) |
608 | { | 618 | { |
609 | // E(S - r_pi - b_pi) | 619 | // E(S - r_pi - b_pi) |
610 | gcry_mpi_sub(tmp, my_offset, rand[p[i]]); | 620 | gcry_mpi_sub (tmp, my_offset, rand[p[i]]); |
611 | gcry_mpi_sub(tmp, tmp, b[p[i]].value); | 621 | gcry_mpi_sub (tmp, tmp, b[p[i]].value); |
612 | GNUNET_assert(2 == | 622 | GNUNET_assert (2 == |
613 | GNUNET_CRYPTO_paillier_encrypt(&session->remote_pubkey, | 623 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, |
614 | tmp, | 624 | tmp, |
615 | 2, | 625 | 2, |
616 | &r[i])); | 626 | &r[i])); |
617 | 627 | ||
618 | // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b) | 628 | // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b) |
619 | if (GNUNET_OK != | 629 | if (GNUNET_OK != |
620 | GNUNET_CRYPTO_paillier_hom_add(&session->remote_pubkey, | 630 | GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey, |
621 | &r[i], | 631 | &r[i], |
622 | &a[p[i]], | 632 | &a[p[i]], |
623 | &r[i])) | 633 | &r[i])) |
624 | { | 634 | { |
625 | GNUNET_break_op(0); | 635 | GNUNET_break_op (0); |
626 | goto error_cleanup; | 636 | goto error_cleanup; |
627 | } | ||
628 | } | 637 | } |
638 | } | ||
629 | 639 | ||
630 | // Calculate Kq = E(S + a_qi) (+) E(S - r_qi) | 640 | // Calculate Kq = E(S + a_qi) (+) E(S - r_qi) |
631 | for (i = 0; i < count; i++) | 641 | for (i = 0; i < count; i++) |
632 | { | 642 | { |
633 | // E(S - r_qi) | 643 | // E(S - r_qi) |
634 | gcry_mpi_sub(tmp, my_offset, rand[q[i]]); | 644 | gcry_mpi_sub (tmp, my_offset, rand[q[i]]); |
635 | GNUNET_assert(2 == | 645 | GNUNET_assert (2 == |
636 | GNUNET_CRYPTO_paillier_encrypt(&session->remote_pubkey, | 646 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, |
637 | tmp, | 647 | tmp, |
638 | 2, | 648 | 2, |
639 | &r_prime[i])); | 649 | &r_prime[i])); |
640 | 650 | ||
641 | // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi) | 651 | // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi) |
642 | if (GNUNET_OK != | 652 | if (GNUNET_OK != |
643 | GNUNET_CRYPTO_paillier_hom_add(&session->remote_pubkey, | 653 | GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey, |
644 | &r_prime[i], | 654 | &r_prime[i], |
645 | &a[q[i]], | 655 | &a[q[i]], |
646 | &r_prime[i])) | 656 | &r_prime[i])) |
647 | { | 657 | { |
648 | GNUNET_break_op(0); | 658 | GNUNET_break_op (0); |
649 | goto error_cleanup; | 659 | goto error_cleanup; |
650 | } | ||
651 | } | 660 | } |
652 | gcry_mpi_release(tmp); | 661 | } |
662 | gcry_mpi_release (tmp); | ||
653 | 663 | ||
654 | // Calculate S' = E(SUM( r_i^2 )) | 664 | // Calculate S' = E(SUM( r_i^2 )) |
655 | tmp = compute_square_sum(rand, count); | 665 | tmp = compute_square_sum (rand, count); |
656 | GNUNET_assert(1 == | 666 | GNUNET_assert (1 == |
657 | GNUNET_CRYPTO_paillier_encrypt(&session->remote_pubkey, | 667 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, |
658 | tmp, | 668 | tmp, |
659 | 1, | 669 | 1, |
660 | &session->s_prime)); | 670 | &session->s_prime)); |
661 | gcry_mpi_release(tmp); | 671 | gcry_mpi_release (tmp); |
662 | 672 | ||
663 | // Calculate S = E(SUM( (r_i + b_i)^2 )) | 673 | // Calculate S = E(SUM( (r_i + b_i)^2 )) |
664 | for (i = 0; i < count; i++) | 674 | for (i = 0; i < count; i++) |
665 | gcry_mpi_add(rand[i], rand[i], b[i].value); | 675 | gcry_mpi_add (rand[i], rand[i], b[i].value); |
666 | tmp = compute_square_sum(rand, count); | 676 | tmp = compute_square_sum (rand, count); |
667 | GNUNET_assert(1 == | 677 | GNUNET_assert (1 == |
668 | GNUNET_CRYPTO_paillier_encrypt(&session->remote_pubkey, | 678 | GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, |
669 | tmp, | 679 | tmp, |
670 | 1, | 680 | 1, |
671 | &session->s)); | 681 | &session->s)); |
672 | gcry_mpi_release(tmp); | 682 | gcry_mpi_release (tmp); |
673 | 683 | ||
674 | session->r = r; | 684 | session->r = r; |
675 | session->r_prime = r_prime; | 685 | session->r_prime = r_prime; |
676 | 686 | ||
677 | for (i = 0; i < count; i++) | 687 | for (i = 0; i < count; i++) |
678 | gcry_mpi_release(rand[i]); | 688 | gcry_mpi_release (rand[i]); |
679 | GNUNET_free(session->e_a); | 689 | GNUNET_free (session->e_a); |
680 | session->e_a = NULL; | 690 | session->e_a = NULL; |
681 | GNUNET_free(p); | 691 | GNUNET_free (p); |
682 | GNUNET_free(q); | 692 | GNUNET_free (q); |
683 | GNUNET_free(rand); | 693 | GNUNET_free (rand); |
684 | return GNUNET_OK; | 694 | return GNUNET_OK; |
685 | 695 | ||
686 | error_cleanup: | 696 | error_cleanup: |
687 | GNUNET_free(r); | 697 | GNUNET_free (r); |
688 | GNUNET_free(r_prime); | 698 | GNUNET_free (r_prime); |
689 | gcry_mpi_release(tmp); | 699 | gcry_mpi_release (tmp); |
690 | GNUNET_free(p); | 700 | GNUNET_free (p); |
691 | GNUNET_free(q); | 701 | GNUNET_free (q); |
692 | for (i = 0; i < count; i++) | 702 | for (i = 0; i < count; i++) |
693 | gcry_mpi_release(rand[i]); | 703 | gcry_mpi_release (rand[i]); |
694 | GNUNET_free(rand); | 704 | GNUNET_free (rand); |
695 | return GNUNET_SYSERR; | 705 | return GNUNET_SYSERR; |
696 | } | 706 | } |
697 | 707 | ||
@@ -706,21 +716,21 @@ error_cleanup: | |||
706 | * TODO: code duplication with Alice! | 716 | * TODO: code duplication with Alice! |
707 | */ | 717 | */ |
708 | static int | 718 | static int |
709 | copy_element_cb(void *cls, | 719 | copy_element_cb (void *cls, |
710 | const struct GNUNET_HashCode *key, | 720 | const struct GNUNET_HashCode *key, |
711 | void *value) | 721 | void *value) |
712 | { | 722 | { |
713 | struct BobServiceSession *s = cls; | 723 | struct BobServiceSession *s = cls; |
714 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 724 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
715 | gcry_mpi_t mval; | 725 | gcry_mpi_t mval; |
716 | int64_t val; | 726 | int64_t val; |
717 | 727 | ||
718 | mval = gcry_mpi_new(0); | 728 | mval = gcry_mpi_new (0); |
719 | val = (int64_t)GNUNET_ntohll(e->value); | 729 | val = (int64_t) GNUNET_ntohll (e->value); |
720 | if (0 > val) | 730 | if (0 > val) |
721 | gcry_mpi_sub_ui(mval, mval, -val); | 731 | gcry_mpi_sub_ui (mval, mval, -val); |
722 | else | 732 | else |
723 | gcry_mpi_add_ui(mval, mval, val); | 733 | gcry_mpi_add_ui (mval, mval, val); |
724 | s->sorted_elements [s->used_element_count].value = mval; | 734 | s->sorted_elements [s->used_element_count].value = mval; |
725 | s->sorted_elements [s->used_element_count].key = &e->key; | 735 | s->sorted_elements [s->used_element_count].key = &e->key; |
726 | s->used_element_count++; | 736 | s->used_element_count++; |
@@ -737,14 +747,14 @@ copy_element_cb(void *cls, | |||
737 | * TODO: code duplication with Alice! | 747 | * TODO: code duplication with Alice! |
738 | */ | 748 | */ |
739 | static int | 749 | static int |
740 | element_cmp(const void *a, | 750 | element_cmp (const void *a, |
741 | const void *b) | 751 | const void *b) |
742 | { | 752 | { |
743 | const struct MpiElement *ma = a; | 753 | const struct MpiElement *ma = a; |
744 | const struct MpiElement *mb = b; | 754 | const struct MpiElement *mb = b; |
745 | 755 | ||
746 | return GNUNET_CRYPTO_hash_cmp(ma->key, | 756 | return GNUNET_CRYPTO_hash_cmp (ma->key, |
747 | mb->key); | 757 | mb->key); |
748 | } | 758 | } |
749 | 759 | ||
750 | 760 | ||
@@ -756,33 +766,34 @@ element_cmp(const void *a, | |||
756 | * @param s session to transmit reply for. | 766 | * @param s session to transmit reply for. |
757 | */ | 767 | */ |
758 | static void | 768 | static void |
759 | transmit_cryptographic_reply(struct BobServiceSession *s) | 769 | transmit_cryptographic_reply (struct BobServiceSession *s) |
760 | { | 770 | { |
761 | struct GNUNET_CADET_Channel *channel; | 771 | struct GNUNET_CADET_Channel *channel; |
762 | 772 | ||
763 | /* TODO: code duplication with Alice! */ | 773 | /* TODO: code duplication with Alice! */ |
764 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 774 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
765 | "Received everything, building reply for Alice\n"); | 775 | "Received everything, building reply for Alice\n"); |
766 | s->sorted_elements | 776 | s->sorted_elements |
767 | = GNUNET_malloc(GNUNET_CONTAINER_multihashmap_size(s->intersected_elements) * | 777 | = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size ( |
768 | sizeof(struct MpiElement)); | 778 | s->intersected_elements) |
779 | * sizeof(struct MpiElement)); | ||
769 | s->used_element_count = 0; | 780 | s->used_element_count = 0; |
770 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, | 781 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, |
771 | ©_element_cb, | 782 | ©_element_cb, |
772 | s); | 783 | s); |
773 | qsort(s->sorted_elements, | 784 | qsort (s->sorted_elements, |
774 | s->used_element_count, | 785 | s->used_element_count, |
775 | sizeof(struct MpiElement), | 786 | sizeof(struct MpiElement), |
776 | &element_cmp); | 787 | &element_cmp); |
777 | if (GNUNET_OK != | 788 | if (GNUNET_OK != |
778 | compute_service_response(s)) | 789 | compute_service_response (s)) |
779 | { | 790 | { |
780 | channel = s->channel; | 791 | channel = s->channel; |
781 | s->channel = NULL; | 792 | s->channel = NULL; |
782 | GNUNET_CADET_channel_destroy(channel); | 793 | GNUNET_CADET_channel_destroy (channel); |
783 | return; | 794 | return; |
784 | } | 795 | } |
785 | transmit_bobs_cryptodata_message(s); | 796 | transmit_bobs_cryptodata_message (s); |
786 | } | 797 | } |
787 | 798 | ||
788 | 799 | ||
@@ -796,8 +807,8 @@ transmit_cryptographic_reply(struct BobServiceSession *s) | |||
796 | * #GNUNET_SYSERR to close it (signal serious error) | 807 | * #GNUNET_SYSERR to close it (signal serious error) |
797 | */ | 808 | */ |
798 | static int | 809 | static int |
799 | check_alices_cryptodata_message(void *cls, | 810 | check_alices_cryptodata_message (void *cls, |
800 | const struct AliceCryptodataMessage *msg) | 811 | const struct AliceCryptodataMessage *msg) |
801 | { | 812 | { |
802 | struct BobServiceSession *s = cls; | 813 | struct BobServiceSession *s = cls; |
803 | uint32_t contained_elements; | 814 | uint32_t contained_elements; |
@@ -805,21 +816,22 @@ check_alices_cryptodata_message(void *cls, | |||
805 | uint16_t msize; | 816 | uint16_t msize; |
806 | unsigned int max; | 817 | unsigned int max; |
807 | 818 | ||
808 | msize = ntohs(msg->header.size); | 819 | msize = ntohs (msg->header.size); |
809 | contained_elements = ntohl(msg->contained_element_count); | 820 | contained_elements = ntohl (msg->contained_element_count); |
810 | /* Our intersection may still be ongoing, but this is nevertheless | 821 | /* Our intersection may still be ongoing, but this is nevertheless |
811 | an upper bound on the required array size */ | 822 | an upper bound on the required array size */ |
812 | max = GNUNET_CONTAINER_multihashmap_size(s->intersected_elements); | 823 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); |
813 | msg_length = sizeof(struct AliceCryptodataMessage) | 824 | msg_length = sizeof(struct AliceCryptodataMessage) |
814 | + contained_elements * sizeof(struct GNUNET_CRYPTO_PaillierCiphertext); | 825 | + contained_elements * sizeof(struct |
826 | GNUNET_CRYPTO_PaillierCiphertext); | ||
815 | if ((msize != msg_length) || | 827 | if ((msize != msg_length) || |
816 | (0 == contained_elements) || | 828 | (0 == contained_elements) || |
817 | (contained_elements > UINT16_MAX) || | 829 | (contained_elements > UINT16_MAX) || |
818 | (max < contained_elements + s->cadet_received_element_count)) | 830 | (max < contained_elements + s->cadet_received_element_count)) |
819 | { | 831 | { |
820 | GNUNET_break_op(0); | 832 | GNUNET_break_op (0); |
821 | return GNUNET_SYSERR; | 833 | return GNUNET_SYSERR; |
822 | } | 834 | } |
823 | return GNUNET_OK; | 835 | return GNUNET_OK; |
824 | } | 836 | } |
825 | 837 | ||
@@ -832,40 +844,41 @@ check_alices_cryptodata_message(void *cls, | |||
832 | * @param msg the actual message | 844 | * @param msg the actual message |
833 | */ | 845 | */ |
834 | static void | 846 | static void |
835 | handle_alices_cryptodata_message(void *cls, | 847 | handle_alices_cryptodata_message (void *cls, |
836 | const struct AliceCryptodataMessage *msg) | 848 | const struct AliceCryptodataMessage *msg) |
837 | { | 849 | { |
838 | struct BobServiceSession *s = cls; | 850 | struct BobServiceSession *s = cls; |
839 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; | 851 | const struct GNUNET_CRYPTO_PaillierCiphertext *payload; |
840 | uint32_t contained_elements; | 852 | uint32_t contained_elements; |
841 | unsigned int max; | 853 | unsigned int max; |
842 | 854 | ||
843 | contained_elements = ntohl(msg->contained_element_count); | 855 | contained_elements = ntohl (msg->contained_element_count); |
844 | /* Our intersection may still be ongoing, but this is nevertheless | 856 | /* Our intersection may still be ongoing, but this is nevertheless |
845 | an upper bound on the required array size */ | 857 | an upper bound on the required array size */ |
846 | max = GNUNET_CONTAINER_multihashmap_size(s->intersected_elements); | 858 | max = GNUNET_CONTAINER_multihashmap_size (s->intersected_elements); |
847 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 859 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
848 | "Received %u crypto values from Alice\n", | 860 | "Received %u crypto values from Alice\n", |
849 | (unsigned int)contained_elements); | 861 | (unsigned int) contained_elements); |
850 | 862 | ||
851 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *)&msg[1]; | 863 | payload = (const struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; |
852 | if (NULL == s->e_a) | 864 | if (NULL == s->e_a) |
853 | s->e_a = GNUNET_new_array(max, | 865 | s->e_a = GNUNET_new_array (max, |
854 | struct GNUNET_CRYPTO_PaillierCiphertext); | 866 | struct GNUNET_CRYPTO_PaillierCiphertext); |
855 | GNUNET_memcpy(&s->e_a[s->cadet_received_element_count], | 867 | GNUNET_memcpy (&s->e_a[s->cadet_received_element_count], |
856 | payload, | 868 | payload, |
857 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) * contained_elements); | 869 | sizeof(struct GNUNET_CRYPTO_PaillierCiphertext) |
870 | * contained_elements); | ||
858 | s->cadet_received_element_count += contained_elements; | 871 | s->cadet_received_element_count += contained_elements; |
859 | 872 | ||
860 | if ((s->cadet_received_element_count == max) && | 873 | if ((s->cadet_received_element_count == max) && |
861 | (NULL == s->intersection_op)) | 874 | (NULL == s->intersection_op)) |
862 | { | 875 | { |
863 | /* intersection has finished also on our side, and | 876 | /* intersection has finished also on our side, and |
864 | we got the full set, so we can proceed with the | 877 | we got the full set, so we can proceed with the |
865 | CADET response(s) */ | 878 | CADET response(s) */ |
866 | transmit_cryptographic_reply(s); | 879 | transmit_cryptographic_reply (s); |
867 | } | 880 | } |
868 | GNUNET_CADET_receive_done(s->channel); | 881 | GNUNET_CADET_receive_done (s->channel); |
869 | } | 882 | } |
870 | 883 | ||
871 | 884 | ||
@@ -879,71 +892,72 @@ handle_alices_cryptodata_message(void *cls, | |||
879 | * @param status what has happened with the set intersection? | 892 | * @param status what has happened with the set intersection? |
880 | */ | 893 | */ |
881 | static void | 894 | static void |
882 | cb_intersection_element_removed(void *cls, | 895 | cb_intersection_element_removed (void *cls, |
883 | const struct GNUNET_SET_Element *element, | 896 | const struct GNUNET_SET_Element *element, |
884 | uint64_t current_size, | 897 | uint64_t current_size, |
885 | enum GNUNET_SET_Status status) | 898 | enum GNUNET_SET_Status status) |
886 | { | 899 | { |
887 | struct BobServiceSession *s = cls; | 900 | struct BobServiceSession *s = cls; |
888 | struct GNUNET_SCALARPRODUCT_Element *se; | 901 | struct GNUNET_SCALARPRODUCT_Element *se; |
889 | 902 | ||
890 | switch (status) | 903 | switch (status) |
904 | { | ||
905 | case GNUNET_SET_STATUS_OK: | ||
906 | /* this element has been removed from the set */ | ||
907 | se = GNUNET_CONTAINER_multihashmap_get (s->intersected_elements, | ||
908 | element->data); | ||
909 | GNUNET_assert (NULL != se); | ||
910 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
911 | "Removed element with key %s and value %lld\n", | ||
912 | GNUNET_h2s (&se->key), | ||
913 | (long long) GNUNET_ntohll (se->value)); | ||
914 | GNUNET_assert (GNUNET_YES == | ||
915 | GNUNET_CONTAINER_multihashmap_remove ( | ||
916 | s->intersected_elements, | ||
917 | element->data, | ||
918 | se)); | ||
919 | GNUNET_free (se); | ||
920 | return; | ||
921 | |||
922 | case GNUNET_SET_STATUS_DONE: | ||
923 | s->intersection_op = NULL; | ||
924 | GNUNET_break (NULL == s->intersection_set); | ||
925 | GNUNET_CADET_receive_done (s->channel); | ||
926 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
927 | "Finished intersection, %d items remain\n", | ||
928 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)); | ||
929 | if (s->client_received_element_count == | ||
930 | GNUNET_CONTAINER_multihashmap_size (s->intersected_elements)) | ||
891 | { | 931 | { |
892 | case GNUNET_SET_STATUS_OK: | 932 | /* CADET transmission from Alice is also already done, |
893 | /* this element has been removed from the set */ | 933 | start with our own reply */ |
894 | se = GNUNET_CONTAINER_multihashmap_get(s->intersected_elements, | 934 | transmit_cryptographic_reply (s); |
895 | element->data); | ||
896 | GNUNET_assert(NULL != se); | ||
897 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
898 | "Removed element with key %s and value %lld\n", | ||
899 | GNUNET_h2s(&se->key), | ||
900 | (long long)GNUNET_ntohll(se->value)); | ||
901 | GNUNET_assert(GNUNET_YES == | ||
902 | GNUNET_CONTAINER_multihashmap_remove(s->intersected_elements, | ||
903 | element->data, | ||
904 | se)); | ||
905 | GNUNET_free(se); | ||
906 | return; | ||
907 | |||
908 | case GNUNET_SET_STATUS_DONE: | ||
909 | s->intersection_op = NULL; | ||
910 | GNUNET_break(NULL == s->intersection_set); | ||
911 | GNUNET_CADET_receive_done(s->channel); | ||
912 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
913 | "Finished intersection, %d items remain\n", | ||
914 | GNUNET_CONTAINER_multihashmap_size(s->intersected_elements)); | ||
915 | if (s->client_received_element_count == | ||
916 | GNUNET_CONTAINER_multihashmap_size(s->intersected_elements)) | ||
917 | { | ||
918 | /* CADET transmission from Alice is also already done, | ||
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; | ||
946 | } | 935 | } |
936 | return; | ||
937 | |||
938 | case GNUNET_SET_STATUS_HALF_DONE: | ||
939 | /* unexpected for intersection */ | ||
940 | GNUNET_break (0); | ||
941 | return; | ||
942 | |||
943 | case GNUNET_SET_STATUS_FAILURE: | ||
944 | /* unhandled status code */ | ||
945 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
946 | "Set intersection failed!\n"); | ||
947 | s->intersection_op = NULL; | ||
948 | if (NULL != s->intersection_set) | ||
949 | { | ||
950 | GNUNET_SET_destroy (s->intersection_set); | ||
951 | s->intersection_set = NULL; | ||
952 | } | ||
953 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
954 | prepare_client_end_notification (s); | ||
955 | return; | ||
956 | |||
957 | default: | ||
958 | GNUNET_break (0); | ||
959 | return; | ||
960 | } | ||
947 | } | 961 | } |
948 | 962 | ||
949 | 963 | ||
@@ -954,31 +968,31 @@ cb_intersection_element_removed(void *cls, | |||
954 | * @param s client session to start intersection for | 968 | * @param s client session to start intersection for |
955 | */ | 969 | */ |
956 | static void | 970 | static void |
957 | start_intersection(struct BobServiceSession *s) | 971 | start_intersection (struct BobServiceSession *s) |
958 | { | 972 | { |
959 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
960 | "Got session with key %s and %u elements, starting intersection.\n", | 974 | "Got session with key %s and %u elements, starting intersection.\n", |
961 | GNUNET_h2s(&s->session_id), | 975 | GNUNET_h2s (&s->session_id), |
962 | (unsigned int)s->total); | 976 | (unsigned int) s->total); |
963 | 977 | ||
964 | s->intersection_op | 978 | s->intersection_op |
965 | = GNUNET_SET_prepare(&s->peer, | 979 | = GNUNET_SET_prepare (&s->peer, |
966 | &s->session_id, | 980 | &s->session_id, |
967 | NULL, | 981 | NULL, |
968 | GNUNET_SET_RESULT_REMOVED, | 982 | GNUNET_SET_RESULT_REMOVED, |
969 | (struct GNUNET_SET_Option[]) { { 0 } }, | 983 | (struct GNUNET_SET_Option[]) { { 0 } }, |
970 | &cb_intersection_element_removed, | 984 | &cb_intersection_element_removed, |
971 | s); | 985 | s); |
972 | if (GNUNET_OK != | 986 | if (GNUNET_OK != |
973 | GNUNET_SET_commit(s->intersection_op, | 987 | GNUNET_SET_commit (s->intersection_op, |
974 | s->intersection_set)) | 988 | s->intersection_set)) |
975 | { | 989 | { |
976 | GNUNET_break(0); | 990 | GNUNET_break (0); |
977 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 991 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
978 | prepare_client_end_notification(s); | 992 | prepare_client_end_notification (s); |
979 | return; | 993 | return; |
980 | } | 994 | } |
981 | GNUNET_SET_destroy(s->intersection_set); | 995 | GNUNET_SET_destroy (s->intersection_set); |
982 | s->intersection_set = NULL; | 996 | s->intersection_set = NULL; |
983 | } | 997 | } |
984 | 998 | ||
@@ -990,15 +1004,15 @@ start_intersection(struct BobServiceSession *s) | |||
990 | * @param msg the actual message | 1004 | * @param msg the actual message |
991 | */ | 1005 | */ |
992 | static void | 1006 | static void |
993 | handle_alices_computation_request(void *cls, | 1007 | handle_alices_computation_request (void *cls, |
994 | const struct ServiceRequestMessage *msg) | 1008 | const struct ServiceRequestMessage *msg) |
995 | { | 1009 | { |
996 | struct BobServiceSession *s = cls; | 1010 | struct BobServiceSession *s = cls; |
997 | 1011 | ||
998 | s->session_id = msg->session_id; // ?? | 1012 | s->session_id = msg->session_id; // ?? |
999 | s->remote_pubkey = msg->public_key; | 1013 | s->remote_pubkey = msg->public_key; |
1000 | if (s->client_received_element_count == s->total) | 1014 | if (s->client_received_element_count == s->total) |
1001 | start_intersection(s); | 1015 | start_intersection (s); |
1002 | } | 1016 | } |
1003 | 1017 | ||
1004 | 1018 | ||
@@ -1013,20 +1027,20 @@ handle_alices_computation_request(void *cls, | |||
1013 | * @return session associated with the channel | 1027 | * @return session associated with the channel |
1014 | */ | 1028 | */ |
1015 | static void * | 1029 | static void * |
1016 | cb_channel_incoming(void *cls, | 1030 | cb_channel_incoming (void *cls, |
1017 | struct GNUNET_CADET_Channel *channel, | 1031 | struct GNUNET_CADET_Channel *channel, |
1018 | const struct GNUNET_PeerIdentity *initiator) | 1032 | const struct GNUNET_PeerIdentity *initiator) |
1019 | { | 1033 | { |
1020 | struct BobServiceSession *s = cls; | 1034 | struct BobServiceSession *s = cls; |
1021 | 1035 | ||
1022 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1036 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1023 | "New incoming channel from peer %s.\n", | 1037 | "New incoming channel from peer %s.\n", |
1024 | GNUNET_i2s(initiator)); | 1038 | GNUNET_i2s (initiator)); |
1025 | GNUNET_CADET_close_port(s->port); | 1039 | GNUNET_CADET_close_port (s->port); |
1026 | s->port = NULL; | 1040 | s->port = NULL; |
1027 | s->channel = channel; | 1041 | s->channel = channel; |
1028 | s->peer = *initiator; | 1042 | s->peer = *initiator; |
1029 | s->cadet_mq = GNUNET_CADET_get_mq(s->channel); | 1043 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); |
1030 | return s; | 1044 | return s; |
1031 | } | 1045 | } |
1032 | 1046 | ||
@@ -1039,25 +1053,28 @@ cb_channel_incoming(void *cls, | |||
1039 | * @return #GNUNET_OK if @a msg is well-formed | 1053 | * @return #GNUNET_OK if @a msg is well-formed |
1040 | */ | 1054 | */ |
1041 | static int | 1055 | static int |
1042 | check_bob_client_message_multipart(void *cls, | 1056 | check_bob_client_message_multipart (void *cls, |
1043 | const struct ComputationBobCryptodataMultipartMessage *msg) | 1057 | const struct |
1058 | ComputationBobCryptodataMultipartMessage * | ||
1059 | msg) | ||
1044 | { | 1060 | { |
1045 | struct BobServiceSession *s = cls; | 1061 | struct BobServiceSession *s = cls; |
1046 | uint32_t contained_count; | 1062 | uint32_t contained_count; |
1047 | uint16_t msize; | 1063 | uint16_t msize; |
1048 | 1064 | ||
1049 | msize = ntohs(msg->header.size); | 1065 | msize = ntohs (msg->header.size); |
1050 | contained_count = ntohl(msg->element_count_contained); | 1066 | contained_count = ntohl (msg->element_count_contained); |
1051 | if ((msize != (sizeof(struct ComputationBobCryptodataMultipartMessage) + | 1067 | if ((msize != (sizeof(struct ComputationBobCryptodataMultipartMessage) |
1052 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element))) || | 1068 | + contained_count * sizeof(struct |
1069 | GNUNET_SCALARPRODUCT_Element))) || | ||
1053 | (0 == contained_count) || | 1070 | (0 == contained_count) || |
1054 | (UINT16_MAX < contained_count) || | 1071 | (UINT16_MAX < contained_count) || |
1055 | (s->total == s->client_received_element_count) || | 1072 | (s->total == s->client_received_element_count) || |
1056 | (s->total < s->client_received_element_count + contained_count)) | 1073 | (s->total < s->client_received_element_count + contained_count)) |
1057 | { | 1074 | { |
1058 | GNUNET_break(0); | 1075 | GNUNET_break (0); |
1059 | return GNUNET_SYSERR; | 1076 | return GNUNET_SYSERR; |
1060 | } | 1077 | } |
1061 | return GNUNET_OK; | 1078 | return GNUNET_OK; |
1062 | } | 1079 | } |
1063 | 1080 | ||
@@ -1070,8 +1087,10 @@ check_bob_client_message_multipart(void *cls, | |||
1070 | * @param msg the actual message | 1087 | * @param msg the actual message |
1071 | */ | 1088 | */ |
1072 | static void | 1089 | static void |
1073 | handle_bob_client_message_multipart(void *cls, | 1090 | handle_bob_client_message_multipart (void *cls, |
1074 | const struct ComputationBobCryptodataMultipartMessage *msg) | 1091 | const struct |
1092 | ComputationBobCryptodataMultipartMessage * | ||
1093 | msg) | ||
1075 | { | 1094 | { |
1076 | struct BobServiceSession *s = cls; | 1095 | struct BobServiceSession *s = cls; |
1077 | uint32_t contained_count; | 1096 | uint32_t contained_count; |
@@ -1079,44 +1098,44 @@ handle_bob_client_message_multipart(void *cls, | |||
1079 | struct GNUNET_SET_Element set_elem; | 1098 | struct GNUNET_SET_Element set_elem; |
1080 | struct GNUNET_SCALARPRODUCT_Element *elem; | 1099 | struct GNUNET_SCALARPRODUCT_Element *elem; |
1081 | 1100 | ||
1082 | contained_count = ntohl(msg->element_count_contained); | 1101 | contained_count = ntohl (msg->element_count_contained); |
1083 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; | 1102 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; |
1084 | for (uint32_t i = 0; i < contained_count; i++) | 1103 | for (uint32_t i = 0; i < contained_count; i++) |
1104 | { | ||
1105 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
1106 | GNUNET_memcpy (elem, | ||
1107 | &elements[i], | ||
1108 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
1109 | if (GNUNET_SYSERR == | ||
1110 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, | ||
1111 | &elem->key, | ||
1112 | elem, | ||
1113 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1085 | { | 1114 | { |
1086 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); | 1115 | GNUNET_break (0); |
1087 | GNUNET_memcpy(elem, | 1116 | GNUNET_free (elem); |
1088 | &elements[i], | 1117 | continue; |
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); | ||
1106 | } | 1118 | } |
1119 | set_elem.data = &elem->key; | ||
1120 | set_elem.size = sizeof(elem->key); | ||
1121 | set_elem.element_type = 0; | ||
1122 | GNUNET_SET_add_element (s->intersection_set, | ||
1123 | &set_elem, | ||
1124 | NULL, NULL); | ||
1125 | } | ||
1107 | s->client_received_element_count += contained_count; | 1126 | s->client_received_element_count += contained_count; |
1108 | GNUNET_SERVICE_client_continue(s->client); | 1127 | GNUNET_SERVICE_client_continue (s->client); |
1109 | if (s->total != s->client_received_element_count) | 1128 | if (s->total != s->client_received_element_count) |
1110 | { | 1129 | { |
1111 | /* more to come */ | 1130 | /* more to come */ |
1112 | return; | 1131 | return; |
1113 | } | 1132 | } |
1114 | if (NULL == s->channel) | 1133 | if (NULL == s->channel) |
1115 | { | 1134 | { |
1116 | /* no Alice waiting for this request, wait for Alice */ | 1135 | /* no Alice waiting for this request, wait for Alice */ |
1117 | return; | 1136 | return; |
1118 | } | 1137 | } |
1119 | start_intersection(s); | 1138 | start_intersection (s); |
1120 | } | 1139 | } |
1121 | 1140 | ||
1122 | 1141 | ||
@@ -1129,8 +1148,8 @@ handle_bob_client_message_multipart(void *cls, | |||
1129 | * @return #GNUNET_OK if @a msg is well-formed | 1148 | * @return #GNUNET_OK if @a msg is well-formed |
1130 | */ | 1149 | */ |
1131 | static int | 1150 | static int |
1132 | check_bob_client_message(void *cls, | 1151 | check_bob_client_message (void *cls, |
1133 | const struct BobComputationMessage *msg) | 1152 | const struct BobComputationMessage *msg) |
1134 | { | 1153 | { |
1135 | struct BobServiceSession *s = cls; | 1154 | struct BobServiceSession *s = cls; |
1136 | uint32_t contained_count; | 1155 | uint32_t contained_count; |
@@ -1138,22 +1157,23 @@ check_bob_client_message(void *cls, | |||
1138 | uint16_t msize; | 1157 | uint16_t msize; |
1139 | 1158 | ||
1140 | if (GNUNET_SCALARPRODUCT_STATUS_INIT != s->status) | 1159 | if (GNUNET_SCALARPRODUCT_STATUS_INIT != s->status) |
1141 | { | 1160 | { |
1142 | GNUNET_break(0); | 1161 | GNUNET_break (0); |
1143 | return GNUNET_SYSERR; | 1162 | return GNUNET_SYSERR; |
1144 | } | 1163 | } |
1145 | msize = ntohs(msg->header.size); | 1164 | msize = ntohs (msg->header.size); |
1146 | total_count = ntohl(msg->element_count_total); | 1165 | total_count = ntohl (msg->element_count_total); |
1147 | contained_count = ntohl(msg->element_count_contained); | 1166 | contained_count = ntohl (msg->element_count_contained); |
1148 | if ((0 == total_count) || | 1167 | if ((0 == total_count) || |
1149 | (0 == contained_count) || | 1168 | (0 == contained_count) || |
1150 | (UINT16_MAX < contained_count) || | 1169 | (UINT16_MAX < contained_count) || |
1151 | (msize != (sizeof(struct BobComputationMessage) + | 1170 | (msize != (sizeof(struct BobComputationMessage) |
1152 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element)))) | 1171 | + contained_count * sizeof(struct |
1153 | { | 1172 | GNUNET_SCALARPRODUCT_Element)))) |
1154 | GNUNET_break_op(0); | 1173 | { |
1155 | return GNUNET_SYSERR; | 1174 | GNUNET_break_op (0); |
1156 | } | 1175 | return GNUNET_SYSERR; |
1176 | } | ||
1157 | return GNUNET_OK; | 1177 | return GNUNET_OK; |
1158 | } | 1178 | } |
1159 | 1179 | ||
@@ -1167,20 +1187,20 @@ check_bob_client_message(void *cls, | |||
1167 | * @param msg the actual message | 1187 | * @param msg the actual message |
1168 | */ | 1188 | */ |
1169 | static void | 1189 | static void |
1170 | handle_bob_client_message(void *cls, | 1190 | handle_bob_client_message (void *cls, |
1171 | const struct BobComputationMessage *msg) | 1191 | const struct BobComputationMessage *msg) |
1172 | { | 1192 | { |
1173 | struct BobServiceSession *s = cls; | 1193 | struct BobServiceSession *s = cls; |
1174 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 1194 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
1175 | GNUNET_MQ_hd_fixed_size(alices_computation_request, | 1195 | GNUNET_MQ_hd_fixed_size (alices_computation_request, |
1176 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION, | 1196 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION, |
1177 | struct ServiceRequestMessage, | 1197 | struct ServiceRequestMessage, |
1178 | NULL), | 1198 | NULL), |
1179 | GNUNET_MQ_hd_var_size(alices_cryptodata_message, | 1199 | GNUNET_MQ_hd_var_size (alices_cryptodata_message, |
1180 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA, | 1200 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA, |
1181 | struct AliceCryptodataMessage, | 1201 | struct AliceCryptodataMessage, |
1182 | NULL), | 1202 | NULL), |
1183 | GNUNET_MQ_handler_end() | 1203 | GNUNET_MQ_handler_end () |
1184 | }; | 1204 | }; |
1185 | uint32_t contained_count; | 1205 | uint32_t contained_count; |
1186 | uint32_t total_count; | 1206 | uint32_t total_count; |
@@ -1188,61 +1208,61 @@ handle_bob_client_message(void *cls, | |||
1188 | struct GNUNET_SET_Element set_elem; | 1208 | struct GNUNET_SET_Element set_elem; |
1189 | struct GNUNET_SCALARPRODUCT_Element *elem; | 1209 | struct GNUNET_SCALARPRODUCT_Element *elem; |
1190 | 1210 | ||
1191 | total_count = ntohl(msg->element_count_total); | 1211 | total_count = ntohl (msg->element_count_total); |
1192 | contained_count = ntohl(msg->element_count_contained); | 1212 | contained_count = ntohl (msg->element_count_contained); |
1193 | 1213 | ||
1194 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; | 1214 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; |
1195 | s->total = total_count; | 1215 | s->total = total_count; |
1196 | s->client_received_element_count = contained_count; | 1216 | s->client_received_element_count = contained_count; |
1197 | s->session_id = msg->session_key; | 1217 | s->session_id = msg->session_key; |
1198 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; | 1218 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; |
1199 | s->intersected_elements | 1219 | s->intersected_elements |
1200 | = GNUNET_CONTAINER_multihashmap_create(s->total, | 1220 | = GNUNET_CONTAINER_multihashmap_create (s->total, |
1201 | GNUNET_YES); | 1221 | GNUNET_YES); |
1202 | s->intersection_set | 1222 | s->intersection_set |
1203 | = GNUNET_SET_create(cfg, | 1223 | = GNUNET_SET_create (cfg, |
1204 | GNUNET_SET_OPERATION_INTERSECTION); | 1224 | GNUNET_SET_OPERATION_INTERSECTION); |
1205 | for (uint32_t i = 0; i < contained_count; i++) | 1225 | for (uint32_t i = 0; i < contained_count; i++) |
1226 | { | ||
1227 | if (0 == GNUNET_ntohll (elements[i].value)) | ||
1228 | continue; | ||
1229 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
1230 | GNUNET_memcpy (elem, | ||
1231 | &elements[i], | ||
1232 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
1233 | if (GNUNET_SYSERR == | ||
1234 | GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, | ||
1235 | &elem->key, | ||
1236 | elem, | ||
1237 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1206 | { | 1238 | { |
1207 | if (0 == GNUNET_ntohll(elements[i].value)) | 1239 | GNUNET_break (0); |
1208 | continue; | 1240 | GNUNET_free (elem); |
1209 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); | 1241 | continue; |
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++; | ||
1230 | } | 1242 | } |
1231 | GNUNET_SERVICE_client_continue(s->client); | 1243 | set_elem.data = &elem->key; |
1244 | set_elem.size = sizeof(elem->key); | ||
1245 | set_elem.element_type = 0; | ||
1246 | GNUNET_SET_add_element (s->intersection_set, | ||
1247 | &set_elem, | ||
1248 | NULL, NULL); | ||
1249 | s->used_element_count++; | ||
1250 | } | ||
1251 | GNUNET_SERVICE_client_continue (s->client); | ||
1232 | /* We're ready, open the port */ | 1252 | /* We're ready, open the port */ |
1233 | s->port = GNUNET_CADET_open_port(my_cadet, | 1253 | s->port = GNUNET_CADET_open_port (my_cadet, |
1234 | &msg->session_key, | 1254 | &msg->session_key, |
1235 | &cb_channel_incoming, | 1255 | &cb_channel_incoming, |
1236 | s, | 1256 | s, |
1237 | NULL, | 1257 | NULL, |
1238 | &cb_channel_destruction, | 1258 | &cb_channel_destruction, |
1239 | cadet_handlers); | 1259 | cadet_handlers); |
1240 | if (NULL == s->port) | 1260 | if (NULL == s->port) |
1241 | { | 1261 | { |
1242 | GNUNET_break(0); | 1262 | GNUNET_break (0); |
1243 | GNUNET_SERVICE_client_drop(s->client); | 1263 | GNUNET_SERVICE_client_drop (s->client); |
1244 | return; | 1264 | return; |
1245 | } | 1265 | } |
1246 | } | 1266 | } |
1247 | 1267 | ||
1248 | 1268 | ||
@@ -1252,16 +1272,16 @@ handle_bob_client_message(void *cls, | |||
1252 | * @param cls unused | 1272 | * @param cls unused |
1253 | */ | 1273 | */ |
1254 | static void | 1274 | static void |
1255 | shutdown_task(void *cls) | 1275 | shutdown_task (void *cls) |
1256 | { | 1276 | { |
1257 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1258 | "Shutting down, initiating cleanup.\n"); | 1278 | "Shutting down, initiating cleanup.\n"); |
1259 | // FIXME: we have to cut our connections to CADET first! | 1279 | // FIXME: we have to cut our connections to CADET first! |
1260 | if (NULL != my_cadet) | 1280 | if (NULL != my_cadet) |
1261 | { | 1281 | { |
1262 | GNUNET_CADET_disconnect(my_cadet); | 1282 | GNUNET_CADET_disconnect (my_cadet); |
1263 | my_cadet = NULL; | 1283 | my_cadet = NULL; |
1264 | } | 1284 | } |
1265 | } | 1285 | } |
1266 | 1286 | ||
1267 | 1287 | ||
@@ -1276,13 +1296,13 @@ shutdown_task(void *cls) | |||
1276 | * @return our `struct BobServiceSession` | 1296 | * @return our `struct BobServiceSession` |
1277 | */ | 1297 | */ |
1278 | static void * | 1298 | static void * |
1279 | client_connect_cb(void *cls, | 1299 | client_connect_cb (void *cls, |
1280 | struct GNUNET_SERVICE_Client *client, | 1300 | struct GNUNET_SERVICE_Client *client, |
1281 | struct GNUNET_MQ_Handle *mq) | 1301 | struct GNUNET_MQ_Handle *mq) |
1282 | { | 1302 | { |
1283 | struct BobServiceSession *s; | 1303 | struct BobServiceSession *s; |
1284 | 1304 | ||
1285 | s = GNUNET_new(struct BobServiceSession); | 1305 | s = GNUNET_new (struct BobServiceSession); |
1286 | s->client = client; | 1306 | s->client = client; |
1287 | s->client_mq = mq; | 1307 | s->client_mq = mq; |
1288 | return s; | 1308 | return s; |
@@ -1300,16 +1320,16 @@ client_connect_cb(void *cls, | |||
1300 | * @param app_cls our `struct BobServiceSession` | 1320 | * @param app_cls our `struct BobServiceSession` |
1301 | */ | 1321 | */ |
1302 | static void | 1322 | static void |
1303 | client_disconnect_cb(void *cls, | 1323 | client_disconnect_cb (void *cls, |
1304 | struct GNUNET_SERVICE_Client *client, | 1324 | struct GNUNET_SERVICE_Client *client, |
1305 | void *app_cls) | 1325 | void *app_cls) |
1306 | { | 1326 | { |
1307 | struct BobServiceSession *s = app_cls; | 1327 | struct BobServiceSession *s = app_cls; |
1308 | 1328 | ||
1309 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1310 | "Client disconnected from us.\n"); | 1330 | "Client disconnected from us.\n"); |
1311 | s->client = NULL; | 1331 | s->client = NULL; |
1312 | destroy_service_session(s); | 1332 | destroy_service_session (s); |
1313 | } | 1333 | } |
1314 | 1334 | ||
1315 | 1335 | ||
@@ -1321,31 +1341,31 @@ client_disconnect_cb(void *cls, | |||
1321 | * @param service the initialized service | 1341 | * @param service the initialized service |
1322 | */ | 1342 | */ |
1323 | static void | 1343 | static void |
1324 | run(void *cls, | 1344 | run (void *cls, |
1325 | const struct GNUNET_CONFIGURATION_Handle *c, | 1345 | const struct GNUNET_CONFIGURATION_Handle *c, |
1326 | struct GNUNET_SERVICE_Handle *service) | 1346 | struct GNUNET_SERVICE_Handle *service) |
1327 | { | 1347 | { |
1328 | cfg = c; | 1348 | cfg = c; |
1329 | /* | 1349 | /* |
1330 | offset has to be sufficiently small to allow computation of: | 1350 | offset has to be sufficiently small to allow computation of: |
1331 | m1+m2 mod n == (S + a) + (S + b) mod n, | 1351 | m1+m2 mod n == (S + a) + (S + b) mod n, |
1332 | 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 */ |
1333 | my_offset = gcry_mpi_new(GNUNET_CRYPTO_PAILLIER_BITS / 3); | 1353 | my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); |
1334 | gcry_mpi_set_bit(my_offset, | 1354 | gcry_mpi_set_bit (my_offset, |
1335 | GNUNET_CRYPTO_PAILLIER_BITS / 3); | 1355 | GNUNET_CRYPTO_PAILLIER_BITS / 3); |
1336 | 1356 | ||
1337 | GNUNET_CRYPTO_paillier_create(&my_pubkey, | 1357 | GNUNET_CRYPTO_paillier_create (&my_pubkey, |
1338 | &my_privkey); | 1358 | &my_privkey); |
1339 | my_cadet = GNUNET_CADET_connect(cfg); | 1359 | my_cadet = GNUNET_CADET_connect (cfg); |
1340 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, | 1360 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1341 | NULL); | 1361 | NULL); |
1342 | if (NULL == my_cadet) | 1362 | if (NULL == my_cadet) |
1343 | { | 1363 | { |
1344 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1364 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1345 | _("Connect to CADET failed\n")); | 1365 | _ ("Connect to CADET failed\n")); |
1346 | GNUNET_SCHEDULER_shutdown(); | 1366 | GNUNET_SCHEDULER_shutdown (); |
1347 | return; | 1367 | return; |
1348 | } | 1368 | } |
1349 | } | 1369 | } |
1350 | 1370 | ||
1351 | 1371 | ||
@@ -1359,15 +1379,15 @@ GNUNET_SERVICE_MAIN | |||
1359 | &client_connect_cb, | 1379 | &client_connect_cb, |
1360 | &client_disconnect_cb, | 1380 | &client_disconnect_cb, |
1361 | NULL, | 1381 | NULL, |
1362 | GNUNET_MQ_hd_var_size(bob_client_message, | 1382 | GNUNET_MQ_hd_var_size (bob_client_message, |
1363 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, | 1383 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, |
1364 | struct BobComputationMessage, | 1384 | struct BobComputationMessage, |
1365 | NULL), | 1385 | NULL), |
1366 | GNUNET_MQ_hd_var_size(bob_client_message_multipart, | 1386 | GNUNET_MQ_hd_var_size (bob_client_message_multipart, |
1367 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, | 1387 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_BOB, |
1368 | struct ComputationBobCryptodataMultipartMessage, | 1388 | struct ComputationBobCryptodataMultipartMessage, |
1369 | NULL), | 1389 | NULL), |
1370 | GNUNET_MQ_handler_end()); | 1390 | GNUNET_MQ_handler_end ()); |
1371 | 1391 | ||
1372 | 1392 | ||
1373 | /* end of gnunet-service-scalarproduct_bob.c */ | 1393 | /* end of gnunet-service-scalarproduct_bob.c */ |