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.c363
1 files changed, 156 insertions, 207 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 */