aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-07-17 10:50:45 +0200
committerChristian Grothoff <christian@grothoff.org>2019-07-17 10:50:45 +0200
commita7ccf828ae4f7e306ffe3e7efebc0e678615f6c5 (patch)
tree71489a2649bb3c9100fccc19d135d832d3cbea05 /src/scalarproduct
parent963c4fe2e94208a251b269e3a6918a71e8de1939 (diff)
downloadgnunet-a7ccf828ae4f7e306ffe3e7efebc0e678615f6c5.tar.gz
gnunet-a7ccf828ae4f7e306ffe3e7efebc0e678615f6c5.zip
remove duplication MQ options, make conversation build
Diffstat (limited to 'src/scalarproduct')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c363
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_alice.c379
2 files changed, 324 insertions, 418 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
index 123a02188..dc2763943 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.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,7 +36,8 @@
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-alice", __VA_ARGS__) 39#define LOG(kind, ...) \
40 GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__)
40 41
41/** 42/**
42 * Maximum allowed result value for the scalarproduct computation. 43 * Maximum allowed result value for the scalarproduct computation.
@@ -69,7 +70,6 @@ struct MpiElement
69 * a_i value, not disclosed to Bob. 70 * a_i value, not disclosed to Bob.
70 */ 71 */
71 gcry_mpi_t value; 72 gcry_mpi_t value;
72
73}; 73};
74 74
75 75
@@ -175,7 +175,6 @@ struct AliceServiceSession
175 * doing harm. 175 * doing harm.
176 */ 176 */
177 int in_destroy; 177 int in_destroy;
178
179}; 178};
180 179
181 180
@@ -214,9 +213,7 @@ static struct GNUNET_CADET_Handle *my_cadet;
214 * @return #GNUNET_OK (continue to iterate) 213 * @return #GNUNET_OK (continue to iterate)
215 */ 214 */
216static int 215static int
217free_element_cb (void *cls, 216free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
218 const struct GNUNET_HashCode *key,
219 void *value)
220{ 217{
221 struct GNUNET_SCALARPRODUCT_Element *e = value; 218 struct GNUNET_SCALARPRODUCT_Element *e = value;
222 219
@@ -265,8 +262,7 @@ destroy_service_session (struct AliceServiceSession *s)
265 } 262 }
266 if (NULL != s->intersection_op) 263 if (NULL != s->intersection_op)
267 { 264 {
268 LOG (GNUNET_ERROR_TYPE_DEBUG, 265 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection, op still ongoing!\n");
269 "Set intersection, op still ongoing!\n");
270 GNUNET_SET_operation_cancel (s->intersection_op); 266 GNUNET_SET_operation_cancel (s->intersection_op);
271 s->intersection_op = NULL; 267 s->intersection_op = NULL;
272 } 268 }
@@ -277,7 +273,7 @@ destroy_service_session (struct AliceServiceSession *s)
277 } 273 }
278 if (NULL != s->sorted_elements) 274 if (NULL != s->sorted_elements)
279 { 275 {
280 for (i=0;i<s->used_element_count;i++) 276 for (i = 0; i < s->used_element_count; i++)
281 gcry_mpi_release (s->sorted_elements[i].value); 277 gcry_mpi_release (s->sorted_elements[i].value);
282 GNUNET_free (s->sorted_elements); 278 GNUNET_free (s->sorted_elements);
283 s->sorted_elements = NULL; 279 s->sorted_elements = NULL;
@@ -305,16 +301,15 @@ prepare_client_end_notification (struct AliceServiceSession *session)
305 301
306 if (NULL == session->client_mq) 302 if (NULL == session->client_mq)
307 return; /* no client left to be notified */ 303 return; /* no client left to be notified */
308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 304 GNUNET_log (
309 "Sending session-end notification with status %d to client for session %s\n", 305 GNUNET_ERROR_TYPE_DEBUG,
310 session->status, 306 "Sending session-end notification with status %d to client for session %s\n",
311 GNUNET_h2s (&session->session_id)); 307 session->status,
312 e = GNUNET_MQ_msg (msg, 308 GNUNET_h2s (&session->session_id));
313 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 309 e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
314 msg->product_length = htonl (0); 310 msg->product_length = htonl (0);
315 msg->status = htonl (session->status); 311 msg->status = htonl (session->status);
316 GNUNET_MQ_send (session->client_mq, 312 GNUNET_MQ_send (session->client_mq, e);
317 e);
318} 313}
319 314
320 315
@@ -347,9 +342,7 @@ transmit_client_response (struct AliceServiceSession *s)
347 if (0 > sign) 342 if (0 > sign)
348 { 343 {
349 range = -1; 344 range = -1;
350 gcry_mpi_sub (value, 345 gcry_mpi_sub (value, value, s->product);
351 value,
352 s->product);
353 } 346 }
354 else if (0 < sign) 347 else if (0 < sign)
355 { 348 {
@@ -364,15 +357,12 @@ transmit_client_response (struct AliceServiceSession *s)
364 gcry_mpi_release (s->product); 357 gcry_mpi_release (s->product);
365 s->product = NULL; 358 s->product = NULL;
366 359
367 if ( (0 != range) && 360 if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD,
368 (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, 361 &product_exported,
369 &product_exported, 362 &product_length,
370 &product_length, 363 value))))
371 value))))
372 { 364 {
373 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, 365 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
374 "gcry_mpi_scan",
375 rc);
376 prepare_client_end_notification (s); 366 prepare_client_end_notification (s);
377 return; 367 return;
378 } 368 }
@@ -385,13 +375,10 @@ transmit_client_response (struct AliceServiceSession *s)
385 msg->product_length = htonl (product_length); 375 msg->product_length = htonl (product_length);
386 if (NULL != product_exported) 376 if (NULL != product_exported)
387 { 377 {
388 GNUNET_memcpy (&msg[1], 378 GNUNET_memcpy (&msg[1], product_exported, product_length);
389 product_exported,
390 product_length);
391 GNUNET_free (product_exported); 379 GNUNET_free (product_exported);
392 } 380 }
393 GNUNET_MQ_send (s->client_mq, 381 GNUNET_MQ_send (s->client_mq, e);
394 e);
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Sent result to client, session %s has ended!\n", 383 "Sent result to client, session %s has ended!\n",
397 GNUNET_h2s (&s->session_id)); 384 GNUNET_h2s (&s->session_id));
@@ -408,8 +395,7 @@ transmit_client_response (struct AliceServiceSession *s)
408 * @param channel connection to the other end (henceforth invalid) 395 * @param channel connection to the other end (henceforth invalid)
409 */ 396 */
410static void 397static void
411cb_channel_destruction (void *cls, 398cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel)
412 const struct GNUNET_CADET_Channel *channel)
413{ 399{
414 struct AliceServiceSession *s = cls; 400 struct AliceServiceSession *s = cls;
415 401
@@ -445,15 +431,11 @@ compute_scalar_product (struct AliceServiceSession *session,
445 int ai_bi; 431 int ai_bi;
446 gcry_mpi_t ret; 432 gcry_mpi_t ret;
447 433
448 g_i_b_i_a_inv = GNUNET_CRYPTO_ecc_pmul_mpi (edc, 434 g_i_b_i_a_inv =
449 prod_g_i_b_i, 435 GNUNET_CRYPTO_ecc_pmul_mpi (edc, prod_g_i_b_i, my_privkey_inv);
450 my_privkey_inv); 436 g_ai_bi = GNUNET_CRYPTO_ecc_add (edc, g_i_b_i_a_inv, prod_h_i_b_i);
451 g_ai_bi = GNUNET_CRYPTO_ecc_add (edc,
452 g_i_b_i_a_inv,
453 prod_h_i_b_i);
454 gcry_mpi_point_release (g_i_b_i_a_inv); 437 gcry_mpi_point_release (g_i_b_i_a_inv);
455 ai_bi = GNUNET_CRYPTO_ecc_dlog (edc, 438 ai_bi = GNUNET_CRYPTO_ecc_dlog (edc, g_ai_bi);
456 g_ai_bi);
457 gcry_mpi_point_release (g_ai_bi); 439 gcry_mpi_point_release (g_ai_bi);
458 if (INT_MAX == ai_bi) 440 if (INT_MAX == ai_bi)
459 { 441 {
@@ -469,7 +451,7 @@ compute_scalar_product (struct AliceServiceSession *session,
469 } 451 }
470 else 452 else
471 { 453 {
472 gcry_mpi_set_ui (ret, - ai_bi); 454 gcry_mpi_set_ui (ret, -ai_bi);
473 gcry_mpi_neg (ret, ret); 455 gcry_mpi_neg (ret, ret);
474 } 456 }
475 return ret; 457 return ret;
@@ -518,13 +500,9 @@ handle_bobs_cryptodata_message (void *cls,
518 "Received %u crypto values from Bob\n", 500 "Received %u crypto values from Bob\n",
519 (unsigned int) contained); 501 (unsigned int) contained);
520 GNUNET_CADET_receive_done (s->channel); 502 GNUNET_CADET_receive_done (s->channel);
521 prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, 503 prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_g_i_b_i);
522 &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);
523 prod_h_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, 505 s->product = compute_scalar_product (s, prod_g_i_b_i, prod_h_i_b_i);
524 &msg->prod_h_i_b_i);
525 s->product = compute_scalar_product (s,
526 prod_g_i_b_i,
527 prod_h_i_b_i);
528 gcry_mpi_point_release (prod_g_i_b_i); 506 gcry_mpi_point_release (prod_g_i_b_i);
529 gcry_mpi_point_release (prod_h_i_b_i); 507 gcry_mpi_point_release (prod_h_i_b_i);
530 transmit_client_response (s); 508 transmit_client_response (s);
@@ -540,9 +518,7 @@ handle_bobs_cryptodata_message (void *cls,
540 * @param value the `struct GNUNET_SCALARPRODUCT_Element *` 518 * @param value the `struct GNUNET_SCALARPRODUCT_Element *`
541 */ 519 */
542static int 520static int
543copy_element_cb (void *cls, 521copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
544 const struct GNUNET_HashCode *key,
545 void *value)
546{ 522{
547 struct AliceServiceSession *s = cls; 523 struct AliceServiceSession *s = cls;
548 struct GNUNET_SCALARPRODUCT_Element *e = value; 524 struct GNUNET_SCALARPRODUCT_Element *e = value;
@@ -555,8 +531,8 @@ copy_element_cb (void *cls,
555 gcry_mpi_sub_ui (mval, mval, -val); 531 gcry_mpi_sub_ui (mval, mval, -val);
556 else 532 else
557 gcry_mpi_add_ui (mval, mval, val); 533 gcry_mpi_add_ui (mval, mval, val);
558 s->sorted_elements [s->used_element_count].value = mval; 534 s->sorted_elements[s->used_element_count].value = mval;
559 s->sorted_elements [s->used_element_count].key = &e->key; 535 s->sorted_elements[s->used_element_count].key = &e->key;
560 s->used_element_count++; 536 s->used_element_count++;
561 return GNUNET_OK; 537 return GNUNET_OK;
562} 538}
@@ -570,14 +546,12 @@ copy_element_cb (void *cls,
570 * @return -1 for a < b, 0 for a=b, 1 for a > b. 546 * @return -1 for a < b, 0 for a=b, 1 for a > b.
571 */ 547 */
572static int 548static int
573element_cmp (const void *a, 549element_cmp (const void *a, const void *b)
574 const void *b)
575{ 550{
576 const struct MpiElement *ma = a; 551 const struct MpiElement *ma = a;
577 const struct MpiElement *mb = b; 552 const struct MpiElement *mb = b;
578 553
579 return GNUNET_CRYPTO_hash_cmp (ma->key, 554 return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key);
580 mb->key);
581} 555}
582 556
583 557
@@ -585,7 +559,10 @@ element_cmp (const void *a,
585 * Maximum number of elements we can put into a single cryptodata 559 * Maximum number of elements we can put into a single cryptodata
586 * message 560 * message
587 */ 561 */
588#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct EccAliceCryptodataMessage)) / sizeof (struct GNUNET_CRYPTO_EccPoint)) 562#define ELEMENT_CAPACITY \
563 ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \
564 sizeof (struct EccAliceCryptodataMessage)) / \
565 sizeof (struct GNUNET_CRYPTO_EccPoint))
589 566
590 567
591/** 568/**
@@ -606,9 +583,9 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
606 unsigned int off; 583 unsigned int off;
607 unsigned int todo_count; 584 unsigned int todo_count;
608 585
609 s->sorted_elements 586 s->sorted_elements = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size (
610 = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements), 587 s->intersected_elements),
611 struct MpiElement); 588 struct MpiElement);
612 s->used_element_count = 0; 589 s->used_element_count = 0;
613 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, 590 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
614 &copy_element_cb, 591 &copy_element_cb,
@@ -631,11 +608,11 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
631 (unsigned int) todo_count, 608 (unsigned int) todo_count,
632 (unsigned int) s->used_element_count); 609 (unsigned int) s->used_element_count);
633 610
634 e = GNUNET_MQ_msg_extra (msg, 611 e =
635 todo_count * 2 * sizeof (struct GNUNET_CRYPTO_EccPoint), 612 GNUNET_MQ_msg_extra (msg,
636 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA); 613 todo_count * 2 *
637 GNUNET_MQ_env_set_options(e, 614 sizeof (struct GNUNET_CRYPTO_EccPoint),
638 GNUNET_MQ_PREF_RELIABLE); 615 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA);
639 msg->contained_element_count = htonl (todo_count); 616 msg->contained_element_count = htonl (todo_count);
640 payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1]; 617 payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1];
641 r_ia = gcry_mpi_new (0); 618 r_ia = gcry_mpi_new (0);
@@ -647,33 +624,22 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
647 gcry_mpi_point_t h_i; 624 gcry_mpi_point_t h_i;
648 625
649 r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc); 626 r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc);
650 g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, 627 g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_i);
651 r_i);
652 /* r_ia = r_i * a */ 628 /* r_ia = r_i * a */
653 gcry_mpi_mul (r_ia, 629 gcry_mpi_mul (r_ia, r_i, my_privkey);
654 r_i,
655 my_privkey);
656 gcry_mpi_release (r_i); 630 gcry_mpi_release (r_i);
657 /* r_ia_ai = r_ia + a_i */ 631 /* r_ia_ai = r_ia + a_i */
658 gcry_mpi_add (r_ia_ai, 632 gcry_mpi_add (r_ia_ai, r_ia, s->sorted_elements[i].value);
659 r_ia, 633 h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_ia_ai);
660 s->sorted_elements[i].value); 634 GNUNET_CRYPTO_ecc_point_to_bin (edc, g_i, &payload[(i - off) * 2]);
661 h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, 635 GNUNET_CRYPTO_ecc_point_to_bin (edc, h_i, &payload[(i - off) * 2 + 1]);
662 r_ia_ai);
663 GNUNET_CRYPTO_ecc_point_to_bin (edc,
664 g_i,
665 &payload[(i - off) * 2]);
666 GNUNET_CRYPTO_ecc_point_to_bin (edc,
667 h_i,
668 &payload[(i - off) * 2 + 1]);
669 gcry_mpi_point_release (g_i); 636 gcry_mpi_point_release (g_i);
670 gcry_mpi_point_release (h_i); 637 gcry_mpi_point_release (h_i);
671 } 638 }
672 gcry_mpi_release (r_ia); 639 gcry_mpi_release (r_ia);
673 gcry_mpi_release (r_ia_ai); 640 gcry_mpi_release (r_ia_ai);
674 off += todo_count; 641 off += todo_count;
675 GNUNET_MQ_send (s->cadet_mq, 642 GNUNET_MQ_send (s->cadet_mq, e);
676 e);
677 } 643 }
678} 644}
679 645
@@ -708,10 +674,11 @@ cb_intersection_element_removed (void *cls,
708 "Intersection removed element with key %s and value %lld\n", 674 "Intersection removed element with key %s and value %lld\n",
709 GNUNET_h2s (&se->key), 675 GNUNET_h2s (&se->key),
710 (long long) GNUNET_ntohll (se->value)); 676 (long long) GNUNET_ntohll (se->value));
711 GNUNET_assert (GNUNET_YES == 677 GNUNET_assert (
712 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, 678 GNUNET_YES ==
713 element->data, 679 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
714 se)); 680 element->data,
681 se));
715 GNUNET_free (se); 682 GNUNET_free (se);
716 return; 683 return;
717 case GNUNET_SET_STATUS_DONE: 684 case GNUNET_SET_STATUS_DONE:
@@ -729,8 +696,7 @@ cb_intersection_element_removed (void *cls,
729 return; 696 return;
730 case GNUNET_SET_STATUS_FAILURE: 697 case GNUNET_SET_STATUS_FAILURE:
731 /* unhandled status code */ 698 /* unhandled status code */
732 LOG (GNUNET_ERROR_TYPE_DEBUG, 699 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
733 "Set intersection failed!\n");
734 if (NULL != s->intersection_listen) 700 if (NULL != s->intersection_listen)
735 { 701 {
736 GNUNET_SET_listen_cancel (s->intersection_listen); 702 GNUNET_SET_listen_cancel (s->intersection_listen);
@@ -778,18 +744,16 @@ cb_intersection_request_alice (void *cls,
778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
779 "Received intersection request from %s!\n", 745 "Received intersection request from %s!\n",
780 GNUNET_i2s (other_peer)); 746 GNUNET_i2s (other_peer));
781 if (0 != GNUNET_memcmp (other_peer, 747 if (0 != GNUNET_memcmp (other_peer, &s->peer))
782 &s->peer))
783 { 748 {
784 GNUNET_break_op (0); 749 GNUNET_break_op (0);
785 return; 750 return;
786 } 751 }
787 s->intersection_op 752 s->intersection_op = GNUNET_SET_accept (request,
788 = GNUNET_SET_accept (request, 753 GNUNET_SET_RESULT_REMOVED,
789 GNUNET_SET_RESULT_REMOVED, 754 (struct GNUNET_SET_Option[]){{0}},
790 (struct GNUNET_SET_Option[]) {{ 0 }}, 755 &cb_intersection_element_removed,
791 &cb_intersection_element_removed, 756 s);
792 s);
793 if (NULL == s->intersection_op) 757 if (NULL == s->intersection_op)
794 { 758 {
795 GNUNET_break (0); 759 GNUNET_break (0);
@@ -797,9 +761,7 @@ cb_intersection_request_alice (void *cls,
797 prepare_client_end_notification (s); 761 prepare_client_end_notification (s);
798 return; 762 return;
799 } 763 }
800 if (GNUNET_OK != 764 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
801 GNUNET_SET_commit (s->intersection_op,
802 s->intersection_set))
803 { 765 {
804 GNUNET_break (0); 766 GNUNET_break (0);
805 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 767 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -817,13 +779,12 @@ cb_intersection_request_alice (void *cls,
817static void 779static void
818client_request_complete_alice (struct AliceServiceSession *s) 780client_request_complete_alice (struct AliceServiceSession *s)
819{ 781{
820 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 782 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
821 GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, 783 {GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message,
822 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, 784 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA,
823 struct EccBobCryptodataMessage, 785 struct EccBobCryptodataMessage,
824 s), 786 s),
825 GNUNET_MQ_handler_end () 787 GNUNET_MQ_handler_end ()};
826 };
827 struct EccServiceRequestMessage *msg; 788 struct EccServiceRequestMessage *msg;
828 struct GNUNET_MQ_Envelope *e; 789 struct GNUNET_MQ_Envelope *e;
829 struct GNUNET_HashCode set_sid; 790 struct GNUNET_HashCode set_sid;
@@ -834,14 +795,13 @@ client_request_complete_alice (struct AliceServiceSession *s)
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
835 "Creating new channel for session with key %s.\n", 796 "Creating new channel for session with key %s.\n",
836 GNUNET_h2s (&s->session_id)); 797 GNUNET_h2s (&s->session_id));
837 s->channel 798 s->channel = GNUNET_CADET_channel_create (my_cadet,
838 = GNUNET_CADET_channel_create (my_cadet, 799 s,
839 s, 800 &s->peer,
840 &s->peer, 801 &s->session_id,
841 &s->session_id, 802 NULL,
842 NULL, 803 &cb_channel_destruction,
843 &cb_channel_destruction, 804 cadet_handlers);
844 cadet_handlers);
845 if (NULL == s->channel) 805 if (NULL == s->channel)
846 { 806 {
847 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 807 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -849,12 +809,11 @@ client_request_complete_alice (struct AliceServiceSession *s)
849 return; 809 return;
850 } 810 }
851 s->cadet_mq = GNUNET_CADET_get_mq (s->channel); 811 s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
852 s->intersection_listen 812 s->intersection_listen = GNUNET_SET_listen (cfg,
853 = GNUNET_SET_listen (cfg, 813 GNUNET_SET_OPERATION_INTERSECTION,
854 GNUNET_SET_OPERATION_INTERSECTION, 814 &set_sid,
855 &set_sid, 815 &cb_intersection_request_alice,
856 &cb_intersection_request_alice, 816 s);
857 s);
858 if (NULL == s->intersection_listen) 817 if (NULL == s->intersection_listen)
859 { 818 {
860 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 819 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -864,13 +823,12 @@ client_request_complete_alice (struct AliceServiceSession *s)
864 return; 823 return;
865 } 824 }
866 825
867 e = GNUNET_MQ_msg (msg, 826 e =
868 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION); 827 GNUNET_MQ_msg (msg,
869 GNUNET_MQ_env_set_options(e, 828 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION);
870 GNUNET_MQ_PREF_RELIABLE); 829 GNUNET_MQ_env_set_options (e, GNUNET_MQ_PRIO_CRITICAL_CONTROL);
871 msg->session_id = s->session_id; 830 msg->session_id = s->session_id;
872 GNUNET_MQ_send (s->cadet_mq, 831 GNUNET_MQ_send (s->cadet_mq, e);
873 e);
874} 832}
875 833
876 834
@@ -883,8 +841,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
883 * @return #GNUNET_OK if @a msg is well-formed 841 * @return #GNUNET_OK if @a msg is well-formed
884 */ 842 */
885static int 843static int
886check_alice_client_message_multipart (void *cls, 844check_alice_client_message_multipart (
887 const struct ComputationBobCryptodataMultipartMessage *msg) 845 void *cls,
846 const struct ComputationBobCryptodataMultipartMessage *msg)
888{ 847{
889 struct AliceServiceSession *s = cls; 848 struct AliceServiceSession *s = cls;
890 uint32_t contained_count; 849 uint32_t contained_count;
@@ -892,11 +851,12 @@ check_alice_client_message_multipart (void *cls,
892 851
893 msize = ntohs (msg->header.size); 852 msize = ntohs (msg->header.size);
894 contained_count = ntohl (msg->element_count_contained); 853 contained_count = ntohl (msg->element_count_contained);
895 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + 854 if ((msize !=
896 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 855 (sizeof (struct ComputationBobCryptodataMultipartMessage) +
897 (0 == contained_count) || 856 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
898 (s->total == s->client_received_element_count) || 857 (0 == contained_count) ||
899 (s->total < s->client_received_element_count + contained_count) ) 858 (s->total == s->client_received_element_count) ||
859 (s->total < s->client_received_element_count + contained_count))
900 { 860 {
901 GNUNET_break_op (0); 861 GNUNET_break_op (0);
902 return GNUNET_SYSERR; 862 return GNUNET_SYSERR;
@@ -913,8 +873,9 @@ check_alice_client_message_multipart (void *cls,
913 * @param msg the actual message 873 * @param msg the actual message
914 */ 874 */
915static void 875static void
916handle_alice_client_message_multipart (void *cls, 876handle_alice_client_message_multipart (
917 const struct ComputationBobCryptodataMultipartMessage *msg) 877 void *cls,
878 const struct ComputationBobCryptodataMultipartMessage *msg)
918{ 879{
919 struct AliceServiceSession *s = cls; 880 struct AliceServiceSession *s = cls;
920 uint32_t contained_count; 881 uint32_t contained_count;
@@ -929,13 +890,13 @@ handle_alice_client_message_multipart (void *cls,
929 { 890 {
930 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 891 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
931 GNUNET_memcpy (elem, 892 GNUNET_memcpy (elem,
932 &elements[i], 893 &elements[i],
933 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 894 sizeof (struct GNUNET_SCALARPRODUCT_Element));
934 if (GNUNET_SYSERR == 895 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
935 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 896 s->intersected_elements,
936 &elem->key, 897 &elem->key,
937 elem, 898 elem,
938 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 899 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
939 { 900 {
940 GNUNET_break (0); 901 GNUNET_break (0);
941 GNUNET_free (elem); 902 GNUNET_free (elem);
@@ -944,9 +905,7 @@ handle_alice_client_message_multipart (void *cls,
944 set_elem.data = &elem->key; 905 set_elem.data = &elem->key;
945 set_elem.size = sizeof (elem->key); 906 set_elem.size = sizeof (elem->key);
946 set_elem.element_type = 0; 907 set_elem.element_type = 0;
947 GNUNET_SET_add_element (s->intersection_set, 908 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
948 &set_elem,
949 NULL, NULL);
950 s->used_element_count++; 909 s->used_element_count++;
951 } 910 }
952 GNUNET_SERVICE_client_continue (s->client); 911 GNUNET_SERVICE_client_continue (s->client);
@@ -957,8 +916,7 @@ handle_alice_client_message_multipart (void *cls,
957 "Received client multipart data, waiting for more!\n"); 916 "Received client multipart data, waiting for more!\n");
958 return; 917 return;
959 } 918 }
960 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n");
961 "Launching computation\n");
962 client_request_complete_alice (s); 920 client_request_complete_alice (s);
963} 921}
964 922
@@ -973,7 +931,7 @@ handle_alice_client_message_multipart (void *cls,
973 */ 931 */
974static int 932static int
975check_alice_client_message (void *cls, 933check_alice_client_message (void *cls,
976 const struct AliceComputationMessage *msg) 934 const struct AliceComputationMessage *msg)
977{ 935{
978 struct AliceServiceSession *s = cls; 936 struct AliceServiceSession *s = cls;
979 uint16_t msize; 937 uint16_t msize;
@@ -990,10 +948,10 @@ check_alice_client_message (void *cls,
990 msize = ntohs (msg->header.size); 948 msize = ntohs (msg->header.size);
991 total_count = ntohl (msg->element_count_total); 949 total_count = ntohl (msg->element_count_total);
992 contained_count = ntohl (msg->element_count_contained); 950 contained_count = ntohl (msg->element_count_contained);
993 if ( (0 == total_count) || 951 if ((0 == total_count) || (0 == contained_count) ||
994 (0 == contained_count) || 952 (msize !=
995 (msize != (sizeof (struct AliceComputationMessage) + 953 (sizeof (struct AliceComputationMessage) +
996 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) 954 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))))
997 { 955 {
998 GNUNET_break_op (0); 956 GNUNET_break_op (0);
999 return GNUNET_SYSERR; 957 return GNUNET_SYSERR;
@@ -1011,7 +969,7 @@ check_alice_client_message (void *cls,
1011 */ 969 */
1012static void 970static void
1013handle_alice_client_message (void *cls, 971handle_alice_client_message (void *cls,
1014 const struct AliceComputationMessage *msg) 972 const struct AliceComputationMessage *msg)
1015{ 973{
1016 struct AliceServiceSession *s = cls; 974 struct AliceServiceSession *s = cls;
1017 uint32_t contained_count; 975 uint32_t contained_count;
@@ -1028,23 +986,23 @@ handle_alice_client_message (void *cls,
1028 s->client_received_element_count = contained_count; 986 s->client_received_element_count = contained_count;
1029 s->session_id = msg->session_key; 987 s->session_id = msg->session_key;
1030 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 988 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1031 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, 989 s->intersected_elements =
1032 GNUNET_YES); 990 GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES);
1033 s->intersection_set = GNUNET_SET_create (cfg, 991 s->intersection_set =
1034 GNUNET_SET_OPERATION_INTERSECTION); 992 GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
1035 for (uint32_t i = 0; i < contained_count; i++) 993 for (uint32_t i = 0; i < contained_count; i++)
1036 { 994 {
1037 if (0 == GNUNET_ntohll (elements[i].value)) 995 if (0 == GNUNET_ntohll (elements[i].value))
1038 continue; 996 continue;
1039 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 997 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1040 GNUNET_memcpy (elem, 998 GNUNET_memcpy (elem,
1041 &elements[i], 999 &elements[i],
1042 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1000 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1043 if (GNUNET_SYSERR == 1001 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1044 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1002 s->intersected_elements,
1045 &elem->key, 1003 &elem->key,
1046 elem, 1004 elem,
1047 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1005 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1048 { 1006 {
1049 /* element with same key encountered twice! */ 1007 /* element with same key encountered twice! */
1050 GNUNET_break (0); 1008 GNUNET_break (0);
@@ -1054,9 +1012,7 @@ handle_alice_client_message (void *cls,
1054 set_elem.data = &elem->key; 1012 set_elem.data = &elem->key;
1055 set_elem.size = sizeof (elem->key); 1013 set_elem.size = sizeof (elem->key);
1056 set_elem.element_type = 0; 1014 set_elem.element_type = 0;
1057 GNUNET_SET_add_element (s->intersection_set, 1015 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1058 &set_elem,
1059 NULL, NULL);
1060 s->used_element_count++; 1016 s->used_element_count++;
1061 } 1017 }
1062 GNUNET_SERVICE_client_continue (s->client); 1018 GNUNET_SERVICE_client_continue (s->client);
@@ -1067,8 +1023,7 @@ handle_alice_client_message (void *cls,
1067 "Received partial client request, waiting for more!\n"); 1023 "Received partial client request, waiting for more!\n");
1068 return; 1024 return;
1069 } 1025 }
1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n");
1071 "Launching computation\n");
1072 client_request_complete_alice (s); 1027 client_request_complete_alice (s);
1073} 1028}
1074 1029
@@ -1082,8 +1037,7 @@ handle_alice_client_message (void *cls,
1082static void 1037static void
1083shutdown_task (void *cls) 1038shutdown_task (void *cls)
1084{ 1039{
1085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
1086 "Shutting down, initiating cleanup.\n");
1087 // FIXME: we have to cut our connections to CADET first! 1041 // FIXME: we have to cut our connections to CADET first!
1088 if (NULL != my_cadet) 1042 if (NULL != my_cadet)
1089 { 1043 {
@@ -1110,8 +1064,8 @@ shutdown_task (void *cls)
1110 */ 1064 */
1111static void * 1065static void *
1112client_connect_cb (void *cls, 1066client_connect_cb (void *cls,
1113 struct GNUNET_SERVICE_Client *client, 1067 struct GNUNET_SERVICE_Client *client,
1114 struct GNUNET_MQ_Handle *mq) 1068 struct GNUNET_MQ_Handle *mq)
1115{ 1069{
1116 struct AliceServiceSession *s; 1070 struct AliceServiceSession *s;
1117 1071
@@ -1134,8 +1088,8 @@ client_connect_cb (void *cls,
1134 */ 1088 */
1135static void 1089static void
1136client_disconnect_cb (void *cls, 1090client_disconnect_cb (void *cls,
1137 struct GNUNET_SERVICE_Client *client, 1091 struct GNUNET_SERVICE_Client *client,
1138 void *app_cls) 1092 void *app_cls)
1139{ 1093{
1140 struct AliceServiceSession *s = app_cls; 1094 struct AliceServiceSession *s = app_cls;
1141 1095
@@ -1161,45 +1115,40 @@ run (void *cls,
1161 struct GNUNET_SERVICE_Handle *service) 1115 struct GNUNET_SERVICE_Handle *service)
1162{ 1116{
1163 cfg = c; 1117 cfg = c;
1164 edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, 1118 edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, MAX_RAM);
1165 MAX_RAM);
1166 /* Select a random 'a' value for Alice */ 1119 /* Select a random 'a' value for Alice */
1167 GNUNET_CRYPTO_ecc_rnd_mpi (edc, 1120 GNUNET_CRYPTO_ecc_rnd_mpi (edc, &my_privkey, &my_privkey_inv);
1168 &my_privkey,
1169 &my_privkey_inv);
1170 my_cadet = GNUNET_CADET_connect (cfg); 1121 my_cadet = GNUNET_CADET_connect (cfg);
1171 if (NULL == my_cadet) 1122 if (NULL == my_cadet)
1172 { 1123 {
1173 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
1174 _("Connect to CADET failed\n"));
1175 GNUNET_SCHEDULER_shutdown (); 1125 GNUNET_SCHEDULER_shutdown ();
1176 return; 1126 return;
1177 } 1127 }
1178 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1128 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1179 NULL);
1180
1181} 1129}
1182 1130
1183 1131
1184/** 1132/**
1185 * Define "main" method using service macro. 1133 * Define "main" method using service macro.
1186 */ 1134 */
1187GNUNET_SERVICE_MAIN 1135GNUNET_SERVICE_MAIN (
1188("scalarproduct-alice", 1136 "scalarproduct-alice",
1189 GNUNET_SERVICE_OPTION_NONE, 1137 GNUNET_SERVICE_OPTION_NONE,
1190 &run, 1138 &run,
1191 &client_connect_cb, 1139 &client_connect_cb,
1192 &client_disconnect_cb, 1140 &client_disconnect_cb,
1193 NULL, 1141 NULL,
1194 GNUNET_MQ_hd_var_size (alice_client_message, 1142 GNUNET_MQ_hd_var_size (alice_client_message,
1195 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 1143 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
1196 struct AliceComputationMessage, 1144 struct AliceComputationMessage,
1197 NULL), 1145 NULL),
1198 GNUNET_MQ_hd_var_size (alice_client_message_multipart, 1146 GNUNET_MQ_hd_var_size (
1199 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, 1147 alice_client_message_multipart,
1200 struct ComputationBobCryptodataMultipartMessage, 1148 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
1201 NULL), 1149 struct ComputationBobCryptodataMultipartMessage,
1202 GNUNET_MQ_handler_end ()); 1150 NULL),
1151 GNUNET_MQ_handler_end ());
1203 1152
1204 1153
1205/* end of gnunet-service-scalarproduct-ecc_alice.c */ 1154/* end of gnunet-service-scalarproduct-ecc_alice.c */
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index 18c5cc49a..e138876f5 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.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,7 +36,8 @@
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-alice", __VA_ARGS__) 39#define LOG(kind, ...) \
40 GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__)
40 41
41/** 42/**
42 * An encrypted element key-value pair. 43 * An encrypted element key-value pair.
@@ -185,7 +186,6 @@ struct AliceServiceSession
185 * doing harm. 186 * doing harm.
186 */ 187 */
187 int in_destroy; 188 int in_destroy;
188
189}; 189};
190 190
191 191
@@ -224,9 +224,7 @@ static struct GNUNET_CADET_Handle *my_cadet;
224 * @return #GNUNET_OK (continue to iterate) 224 * @return #GNUNET_OK (continue to iterate)
225 */ 225 */
226static int 226static int
227free_element_cb (void *cls, 227free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
228 const struct GNUNET_HashCode *key,
229 void *value)
230{ 228{
231 struct GNUNET_SCALARPRODUCT_Element *e = value; 229 struct GNUNET_SCALARPRODUCT_Element *e = value;
232 230
@@ -283,7 +281,7 @@ destroy_service_session (struct AliceServiceSession *s)
283 } 281 }
284 if (NULL != s->sorted_elements) 282 if (NULL != s->sorted_elements)
285 { 283 {
286 for (unsigned int i=0;i<s->used_element_count;i++) 284 for (unsigned int i = 0; i < s->used_element_count; i++)
287 gcry_mpi_release (s->sorted_elements[i].value); 285 gcry_mpi_release (s->sorted_elements[i].value);
288 GNUNET_free (s->sorted_elements); 286 GNUNET_free (s->sorted_elements);
289 s->sorted_elements = NULL; 287 s->sorted_elements = NULL;
@@ -321,16 +319,15 @@ prepare_client_end_notification (struct AliceServiceSession *session)
321 319
322 if (NULL == session->client_mq) 320 if (NULL == session->client_mq)
323 return; /* no client left to be notified */ 321 return; /* no client left to be notified */
324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 322 GNUNET_log (
325 "Sending session-end notification with status %d to client for session %s\n", 323 GNUNET_ERROR_TYPE_DEBUG,
326 session->status, 324 "Sending session-end notification with status %d to client for session %s\n",
327 GNUNET_h2s (&session->session_id)); 325 session->status,
328 e = GNUNET_MQ_msg (msg, 326 GNUNET_h2s (&session->session_id));
329 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 327 e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
330 msg->product_length = htonl (0); 328 msg->product_length = htonl (0);
331 msg->status = htonl (session->status); 329 msg->status = htonl (session->status);
332 GNUNET_MQ_send (session->client_mq, 330 GNUNET_MQ_send (session->client_mq, e);
333 e);
334} 331}
335 332
336 333
@@ -363,9 +360,7 @@ transmit_client_response (struct AliceServiceSession *s)
363 if (0 > sign) 360 if (0 > sign)
364 { 361 {
365 range = -1; 362 range = -1;
366 gcry_mpi_sub (value, 363 gcry_mpi_sub (value, value, s->product);
367 value,
368 s->product);
369 } 364 }
370 else if (0 < sign) 365 else if (0 < sign)
371 { 366 {
@@ -380,15 +375,12 @@ transmit_client_response (struct AliceServiceSession *s)
380 gcry_mpi_release (s->product); 375 gcry_mpi_release (s->product);
381 s->product = NULL; 376 s->product = NULL;
382 377
383 if ( (0 != range) && 378 if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD,
384 (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, 379 &product_exported,
385 &product_exported, 380 &product_length,
386 &product_length, 381 value))))
387 value))))
388 { 382 {
389 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, 383 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
390 "gcry_mpi_scan",
391 rc);
392 prepare_client_end_notification (s); 384 prepare_client_end_notification (s);
393 return; 385 return;
394 } 386 }
@@ -401,20 +393,16 @@ transmit_client_response (struct AliceServiceSession *s)
401 msg->product_length = htonl (product_length); 393 msg->product_length = htonl (product_length);
402 if (NULL != product_exported) 394 if (NULL != product_exported)
403 { 395 {
404 GNUNET_memcpy (&msg[1], 396 GNUNET_memcpy (&msg[1], product_exported, product_length);
405 product_exported,
406 product_length);
407 GNUNET_free (product_exported); 397 GNUNET_free (product_exported);
408 } 398 }
409 GNUNET_MQ_send (s->client_mq, 399 GNUNET_MQ_send (s->client_mq, e);
410 e);
411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
412 "Sent result to client, session %s has ended!\n", 401 "Sent result to client, session %s has ended!\n",
413 GNUNET_h2s (&s->session_id)); 402 GNUNET_h2s (&s->session_id));
414} 403}
415 404
416 405
417
418/** 406/**
419 * Function called whenever a channel is destroyed. Should clean up 407 * Function called whenever a channel is destroyed. Should clean up
420 * any associated state. 408 * any associated state.
@@ -425,8 +413,7 @@ transmit_client_response (struct AliceServiceSession *s)
425 * @param channel connection to the other end (henceforth invalid) 413 * @param channel connection to the other end (henceforth invalid)
426 */ 414 */
427static void 415static void
428cb_channel_destruction (void *cls, 416cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel)
429 const struct GNUNET_CADET_Channel *channel)
430{ 417{
431 struct AliceServiceSession *s = cls; 418 struct AliceServiceSession *s = cls;
432 419
@@ -479,8 +466,7 @@ compute_square_sum_mpi_elements (const struct MpiElement *vector,
479 * @return an MPI value containing the calculated sum, never NULL 466 * @return an MPI value containing the calculated sum, never NULL
480 */ 467 */
481static gcry_mpi_t 468static gcry_mpi_t
482compute_square_sum (const gcry_mpi_t *vector, 469compute_square_sum (const gcry_mpi_t *vector, uint32_t length)
483 uint32_t length)
484{ 470{
485 gcry_mpi_t elem; 471 gcry_mpi_t elem;
486 gcry_mpi_t sum; 472 gcry_mpi_t sum;
@@ -531,28 +517,19 @@ compute_scalar_product (struct AliceServiceSession *session)
531 &my_pubkey, 517 &my_pubkey,
532 &session->r[i], 518 &session->r[i],
533 r[i]); 519 r[i]);
534 gcry_mpi_sub (r[i], 520 gcry_mpi_sub (r[i], r[i], my_offset);
535 r[i], 521 gcry_mpi_sub (r[i], r[i], my_offset);
536 my_offset);
537 gcry_mpi_sub (r[i],
538 r[i],
539 my_offset);
540 r_prime[i] = gcry_mpi_new (0); 522 r_prime[i] = gcry_mpi_new (0);
541 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 523 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
542 &my_pubkey, 524 &my_pubkey,
543 &session->r_prime[i], 525 &session->r_prime[i],
544 r_prime[i]); 526 r_prime[i]);
545 gcry_mpi_sub (r_prime[i], 527 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset);
546 r_prime[i], 528 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset);
547 my_offset);
548 gcry_mpi_sub (r_prime[i],
549 r_prime[i],
550 my_offset);
551 } 529 }
552 530
553 // calculate t = sum(ai) 531 // calculate t = sum(ai)
554 t = compute_square_sum_mpi_elements (session->sorted_elements, 532 t = compute_square_sum_mpi_elements (session->sorted_elements, count);
555 count);
556 // calculate U 533 // calculate U
557 u = gcry_mpi_new (0); 534 u = gcry_mpi_new (0);
558 tmp = compute_square_sum (r, count); 535 tmp = compute_square_sum (r, count);
@@ -570,10 +547,7 @@ compute_scalar_product (struct AliceServiceSession *session)
570 GNUNET_assert (s_prime = gcry_mpi_new (0)); 547 GNUNET_assert (s_prime = gcry_mpi_new (0));
571 548
572 // compute P 549 // compute P
573 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 550 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, &session->s, s);
574 &my_pubkey,
575 &session->s,
576 s);
577 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 551 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
578 &my_pubkey, 552 &my_pubkey,
579 &session->s_prime, 553 &session->s_prime,
@@ -627,8 +601,9 @@ compute_scalar_product (struct AliceServiceSession *session)
627 * #GNUNET_SYSERR to close it (signal serious error) 601 * #GNUNET_SYSERR to close it (signal serious error)
628 */ 602 */
629static int 603static int
630check_bobs_cryptodata_multipart (void *cls, 604check_bobs_cryptodata_multipart (
631 const struct BobCryptodataMultipartMessage *msg) 605 void *cls,
606 const struct BobCryptodataMultipartMessage *msg)
632{ 607{
633 struct AliceServiceSession *s = cls; 608 struct AliceServiceSession *s = cls;
634 uint32_t contained; 609 uint32_t contained;
@@ -637,10 +612,11 @@ check_bobs_cryptodata_multipart (void *cls,
637 612
638 msg_size = ntohs (msg->header.size); 613 msg_size = ntohs (msg->header.size);
639 contained = ntohl (msg->contained_element_count); 614 contained = ntohl (msg->contained_element_count);
640 required_size = sizeof (struct BobCryptodataMultipartMessage) 615 required_size =
641 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 616 sizeof (struct BobCryptodataMultipartMessage) +
642 if ( (required_size != msg_size) || 617 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
643 (s->cadet_received_element_count + contained > s->used_element_count) ) 618 if ((required_size != msg_size) ||
619 (s->cadet_received_element_count + contained > s->used_element_count))
644 { 620 {
645 GNUNET_break (0); 621 GNUNET_break (0);
646 return GNUNET_SYSERR; 622 return GNUNET_SYSERR;
@@ -656,8 +632,9 @@ check_bobs_cryptodata_multipart (void *cls,
656 * @param msg the actual message 632 * @param msg the actual message
657 */ 633 */
658static void 634static void
659handle_bobs_cryptodata_multipart (void *cls, 635handle_bobs_cryptodata_multipart (
660 const struct BobCryptodataMultipartMessage *msg) 636 void *cls,
637 const struct BobCryptodataMultipartMessage *msg)
661{ 638{
662 struct AliceServiceSession *s = cls; 639 struct AliceServiceSession *s = cls;
663 const struct GNUNET_CRYPTO_PaillierCiphertext *payload; 640 const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
@@ -710,12 +687,12 @@ check_bobs_cryptodata_message (void *cls,
710 687
711 msg_size = ntohs (msg->header.size); 688 msg_size = ntohs (msg->header.size);
712 contained = ntohl (msg->contained_element_count); 689 contained = ntohl (msg->contained_element_count);
713 required_size = sizeof (struct BobCryptodataMessage) 690 required_size =
714 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) 691 sizeof (struct BobCryptodataMessage) +
715 + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 692 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) +
716 if ( (msg_size != required_size) || 693 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
717 (contained > UINT16_MAX) || 694 if ((msg_size != required_size) || (contained > UINT16_MAX) ||
718 (s->used_element_count < contained) ) 695 (s->used_element_count < contained))
719 { 696 {
720 GNUNET_break_op (0); 697 GNUNET_break_op (0);
721 return GNUNET_SYSERR; 698 return GNUNET_SYSERR;
@@ -800,9 +777,7 @@ handle_bobs_cryptodata_message (void *cls,
800 * @param value the `struct GNUNET_SCALARPRODUCT_Element *` 777 * @param value the `struct GNUNET_SCALARPRODUCT_Element *`
801 */ 778 */
802static int 779static int
803copy_element_cb (void *cls, 780copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
804 const struct GNUNET_HashCode *key,
805 void *value)
806{ 781{
807 struct AliceServiceSession *s = cls; 782 struct AliceServiceSession *s = cls;
808 struct GNUNET_SCALARPRODUCT_Element *e = value; 783 struct GNUNET_SCALARPRODUCT_Element *e = value;
@@ -815,8 +790,8 @@ copy_element_cb (void *cls,
815 gcry_mpi_sub_ui (mval, mval, -val); 790 gcry_mpi_sub_ui (mval, mval, -val);
816 else 791 else
817 gcry_mpi_add_ui (mval, mval, val); 792 gcry_mpi_add_ui (mval, mval, val);
818 s->sorted_elements [s->used_element_count].value = mval; 793 s->sorted_elements[s->used_element_count].value = mval;
819 s->sorted_elements [s->used_element_count].key = &e->key; 794 s->sorted_elements[s->used_element_count].key = &e->key;
820 s->used_element_count++; 795 s->used_element_count++;
821 return GNUNET_OK; 796 return GNUNET_OK;
822} 797}
@@ -830,14 +805,12 @@ copy_element_cb (void *cls,
830 * @return -1 for a < b, 0 for a=b, 1 for a > b. 805 * @return -1 for a < b, 0 for a=b, 1 for a > b.
831 */ 806 */
832static int 807static int
833element_cmp (const void *a, 808element_cmp (const void *a, const void *b)
834 const void *b)
835{ 809{
836 const struct MpiElement *ma = a; 810 const struct MpiElement *ma = a;
837 const struct MpiElement *mb = b; 811 const struct MpiElement *mb = b;
838 812
839 return GNUNET_CRYPTO_hash_cmp (ma->key, 813 return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key);
840 mb->key);
841} 814}
842 815
843 816
@@ -845,7 +818,10 @@ element_cmp (const void *a,
845 * Maximum number of elements we can put into a single cryptodata 818 * Maximum number of elements we can put into a single cryptodata
846 * message 819 * message
847 */ 820 */
848#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct AliceCryptodataMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) 821#define ELEMENT_CAPACITY \
822 ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \
823 sizeof (struct AliceCryptodataMessage)) / \
824 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
849 825
850 826
851/** 827/**
@@ -865,9 +841,9 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
865 gcry_mpi_t a; 841 gcry_mpi_t a;
866 uint32_t off; 842 uint32_t off;
867 843
868 s->sorted_elements 844 s->sorted_elements = GNUNET_malloc (
869 = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * 845 GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) *
870 sizeof (struct MpiElement)); 846 sizeof (struct MpiElement));
871 s->used_element_count = 0; 847 s->used_element_count = 0;
872 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, 848 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
873 &copy_element_cb, 849 &copy_element_cb,
@@ -890,29 +866,24 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
890 (unsigned int) todo_count, 866 (unsigned int) todo_count,
891 (unsigned int) s->used_element_count); 867 (unsigned int) s->used_element_count);
892 868
893 e = GNUNET_MQ_msg_extra (msg, 869 e =
894 todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), 870 GNUNET_MQ_msg_extra (msg,
895 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); 871 todo_count *
896 GNUNET_MQ_env_set_options(e, 872 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext),
897 GNUNET_MQ_PREF_RELIABLE); 873 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA);
898 msg->contained_element_count = htonl (todo_count); 874 msg->contained_element_count = htonl (todo_count);
899 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 875 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
900 a = gcry_mpi_new (0); 876 a = gcry_mpi_new (0);
901 for (i = off; i < off + todo_count; i++) 877 for (i = off; i < off + todo_count; i++)
902 { 878 {
903 gcry_mpi_add (a, 879 gcry_mpi_add (a, s->sorted_elements[i].value, my_offset);
904 s->sorted_elements[i].value, 880 GNUNET_assert (
905 my_offset); 881 3 ==
906 GNUNET_assert (3 == 882 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - off]));
907 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey,
908 a,
909 3,
910 &payload[i - off]));
911 } 883 }
912 gcry_mpi_release (a); 884 gcry_mpi_release (a);
913 off += todo_count; 885 off += todo_count;
914 GNUNET_MQ_send (s->cadet_mq, 886 GNUNET_MQ_send (s->cadet_mq, e);
915 e);
916 } 887 }
917} 888}
918 889
@@ -947,10 +918,11 @@ cb_intersection_element_removed (void *cls,
947 "Intersection removed element with key %s and value %lld\n", 918 "Intersection removed element with key %s and value %lld\n",
948 GNUNET_h2s (&se->key), 919 GNUNET_h2s (&se->key),
949 (long long) GNUNET_ntohll (se->value)); 920 (long long) GNUNET_ntohll (se->value));
950 GNUNET_assert (GNUNET_YES == 921 GNUNET_assert (
951 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, 922 GNUNET_YES ==
952 element->data, 923 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
953 se)); 924 element->data,
925 se));
954 GNUNET_free (se); 926 GNUNET_free (se);
955 return; 927 return;
956 case GNUNET_SET_STATUS_DONE: 928 case GNUNET_SET_STATUS_DONE:
@@ -968,8 +940,7 @@ cb_intersection_element_removed (void *cls,
968 return; 940 return;
969 case GNUNET_SET_STATUS_FAILURE: 941 case GNUNET_SET_STATUS_FAILURE:
970 /* unhandled status code */ 942 /* unhandled status code */
971 LOG (GNUNET_ERROR_TYPE_DEBUG, 943 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
972 "Set intersection failed!\n");
973 if (NULL != s->intersection_listen) 944 if (NULL != s->intersection_listen)
974 { 945 {
975 GNUNET_SET_listen_cancel (s->intersection_listen); 946 GNUNET_SET_listen_cancel (s->intersection_listen);
@@ -1014,18 +985,16 @@ cb_intersection_request_alice (void *cls,
1014{ 985{
1015 struct AliceServiceSession *s = cls; 986 struct AliceServiceSession *s = cls;
1016 987
1017 if (0 != GNUNET_memcmp (other_peer, 988 if (0 != GNUNET_memcmp (other_peer, &s->peer))
1018 &s->peer))
1019 { 989 {
1020 GNUNET_break_op (0); 990 GNUNET_break_op (0);
1021 return; 991 return;
1022 } 992 }
1023 s->intersection_op 993 s->intersection_op = GNUNET_SET_accept (request,
1024 = GNUNET_SET_accept (request, 994 GNUNET_SET_RESULT_REMOVED,
1025 GNUNET_SET_RESULT_REMOVED, 995 (struct GNUNET_SET_Option[]){{0}},
1026 (struct GNUNET_SET_Option[]) {{ 0 }}, 996 &cb_intersection_element_removed,
1027 &cb_intersection_element_removed, 997 s);
1028 s);
1029 if (NULL == s->intersection_op) 998 if (NULL == s->intersection_op)
1030 { 999 {
1031 GNUNET_break (0); 1000 GNUNET_break (0);
@@ -1033,9 +1002,7 @@ cb_intersection_request_alice (void *cls,
1033 prepare_client_end_notification (s); 1002 prepare_client_end_notification (s);
1034 return; 1003 return;
1035 } 1004 }
1036 if (GNUNET_OK != 1005 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
1037 GNUNET_SET_commit (s->intersection_op,
1038 s->intersection_set))
1039 { 1006 {
1040 GNUNET_break (0); 1007 GNUNET_break (0);
1041 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1008 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1053,31 +1020,30 @@ cb_intersection_request_alice (void *cls,
1053static void 1020static void
1054client_request_complete_alice (struct AliceServiceSession *s) 1021client_request_complete_alice (struct AliceServiceSession *s)
1055{ 1022{
1056 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1023 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1057 GNUNET_MQ_hd_var_size (bobs_cryptodata_message, 1024 {GNUNET_MQ_hd_var_size (bobs_cryptodata_message,
1058 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, 1025 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
1059 struct BobCryptodataMessage, 1026 struct BobCryptodataMessage,
1060 s), 1027 s),
1061 GNUNET_MQ_hd_var_size (bobs_cryptodata_multipart, 1028 GNUNET_MQ_hd_var_size (
1062 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, 1029 bobs_cryptodata_multipart,
1063 struct BobCryptodataMultipartMessage, 1030 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
1064 s), 1031 struct BobCryptodataMultipartMessage,
1065 GNUNET_MQ_handler_end () 1032 s),
1066 }; 1033 GNUNET_MQ_handler_end ()};
1067 struct ServiceRequestMessage *msg; 1034 struct ServiceRequestMessage *msg;
1068 struct GNUNET_MQ_Envelope *e; 1035 struct GNUNET_MQ_Envelope *e;
1069 1036
1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1071 "Creating new channel for session with key %s.\n", 1038 "Creating new channel for session with key %s.\n",
1072 GNUNET_h2s (&s->session_id)); 1039 GNUNET_h2s (&s->session_id));
1073 s->channel 1040 s->channel = GNUNET_CADET_channel_create (my_cadet,
1074 = GNUNET_CADET_channel_create (my_cadet, 1041 s,
1075 s, 1042 &s->peer,
1076 &s->peer, 1043 &s->session_id,
1077 &s->session_id, 1044 NULL,
1078 NULL, 1045 &cb_channel_destruction,
1079 &cb_channel_destruction, 1046 cadet_handlers);
1080 cadet_handlers);
1081 if (NULL == s->channel) 1047 if (NULL == s->channel)
1082 { 1048 {
1083 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1049 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1085,12 +1051,11 @@ client_request_complete_alice (struct AliceServiceSession *s)
1085 return; 1051 return;
1086 } 1052 }
1087 s->cadet_mq = GNUNET_CADET_get_mq (s->channel); 1053 s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
1088 s->intersection_listen 1054 s->intersection_listen = GNUNET_SET_listen (cfg,
1089 = GNUNET_SET_listen (cfg, 1055 GNUNET_SET_OPERATION_INTERSECTION,
1090 GNUNET_SET_OPERATION_INTERSECTION, 1056 &s->session_id,
1091 &s->session_id, 1057 &cb_intersection_request_alice,
1092 &cb_intersection_request_alice, 1058 s);
1093 s);
1094 if (NULL == s->intersection_listen) 1059 if (NULL == s->intersection_listen)
1095 { 1060 {
1096 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1061 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1102,12 +1067,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
1102 1067
1103 e = GNUNET_MQ_msg (msg, 1068 e = GNUNET_MQ_msg (msg,
1104 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION); 1069 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION);
1105 GNUNET_MQ_env_set_options(e,
1106 GNUNET_MQ_PREF_RELIABLE);
1107 msg->session_id = s->session_id; 1070 msg->session_id = s->session_id;
1108 msg->public_key = my_pubkey; 1071 msg->public_key = my_pubkey;
1109 GNUNET_MQ_send (s->cadet_mq, 1072 GNUNET_MQ_send (s->cadet_mq, e);
1110 e);
1111} 1073}
1112 1074
1113 1075
@@ -1120,8 +1082,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
1120 * @return #GNUNET_OK if @a msg is well-formed 1082 * @return #GNUNET_OK if @a msg is well-formed
1121 */ 1083 */
1122static int 1084static int
1123check_alice_client_message_multipart (void *cls, 1085check_alice_client_message_multipart (
1124 const struct ComputationBobCryptodataMultipartMessage *msg) 1086 void *cls,
1087 const struct ComputationBobCryptodataMultipartMessage *msg)
1125{ 1088{
1126 struct AliceServiceSession *s = cls; 1089 struct AliceServiceSession *s = cls;
1127 uint32_t contained_count; 1090 uint32_t contained_count;
@@ -1129,11 +1092,12 @@ check_alice_client_message_multipart (void *cls,
1129 1092
1130 msize = ntohs (msg->header.size); 1093 msize = ntohs (msg->header.size);
1131 contained_count = ntohl (msg->element_count_contained); 1094 contained_count = ntohl (msg->element_count_contained);
1132 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + 1095 if ((msize !=
1133 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 1096 (sizeof (struct ComputationBobCryptodataMultipartMessage) +
1134 (0 == contained_count) || 1097 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
1135 (s->total == s->client_received_element_count) || 1098 (0 == contained_count) ||
1136 (s->total < s->client_received_element_count + contained_count) ) 1099 (s->total == s->client_received_element_count) ||
1100 (s->total < s->client_received_element_count + contained_count))
1137 { 1101 {
1138 GNUNET_break_op (0); 1102 GNUNET_break_op (0);
1139 return GNUNET_SYSERR; 1103 return GNUNET_SYSERR;
@@ -1150,8 +1114,9 @@ check_alice_client_message_multipart (void *cls,
1150 * @param msg the actual message 1114 * @param msg the actual message
1151 */ 1115 */
1152static void 1116static void
1153handle_alice_client_message_multipart (void *cls, 1117handle_alice_client_message_multipart (
1154 const struct ComputationBobCryptodataMultipartMessage *msg) 1118 void *cls,
1119 const struct ComputationBobCryptodataMultipartMessage *msg)
1155{ 1120{
1156 struct AliceServiceSession *s = cls; 1121 struct AliceServiceSession *s = cls;
1157 uint32_t contained_count; 1122 uint32_t contained_count;
@@ -1166,13 +1131,13 @@ handle_alice_client_message_multipart (void *cls,
1166 { 1131 {
1167 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1132 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1168 GNUNET_memcpy (elem, 1133 GNUNET_memcpy (elem,
1169 &elements[i], 1134 &elements[i],
1170 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1135 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1171 if (GNUNET_SYSERR == 1136 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1172 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1137 s->intersected_elements,
1173 &elem->key, 1138 &elem->key,
1174 elem, 1139 elem,
1175 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1140 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1176 { 1141 {
1177 GNUNET_break (0); 1142 GNUNET_break (0);
1178 GNUNET_free (elem); 1143 GNUNET_free (elem);
@@ -1181,9 +1146,7 @@ handle_alice_client_message_multipart (void *cls,
1181 set_elem.data = &elem->key; 1146 set_elem.data = &elem->key;
1182 set_elem.size = sizeof (elem->key); 1147 set_elem.size = sizeof (elem->key);
1183 set_elem.element_type = 0; 1148 set_elem.element_type = 0;
1184 GNUNET_SET_add_element (s->intersection_set, 1149 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1185 &set_elem,
1186 NULL, NULL);
1187 s->used_element_count++; 1150 s->used_element_count++;
1188 } 1151 }
1189 GNUNET_SERVICE_client_continue (s->client); 1152 GNUNET_SERVICE_client_continue (s->client);
@@ -1206,7 +1169,7 @@ handle_alice_client_message_multipart (void *cls,
1206 */ 1169 */
1207static int 1170static int
1208check_alice_client_message (void *cls, 1171check_alice_client_message (void *cls,
1209 const struct AliceComputationMessage *msg) 1172 const struct AliceComputationMessage *msg)
1210{ 1173{
1211 struct AliceServiceSession *s = cls; 1174 struct AliceServiceSession *s = cls;
1212 uint16_t msize; 1175 uint16_t msize;
@@ -1223,10 +1186,10 @@ check_alice_client_message (void *cls,
1223 msize = ntohs (msg->header.size); 1186 msize = ntohs (msg->header.size);
1224 total_count = ntohl (msg->element_count_total); 1187 total_count = ntohl (msg->element_count_total);
1225 contained_count = ntohl (msg->element_count_contained); 1188 contained_count = ntohl (msg->element_count_contained);
1226 if ( (0 == total_count) || 1189 if ((0 == total_count) || (0 == contained_count) ||
1227 (0 == contained_count) || 1190 (msize !=
1228 (msize != (sizeof (struct AliceComputationMessage) + 1191 (sizeof (struct AliceComputationMessage) +
1229 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) 1192 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))))
1230 { 1193 {
1231 GNUNET_break_op (0); 1194 GNUNET_break_op (0);
1232 return GNUNET_SYSERR; 1195 return GNUNET_SYSERR;
@@ -1244,7 +1207,7 @@ check_alice_client_message (void *cls,
1244 */ 1207 */
1245static void 1208static void
1246handle_alice_client_message (void *cls, 1209handle_alice_client_message (void *cls,
1247 const struct AliceComputationMessage *msg) 1210 const struct AliceComputationMessage *msg)
1248{ 1211{
1249 struct AliceServiceSession *s = cls; 1212 struct AliceServiceSession *s = cls;
1250 uint32_t contained_count; 1213 uint32_t contained_count;
@@ -1261,10 +1224,10 @@ handle_alice_client_message (void *cls,
1261 s->client_received_element_count = contained_count; 1224 s->client_received_element_count = contained_count;
1262 s->session_id = msg->session_key; 1225 s->session_id = msg->session_key;
1263 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 1226 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1264 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, 1227 s->intersected_elements =
1265 GNUNET_YES); 1228 GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES);
1266 s->intersection_set = GNUNET_SET_create (cfg, 1229 s->intersection_set =
1267 GNUNET_SET_OPERATION_INTERSECTION); 1230 GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
1268 1231
1269 for (uint32_t i = 0; i < contained_count; i++) 1232 for (uint32_t i = 0; i < contained_count; i++)
1270 { 1233 {
@@ -1272,13 +1235,13 @@ handle_alice_client_message (void *cls,
1272 continue; 1235 continue;
1273 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1236 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1274 GNUNET_memcpy (elem, 1237 GNUNET_memcpy (elem,
1275 &elements[i], 1238 &elements[i],
1276 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1239 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1277 if (GNUNET_SYSERR == 1240 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1278 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1241 s->intersected_elements,
1279 &elem->key, 1242 &elem->key,
1280 elem, 1243 elem,
1281 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1244 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1282 { 1245 {
1283 /* element with same key encountered twice! */ 1246 /* element with same key encountered twice! */
1284 GNUNET_break (0); 1247 GNUNET_break (0);
@@ -1288,9 +1251,7 @@ handle_alice_client_message (void *cls,
1288 set_elem.data = &elem->key; 1251 set_elem.data = &elem->key;
1289 set_elem.size = sizeof (elem->key); 1252 set_elem.size = sizeof (elem->key);
1290 set_elem.element_type = 0; 1253 set_elem.element_type = 0;
1291 GNUNET_SET_add_element (s->intersection_set, 1254 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1292 &set_elem,
1293 NULL, NULL);
1294 s->used_element_count++; 1255 s->used_element_count++;
1295 } 1256 }
1296 GNUNET_SERVICE_client_continue (s->client); 1257 GNUNET_SERVICE_client_continue (s->client);
@@ -1311,8 +1272,7 @@ handle_alice_client_message (void *cls,
1311static void 1272static void
1312shutdown_task (void *cls) 1273shutdown_task (void *cls)
1313{ 1274{
1314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
1315 "Shutting down, initiating cleanup.\n");
1316 // FIXME: we have to cut our connections to CADET first! 1276 // FIXME: we have to cut our connections to CADET first!
1317 if (NULL != my_cadet) 1277 if (NULL != my_cadet)
1318 { 1278 {
@@ -1334,8 +1294,8 @@ shutdown_task (void *cls)
1334 */ 1294 */
1335static void * 1295static void *
1336client_connect_cb (void *cls, 1296client_connect_cb (void *cls,
1337 struct GNUNET_SERVICE_Client *client, 1297 struct GNUNET_SERVICE_Client *client,
1338 struct GNUNET_MQ_Handle *mq) 1298 struct GNUNET_MQ_Handle *mq)
1339{ 1299{
1340 struct AliceServiceSession *s; 1300 struct AliceServiceSession *s;
1341 1301
@@ -1358,8 +1318,8 @@ client_connect_cb (void *cls,
1358 */ 1318 */
1359static void 1319static void
1360client_disconnect_cb (void *cls, 1320client_disconnect_cb (void *cls,
1361 struct GNUNET_SERVICE_Client *client, 1321 struct GNUNET_SERVICE_Client *client,
1362 void *app_cls) 1322 void *app_cls)
1363{ 1323{
1364 struct AliceServiceSession *s = app_cls; 1324 struct AliceServiceSession *s = app_cls;
1365 1325
@@ -1390,17 +1350,13 @@ run (void *cls,
1390 m1+m2 mod n == (S + a) + (S + b) mod n, 1350 m1+m2 mod n == (S + a) + (S + b) mod n,
1391 if we have more complex operations, this factor needs to be lowered */ 1351 if we have more complex operations, this factor needs to be lowered */
1392 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); 1352 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3);
1393 gcry_mpi_set_bit (my_offset, 1353 gcry_mpi_set_bit (my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3);
1394 GNUNET_CRYPTO_PAILLIER_BITS / 3); 1354 GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey);
1395 GNUNET_CRYPTO_paillier_create (&my_pubkey,
1396 &my_privkey);
1397 my_cadet = GNUNET_CADET_connect (cfg); 1355 my_cadet = GNUNET_CADET_connect (cfg);
1398 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1356 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1399 NULL);
1400 if (NULL == my_cadet) 1357 if (NULL == my_cadet)
1401 { 1358 {
1402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
1403 _("Connect to CADET failed\n"));
1404 GNUNET_SCHEDULER_shutdown (); 1360 GNUNET_SCHEDULER_shutdown ();
1405 return; 1361 return;
1406 } 1362 }
@@ -1410,22 +1366,23 @@ run (void *cls,
1410/** 1366/**
1411 * Define "main" method using service macro. 1367 * Define "main" method using service macro.
1412 */ 1368 */
1413GNUNET_SERVICE_MAIN 1369GNUNET_SERVICE_MAIN (
1414("scalarproduct-alice", 1370 "scalarproduct-alice",
1415 GNUNET_SERVICE_OPTION_NONE, 1371 GNUNET_SERVICE_OPTION_NONE,
1416 &run, 1372 &run,
1417 &client_connect_cb, 1373 &client_connect_cb,
1418 &client_disconnect_cb, 1374 &client_disconnect_cb,
1419 NULL, 1375 NULL,
1420 GNUNET_MQ_hd_var_size (alice_client_message, 1376 GNUNET_MQ_hd_var_size (alice_client_message,
1421 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 1377 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
1422 struct AliceComputationMessage, 1378 struct AliceComputationMessage,
1423 NULL), 1379 NULL),
1424 GNUNET_MQ_hd_var_size (alice_client_message_multipart, 1380 GNUNET_MQ_hd_var_size (
1425 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, 1381 alice_client_message_multipart,
1426 struct ComputationBobCryptodataMultipartMessage, 1382 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
1427 NULL), 1383 struct ComputationBobCryptodataMultipartMessage,
1428 GNUNET_MQ_handler_end ()); 1384 NULL),
1385 GNUNET_MQ_handler_end ());
1429 1386
1430 1387
1431/* end of gnunet-service-scalarproduct_alice.c */ 1388/* end of gnunet-service-scalarproduct_alice.c */