aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-11-30 20:40:27 +0000
committerChristian Grothoff <christian@grothoff.org>2014-11-30 20:40:27 +0000
commitb55fbe08e368c3b77897615c577ff9b537485e26 (patch)
tree1035ab079a92f4722b82cdd4ba1100e1d180a163 /src/scalarproduct
parent3f1b003aafd4426576369f229ca6740a77cd7504 (diff)
downloadgnunet-b55fbe08e368c3b77897615c577ff9b537485e26.tar.gz
gnunet-b55fbe08e368c3b77897615c577ff9b537485e26.zip
simplify logic
Diffstat (limited to 'src/scalarproduct')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct.c298
1 files changed, 150 insertions, 148 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c
index 1b4cbd674..b5fc1471f 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct.c
@@ -55,12 +55,17 @@ GNUNET_NETWORK_STRUCT_BEGIN
55struct ServiceRequestMessage 55struct ServiceRequestMessage
56{ 56{
57 /** 57 /**
58 * GNUNET message header 58 * Type is #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION
59 */ 59 */
60 struct GNUNET_MessageHeader header; 60 struct GNUNET_MessageHeader header;
61 61
62 /** 62 /**
63 * the transaction/session key used to identify a session 63 * For alignment. Always zero.
64 */
65 uint32_t reserved;
66
67 /**
68 * The transaction/session key used to identify a session
64 */ 69 */
65 struct GNUNET_HashCode session_id; 70 struct GNUNET_HashCode session_id;
66 71
@@ -73,17 +78,18 @@ struct ServiceRequestMessage
73 78
74 79
75/** 80/**
76 * FIXME. 81 * Vector of Pallier-encrypted values sent by Alice to Bob
82 * (after set intersection).
77 */ 83 */
78struct AliceCryptodataMessage 84struct AliceCryptodataMessage
79{ 85{
80 /** 86 /**
81 * GNUNET message header 87 * Type is #GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA
82 */ 88 */
83 struct GNUNET_MessageHeader header; 89 struct GNUNET_MessageHeader header;
84 90
85 /** 91 /**
86 * how many elements we appended to this message 92 * How many elements we appended to this message? In NBO.
87 */ 93 */
88 uint32_t contained_element_count GNUNET_PACKED; 94 uint32_t contained_element_count GNUNET_PACKED;
89 95
@@ -95,7 +101,7 @@ struct AliceCryptodataMessage
95 101
96/** 102/**
97 * Multipart Message type passed between to supply additional elements 103 * Multipart Message type passed between to supply additional elements
98 * for the peer 104 * for the peer.
99 */ 105 */
100struct MultipartMessage 106struct MultipartMessage
101{ 107{
@@ -105,17 +111,19 @@ struct MultipartMessage
105 struct GNUNET_MessageHeader header; 111 struct GNUNET_MessageHeader header;
106 112
107 /** 113 /**
108 * how many elements we supply within this message 114 * How many elements we supply within this message? In NBO.
109 */ 115 */
110 uint32_t contained_element_count GNUNET_PACKED; 116 uint32_t contained_element_count GNUNET_PACKED;
111 117
112 // struct GNUNET_CRYPTO_PaillierCiphertext[multipart_element_count] 118 /**
119 * struct GNUNET_CRYPTO_PaillierCiphertext[multipart_element_count]
120 */
113}; 121};
114 122
115 123
116/** 124/**
117 * Message type passed from responding service Bob to responding service Alice 125 * Message type passed from responding service Bob to responding service Alice
118 * to complete a request and allow Alice to compute the result 126 * to complete a request and allow Alice to compute the result.
119 */ 127 */
120struct ServiceResponseMessage 128struct ServiceResponseMessage
121{ 129{
@@ -125,23 +133,24 @@ struct ServiceResponseMessage
125 struct GNUNET_MessageHeader header; 133 struct GNUNET_MessageHeader header;
126 134
127 /** 135 /**
128 * how many elements the session input had 136 * How many elements the session input had (in NBO).
129 */ 137 */
130 uint32_t total_element_count GNUNET_PACKED; 138 uint32_t total_element_count GNUNET_PACKED;
131 139
132 /** 140 /**
133 * how many elements were included after the mask was applied 141 * How many elements were included after the mask was applied
134 * including all multipart msgs. 142 * including all multipart msgs (in NBO).
135 */ 143 */
136 uint32_t used_element_count GNUNET_PACKED; 144 uint32_t used_element_count GNUNET_PACKED;
137 145
138 /** 146 /**
139 * how many elements this individual message delivers 147 * How many elements this individual message delivers (in NBO).
140 */ 148 */
141 uint32_t contained_element_count GNUNET_PACKED; 149 uint32_t contained_element_count GNUNET_PACKED;
142 150
143 /** 151 /**
144 * the transaction/session key used to identify a session 152 * The transaction/session key used to identify a session.
153 * FIXME: needed? CADET should already identify sessions!
145 */ 154 */
146 struct GNUNET_HashCode key; 155 struct GNUNET_HashCode key;
147 156
@@ -154,16 +163,27 @@ GNUNET_NETWORK_STRUCT_END
154 163
155 164
156/** 165/**
157 * role a peer in a session can assume 166 * Role a peer in a session can assume.
158 */ 167 */
159enum PeerRole 168enum PeerRole
160{ 169{
170 /**
171 * Alice is the peer that learns the result of the scalar product
172 * calculation.
173 */
161 ALICE, 174 ALICE,
175
176 /**
177 * Bob merely provides his vector to compute the scalar product, but
178 * does not learn anything about Alice's vector (except which elements
179 * Alice's vector may contain, as the compute an intersection).
180 */
162 BOB 181 BOB
163}; 182};
164 183
184
165/** 185/**
166 * DLL for sorting elements 186 * DLL for sorting elements.
167 */ 187 */
168struct SortedValue 188struct SortedValue
169{ 189{
@@ -183,7 +203,7 @@ struct SortedValue
183 struct GNUNET_SCALARPRODUCT_Element *elem; 203 struct GNUNET_SCALARPRODUCT_Element *elem;
184 204
185 /** 205 /**
186 * the element's value converted to MPI 206 * The element's value converted to MPI
187 */ 207 */
188 gcry_mpi_t val; 208 gcry_mpi_t val;
189}; 209};
@@ -194,18 +214,18 @@ struct SortedValue
194 * 214 *
195 * a request form the client to our final response. 215 * a request form the client to our final response.
196 * or 216 * or
197 * a request from a service to us(service). 217 * a request from a service to us (service).
198 */ 218 */
199struct ServiceSession 219struct ServiceSession
200{ 220{
201 221
202 /** 222 /**
203 * session information is kept in a DLL 223 * Session information is kept in a DLL
204 */ 224 */
205 struct ServiceSession *next; 225 struct ServiceSession *next;
206 226
207 /** 227 /**
208 * session information is kept in a DLL 228 * Session information is kept in a DLL
209 */ 229 */
210 struct ServiceSession *prev; 230 struct ServiceSession *prev;
211 231
@@ -220,7 +240,7 @@ struct ServiceSession
220 struct GNUNET_PeerIdentity peer; 240 struct GNUNET_PeerIdentity peer;
221 241
222 /** 242 /**
223 * the client this request is related to 243 * The client this request is related to.
224 */ 244 */
225 struct GNUNET_SERVER_Client *client; 245 struct GNUNET_SERVER_Client *client;
226 246
@@ -252,11 +272,6 @@ struct ServiceSession
252 struct GNUNET_SET_ListenHandle *intersection_listen; 272 struct GNUNET_SET_ListenHandle *intersection_listen;
253 273
254 /** 274 /**
255 * Public key of the remote service, only used by Bob
256 */
257 struct GNUNET_CRYPTO_PaillierPublicKey remote_pubkey;
258
259 /**
260 * DLL for sorting elements after intersection 275 * DLL for sorting elements after intersection
261 */ 276 */
262 struct SortedValue *a_head; 277 struct SortedValue *a_head;
@@ -287,14 +302,14 @@ struct ServiceSession
287 struct GNUNET_CRYPTO_PaillierCiphertext *r_prime; 302 struct GNUNET_CRYPTO_PaillierCiphertext *r_prime;
288 303
289 /** 304 /**
290 * Bob's s 305 * Bob's "s"
291 */ 306 */
292 struct GNUNET_CRYPTO_PaillierCiphertext *s; 307 struct GNUNET_CRYPTO_PaillierCiphertext s;
293 308
294 /** 309 /**
295 * Bob's s' 310 * Bob's "s'"
296 */ 311 */
297 struct GNUNET_CRYPTO_PaillierCiphertext *s_prime; 312 struct GNUNET_CRYPTO_PaillierCiphertext s_prime;
298 313
299 /** 314 /**
300 * Bob's matching response session from the client 315 * Bob's matching response session from the client
@@ -317,6 +332,11 @@ struct ServiceSession
317 struct GNUNET_CADET_Channel *channel; 332 struct GNUNET_CADET_Channel *channel;
318 333
319 /** 334 /**
335 * Public key of the remote service, only used by Bob
336 */
337 struct GNUNET_CRYPTO_PaillierPublicKey remote_pubkey;
338
339 /**
320 * Handle to a task that sends a msg to the our client 340 * Handle to a task that sends a msg to the our client
321 */ 341 */
322 GNUNET_SCHEDULER_TaskIdentifier client_notification_task; 342 GNUNET_SCHEDULER_TaskIdentifier client_notification_task;
@@ -533,16 +553,6 @@ free_session_variables (struct ServiceSession *s)
533 GNUNET_free (s->r_prime); 553 GNUNET_free (s->r_prime);
534 s->r_prime = NULL; 554 s->r_prime = NULL;
535 } 555 }
536 if (s->s)
537 {
538 GNUNET_free (s->s);
539 s->s = NULL;
540 }
541 if (s->s_prime)
542 {
543 GNUNET_free (s->s_prime);
544 s->s_prime = NULL;
545 }
546 if (s->product) 556 if (s->product)
547 { 557 {
548 gcry_mpi_release (s->product); 558 gcry_mpi_release (s->product);
@@ -714,60 +724,61 @@ cb_client_disconnect (void *cls,
714 * @param tc the task context handed to us by the scheduler, unused 724 * @param tc the task context handed to us by the scheduler, unused
715 */ 725 */
716static void 726static void
717prepare_client_end_notification (void * cls, 727prepare_client_end_notification (void *cls,
718 const struct GNUNET_SCHEDULER_TaskContext * tc) 728 const struct GNUNET_SCHEDULER_TaskContext *tc)
719{ 729{
720 struct ServiceSession * s = cls; 730 struct ServiceSession *session = cls;
721 struct ClientResponseMessage *msg; 731 struct ClientResponseMessage *msg;
722 732
723 s->client_notification_task = GNUNET_SCHEDULER_NO_TASK; 733 session->client_notification_task = GNUNET_SCHEDULER_NO_TASK;
724 734
725 msg = GNUNET_new (struct ClientResponseMessage); 735 msg = GNUNET_new (struct ClientResponseMessage);
726 msg->header.size = htons (sizeof (struct ClientResponseMessage)); 736 msg->header.size = htons (sizeof (struct ClientResponseMessage));
727 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 737 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
728 // signal error if not signalized, positive result-range field but zero length. 738 // signal error if not signalized, positive result-range field but zero length.
729 msg->product_length = htonl (0); 739 msg->product_length = htonl (0);
730 msg->status = htonl(s->active); 740 msg->status = htonl(session->active);
731 s->msg = &msg->header; 741 session->msg = &msg->header;
732 742
733 //transmit this message to our client 743 //transmit this message to our client
734 s->client_transmit_handle 744 session->client_transmit_handle
735 = GNUNET_SERVER_notify_transmit_ready (s->client, 745 = GNUNET_SERVER_notify_transmit_ready (session->client,
736 sizeof (struct ClientResponseMessage), 746 sizeof (struct ClientResponseMessage),
737 GNUNET_TIME_UNIT_FOREVER_REL, 747 GNUNET_TIME_UNIT_FOREVER_REL,
738 &cb_transfer_message, 748 &cb_transfer_message,
739 s); 749 session);
740 750
741 // if we could not even queue our request, something is wrong 751 // if we could not even queue our request, something is wrong
742 if (NULL == s->client_transmit_handle) 752 if (NULL == session->client_transmit_handle)
743 { 753 {
744 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 754 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
745 _("Could not send message to client (%p)!\n"), 755 _("Could not send message to client (%p)!\n"),
746 s->client); 756 session->client);
747 GNUNET_SERVER_client_disconnect (s->client); 757 GNUNET_SERVER_client_disconnect (session->client);
748 free_session_variables(s); 758 free_session_variables (session);
749 GNUNET_CONTAINER_DLL_remove (from_client_head, 759 GNUNET_CONTAINER_DLL_remove (from_client_head,
750 from_client_tail, 760 from_client_tail,
751 s); 761 session);
752 GNUNET_free(s); 762 GNUNET_free (session);
753 return; 763 return;
754 } 764 }
755 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 765 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
756 _("Sending session-end notification to client (%p) for session %s\n"), 766 _("Sending session-end notification to client (%p) for session %s\n"),
757 s->client, 767 session->client,
758 GNUNET_h2s (&s->session_id)); 768 GNUNET_h2s (&session->session_id));
759} 769}
760 770
761 771
762/** 772/**
763 * Executed by Alice, fills in a service-request message and sends it to the given peer 773 * Executed by Alice, fills in a service-request message and sends it
774 * to the given peer.
764 * 775 *
765 * @param cls the session associated with this request 776 * @param cls the session associated with this request
766 */ 777 */
767static void 778static void
768prepare_alices_cyrptodata_message (void *cls) 779prepare_alices_cyrptodata_message (void *cls)
769{ 780{
770 struct ServiceSession * s = cls; 781 struct ServiceSession *session = cls;
771 struct AliceCryptodataMessage * msg; 782 struct AliceCryptodataMessage * msg;
772 struct GNUNET_CRYPTO_PaillierCiphertext * payload; 783 struct GNUNET_CRYPTO_PaillierCiphertext * payload;
773 unsigned int i; 784 unsigned int i;
@@ -776,62 +787,63 @@ prepare_alices_cyrptodata_message (void *cls)
776 787
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
778 "Successfully created new channel to peer (%s)!\n", 789 "Successfully created new channel to peer (%s)!\n",
779 GNUNET_i2s (&s->peer)); 790 GNUNET_i2s (&session->peer));
780 791
781 msg_length = sizeof (struct AliceCryptodataMessage) 792 msg_length = sizeof (struct AliceCryptodataMessage)
782 + s->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 793 + session->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
783 794
784 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > msg_length) 795 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > msg_length)
785 { 796 {
786 s->transferred_element_count = s->used_element_count; 797 session->transferred_element_count = session->used_element_count;
787 } 798 }
788 else 799 else
789 { 800 {
790 //create a multipart msg, first we calculate a new msg size for the head msg 801 //create a multipart msg, first we calculate a new msg size for the head msg
791 s->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct AliceCryptodataMessage)) 802 session->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct AliceCryptodataMessage))
792 / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 803 / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
793 msg_length = sizeof (struct AliceCryptodataMessage) 804 msg_length = sizeof (struct AliceCryptodataMessage)
794 +s->transferred_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 805 + session->transferred_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
795 } 806 }
796 807
797 msg = GNUNET_malloc (msg_length); 808 msg = GNUNET_malloc (msg_length);
798 msg->header.size = htons (msg_length); 809 msg->header.size = htons (msg_length);
799 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA); 810 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA);
800 msg->contained_element_count = htonl (s->transferred_element_count); 811 msg->contained_element_count = htonl (session->transferred_element_count);
801 812
802 // fill in the payload 813 // fill in the payload
803 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 814 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
804 815
805 // now copy over the sorted element vector 816 // now copy over the sorted element vector
806 a = gcry_mpi_new (0); 817 a = gcry_mpi_new (0);
807 for (i = 0; i < s->transferred_element_count; i++) 818 for (i = 0; i < session->transferred_element_count; i++)
808 { 819 {
809 gcry_mpi_add (a, s->sorted_elements[i], my_offset); 820 gcry_mpi_add (a, session->sorted_elements[i], my_offset);
810 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i]); 821 GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i]);
811 } 822 }
812 gcry_mpi_release (a); 823 gcry_mpi_release (a);
813 824
814 s->msg = (struct GNUNET_MessageHeader *) msg; 825 session->msg = (struct GNUNET_MessageHeader *) msg;
815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
816 "Transmitting service request.\n"); 827 "Transmitting service request.\n");
817 828
818 //transmit via cadet messaging 829 //transmit via cadet messaging
819 s->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (s->channel, 830 session->service_transmit_handle
820 GNUNET_YES, 831 = GNUNET_CADET_notify_transmit_ready (session->channel,
821 GNUNET_TIME_UNIT_FOREVER_REL, 832 GNUNET_YES,
822 msg_length, 833 GNUNET_TIME_UNIT_FOREVER_REL,
823 &cb_transfer_message, 834 msg_length,
824 s); 835 &cb_transfer_message,
825 if (NULL == s->service_transmit_handle) 836 session);
837 if (NULL == session->service_transmit_handle)
826 { 838 {
827 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 839 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
828 _("Could not send message to channel!\n")); 840 _("Could not send message to channel!\n"));
829 GNUNET_free (msg); 841 GNUNET_free (msg);
830 s->msg = NULL; 842 session->msg = NULL;
831 s->active = GNUNET_SYSERR; 843 session->active = GNUNET_SYSERR;
832 s->client_notification_task = 844 session->client_notification_task
833 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 845 = GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
834 s); 846 session);
835 return; 847 return;
836 } 848 }
837} 849}
@@ -846,7 +858,7 @@ prepare_alices_cyrptodata_message (void *cls)
846static void 858static void
847prepare_bobs_cryptodata_message_multipart (void *cls) 859prepare_bobs_cryptodata_message_multipart (void *cls)
848{ 860{
849 struct ServiceSession * s = cls; 861 struct ServiceSession *session = cls;
850 struct GNUNET_CRYPTO_PaillierCiphertext * payload; 862 struct GNUNET_CRYPTO_PaillierCiphertext * payload;
851 struct MultipartMessage * msg; 863 struct MultipartMessage * msg;
852 unsigned int i; 864 unsigned int i;
@@ -855,7 +867,7 @@ prepare_bobs_cryptodata_message_multipart (void *cls)
855 uint32_t todo_count; 867 uint32_t todo_count;
856 868
857 msg_length = sizeof (struct MultipartMessage); 869 msg_length = sizeof (struct MultipartMessage);
858 todo_count = s->used_element_count - s->transferred_element_count; 870 todo_count = session->used_element_count - session->transferred_element_count;
859 871
860 if (todo_count > MULTIPART_ELEMENT_CAPACITY / 2) 872 if (todo_count > MULTIPART_ELEMENT_CAPACITY / 2)
861 // send the currently possible maximum chunk, we always transfer both permutations 873 // send the currently possible maximum chunk, we always transfer both permutations
@@ -868,54 +880,53 @@ prepare_bobs_cryptodata_message_multipart (void *cls)
868 msg->contained_element_count = htonl (todo_count); 880 msg->contained_element_count = htonl (todo_count);
869 881
870 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 882 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
871 for (i = s->transferred_element_count, j = 0; i < s->transferred_element_count + todo_count; i++) 883 for (i = session->transferred_element_count, j = 0; i < session->transferred_element_count + todo_count; i++)
872 { 884 {
873 //r[i][p] and r[i][q] 885 //r[i][p] and r[i][q]
874 memcpy (&payload[j++], 886 memcpy (&payload[j++],
875 &s->r[i], 887 &session->r[i],
876 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 888 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
877 memcpy (&payload[j++], 889 memcpy (&payload[j++],
878 &s->r_prime[i], 890 &session->r_prime[i],
879 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 891 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
880 } 892 }
881 s->transferred_element_count += todo_count; 893 session->transferred_element_count += todo_count;
882 s->msg = (struct GNUNET_MessageHeader *) msg; 894 session->msg = (struct GNUNET_MessageHeader *) msg;
883 s->service_transmit_handle = 895 session->service_transmit_handle
884 GNUNET_CADET_notify_transmit_ready (s->channel, 896 = GNUNET_CADET_notify_transmit_ready (session->channel,
885 GNUNET_YES, 897 GNUNET_YES,
886 GNUNET_TIME_UNIT_FOREVER_REL, 898 GNUNET_TIME_UNIT_FOREVER_REL,
887 msg_length, 899 msg_length,
888 &cb_transfer_message, 900 &cb_transfer_message,
889 s); 901 session);
890 if (NULL == s->service_transmit_handle) 902 if (NULL == session->service_transmit_handle)
891 { 903 {
892 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 904 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
893 _("Could not send service-response message via cadet!)\n")); 905 _("Could not send service-response message via CADET!)\n"));
894 906
895 GNUNET_free (msg); 907 GNUNET_free (msg);
896 s->msg = NULL; 908 session->msg = NULL;
897 GNUNET_CADET_channel_destroy(s->channel); 909 GNUNET_CADET_channel_destroy (session->channel);
898 s->response->active = GNUNET_SYSERR; 910 session->response->active = GNUNET_SYSERR;
899 911
900 GNUNET_CONTAINER_DLL_remove (from_service_head, 912 GNUNET_CONTAINER_DLL_remove (from_service_head,
901 from_service_tail, 913 from_service_tail,
902 s); 914 session);
903 915 session->response->client_notification_task
904 s->response->client_notification_task
905 = GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 916 = GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
906 s->response); 917 session->response);
907 free_session_variables(s); 918 free_session_variables (session);
908 GNUNET_free(s); 919 GNUNET_free (session);
909 return; 920 return;
910 } 921 }
911 if (s->transferred_element_count == s->used_element_count) 922 if (session->transferred_element_count == session->used_element_count)
912 { 923 {
913 // final part 924 // final part
914 s->active = GNUNET_NO; 925 session->active = GNUNET_NO;
915 GNUNET_free (s->r_prime); 926 GNUNET_free (session->r_prime);
916 GNUNET_free (s->r); 927 GNUNET_free (session->r);
917 s->r_prime = NULL; 928 session->r_prime = NULL;
918 s->r = NULL; 929 session->r = NULL;
919 } 930 }
920} 931}
921 932
@@ -933,8 +944,7 @@ prepare_bobs_cryptodata_message_multipart (void *cls)
933 */ 944 */
934static void 945static void
935prepare_bobs_cryptodata_message (void *cls, 946prepare_bobs_cryptodata_message (void *cls,
936 const struct GNUNET_SCHEDULER_TaskContext 947 const struct GNUNET_SCHEDULER_TaskContext *tc)
937 * tc)
938{ 948{
939 struct ServiceSession * s = cls; 949 struct ServiceSession * s = cls;
940 struct ServiceResponseMessage *msg; 950 struct ServiceResponseMessage *msg;
@@ -961,15 +971,15 @@ prepare_bobs_cryptodata_message (void *cls,
961 msg->total_element_count = htonl (s->total); 971 msg->total_element_count = htonl (s->total);
962 msg->used_element_count = htonl (s->used_element_count); 972 msg->used_element_count = htonl (s->used_element_count);
963 msg->contained_element_count = htonl (s->transferred_element_count); 973 msg->contained_element_count = htonl (s->transferred_element_count);
964 memcpy (&msg->key, &s->session_id, sizeof (struct GNUNET_HashCode)); 974 msg->key = s->session_id;
965 975
966 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 976 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
967 memcpy (&payload[0], s->s, sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 977 memcpy (&payload[0],
968 memcpy (&payload[1], s->s_prime, sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 978 &s->s,
969 GNUNET_free (s->s_prime); 979 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
970 s->s_prime = NULL; 980 memcpy (&payload[1],
971 GNUNET_free (s->s); 981 &s->s_prime,
972 s->s = NULL; 982 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
973 983
974 payload = &payload[2]; 984 payload = &payload[2];
975 // convert k[][] 985 // convert k[][]
@@ -1043,30 +1053,28 @@ static void
1043compute_service_response (struct ServiceSession *session) 1053compute_service_response (struct ServiceSession *session)
1044{ 1054{
1045 int i; 1055 int i;
1046 unsigned int * p; 1056 unsigned int *p;
1047 unsigned int * q; 1057 unsigned int *q;
1048 uint32_t count; 1058 uint32_t count;
1049 gcry_mpi_t *rand; 1059 gcry_mpi_t *rand;
1050 gcry_mpi_t tmp; 1060 gcry_mpi_t tmp;
1051 gcry_mpi_t * b; 1061 gcry_mpi_t *b;
1052 struct GNUNET_CRYPTO_PaillierCiphertext * a; 1062 struct GNUNET_CRYPTO_PaillierCiphertext *a;
1053 struct GNUNET_CRYPTO_PaillierCiphertext * r; 1063 struct GNUNET_CRYPTO_PaillierCiphertext *r;
1054 struct GNUNET_CRYPTO_PaillierCiphertext * r_prime; 1064 struct GNUNET_CRYPTO_PaillierCiphertext *r_prime;
1055 struct GNUNET_CRYPTO_PaillierCiphertext * s;
1056 struct GNUNET_CRYPTO_PaillierCiphertext * s_prime;
1057 1065
1058 count = session->used_element_count; 1066 count = session->used_element_count;
1059 a = session->e_a; 1067 a = session->e_a;
1060 b = session->sorted_elements; 1068 b = session->sorted_elements;
1061 q = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, count); 1069 q = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
1062 p = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, count); 1070 count);
1071 p = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK,
1072 count);
1063 rand = GNUNET_malloc (sizeof (gcry_mpi_t) * count); 1073 rand = GNUNET_malloc (sizeof (gcry_mpi_t) * count);
1064 for (i = 0; i < count; i++) 1074 for (i = 0; i < count; i++)
1065 GNUNET_assert (NULL != (rand[i] = gcry_mpi_new (0))); 1075 GNUNET_assert (NULL != (rand[i] = gcry_mpi_new (0)));
1066 r = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * count); 1076 r = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * count);
1067 r_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * count); 1077 r_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * count);
1068 s = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
1069 s_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
1070 1078
1071 for (i = 0; i < count; i++) 1079 for (i = 0; i < count; i++)
1072 { 1080 {
@@ -1128,7 +1136,7 @@ compute_service_response (struct ServiceSession *session)
1128 GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, 1136 GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
1129 tmp, 1137 tmp,
1130 1, 1138 1,
1131 s_prime); 1139 &session->s_prime);
1132 1140
1133 // Calculate S = E(SUM( (r_i + b_i)^2 )) 1141 // Calculate S = E(SUM( (r_i + b_i)^2 ))
1134 for (i = 0; i < count; i++) 1142 for (i = 0; i < count; i++)
@@ -1137,12 +1145,10 @@ compute_service_response (struct ServiceSession *session)
1137 GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey, 1145 GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
1138 tmp, 1146 tmp,
1139 1, 1147 1,
1140 s); 1148 &session->s);
1141 1149
1142 session->r = r; 1150 session->r = r;
1143 session->r_prime = r_prime; 1151 session->r_prime = r_prime;
1144 session->s = s;
1145 session->s_prime = s_prime;
1146 1152
1147 // release rand, b and a 1153 // release rand, b and a
1148 for (i = 0; i < count; i++) 1154 for (i = 0; i < count; i++)
@@ -1159,7 +1165,8 @@ compute_service_response (struct ServiceSession *session)
1159 GNUNET_free (rand); 1165 GNUNET_free (rand);
1160 1166
1161 // copy the r[], r_prime[], S and Stick into a new message, prepare_service_response frees these 1167 // copy the r[], r_prime[], S and Stick into a new message, prepare_service_response frees these
1162 GNUNET_SCHEDULER_add_now (&prepare_bobs_cryptodata_message, s); 1168 GNUNET_SCHEDULER_add_now (&prepare_bobs_cryptodata_message,
1169 session);
1163} 1170}
1164 1171
1165 1172
@@ -2055,10 +2062,12 @@ compute_scalar_product (struct ServiceSession *session)
2055 // compute P 2062 // compute P
2056 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 2063 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
2057 &my_pubkey, 2064 &my_pubkey,
2058 session->s, s); 2065 &session->s,
2066 s);
2059 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, 2067 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
2060 &my_pubkey, 2068 &my_pubkey,
2061 session->s_prime, s_prime); 2069 &session->s_prime,
2070 s_prime);
2062 2071
2063 // compute P 2072 // compute P
2064 gcry_mpi_add (p, s, t); 2073 gcry_mpi_add (p, s, t);
@@ -2089,10 +2098,6 @@ compute_scalar_product (struct ServiceSession *session)
2089 } 2098 }
2090 GNUNET_free (session->a_head); 2099 GNUNET_free (session->a_head);
2091 session->a_head = NULL; 2100 session->a_head = NULL;
2092 GNUNET_free (session->s);
2093 session->s = NULL;
2094 GNUNET_free (session->s_prime);
2095 session->s_prime = NULL;
2096 GNUNET_free (session->r); 2101 GNUNET_free (session->r);
2097 session->r = NULL; 2102 session->r = NULL;
2098 GNUNET_free (session->r_prime); 2103 GNUNET_free (session->r_prime);
@@ -2588,13 +2593,10 @@ handle_bobs_cryptodata_message (void *cls,
2588 s->transferred_element_count = contained; 2593 s->transferred_element_count = contained;
2589 //convert s 2594 //convert s
2590 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 2595 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
2591 2596 memcpy (&s->s,
2592 s->s = GNUNET_new (struct GNUNET_CRYPTO_PaillierCiphertext);
2593 s->s_prime = GNUNET_new (struct GNUNET_CRYPTO_PaillierCiphertext);
2594 memcpy (s->s,
2595 &payload[0], 2597 &payload[0],
2596 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2598 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2597 memcpy (s->s_prime, 2599 memcpy (&s->s_prime,
2598 &payload[1], 2600 &payload[1],
2599 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2601 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2600 2602