aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct/gnunet-service-scalarproduct_alice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct_alice.c')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_alice.c376
1 files changed, 168 insertions, 208 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index 393a1951b..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,27 +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 *
872 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext),
873 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA);
896 msg->contained_element_count = htonl (todo_count); 874 msg->contained_element_count = htonl (todo_count);
897 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 875 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
898 a = gcry_mpi_new (0); 876 a = gcry_mpi_new (0);
899 for (i = off; i < off + todo_count; i++) 877 for (i = off; i < off + todo_count; i++)
900 { 878 {
901 gcry_mpi_add (a, 879 gcry_mpi_add (a, s->sorted_elements[i].value, my_offset);
902 s->sorted_elements[i].value, 880 GNUNET_assert (
903 my_offset); 881 3 ==
904 GNUNET_assert (3 == 882 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - off]));
905 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey,
906 a,
907 3,
908 &payload[i - off]));
909 } 883 }
910 gcry_mpi_release (a); 884 gcry_mpi_release (a);
911 off += todo_count; 885 off += todo_count;
912 GNUNET_MQ_send (s->cadet_mq, 886 GNUNET_MQ_send (s->cadet_mq, e);
913 e);
914 } 887 }
915} 888}
916 889
@@ -945,10 +918,11 @@ cb_intersection_element_removed (void *cls,
945 "Intersection removed element with key %s and value %lld\n", 918 "Intersection removed element with key %s and value %lld\n",
946 GNUNET_h2s (&se->key), 919 GNUNET_h2s (&se->key),
947 (long long) GNUNET_ntohll (se->value)); 920 (long long) GNUNET_ntohll (se->value));
948 GNUNET_assert (GNUNET_YES == 921 GNUNET_assert (
949 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, 922 GNUNET_YES ==
950 element->data, 923 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
951 se)); 924 element->data,
925 se));
952 GNUNET_free (se); 926 GNUNET_free (se);
953 return; 927 return;
954 case GNUNET_SET_STATUS_DONE: 928 case GNUNET_SET_STATUS_DONE:
@@ -966,8 +940,7 @@ cb_intersection_element_removed (void *cls,
966 return; 940 return;
967 case GNUNET_SET_STATUS_FAILURE: 941 case GNUNET_SET_STATUS_FAILURE:
968 /* unhandled status code */ 942 /* unhandled status code */
969 LOG (GNUNET_ERROR_TYPE_DEBUG, 943 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
970 "Set intersection failed!\n");
971 if (NULL != s->intersection_listen) 944 if (NULL != s->intersection_listen)
972 { 945 {
973 GNUNET_SET_listen_cancel (s->intersection_listen); 946 GNUNET_SET_listen_cancel (s->intersection_listen);
@@ -1012,18 +985,16 @@ cb_intersection_request_alice (void *cls,
1012{ 985{
1013 struct AliceServiceSession *s = cls; 986 struct AliceServiceSession *s = cls;
1014 987
1015 if (0 != GNUNET_memcmp (other_peer, 988 if (0 != GNUNET_memcmp (other_peer, &s->peer))
1016 &s->peer))
1017 { 989 {
1018 GNUNET_break_op (0); 990 GNUNET_break_op (0);
1019 return; 991 return;
1020 } 992 }
1021 s->intersection_op 993 s->intersection_op = GNUNET_SET_accept (request,
1022 = GNUNET_SET_accept (request, 994 GNUNET_SET_RESULT_REMOVED,
1023 GNUNET_SET_RESULT_REMOVED, 995 (struct GNUNET_SET_Option[]){{0}},
1024 (struct GNUNET_SET_Option[]) {{ 0 }}, 996 &cb_intersection_element_removed,
1025 &cb_intersection_element_removed, 997 s);
1026 s);
1027 if (NULL == s->intersection_op) 998 if (NULL == s->intersection_op)
1028 { 999 {
1029 GNUNET_break (0); 1000 GNUNET_break (0);
@@ -1031,9 +1002,7 @@ cb_intersection_request_alice (void *cls,
1031 prepare_client_end_notification (s); 1002 prepare_client_end_notification (s);
1032 return; 1003 return;
1033 } 1004 }
1034 if (GNUNET_OK != 1005 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
1035 GNUNET_SET_commit (s->intersection_op,
1036 s->intersection_set))
1037 { 1006 {
1038 GNUNET_break (0); 1007 GNUNET_break (0);
1039 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1008 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1051,32 +1020,30 @@ cb_intersection_request_alice (void *cls,
1051static void 1020static void
1052client_request_complete_alice (struct AliceServiceSession *s) 1021client_request_complete_alice (struct AliceServiceSession *s)
1053{ 1022{
1054 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1023 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1055 GNUNET_MQ_hd_var_size (bobs_cryptodata_message, 1024 {GNUNET_MQ_hd_var_size (bobs_cryptodata_message,
1056 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, 1025 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
1057 struct BobCryptodataMessage, 1026 struct BobCryptodataMessage,
1058 s), 1027 s),
1059 GNUNET_MQ_hd_var_size (bobs_cryptodata_multipart, 1028 GNUNET_MQ_hd_var_size (
1060 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, 1029 bobs_cryptodata_multipart,
1061 struct BobCryptodataMultipartMessage, 1030 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
1062 s), 1031 struct BobCryptodataMultipartMessage,
1063 GNUNET_MQ_handler_end () 1032 s),
1064 }; 1033 GNUNET_MQ_handler_end ()};
1065 struct ServiceRequestMessage *msg; 1034 struct ServiceRequestMessage *msg;
1066 struct GNUNET_MQ_Envelope *e; 1035 struct GNUNET_MQ_Envelope *e;
1067 1036
1068 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1069 "Creating new channel for session with key %s.\n", 1038 "Creating new channel for session with key %s.\n",
1070 GNUNET_h2s (&s->session_id)); 1039 GNUNET_h2s (&s->session_id));
1071 s->channel 1040 s->channel = GNUNET_CADET_channel_create (my_cadet,
1072 = GNUNET_CADET_channel_create (my_cadet, 1041 s,
1073 s, 1042 &s->peer,
1074 &s->peer, 1043 &s->session_id,
1075 &s->session_id, 1044 NULL,
1076 GNUNET_CADET_OPTION_RELIABLE, 1045 &cb_channel_destruction,
1077 NULL, 1046 cadet_handlers);
1078 &cb_channel_destruction,
1079 cadet_handlers);
1080 if (NULL == s->channel) 1047 if (NULL == s->channel)
1081 { 1048 {
1082 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1049 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1084,12 +1051,11 @@ client_request_complete_alice (struct AliceServiceSession *s)
1084 return; 1051 return;
1085 } 1052 }
1086 s->cadet_mq = GNUNET_CADET_get_mq (s->channel); 1053 s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
1087 s->intersection_listen 1054 s->intersection_listen = GNUNET_SET_listen (cfg,
1088 = GNUNET_SET_listen (cfg, 1055 GNUNET_SET_OPERATION_INTERSECTION,
1089 GNUNET_SET_OPERATION_INTERSECTION, 1056 &s->session_id,
1090 &s->session_id, 1057 &cb_intersection_request_alice,
1091 &cb_intersection_request_alice, 1058 s);
1092 s);
1093 if (NULL == s->intersection_listen) 1059 if (NULL == s->intersection_listen)
1094 { 1060 {
1095 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1061 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1103,8 +1069,7 @@ client_request_complete_alice (struct AliceServiceSession *s)
1103 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION); 1069 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION);
1104 msg->session_id = s->session_id; 1070 msg->session_id = s->session_id;
1105 msg->public_key = my_pubkey; 1071 msg->public_key = my_pubkey;
1106 GNUNET_MQ_send (s->cadet_mq, 1072 GNUNET_MQ_send (s->cadet_mq, e);
1107 e);
1108} 1073}
1109 1074
1110 1075
@@ -1117,8 +1082,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
1117 * @return #GNUNET_OK if @a msg is well-formed 1082 * @return #GNUNET_OK if @a msg is well-formed
1118 */ 1083 */
1119static int 1084static int
1120check_alice_client_message_multipart (void *cls, 1085check_alice_client_message_multipart (
1121 const struct ComputationBobCryptodataMultipartMessage *msg) 1086 void *cls,
1087 const struct ComputationBobCryptodataMultipartMessage *msg)
1122{ 1088{
1123 struct AliceServiceSession *s = cls; 1089 struct AliceServiceSession *s = cls;
1124 uint32_t contained_count; 1090 uint32_t contained_count;
@@ -1126,11 +1092,12 @@ check_alice_client_message_multipart (void *cls,
1126 1092
1127 msize = ntohs (msg->header.size); 1093 msize = ntohs (msg->header.size);
1128 contained_count = ntohl (msg->element_count_contained); 1094 contained_count = ntohl (msg->element_count_contained);
1129 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + 1095 if ((msize !=
1130 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 1096 (sizeof (struct ComputationBobCryptodataMultipartMessage) +
1131 (0 == contained_count) || 1097 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
1132 (s->total == s->client_received_element_count) || 1098 (0 == contained_count) ||
1133 (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))
1134 { 1101 {
1135 GNUNET_break_op (0); 1102 GNUNET_break_op (0);
1136 return GNUNET_SYSERR; 1103 return GNUNET_SYSERR;
@@ -1147,8 +1114,9 @@ check_alice_client_message_multipart (void *cls,
1147 * @param msg the actual message 1114 * @param msg the actual message
1148 */ 1115 */
1149static void 1116static void
1150handle_alice_client_message_multipart (void *cls, 1117handle_alice_client_message_multipart (
1151 const struct ComputationBobCryptodataMultipartMessage *msg) 1118 void *cls,
1119 const struct ComputationBobCryptodataMultipartMessage *msg)
1152{ 1120{
1153 struct AliceServiceSession *s = cls; 1121 struct AliceServiceSession *s = cls;
1154 uint32_t contained_count; 1122 uint32_t contained_count;
@@ -1163,13 +1131,13 @@ handle_alice_client_message_multipart (void *cls,
1163 { 1131 {
1164 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1132 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1165 GNUNET_memcpy (elem, 1133 GNUNET_memcpy (elem,
1166 &elements[i], 1134 &elements[i],
1167 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1135 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1168 if (GNUNET_SYSERR == 1136 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1169 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1137 s->intersected_elements,
1170 &elem->key, 1138 &elem->key,
1171 elem, 1139 elem,
1172 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1140 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1173 { 1141 {
1174 GNUNET_break (0); 1142 GNUNET_break (0);
1175 GNUNET_free (elem); 1143 GNUNET_free (elem);
@@ -1178,9 +1146,7 @@ handle_alice_client_message_multipart (void *cls,
1178 set_elem.data = &elem->key; 1146 set_elem.data = &elem->key;
1179 set_elem.size = sizeof (elem->key); 1147 set_elem.size = sizeof (elem->key);
1180 set_elem.element_type = 0; 1148 set_elem.element_type = 0;
1181 GNUNET_SET_add_element (s->intersection_set, 1149 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1182 &set_elem,
1183 NULL, NULL);
1184 s->used_element_count++; 1150 s->used_element_count++;
1185 } 1151 }
1186 GNUNET_SERVICE_client_continue (s->client); 1152 GNUNET_SERVICE_client_continue (s->client);
@@ -1203,7 +1169,7 @@ handle_alice_client_message_multipart (void *cls,
1203 */ 1169 */
1204static int 1170static int
1205check_alice_client_message (void *cls, 1171check_alice_client_message (void *cls,
1206 const struct AliceComputationMessage *msg) 1172 const struct AliceComputationMessage *msg)
1207{ 1173{
1208 struct AliceServiceSession *s = cls; 1174 struct AliceServiceSession *s = cls;
1209 uint16_t msize; 1175 uint16_t msize;
@@ -1220,10 +1186,10 @@ check_alice_client_message (void *cls,
1220 msize = ntohs (msg->header.size); 1186 msize = ntohs (msg->header.size);
1221 total_count = ntohl (msg->element_count_total); 1187 total_count = ntohl (msg->element_count_total);
1222 contained_count = ntohl (msg->element_count_contained); 1188 contained_count = ntohl (msg->element_count_contained);
1223 if ( (0 == total_count) || 1189 if ((0 == total_count) || (0 == contained_count) ||
1224 (0 == contained_count) || 1190 (msize !=
1225 (msize != (sizeof (struct AliceComputationMessage) + 1191 (sizeof (struct AliceComputationMessage) +
1226 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) 1192 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))))
1227 { 1193 {
1228 GNUNET_break_op (0); 1194 GNUNET_break_op (0);
1229 return GNUNET_SYSERR; 1195 return GNUNET_SYSERR;
@@ -1241,7 +1207,7 @@ check_alice_client_message (void *cls,
1241 */ 1207 */
1242static void 1208static void
1243handle_alice_client_message (void *cls, 1209handle_alice_client_message (void *cls,
1244 const struct AliceComputationMessage *msg) 1210 const struct AliceComputationMessage *msg)
1245{ 1211{
1246 struct AliceServiceSession *s = cls; 1212 struct AliceServiceSession *s = cls;
1247 uint32_t contained_count; 1213 uint32_t contained_count;
@@ -1258,10 +1224,10 @@ handle_alice_client_message (void *cls,
1258 s->client_received_element_count = contained_count; 1224 s->client_received_element_count = contained_count;
1259 s->session_id = msg->session_key; 1225 s->session_id = msg->session_key;
1260 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 1226 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1261 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, 1227 s->intersected_elements =
1262 GNUNET_YES); 1228 GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES);
1263 s->intersection_set = GNUNET_SET_create (cfg, 1229 s->intersection_set =
1264 GNUNET_SET_OPERATION_INTERSECTION); 1230 GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
1265 1231
1266 for (uint32_t i = 0; i < contained_count; i++) 1232 for (uint32_t i = 0; i < contained_count; i++)
1267 { 1233 {
@@ -1269,13 +1235,13 @@ handle_alice_client_message (void *cls,
1269 continue; 1235 continue;
1270 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1236 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1271 GNUNET_memcpy (elem, 1237 GNUNET_memcpy (elem,
1272 &elements[i], 1238 &elements[i],
1273 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1239 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1274 if (GNUNET_SYSERR == 1240 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1275 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1241 s->intersected_elements,
1276 &elem->key, 1242 &elem->key,
1277 elem, 1243 elem,
1278 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1244 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1279 { 1245 {
1280 /* element with same key encountered twice! */ 1246 /* element with same key encountered twice! */
1281 GNUNET_break (0); 1247 GNUNET_break (0);
@@ -1285,9 +1251,7 @@ handle_alice_client_message (void *cls,
1285 set_elem.data = &elem->key; 1251 set_elem.data = &elem->key;
1286 set_elem.size = sizeof (elem->key); 1252 set_elem.size = sizeof (elem->key);
1287 set_elem.element_type = 0; 1253 set_elem.element_type = 0;
1288 GNUNET_SET_add_element (s->intersection_set, 1254 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1289 &set_elem,
1290 NULL, NULL);
1291 s->used_element_count++; 1255 s->used_element_count++;
1292 } 1256 }
1293 GNUNET_SERVICE_client_continue (s->client); 1257 GNUNET_SERVICE_client_continue (s->client);
@@ -1308,8 +1272,7 @@ handle_alice_client_message (void *cls,
1308static void 1272static void
1309shutdown_task (void *cls) 1273shutdown_task (void *cls)
1310{ 1274{
1311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
1312 "Shutting down, initiating cleanup.\n");
1313 // FIXME: we have to cut our connections to CADET first! 1276 // FIXME: we have to cut our connections to CADET first!
1314 if (NULL != my_cadet) 1277 if (NULL != my_cadet)
1315 { 1278 {
@@ -1331,8 +1294,8 @@ shutdown_task (void *cls)
1331 */ 1294 */
1332static void * 1295static void *
1333client_connect_cb (void *cls, 1296client_connect_cb (void *cls,
1334 struct GNUNET_SERVICE_Client *client, 1297 struct GNUNET_SERVICE_Client *client,
1335 struct GNUNET_MQ_Handle *mq) 1298 struct GNUNET_MQ_Handle *mq)
1336{ 1299{
1337 struct AliceServiceSession *s; 1300 struct AliceServiceSession *s;
1338 1301
@@ -1355,8 +1318,8 @@ client_connect_cb (void *cls,
1355 */ 1318 */
1356static void 1319static void
1357client_disconnect_cb (void *cls, 1320client_disconnect_cb (void *cls,
1358 struct GNUNET_SERVICE_Client *client, 1321 struct GNUNET_SERVICE_Client *client,
1359 void *app_cls) 1322 void *app_cls)
1360{ 1323{
1361 struct AliceServiceSession *s = app_cls; 1324 struct AliceServiceSession *s = app_cls;
1362 1325
@@ -1387,17 +1350,13 @@ run (void *cls,
1387 m1+m2 mod n == (S + a) + (S + b) mod n, 1350 m1+m2 mod n == (S + a) + (S + b) mod n,
1388 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 */
1389 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); 1352 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3);
1390 gcry_mpi_set_bit (my_offset, 1353 gcry_mpi_set_bit (my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3);
1391 GNUNET_CRYPTO_PAILLIER_BITS / 3); 1354 GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey);
1392 GNUNET_CRYPTO_paillier_create (&my_pubkey,
1393 &my_privkey);
1394 my_cadet = GNUNET_CADET_connect (cfg); 1355 my_cadet = GNUNET_CADET_connect (cfg);
1395 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1356 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1396 NULL);
1397 if (NULL == my_cadet) 1357 if (NULL == my_cadet)
1398 { 1358 {
1399 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
1400 _("Connect to CADET failed\n"));
1401 GNUNET_SCHEDULER_shutdown (); 1360 GNUNET_SCHEDULER_shutdown ();
1402 return; 1361 return;
1403 } 1362 }
@@ -1407,22 +1366,23 @@ run (void *cls,
1407/** 1366/**
1408 * Define "main" method using service macro. 1367 * Define "main" method using service macro.
1409 */ 1368 */
1410GNUNET_SERVICE_MAIN 1369GNUNET_SERVICE_MAIN (
1411("scalarproduct-alice", 1370 "scalarproduct-alice",
1412 GNUNET_SERVICE_OPTION_NONE, 1371 GNUNET_SERVICE_OPTION_NONE,
1413 &run, 1372 &run,
1414 &client_connect_cb, 1373 &client_connect_cb,
1415 &client_disconnect_cb, 1374 &client_disconnect_cb,
1416 NULL, 1375 NULL,
1417 GNUNET_MQ_hd_var_size (alice_client_message, 1376 GNUNET_MQ_hd_var_size (alice_client_message,
1418 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 1377 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
1419 struct AliceComputationMessage, 1378 struct AliceComputationMessage,
1420 NULL), 1379 NULL),
1421 GNUNET_MQ_hd_var_size (alice_client_message_multipart, 1380 GNUNET_MQ_hd_var_size (
1422 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, 1381 alice_client_message_multipart,
1423 struct ComputationBobCryptodataMultipartMessage, 1382 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
1424 NULL), 1383 struct ComputationBobCryptodataMultipartMessage,
1425 GNUNET_MQ_handler_end ()); 1384 NULL),
1385 GNUNET_MQ_handler_end ());
1426 1386
1427 1387
1428/* end of gnunet-service-scalarproduct_alice.c */ 1388/* end of gnunet-service-scalarproduct_alice.c */