aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c360
1 files changed, 156 insertions, 204 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c
index 4b1a09e50..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,9 +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 *
614 sizeof (struct GNUNET_CRYPTO_EccPoint),
615 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA);
637 msg->contained_element_count = htonl (todo_count); 616 msg->contained_element_count = htonl (todo_count);
638 payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1]; 617 payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1];
639 r_ia = gcry_mpi_new (0); 618 r_ia = gcry_mpi_new (0);
@@ -645,33 +624,22 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
645 gcry_mpi_point_t h_i; 624 gcry_mpi_point_t h_i;
646 625
647 r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc); 626 r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc);
648 g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, 627 g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_i);
649 r_i);
650 /* r_ia = r_i * a */ 628 /* r_ia = r_i * a */
651 gcry_mpi_mul (r_ia, 629 gcry_mpi_mul (r_ia, r_i, my_privkey);
652 r_i,
653 my_privkey);
654 gcry_mpi_release (r_i); 630 gcry_mpi_release (r_i);
655 /* r_ia_ai = r_ia + a_i */ 631 /* r_ia_ai = r_ia + a_i */
656 gcry_mpi_add (r_ia_ai, 632 gcry_mpi_add (r_ia_ai, r_ia, s->sorted_elements[i].value);
657 r_ia, 633 h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_ia_ai);
658 s->sorted_elements[i].value); 634 GNUNET_CRYPTO_ecc_point_to_bin (edc, g_i, &payload[(i - off) * 2]);
659 h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, 635 GNUNET_CRYPTO_ecc_point_to_bin (edc, h_i, &payload[(i - off) * 2 + 1]);
660 r_ia_ai);
661 GNUNET_CRYPTO_ecc_point_to_bin (edc,
662 g_i,
663 &payload[(i - off) * 2]);
664 GNUNET_CRYPTO_ecc_point_to_bin (edc,
665 h_i,
666 &payload[(i - off) * 2 + 1]);
667 gcry_mpi_point_release (g_i); 636 gcry_mpi_point_release (g_i);
668 gcry_mpi_point_release (h_i); 637 gcry_mpi_point_release (h_i);
669 } 638 }
670 gcry_mpi_release (r_ia); 639 gcry_mpi_release (r_ia);
671 gcry_mpi_release (r_ia_ai); 640 gcry_mpi_release (r_ia_ai);
672 off += todo_count; 641 off += todo_count;
673 GNUNET_MQ_send (s->cadet_mq, 642 GNUNET_MQ_send (s->cadet_mq, e);
674 e);
675 } 643 }
676} 644}
677 645
@@ -706,10 +674,11 @@ cb_intersection_element_removed (void *cls,
706 "Intersection removed element with key %s and value %lld\n", 674 "Intersection removed element with key %s and value %lld\n",
707 GNUNET_h2s (&se->key), 675 GNUNET_h2s (&se->key),
708 (long long) GNUNET_ntohll (se->value)); 676 (long long) GNUNET_ntohll (se->value));
709 GNUNET_assert (GNUNET_YES == 677 GNUNET_assert (
710 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, 678 GNUNET_YES ==
711 element->data, 679 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
712 se)); 680 element->data,
681 se));
713 GNUNET_free (se); 682 GNUNET_free (se);
714 return; 683 return;
715 case GNUNET_SET_STATUS_DONE: 684 case GNUNET_SET_STATUS_DONE:
@@ -727,8 +696,7 @@ cb_intersection_element_removed (void *cls,
727 return; 696 return;
728 case GNUNET_SET_STATUS_FAILURE: 697 case GNUNET_SET_STATUS_FAILURE:
729 /* unhandled status code */ 698 /* unhandled status code */
730 LOG (GNUNET_ERROR_TYPE_DEBUG, 699 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
731 "Set intersection failed!\n");
732 if (NULL != s->intersection_listen) 700 if (NULL != s->intersection_listen)
733 { 701 {
734 GNUNET_SET_listen_cancel (s->intersection_listen); 702 GNUNET_SET_listen_cancel (s->intersection_listen);
@@ -776,18 +744,16 @@ cb_intersection_request_alice (void *cls,
776 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
777 "Received intersection request from %s!\n", 745 "Received intersection request from %s!\n",
778 GNUNET_i2s (other_peer)); 746 GNUNET_i2s (other_peer));
779 if (0 != GNUNET_memcmp (other_peer, 747 if (0 != GNUNET_memcmp (other_peer, &s->peer))
780 &s->peer))
781 { 748 {
782 GNUNET_break_op (0); 749 GNUNET_break_op (0);
783 return; 750 return;
784 } 751 }
785 s->intersection_op 752 s->intersection_op = GNUNET_SET_accept (request,
786 = GNUNET_SET_accept (request, 753 GNUNET_SET_RESULT_REMOVED,
787 GNUNET_SET_RESULT_REMOVED, 754 (struct GNUNET_SET_Option[]){{0}},
788 (struct GNUNET_SET_Option[]) {{ 0 }}, 755 &cb_intersection_element_removed,
789 &cb_intersection_element_removed, 756 s);
790 s);
791 if (NULL == s->intersection_op) 757 if (NULL == s->intersection_op)
792 { 758 {
793 GNUNET_break (0); 759 GNUNET_break (0);
@@ -795,9 +761,7 @@ cb_intersection_request_alice (void *cls,
795 prepare_client_end_notification (s); 761 prepare_client_end_notification (s);
796 return; 762 return;
797 } 763 }
798 if (GNUNET_OK != 764 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
799 GNUNET_SET_commit (s->intersection_op,
800 s->intersection_set))
801 { 765 {
802 GNUNET_break (0); 766 GNUNET_break (0);
803 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 767 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -815,13 +779,12 @@ cb_intersection_request_alice (void *cls,
815static void 779static void
816client_request_complete_alice (struct AliceServiceSession *s) 780client_request_complete_alice (struct AliceServiceSession *s)
817{ 781{
818 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 782 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
819 GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, 783 {GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message,
820 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, 784 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA,
821 struct EccBobCryptodataMessage, 785 struct EccBobCryptodataMessage,
822 s), 786 s),
823 GNUNET_MQ_handler_end () 787 GNUNET_MQ_handler_end ()};
824 };
825 struct EccServiceRequestMessage *msg; 788 struct EccServiceRequestMessage *msg;
826 struct GNUNET_MQ_Envelope *e; 789 struct GNUNET_MQ_Envelope *e;
827 struct GNUNET_HashCode set_sid; 790 struct GNUNET_HashCode set_sid;
@@ -832,15 +795,13 @@ client_request_complete_alice (struct AliceServiceSession *s)
832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
833 "Creating new channel for session with key %s.\n", 796 "Creating new channel for session with key %s.\n",
834 GNUNET_h2s (&s->session_id)); 797 GNUNET_h2s (&s->session_id));
835 s->channel 798 s->channel = GNUNET_CADET_channel_create (my_cadet,
836 = GNUNET_CADET_channel_create (my_cadet, 799 s,
837 s, 800 &s->peer,
838 &s->peer, 801 &s->session_id,
839 &s->session_id, 802 NULL,
840 GNUNET_CADET_OPTION_RELIABLE, 803 &cb_channel_destruction,
841 NULL, 804 cadet_handlers);
842 &cb_channel_destruction,
843 cadet_handlers);
844 if (NULL == s->channel) 805 if (NULL == s->channel)
845 { 806 {
846 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 807 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -848,12 +809,11 @@ client_request_complete_alice (struct AliceServiceSession *s)
848 return; 809 return;
849 } 810 }
850 s->cadet_mq = GNUNET_CADET_get_mq (s->channel); 811 s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
851 s->intersection_listen 812 s->intersection_listen = GNUNET_SET_listen (cfg,
852 = GNUNET_SET_listen (cfg, 813 GNUNET_SET_OPERATION_INTERSECTION,
853 GNUNET_SET_OPERATION_INTERSECTION, 814 &set_sid,
854 &set_sid, 815 &cb_intersection_request_alice,
855 &cb_intersection_request_alice, 816 s);
856 s);
857 if (NULL == s->intersection_listen) 817 if (NULL == s->intersection_listen)
858 { 818 {
859 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 819 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -863,11 +823,12 @@ client_request_complete_alice (struct AliceServiceSession *s)
863 return; 823 return;
864 } 824 }
865 825
866 e = GNUNET_MQ_msg (msg, 826 e =
867 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION); 827 GNUNET_MQ_msg (msg,
828 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION);
829 GNUNET_MQ_env_set_options (e, GNUNET_MQ_PRIO_CRITICAL_CONTROL);
868 msg->session_id = s->session_id; 830 msg->session_id = s->session_id;
869 GNUNET_MQ_send (s->cadet_mq, 831 GNUNET_MQ_send (s->cadet_mq, e);
870 e);
871} 832}
872 833
873 834
@@ -880,8 +841,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
880 * @return #GNUNET_OK if @a msg is well-formed 841 * @return #GNUNET_OK if @a msg is well-formed
881 */ 842 */
882static int 843static int
883check_alice_client_message_multipart (void *cls, 844check_alice_client_message_multipart (
884 const struct ComputationBobCryptodataMultipartMessage *msg) 845 void *cls,
846 const struct ComputationBobCryptodataMultipartMessage *msg)
885{ 847{
886 struct AliceServiceSession *s = cls; 848 struct AliceServiceSession *s = cls;
887 uint32_t contained_count; 849 uint32_t contained_count;
@@ -889,11 +851,12 @@ check_alice_client_message_multipart (void *cls,
889 851
890 msize = ntohs (msg->header.size); 852 msize = ntohs (msg->header.size);
891 contained_count = ntohl (msg->element_count_contained); 853 contained_count = ntohl (msg->element_count_contained);
892 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + 854 if ((msize !=
893 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 855 (sizeof (struct ComputationBobCryptodataMultipartMessage) +
894 (0 == contained_count) || 856 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
895 (s->total == s->client_received_element_count) || 857 (0 == contained_count) ||
896 (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))
897 { 860 {
898 GNUNET_break_op (0); 861 GNUNET_break_op (0);
899 return GNUNET_SYSERR; 862 return GNUNET_SYSERR;
@@ -910,8 +873,9 @@ check_alice_client_message_multipart (void *cls,
910 * @param msg the actual message 873 * @param msg the actual message
911 */ 874 */
912static void 875static void
913handle_alice_client_message_multipart (void *cls, 876handle_alice_client_message_multipart (
914 const struct ComputationBobCryptodataMultipartMessage *msg) 877 void *cls,
878 const struct ComputationBobCryptodataMultipartMessage *msg)
915{ 879{
916 struct AliceServiceSession *s = cls; 880 struct AliceServiceSession *s = cls;
917 uint32_t contained_count; 881 uint32_t contained_count;
@@ -926,13 +890,13 @@ handle_alice_client_message_multipart (void *cls,
926 { 890 {
927 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 891 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
928 GNUNET_memcpy (elem, 892 GNUNET_memcpy (elem,
929 &elements[i], 893 &elements[i],
930 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 894 sizeof (struct GNUNET_SCALARPRODUCT_Element));
931 if (GNUNET_SYSERR == 895 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
932 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 896 s->intersected_elements,
933 &elem->key, 897 &elem->key,
934 elem, 898 elem,
935 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 899 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
936 { 900 {
937 GNUNET_break (0); 901 GNUNET_break (0);
938 GNUNET_free (elem); 902 GNUNET_free (elem);
@@ -941,9 +905,7 @@ handle_alice_client_message_multipart (void *cls,
941 set_elem.data = &elem->key; 905 set_elem.data = &elem->key;
942 set_elem.size = sizeof (elem->key); 906 set_elem.size = sizeof (elem->key);
943 set_elem.element_type = 0; 907 set_elem.element_type = 0;
944 GNUNET_SET_add_element (s->intersection_set, 908 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
945 &set_elem,
946 NULL, NULL);
947 s->used_element_count++; 909 s->used_element_count++;
948 } 910 }
949 GNUNET_SERVICE_client_continue (s->client); 911 GNUNET_SERVICE_client_continue (s->client);
@@ -954,8 +916,7 @@ handle_alice_client_message_multipart (void *cls,
954 "Received client multipart data, waiting for more!\n"); 916 "Received client multipart data, waiting for more!\n");
955 return; 917 return;
956 } 918 }
957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n");
958 "Launching computation\n");
959 client_request_complete_alice (s); 920 client_request_complete_alice (s);
960} 921}
961 922
@@ -970,7 +931,7 @@ handle_alice_client_message_multipart (void *cls,
970 */ 931 */
971static int 932static int
972check_alice_client_message (void *cls, 933check_alice_client_message (void *cls,
973 const struct AliceComputationMessage *msg) 934 const struct AliceComputationMessage *msg)
974{ 935{
975 struct AliceServiceSession *s = cls; 936 struct AliceServiceSession *s = cls;
976 uint16_t msize; 937 uint16_t msize;
@@ -987,10 +948,10 @@ check_alice_client_message (void *cls,
987 msize = ntohs (msg->header.size); 948 msize = ntohs (msg->header.size);
988 total_count = ntohl (msg->element_count_total); 949 total_count = ntohl (msg->element_count_total);
989 contained_count = ntohl (msg->element_count_contained); 950 contained_count = ntohl (msg->element_count_contained);
990 if ( (0 == total_count) || 951 if ((0 == total_count) || (0 == contained_count) ||
991 (0 == contained_count) || 952 (msize !=
992 (msize != (sizeof (struct AliceComputationMessage) + 953 (sizeof (struct AliceComputationMessage) +
993 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) 954 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))))
994 { 955 {
995 GNUNET_break_op (0); 956 GNUNET_break_op (0);
996 return GNUNET_SYSERR; 957 return GNUNET_SYSERR;
@@ -1008,7 +969,7 @@ check_alice_client_message (void *cls,
1008 */ 969 */
1009static void 970static void
1010handle_alice_client_message (void *cls, 971handle_alice_client_message (void *cls,
1011 const struct AliceComputationMessage *msg) 972 const struct AliceComputationMessage *msg)
1012{ 973{
1013 struct AliceServiceSession *s = cls; 974 struct AliceServiceSession *s = cls;
1014 uint32_t contained_count; 975 uint32_t contained_count;
@@ -1025,23 +986,23 @@ handle_alice_client_message (void *cls,
1025 s->client_received_element_count = contained_count; 986 s->client_received_element_count = contained_count;
1026 s->session_id = msg->session_key; 987 s->session_id = msg->session_key;
1027 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 988 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1028 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, 989 s->intersected_elements =
1029 GNUNET_YES); 990 GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES);
1030 s->intersection_set = GNUNET_SET_create (cfg, 991 s->intersection_set =
1031 GNUNET_SET_OPERATION_INTERSECTION); 992 GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
1032 for (uint32_t i = 0; i < contained_count; i++) 993 for (uint32_t i = 0; i < contained_count; i++)
1033 { 994 {
1034 if (0 == GNUNET_ntohll (elements[i].value)) 995 if (0 == GNUNET_ntohll (elements[i].value))
1035 continue; 996 continue;
1036 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 997 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1037 GNUNET_memcpy (elem, 998 GNUNET_memcpy (elem,
1038 &elements[i], 999 &elements[i],
1039 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1000 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1040 if (GNUNET_SYSERR == 1001 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1041 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1002 s->intersected_elements,
1042 &elem->key, 1003 &elem->key,
1043 elem, 1004 elem,
1044 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1005 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1045 { 1006 {
1046 /* element with same key encountered twice! */ 1007 /* element with same key encountered twice! */
1047 GNUNET_break (0); 1008 GNUNET_break (0);
@@ -1051,9 +1012,7 @@ handle_alice_client_message (void *cls,
1051 set_elem.data = &elem->key; 1012 set_elem.data = &elem->key;
1052 set_elem.size = sizeof (elem->key); 1013 set_elem.size = sizeof (elem->key);
1053 set_elem.element_type = 0; 1014 set_elem.element_type = 0;
1054 GNUNET_SET_add_element (s->intersection_set, 1015 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1055 &set_elem,
1056 NULL, NULL);
1057 s->used_element_count++; 1016 s->used_element_count++;
1058 } 1017 }
1059 GNUNET_SERVICE_client_continue (s->client); 1018 GNUNET_SERVICE_client_continue (s->client);
@@ -1064,8 +1023,7 @@ handle_alice_client_message (void *cls,
1064 "Received partial client request, waiting for more!\n"); 1023 "Received partial client request, waiting for more!\n");
1065 return; 1024 return;
1066 } 1025 }
1067 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n");
1068 "Launching computation\n");
1069 client_request_complete_alice (s); 1027 client_request_complete_alice (s);
1070} 1028}
1071 1029
@@ -1079,8 +1037,7 @@ handle_alice_client_message (void *cls,
1079static void 1037static void
1080shutdown_task (void *cls) 1038shutdown_task (void *cls)
1081{ 1039{
1082 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
1083 "Shutting down, initiating cleanup.\n");
1084 // FIXME: we have to cut our connections to CADET first! 1041 // FIXME: we have to cut our connections to CADET first!
1085 if (NULL != my_cadet) 1042 if (NULL != my_cadet)
1086 { 1043 {
@@ -1107,8 +1064,8 @@ shutdown_task (void *cls)
1107 */ 1064 */
1108static void * 1065static void *
1109client_connect_cb (void *cls, 1066client_connect_cb (void *cls,
1110 struct GNUNET_SERVICE_Client *client, 1067 struct GNUNET_SERVICE_Client *client,
1111 struct GNUNET_MQ_Handle *mq) 1068 struct GNUNET_MQ_Handle *mq)
1112{ 1069{
1113 struct AliceServiceSession *s; 1070 struct AliceServiceSession *s;
1114 1071
@@ -1131,8 +1088,8 @@ client_connect_cb (void *cls,
1131 */ 1088 */
1132static void 1089static void
1133client_disconnect_cb (void *cls, 1090client_disconnect_cb (void *cls,
1134 struct GNUNET_SERVICE_Client *client, 1091 struct GNUNET_SERVICE_Client *client,
1135 void *app_cls) 1092 void *app_cls)
1136{ 1093{
1137 struct AliceServiceSession *s = app_cls; 1094 struct AliceServiceSession *s = app_cls;
1138 1095
@@ -1158,45 +1115,40 @@ run (void *cls,
1158 struct GNUNET_SERVICE_Handle *service) 1115 struct GNUNET_SERVICE_Handle *service)
1159{ 1116{
1160 cfg = c; 1117 cfg = c;
1161 edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, 1118 edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, MAX_RAM);
1162 MAX_RAM);
1163 /* Select a random 'a' value for Alice */ 1119 /* Select a random 'a' value for Alice */
1164 GNUNET_CRYPTO_ecc_rnd_mpi (edc, 1120 GNUNET_CRYPTO_ecc_rnd_mpi (edc, &my_privkey, &my_privkey_inv);
1165 &my_privkey,
1166 &my_privkey_inv);
1167 my_cadet = GNUNET_CADET_connect (cfg); 1121 my_cadet = GNUNET_CADET_connect (cfg);
1168 if (NULL == my_cadet) 1122 if (NULL == my_cadet)
1169 { 1123 {
1170 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
1171 _("Connect to CADET failed\n"));
1172 GNUNET_SCHEDULER_shutdown (); 1125 GNUNET_SCHEDULER_shutdown ();
1173 return; 1126 return;
1174 } 1127 }
1175 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1128 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1176 NULL);
1177
1178} 1129}
1179 1130
1180 1131
1181/** 1132/**
1182 * Define "main" method using service macro. 1133 * Define "main" method using service macro.
1183 */ 1134 */
1184GNUNET_SERVICE_MAIN 1135GNUNET_SERVICE_MAIN (
1185("scalarproduct-alice", 1136 "scalarproduct-alice",
1186 GNUNET_SERVICE_OPTION_NONE, 1137 GNUNET_SERVICE_OPTION_NONE,
1187 &run, 1138 &run,
1188 &client_connect_cb, 1139 &client_connect_cb,
1189 &client_disconnect_cb, 1140 &client_disconnect_cb,
1190 NULL, 1141 NULL,
1191 GNUNET_MQ_hd_var_size (alice_client_message, 1142 GNUNET_MQ_hd_var_size (alice_client_message,
1192 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 1143 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
1193 struct AliceComputationMessage, 1144 struct AliceComputationMessage,
1194 NULL), 1145 NULL),
1195 GNUNET_MQ_hd_var_size (alice_client_message_multipart, 1146 GNUNET_MQ_hd_var_size (
1196 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, 1147 alice_client_message_multipart,
1197 struct ComputationBobCryptodataMultipartMessage, 1148 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
1198 NULL), 1149 struct ComputationBobCryptodataMultipartMessage,
1199 GNUNET_MQ_handler_end ()); 1150 NULL),
1151 GNUNET_MQ_handler_end ());
1200 1152
1201 1153
1202/* end of gnunet-service-scalarproduct-ecc_alice.c */ 1154/* end of gnunet-service-scalarproduct-ecc_alice.c */