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.c379
1 files changed, 168 insertions, 211 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index 18c5cc49a..e138876f5 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -36,7 +36,8 @@
36#include "scalarproduct.h" 36#include "scalarproduct.h"
37#include "gnunet-service-scalarproduct.h" 37#include "gnunet-service-scalarproduct.h"
38 38
39#define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) 39#define LOG(kind, ...) \
40 GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__)
40 41
41/** 42/**
42 * An encrypted element key-value pair. 43 * An encrypted element key-value pair.
@@ -185,7 +186,6 @@ struct AliceServiceSession
185 * doing harm. 186 * doing harm.
186 */ 187 */
187 int in_destroy; 188 int in_destroy;
188
189}; 189};
190 190
191 191
@@ -224,9 +224,7 @@ static struct GNUNET_CADET_Handle *my_cadet;
224 * @return #GNUNET_OK (continue to iterate) 224 * @return #GNUNET_OK (continue to iterate)
225 */ 225 */
226static int 226static int
227free_element_cb (void *cls, 227free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
228 const struct GNUNET_HashCode *key,
229 void *value)
230{ 228{
231 struct GNUNET_SCALARPRODUCT_Element *e = value; 229 struct GNUNET_SCALARPRODUCT_Element *e = value;
232 230
@@ -283,7 +281,7 @@ destroy_service_session (struct AliceServiceSession *s)
283 } 281 }
284 if (NULL != s->sorted_elements) 282 if (NULL != s->sorted_elements)
285 { 283 {
286 for (unsigned int i=0;i<s->used_element_count;i++) 284 for (unsigned int i = 0; i < s->used_element_count; i++)
287 gcry_mpi_release (s->sorted_elements[i].value); 285 gcry_mpi_release (s->sorted_elements[i].value);
288 GNUNET_free (s->sorted_elements); 286 GNUNET_free (s->sorted_elements);
289 s->sorted_elements = NULL; 287 s->sorted_elements = NULL;
@@ -321,16 +319,15 @@ prepare_client_end_notification (struct AliceServiceSession *session)
321 319
322 if (NULL == session->client_mq) 320 if (NULL == session->client_mq)
323 return; /* no client left to be notified */ 321 return; /* no client left to be notified */
324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 322 GNUNET_log (
325 "Sending session-end notification with status %d to client for session %s\n", 323 GNUNET_ERROR_TYPE_DEBUG,
326 session->status, 324 "Sending session-end notification with status %d to client for session %s\n",
327 GNUNET_h2s (&session->session_id)); 325 session->status,
328 e = GNUNET_MQ_msg (msg, 326 GNUNET_h2s (&session->session_id));
329 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 327 e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
330 msg->product_length = htonl (0); 328 msg->product_length = htonl (0);
331 msg->status = htonl (session->status); 329 msg->status = htonl (session->status);
332 GNUNET_MQ_send (session->client_mq, 330 GNUNET_MQ_send (session->client_mq, e);
333 e);
334} 331}
335 332
336 333
@@ -363,9 +360,7 @@ transmit_client_response (struct AliceServiceSession *s)
363 if (0 > sign) 360 if (0 > sign)
364 { 361 {
365 range = -1; 362 range = -1;
366 gcry_mpi_sub (value, 363 gcry_mpi_sub (value, value, s->product);
367 value,
368 s->product);
369 } 364 }
370 else if (0 < sign) 365 else if (0 < sign)
371 { 366 {
@@ -380,15 +375,12 @@ transmit_client_response (struct AliceServiceSession *s)
380 gcry_mpi_release (s->product); 375 gcry_mpi_release (s->product);
381 s->product = NULL; 376 s->product = NULL;
382 377
383 if ( (0 != range) && 378 if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD,
384 (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, 379 &product_exported,
385 &product_exported, 380 &product_length,
386 &product_length, 381 value))))
387 value))))
388 { 382 {
389 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, 383 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
390 "gcry_mpi_scan",
391 rc);
392 prepare_client_end_notification (s); 384 prepare_client_end_notification (s);
393 return; 385 return;
394 } 386 }
@@ -401,20 +393,16 @@ transmit_client_response (struct AliceServiceSession *s)
401 msg->product_length = htonl (product_length); 393 msg->product_length = htonl (product_length);
402 if (NULL != product_exported) 394 if (NULL != product_exported)
403 { 395 {
404 GNUNET_memcpy (&msg[1], 396 GNUNET_memcpy (&msg[1], product_exported, product_length);
405 product_exported,
406 product_length);
407 GNUNET_free (product_exported); 397 GNUNET_free (product_exported);
408 } 398 }
409 GNUNET_MQ_send (s->client_mq, 399 GNUNET_MQ_send (s->client_mq, e);
410 e);
411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
412 "Sent result to client, session %s has ended!\n", 401 "Sent result to client, session %s has ended!\n",
413 GNUNET_h2s (&s->session_id)); 402 GNUNET_h2s (&s->session_id));
414} 403}
415 404
416 405
417
418/** 406/**
419 * Function called whenever a channel is destroyed. Should clean up 407 * Function called whenever a channel is destroyed. Should clean up
420 * any associated state. 408 * any associated state.
@@ -425,8 +413,7 @@ transmit_client_response (struct AliceServiceSession *s)
425 * @param channel connection to the other end (henceforth invalid) 413 * @param channel connection to the other end (henceforth invalid)
426 */ 414 */
427static void 415static void
428cb_channel_destruction (void *cls, 416cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel)
429 const struct GNUNET_CADET_Channel *channel)
430{ 417{
431 struct AliceServiceSession *s = cls; 418 struct AliceServiceSession *s = cls;
432 419
@@ -479,8 +466,7 @@ compute_square_sum_mpi_elements (const struct MpiElement *vector,
479 * @return an MPI value containing the calculated sum, never NULL 466 * @return an MPI value containing the calculated sum, never NULL
480 */ 467 */
481static gcry_mpi_t 468static gcry_mpi_t
482compute_square_sum (const gcry_mpi_t *vector, 469compute_square_sum (const gcry_mpi_t *vector, uint32_t length)
483 uint32_t length)
484{ 470{
485 gcry_mpi_t elem; 471 gcry_mpi_t elem;
486 gcry_mpi_t sum; 472 gcry_mpi_t sum;
@@ -531,28 +517,19 @@ compute_scalar_product (struct AliceServiceSession *session)
531 &my_pubkey, 517 &my_pubkey,
532 &session->r[i], 518 &session->r[i],
533 r[i]); 519 r[i]);
534 gcry_mpi_sub (r[i], 520 gcry_mpi_sub (r[i], r[i], my_offset);
535 r[i], 521 gcry_mpi_sub (r[i], r[i], my_offset);
536 my_offset);
537 gcry_mpi_sub (r[i],
538 r[i],
539 my_offset);
540 r_prime[i] = gcry_mpi_new (0); 522 r_prime[i] = gcry_mpi_new (0);
541 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 523 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
542 &my_pubkey, 524 &my_pubkey,
543 &session->r_prime[i], 525 &session->r_prime[i],
544 r_prime[i]); 526 r_prime[i]);
545 gcry_mpi_sub (r_prime[i], 527 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset);
546 r_prime[i], 528 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset);
547 my_offset);
548 gcry_mpi_sub (r_prime[i],
549 r_prime[i],
550 my_offset);
551 } 529 }
552 530
553 // calculate t = sum(ai) 531 // calculate t = sum(ai)
554 t = compute_square_sum_mpi_elements (session->sorted_elements, 532 t = compute_square_sum_mpi_elements (session->sorted_elements, count);
555 count);
556 // calculate U 533 // calculate U
557 u = gcry_mpi_new (0); 534 u = gcry_mpi_new (0);
558 tmp = compute_square_sum (r, count); 535 tmp = compute_square_sum (r, count);
@@ -570,10 +547,7 @@ compute_scalar_product (struct AliceServiceSession *session)
570 GNUNET_assert (s_prime = gcry_mpi_new (0)); 547 GNUNET_assert (s_prime = gcry_mpi_new (0));
571 548
572 // compute P 549 // compute P
573 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 550 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, &session->s, s);
574 &my_pubkey,
575 &session->s,
576 s);
577 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 551 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
578 &my_pubkey, 552 &my_pubkey,
579 &session->s_prime, 553 &session->s_prime,
@@ -627,8 +601,9 @@ compute_scalar_product (struct AliceServiceSession *session)
627 * #GNUNET_SYSERR to close it (signal serious error) 601 * #GNUNET_SYSERR to close it (signal serious error)
628 */ 602 */
629static int 603static int
630check_bobs_cryptodata_multipart (void *cls, 604check_bobs_cryptodata_multipart (
631 const struct BobCryptodataMultipartMessage *msg) 605 void *cls,
606 const struct BobCryptodataMultipartMessage *msg)
632{ 607{
633 struct AliceServiceSession *s = cls; 608 struct AliceServiceSession *s = cls;
634 uint32_t contained; 609 uint32_t contained;
@@ -637,10 +612,11 @@ check_bobs_cryptodata_multipart (void *cls,
637 612
638 msg_size = ntohs (msg->header.size); 613 msg_size = ntohs (msg->header.size);
639 contained = ntohl (msg->contained_element_count); 614 contained = ntohl (msg->contained_element_count);
640 required_size = sizeof (struct BobCryptodataMultipartMessage) 615 required_size =
641 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 616 sizeof (struct BobCryptodataMultipartMessage) +
642 if ( (required_size != msg_size) || 617 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
643 (s->cadet_received_element_count + contained > s->used_element_count) ) 618 if ((required_size != msg_size) ||
619 (s->cadet_received_element_count + contained > s->used_element_count))
644 { 620 {
645 GNUNET_break (0); 621 GNUNET_break (0);
646 return GNUNET_SYSERR; 622 return GNUNET_SYSERR;
@@ -656,8 +632,9 @@ check_bobs_cryptodata_multipart (void *cls,
656 * @param msg the actual message 632 * @param msg the actual message
657 */ 633 */
658static void 634static void
659handle_bobs_cryptodata_multipart (void *cls, 635handle_bobs_cryptodata_multipart (
660 const struct BobCryptodataMultipartMessage *msg) 636 void *cls,
637 const struct BobCryptodataMultipartMessage *msg)
661{ 638{
662 struct AliceServiceSession *s = cls; 639 struct AliceServiceSession *s = cls;
663 const struct GNUNET_CRYPTO_PaillierCiphertext *payload; 640 const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
@@ -710,12 +687,12 @@ check_bobs_cryptodata_message (void *cls,
710 687
711 msg_size = ntohs (msg->header.size); 688 msg_size = ntohs (msg->header.size);
712 contained = ntohl (msg->contained_element_count); 689 contained = ntohl (msg->contained_element_count);
713 required_size = sizeof (struct BobCryptodataMessage) 690 required_size =
714 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) 691 sizeof (struct BobCryptodataMessage) +
715 + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 692 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) +
716 if ( (msg_size != required_size) || 693 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
717 (contained > UINT16_MAX) || 694 if ((msg_size != required_size) || (contained > UINT16_MAX) ||
718 (s->used_element_count < contained) ) 695 (s->used_element_count < contained))
719 { 696 {
720 GNUNET_break_op (0); 697 GNUNET_break_op (0);
721 return GNUNET_SYSERR; 698 return GNUNET_SYSERR;
@@ -800,9 +777,7 @@ handle_bobs_cryptodata_message (void *cls,
800 * @param value the `struct GNUNET_SCALARPRODUCT_Element *` 777 * @param value the `struct GNUNET_SCALARPRODUCT_Element *`
801 */ 778 */
802static int 779static int
803copy_element_cb (void *cls, 780copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
804 const struct GNUNET_HashCode *key,
805 void *value)
806{ 781{
807 struct AliceServiceSession *s = cls; 782 struct AliceServiceSession *s = cls;
808 struct GNUNET_SCALARPRODUCT_Element *e = value; 783 struct GNUNET_SCALARPRODUCT_Element *e = value;
@@ -815,8 +790,8 @@ copy_element_cb (void *cls,
815 gcry_mpi_sub_ui (mval, mval, -val); 790 gcry_mpi_sub_ui (mval, mval, -val);
816 else 791 else
817 gcry_mpi_add_ui (mval, mval, val); 792 gcry_mpi_add_ui (mval, mval, val);
818 s->sorted_elements [s->used_element_count].value = mval; 793 s->sorted_elements[s->used_element_count].value = mval;
819 s->sorted_elements [s->used_element_count].key = &e->key; 794 s->sorted_elements[s->used_element_count].key = &e->key;
820 s->used_element_count++; 795 s->used_element_count++;
821 return GNUNET_OK; 796 return GNUNET_OK;
822} 797}
@@ -830,14 +805,12 @@ copy_element_cb (void *cls,
830 * @return -1 for a < b, 0 for a=b, 1 for a > b. 805 * @return -1 for a < b, 0 for a=b, 1 for a > b.
831 */ 806 */
832static int 807static int
833element_cmp (const void *a, 808element_cmp (const void *a, const void *b)
834 const void *b)
835{ 809{
836 const struct MpiElement *ma = a; 810 const struct MpiElement *ma = a;
837 const struct MpiElement *mb = b; 811 const struct MpiElement *mb = b;
838 812
839 return GNUNET_CRYPTO_hash_cmp (ma->key, 813 return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key);
840 mb->key);
841} 814}
842 815
843 816
@@ -845,7 +818,10 @@ element_cmp (const void *a,
845 * Maximum number of elements we can put into a single cryptodata 818 * Maximum number of elements we can put into a single cryptodata
846 * message 819 * message
847 */ 820 */
848#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct AliceCryptodataMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)) 821#define ELEMENT_CAPACITY \
822 ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \
823 sizeof (struct AliceCryptodataMessage)) / \
824 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
849 825
850 826
851/** 827/**
@@ -865,9 +841,9 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
865 gcry_mpi_t a; 841 gcry_mpi_t a;
866 uint32_t off; 842 uint32_t off;
867 843
868 s->sorted_elements 844 s->sorted_elements = GNUNET_malloc (
869 = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) * 845 GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) *
870 sizeof (struct MpiElement)); 846 sizeof (struct MpiElement));
871 s->used_element_count = 0; 847 s->used_element_count = 0;
872 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, 848 GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
873 &copy_element_cb, 849 &copy_element_cb,
@@ -890,29 +866,24 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
890 (unsigned int) todo_count, 866 (unsigned int) todo_count,
891 (unsigned int) s->used_element_count); 867 (unsigned int) s->used_element_count);
892 868
893 e = GNUNET_MQ_msg_extra (msg, 869 e =
894 todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext), 870 GNUNET_MQ_msg_extra (msg,
895 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); 871 todo_count *
896 GNUNET_MQ_env_set_options(e, 872 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext),
897 GNUNET_MQ_PREF_RELIABLE); 873 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA);
898 msg->contained_element_count = htonl (todo_count); 874 msg->contained_element_count = htonl (todo_count);
899 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 875 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
900 a = gcry_mpi_new (0); 876 a = gcry_mpi_new (0);
901 for (i = off; i < off + todo_count; i++) 877 for (i = off; i < off + todo_count; i++)
902 { 878 {
903 gcry_mpi_add (a, 879 gcry_mpi_add (a, s->sorted_elements[i].value, my_offset);
904 s->sorted_elements[i].value, 880 GNUNET_assert (
905 my_offset); 881 3 ==
906 GNUNET_assert (3 == 882 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - off]));
907 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey,
908 a,
909 3,
910 &payload[i - off]));
911 } 883 }
912 gcry_mpi_release (a); 884 gcry_mpi_release (a);
913 off += todo_count; 885 off += todo_count;
914 GNUNET_MQ_send (s->cadet_mq, 886 GNUNET_MQ_send (s->cadet_mq, e);
915 e);
916 } 887 }
917} 888}
918 889
@@ -947,10 +918,11 @@ cb_intersection_element_removed (void *cls,
947 "Intersection removed element with key %s and value %lld\n", 918 "Intersection removed element with key %s and value %lld\n",
948 GNUNET_h2s (&se->key), 919 GNUNET_h2s (&se->key),
949 (long long) GNUNET_ntohll (se->value)); 920 (long long) GNUNET_ntohll (se->value));
950 GNUNET_assert (GNUNET_YES == 921 GNUNET_assert (
951 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, 922 GNUNET_YES ==
952 element->data, 923 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
953 se)); 924 element->data,
925 se));
954 GNUNET_free (se); 926 GNUNET_free (se);
955 return; 927 return;
956 case GNUNET_SET_STATUS_DONE: 928 case GNUNET_SET_STATUS_DONE:
@@ -968,8 +940,7 @@ cb_intersection_element_removed (void *cls,
968 return; 940 return;
969 case GNUNET_SET_STATUS_FAILURE: 941 case GNUNET_SET_STATUS_FAILURE:
970 /* unhandled status code */ 942 /* unhandled status code */
971 LOG (GNUNET_ERROR_TYPE_DEBUG, 943 LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
972 "Set intersection failed!\n");
973 if (NULL != s->intersection_listen) 944 if (NULL != s->intersection_listen)
974 { 945 {
975 GNUNET_SET_listen_cancel (s->intersection_listen); 946 GNUNET_SET_listen_cancel (s->intersection_listen);
@@ -1014,18 +985,16 @@ cb_intersection_request_alice (void *cls,
1014{ 985{
1015 struct AliceServiceSession *s = cls; 986 struct AliceServiceSession *s = cls;
1016 987
1017 if (0 != GNUNET_memcmp (other_peer, 988 if (0 != GNUNET_memcmp (other_peer, &s->peer))
1018 &s->peer))
1019 { 989 {
1020 GNUNET_break_op (0); 990 GNUNET_break_op (0);
1021 return; 991 return;
1022 } 992 }
1023 s->intersection_op 993 s->intersection_op = GNUNET_SET_accept (request,
1024 = GNUNET_SET_accept (request, 994 GNUNET_SET_RESULT_REMOVED,
1025 GNUNET_SET_RESULT_REMOVED, 995 (struct GNUNET_SET_Option[]){{0}},
1026 (struct GNUNET_SET_Option[]) {{ 0 }}, 996 &cb_intersection_element_removed,
1027 &cb_intersection_element_removed, 997 s);
1028 s);
1029 if (NULL == s->intersection_op) 998 if (NULL == s->intersection_op)
1030 { 999 {
1031 GNUNET_break (0); 1000 GNUNET_break (0);
@@ -1033,9 +1002,7 @@ cb_intersection_request_alice (void *cls,
1033 prepare_client_end_notification (s); 1002 prepare_client_end_notification (s);
1034 return; 1003 return;
1035 } 1004 }
1036 if (GNUNET_OK != 1005 if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
1037 GNUNET_SET_commit (s->intersection_op,
1038 s->intersection_set))
1039 { 1006 {
1040 GNUNET_break (0); 1007 GNUNET_break (0);
1041 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1008 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1053,31 +1020,30 @@ cb_intersection_request_alice (void *cls,
1053static void 1020static void
1054client_request_complete_alice (struct AliceServiceSession *s) 1021client_request_complete_alice (struct AliceServiceSession *s)
1055{ 1022{
1056 struct GNUNET_MQ_MessageHandler cadet_handlers[] = { 1023 struct GNUNET_MQ_MessageHandler cadet_handlers[] =
1057 GNUNET_MQ_hd_var_size (bobs_cryptodata_message, 1024 {GNUNET_MQ_hd_var_size (bobs_cryptodata_message,
1058 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, 1025 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
1059 struct BobCryptodataMessage, 1026 struct BobCryptodataMessage,
1060 s), 1027 s),
1061 GNUNET_MQ_hd_var_size (bobs_cryptodata_multipart, 1028 GNUNET_MQ_hd_var_size (
1062 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, 1029 bobs_cryptodata_multipart,
1063 struct BobCryptodataMultipartMessage, 1030 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
1064 s), 1031 struct BobCryptodataMultipartMessage,
1065 GNUNET_MQ_handler_end () 1032 s),
1066 }; 1033 GNUNET_MQ_handler_end ()};
1067 struct ServiceRequestMessage *msg; 1034 struct ServiceRequestMessage *msg;
1068 struct GNUNET_MQ_Envelope *e; 1035 struct GNUNET_MQ_Envelope *e;
1069 1036
1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1071 "Creating new channel for session with key %s.\n", 1038 "Creating new channel for session with key %s.\n",
1072 GNUNET_h2s (&s->session_id)); 1039 GNUNET_h2s (&s->session_id));
1073 s->channel 1040 s->channel = GNUNET_CADET_channel_create (my_cadet,
1074 = GNUNET_CADET_channel_create (my_cadet, 1041 s,
1075 s, 1042 &s->peer,
1076 &s->peer, 1043 &s->session_id,
1077 &s->session_id, 1044 NULL,
1078 NULL, 1045 &cb_channel_destruction,
1079 &cb_channel_destruction, 1046 cadet_handlers);
1080 cadet_handlers);
1081 if (NULL == s->channel) 1047 if (NULL == s->channel)
1082 { 1048 {
1083 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1049 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1085,12 +1051,11 @@ client_request_complete_alice (struct AliceServiceSession *s)
1085 return; 1051 return;
1086 } 1052 }
1087 s->cadet_mq = GNUNET_CADET_get_mq (s->channel); 1053 s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
1088 s->intersection_listen 1054 s->intersection_listen = GNUNET_SET_listen (cfg,
1089 = GNUNET_SET_listen (cfg, 1055 GNUNET_SET_OPERATION_INTERSECTION,
1090 GNUNET_SET_OPERATION_INTERSECTION, 1056 &s->session_id,
1091 &s->session_id, 1057 &cb_intersection_request_alice,
1092 &cb_intersection_request_alice, 1058 s);
1093 s);
1094 if (NULL == s->intersection_listen) 1059 if (NULL == s->intersection_listen)
1095 { 1060 {
1096 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; 1061 s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1102,12 +1067,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
1102 1067
1103 e = GNUNET_MQ_msg (msg, 1068 e = GNUNET_MQ_msg (msg,
1104 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION); 1069 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION);
1105 GNUNET_MQ_env_set_options(e,
1106 GNUNET_MQ_PREF_RELIABLE);
1107 msg->session_id = s->session_id; 1070 msg->session_id = s->session_id;
1108 msg->public_key = my_pubkey; 1071 msg->public_key = my_pubkey;
1109 GNUNET_MQ_send (s->cadet_mq, 1072 GNUNET_MQ_send (s->cadet_mq, e);
1110 e);
1111} 1073}
1112 1074
1113 1075
@@ -1120,8 +1082,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
1120 * @return #GNUNET_OK if @a msg is well-formed 1082 * @return #GNUNET_OK if @a msg is well-formed
1121 */ 1083 */
1122static int 1084static int
1123check_alice_client_message_multipart (void *cls, 1085check_alice_client_message_multipart (
1124 const struct ComputationBobCryptodataMultipartMessage *msg) 1086 void *cls,
1087 const struct ComputationBobCryptodataMultipartMessage *msg)
1125{ 1088{
1126 struct AliceServiceSession *s = cls; 1089 struct AliceServiceSession *s = cls;
1127 uint32_t contained_count; 1090 uint32_t contained_count;
@@ -1129,11 +1092,12 @@ check_alice_client_message_multipart (void *cls,
1129 1092
1130 msize = ntohs (msg->header.size); 1093 msize = ntohs (msg->header.size);
1131 contained_count = ntohl (msg->element_count_contained); 1094 contained_count = ntohl (msg->element_count_contained);
1132 if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) + 1095 if ((msize !=
1133 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || 1096 (sizeof (struct ComputationBobCryptodataMultipartMessage) +
1134 (0 == contained_count) || 1097 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
1135 (s->total == s->client_received_element_count) || 1098 (0 == contained_count) ||
1136 (s->total < s->client_received_element_count + contained_count) ) 1099 (s->total == s->client_received_element_count) ||
1100 (s->total < s->client_received_element_count + contained_count))
1137 { 1101 {
1138 GNUNET_break_op (0); 1102 GNUNET_break_op (0);
1139 return GNUNET_SYSERR; 1103 return GNUNET_SYSERR;
@@ -1150,8 +1114,9 @@ check_alice_client_message_multipart (void *cls,
1150 * @param msg the actual message 1114 * @param msg the actual message
1151 */ 1115 */
1152static void 1116static void
1153handle_alice_client_message_multipart (void *cls, 1117handle_alice_client_message_multipart (
1154 const struct ComputationBobCryptodataMultipartMessage *msg) 1118 void *cls,
1119 const struct ComputationBobCryptodataMultipartMessage *msg)
1155{ 1120{
1156 struct AliceServiceSession *s = cls; 1121 struct AliceServiceSession *s = cls;
1157 uint32_t contained_count; 1122 uint32_t contained_count;
@@ -1166,13 +1131,13 @@ handle_alice_client_message_multipart (void *cls,
1166 { 1131 {
1167 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1132 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1168 GNUNET_memcpy (elem, 1133 GNUNET_memcpy (elem,
1169 &elements[i], 1134 &elements[i],
1170 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1135 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1171 if (GNUNET_SYSERR == 1136 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1172 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1137 s->intersected_elements,
1173 &elem->key, 1138 &elem->key,
1174 elem, 1139 elem,
1175 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1140 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1176 { 1141 {
1177 GNUNET_break (0); 1142 GNUNET_break (0);
1178 GNUNET_free (elem); 1143 GNUNET_free (elem);
@@ -1181,9 +1146,7 @@ handle_alice_client_message_multipart (void *cls,
1181 set_elem.data = &elem->key; 1146 set_elem.data = &elem->key;
1182 set_elem.size = sizeof (elem->key); 1147 set_elem.size = sizeof (elem->key);
1183 set_elem.element_type = 0; 1148 set_elem.element_type = 0;
1184 GNUNET_SET_add_element (s->intersection_set, 1149 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1185 &set_elem,
1186 NULL, NULL);
1187 s->used_element_count++; 1150 s->used_element_count++;
1188 } 1151 }
1189 GNUNET_SERVICE_client_continue (s->client); 1152 GNUNET_SERVICE_client_continue (s->client);
@@ -1206,7 +1169,7 @@ handle_alice_client_message_multipart (void *cls,
1206 */ 1169 */
1207static int 1170static int
1208check_alice_client_message (void *cls, 1171check_alice_client_message (void *cls,
1209 const struct AliceComputationMessage *msg) 1172 const struct AliceComputationMessage *msg)
1210{ 1173{
1211 struct AliceServiceSession *s = cls; 1174 struct AliceServiceSession *s = cls;
1212 uint16_t msize; 1175 uint16_t msize;
@@ -1223,10 +1186,10 @@ check_alice_client_message (void *cls,
1223 msize = ntohs (msg->header.size); 1186 msize = ntohs (msg->header.size);
1224 total_count = ntohl (msg->element_count_total); 1187 total_count = ntohl (msg->element_count_total);
1225 contained_count = ntohl (msg->element_count_contained); 1188 contained_count = ntohl (msg->element_count_contained);
1226 if ( (0 == total_count) || 1189 if ((0 == total_count) || (0 == contained_count) ||
1227 (0 == contained_count) || 1190 (msize !=
1228 (msize != (sizeof (struct AliceComputationMessage) + 1191 (sizeof (struct AliceComputationMessage) +
1229 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ) 1192 contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))))
1230 { 1193 {
1231 GNUNET_break_op (0); 1194 GNUNET_break_op (0);
1232 return GNUNET_SYSERR; 1195 return GNUNET_SYSERR;
@@ -1244,7 +1207,7 @@ check_alice_client_message (void *cls,
1244 */ 1207 */
1245static void 1208static void
1246handle_alice_client_message (void *cls, 1209handle_alice_client_message (void *cls,
1247 const struct AliceComputationMessage *msg) 1210 const struct AliceComputationMessage *msg)
1248{ 1211{
1249 struct AliceServiceSession *s = cls; 1212 struct AliceServiceSession *s = cls;
1250 uint32_t contained_count; 1213 uint32_t contained_count;
@@ -1261,10 +1224,10 @@ handle_alice_client_message (void *cls,
1261 s->client_received_element_count = contained_count; 1224 s->client_received_element_count = contained_count;
1262 s->session_id = msg->session_key; 1225 s->session_id = msg->session_key;
1263 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; 1226 elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
1264 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, 1227 s->intersected_elements =
1265 GNUNET_YES); 1228 GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES);
1266 s->intersection_set = GNUNET_SET_create (cfg, 1229 s->intersection_set =
1267 GNUNET_SET_OPERATION_INTERSECTION); 1230 GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
1268 1231
1269 for (uint32_t i = 0; i < contained_count; i++) 1232 for (uint32_t i = 0; i < contained_count; i++)
1270 { 1233 {
@@ -1272,13 +1235,13 @@ handle_alice_client_message (void *cls,
1272 continue; 1235 continue;
1273 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1236 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1274 GNUNET_memcpy (elem, 1237 GNUNET_memcpy (elem,
1275 &elements[i], 1238 &elements[i],
1276 sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1239 sizeof (struct GNUNET_SCALARPRODUCT_Element));
1277 if (GNUNET_SYSERR == 1240 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
1278 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1241 s->intersected_elements,
1279 &elem->key, 1242 &elem->key,
1280 elem, 1243 elem,
1281 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 1244 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1282 { 1245 {
1283 /* element with same key encountered twice! */ 1246 /* element with same key encountered twice! */
1284 GNUNET_break (0); 1247 GNUNET_break (0);
@@ -1288,9 +1251,7 @@ handle_alice_client_message (void *cls,
1288 set_elem.data = &elem->key; 1251 set_elem.data = &elem->key;
1289 set_elem.size = sizeof (elem->key); 1252 set_elem.size = sizeof (elem->key);
1290 set_elem.element_type = 0; 1253 set_elem.element_type = 0;
1291 GNUNET_SET_add_element (s->intersection_set, 1254 GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
1292 &set_elem,
1293 NULL, NULL);
1294 s->used_element_count++; 1255 s->used_element_count++;
1295 } 1256 }
1296 GNUNET_SERVICE_client_continue (s->client); 1257 GNUNET_SERVICE_client_continue (s->client);
@@ -1311,8 +1272,7 @@ handle_alice_client_message (void *cls,
1311static void 1272static void
1312shutdown_task (void *cls) 1273shutdown_task (void *cls)
1313{ 1274{
1314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
1315 "Shutting down, initiating cleanup.\n");
1316 // FIXME: we have to cut our connections to CADET first! 1276 // FIXME: we have to cut our connections to CADET first!
1317 if (NULL != my_cadet) 1277 if (NULL != my_cadet)
1318 { 1278 {
@@ -1334,8 +1294,8 @@ shutdown_task (void *cls)
1334 */ 1294 */
1335static void * 1295static void *
1336client_connect_cb (void *cls, 1296client_connect_cb (void *cls,
1337 struct GNUNET_SERVICE_Client *client, 1297 struct GNUNET_SERVICE_Client *client,
1338 struct GNUNET_MQ_Handle *mq) 1298 struct GNUNET_MQ_Handle *mq)
1339{ 1299{
1340 struct AliceServiceSession *s; 1300 struct AliceServiceSession *s;
1341 1301
@@ -1358,8 +1318,8 @@ client_connect_cb (void *cls,
1358 */ 1318 */
1359static void 1319static void
1360client_disconnect_cb (void *cls, 1320client_disconnect_cb (void *cls,
1361 struct GNUNET_SERVICE_Client *client, 1321 struct GNUNET_SERVICE_Client *client,
1362 void *app_cls) 1322 void *app_cls)
1363{ 1323{
1364 struct AliceServiceSession *s = app_cls; 1324 struct AliceServiceSession *s = app_cls;
1365 1325
@@ -1390,17 +1350,13 @@ run (void *cls,
1390 m1+m2 mod n == (S + a) + (S + b) mod n, 1350 m1+m2 mod n == (S + a) + (S + b) mod n,
1391 if we have more complex operations, this factor needs to be lowered */ 1351 if we have more complex operations, this factor needs to be lowered */
1392 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3); 1352 my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3);
1393 gcry_mpi_set_bit (my_offset, 1353 gcry_mpi_set_bit (my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3);
1394 GNUNET_CRYPTO_PAILLIER_BITS / 3); 1354 GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey);
1395 GNUNET_CRYPTO_paillier_create (&my_pubkey,
1396 &my_privkey);
1397 my_cadet = GNUNET_CADET_connect (cfg); 1355 my_cadet = GNUNET_CADET_connect (cfg);
1398 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 1356 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1399 NULL);
1400 if (NULL == my_cadet) 1357 if (NULL == my_cadet)
1401 { 1358 {
1402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
1403 _("Connect to CADET failed\n"));
1404 GNUNET_SCHEDULER_shutdown (); 1360 GNUNET_SCHEDULER_shutdown ();
1405 return; 1361 return;
1406 } 1362 }
@@ -1410,22 +1366,23 @@ run (void *cls,
1410/** 1366/**
1411 * Define "main" method using service macro. 1367 * Define "main" method using service macro.
1412 */ 1368 */
1413GNUNET_SERVICE_MAIN 1369GNUNET_SERVICE_MAIN (
1414("scalarproduct-alice", 1370 "scalarproduct-alice",
1415 GNUNET_SERVICE_OPTION_NONE, 1371 GNUNET_SERVICE_OPTION_NONE,
1416 &run, 1372 &run,
1417 &client_connect_cb, 1373 &client_connect_cb,
1418 &client_disconnect_cb, 1374 &client_disconnect_cb,
1419 NULL, 1375 NULL,
1420 GNUNET_MQ_hd_var_size (alice_client_message, 1376 GNUNET_MQ_hd_var_size (alice_client_message,
1421 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 1377 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
1422 struct AliceComputationMessage, 1378 struct AliceComputationMessage,
1423 NULL), 1379 NULL),
1424 GNUNET_MQ_hd_var_size (alice_client_message_multipart, 1380 GNUNET_MQ_hd_var_size (
1425 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, 1381 alice_client_message_multipart,
1426 struct ComputationBobCryptodataMultipartMessage, 1382 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
1427 NULL), 1383 struct ComputationBobCryptodataMultipartMessage,
1428 GNUNET_MQ_handler_end ()); 1384 NULL),
1385 GNUNET_MQ_handler_end ());
1429 1386
1430 1387
1431/* end of gnunet-service-scalarproduct_alice.c */ 1388/* end of gnunet-service-scalarproduct_alice.c */