aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-11-30 20:22:15 +0000
committerChristian Grothoff <christian@grothoff.org>2014-11-30 20:22:15 +0000
commit3f1b003aafd4426576369f229ca6740a77cd7504 (patch)
treeb3579ebbcf676c2069f851c7237e817a337f9aef /src/scalarproduct
parent8e013a4a1792ec10f213d7d0c1b7e5442b9559cf (diff)
downloadgnunet-3f1b003aafd4426576369f229ca6740a77cd7504.tar.gz
gnunet-3f1b003aafd4426576369f229ca6740a77cd7504.zip
-indentation fixes, some fixes to message size checks, some code cleanup
Diffstat (limited to 'src/scalarproduct')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct.c651
-rw-r--r--src/scalarproduct/scalarproduct_api.c4
2 files changed, 389 insertions, 266 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c
index 170bf89a6..1b4cbd674 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct.c
@@ -170,17 +170,17 @@ struct SortedValue
170 /** 170 /**
171 * Sorted Values are kept in a DLL 171 * Sorted Values are kept in a DLL
172 */ 172 */
173 struct SortedValue * next; 173 struct SortedValue *next;
174 174
175 /** 175 /**
176 * Sorted Values are kept in a DLL 176 * Sorted Values are kept in a DLL
177 */ 177 */
178 struct SortedValue * prev; 178 struct SortedValue *prev;
179 179
180 /** 180 /**
181 * The element's id+integer-value 181 * The element's id+integer-value
182 */ 182 */
183 struct GNUNET_SCALARPRODUCT_Element * elem; 183 struct GNUNET_SCALARPRODUCT_Element *elem;
184 184
185 /** 185 /**
186 * the element's value converted to MPI 186 * the element's value converted to MPI
@@ -198,15 +198,6 @@ struct SortedValue
198 */ 198 */
199struct ServiceSession 199struct ServiceSession
200{ 200{
201 /**
202 * Is this session active (#GNUNET_YES), Concluded (#GNUNET_NO), or had an error (#GNUNET_SYSERR)
203 */
204 int32_t active;
205
206 /**
207 * the role this peer has
208 */
209 enum PeerRole role;
210 201
211 /** 202 /**
212 * session information is kept in a DLL 203 * session information is kept in a DLL
@@ -239,26 +230,11 @@ struct ServiceSession
239 struct GNUNET_MessageHeader *msg; 230 struct GNUNET_MessageHeader *msg;
240 231
241 /** 232 /**
242 * how many elements we were supplied with from the client
243 */
244 uint32_t total;
245
246 /**
247 * all non-0-value'd elements transmitted to us 233 * all non-0-value'd elements transmitted to us
248 */ 234 */
249 struct GNUNET_CONTAINER_MultiHashMap *intersected_elements; 235 struct GNUNET_CONTAINER_MultiHashMap *intersected_elements;
250 236
251 /** 237 /**
252 * how many elements actually are used for the scalar product
253 */
254 uint32_t used_element_count;
255
256 /**
257 * already transferred elements (sent/received) for multipart messages, less or equal than @e used_element_count for
258 */
259 uint32_t transferred_element_count;
260
261 /**
262 * Set of elements for which will conduction an intersection. 238 * Set of elements for which will conduction an intersection.
263 * the resulting elements are then used for computing the scalar product. 239 * the resulting elements are then used for computing the scalar product.
264 */ 240 */
@@ -278,7 +254,7 @@ struct ServiceSession
278 /** 254 /**
279 * Public key of the remote service, only used by Bob 255 * Public key of the remote service, only used by Bob
280 */ 256 */
281 struct GNUNET_CRYPTO_PaillierPublicKey *remote_pubkey; 257 struct GNUNET_CRYPTO_PaillierPublicKey remote_pubkey;
282 258
283 /** 259 /**
284 * DLL for sorting elements after intersection 260 * DLL for sorting elements after intersection
@@ -326,11 +302,6 @@ struct ServiceSession
326 struct ServiceSession *response; 302 struct ServiceSession *response;
327 303
328 /** 304 /**
329 * The computed scalar
330 */
331 gcry_mpi_t product;
332
333 /**
334 * My transmit handle for the current message to a Alice/Bob 305 * My transmit handle for the current message to a Alice/Bob
335 */ 306 */
336 struct GNUNET_CADET_TransmitHandle *service_transmit_handle; 307 struct GNUNET_CADET_TransmitHandle *service_transmit_handle;
@@ -349,31 +320,38 @@ struct ServiceSession
349 * Handle to a task that sends a msg to the our client 320 * Handle to a task that sends a msg to the our client
350 */ 321 */
351 GNUNET_SCHEDULER_TaskIdentifier client_notification_task; 322 GNUNET_SCHEDULER_TaskIdentifier client_notification_task;
352};
353 323
324 /**
325 * The computed scalar
326 */
327 gcry_mpi_t product;
354 328
355/** 329 /**
356 * Send a multi part chunk of a service request from alice to bob. 330 * how many elements we were supplied with from the client
357 * This element only contains a part of the elements-vector (session->a[]), 331 */
358 * mask and public key set have to be contained within the first message 332 uint32_t total;
359 * 333
360 * This allows a ~32kbit key length while using 32000 elements or 62000 elements per request. 334 /**
361 * 335 * how many elements actually are used for the scalar product
362 * @param cls the associated service session 336 */
363 */ 337 uint32_t used_element_count;
364static void
365prepare_alices_cyrptodata_message_multipart (void *cls);
366 338
339 /**
340 * already transferred elements (sent/received) for multipart messages, less or equal than @e used_element_count for
341 */
342 uint32_t transferred_element_count;
367 343
368/** 344 /**
369 * Send a multi part chunk of a service response from Bob to Alice. 345 * Is this session active (#GNUNET_YES), Concluded (#GNUNET_NO), or had an error (#GNUNET_SYSERR)
370 * This element only contains the two permutations of R, R'. 346 */
371 * 347 int32_t active;
372 * @param cls the associated service session
373 */
374static void
375prepare_bobs_cryptodata_message_multipart (void *cls);
376 348
349 /**
350 * the role this peer has
351 */
352 enum PeerRole role;
353
354};
377 355
378 356
379/** 357/**
@@ -441,6 +419,29 @@ static int do_shutdown;
441 419
442 420
443/** 421/**
422 * Send a multi part chunk of a service request from alice to bob.
423 * This element only contains a part of the elements-vector (session->a[]),
424 * mask and public key set have to be contained within the first message
425 *
426 * This allows a ~32kbit key length while using 32000 elements or 62000 elements per request.
427 *
428 * @param cls the associated service session
429 */
430static void
431prepare_alices_cyrptodata_message_multipart (void *cls);
432
433
434/**
435 * Send a multi part chunk of a service response from Bob to Alice.
436 * This element only contains the two permutations of R, R'.
437 *
438 * @param cls the associated service session
439 */
440static void
441prepare_bobs_cryptodata_message_multipart (void *cls);
442
443
444/**
444 * computes the square sum over a vector of a given length. 445 * computes the square sum over a vector of a given length.
445 * 446 *
446 * @param vector the vector to encrypt 447 * @param vector the vector to encrypt
@@ -491,11 +492,6 @@ free_session_variables (struct ServiceSession *s)
491 GNUNET_free (s->e_a); 492 GNUNET_free (s->e_a);
492 s->e_a = NULL; 493 s->e_a = NULL;
493 } 494 }
494 if (s->remote_pubkey)
495 {
496 GNUNET_free(s->remote_pubkey);
497 s->remote_pubkey=NULL;
498 }
499 if (s->sorted_elements) 495 if (s->sorted_elements)
500 { 496 {
501 GNUNET_free (s->sorted_elements); 497 GNUNET_free (s->sorted_elements);
@@ -675,7 +671,8 @@ cb_client_disconnect (void *cls,
675 if (NULL == client) 671 if (NULL == client)
676 return; 672 return;
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
678 _ ("Client %p disconnected from us.\n"), client); 674 "Client %p disconnected from us.\n",
675 client);
679 s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); 676 s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession);
680 if (NULL == s) 677 if (NULL == s)
681 return; 678 return;
@@ -778,13 +775,14 @@ prepare_alices_cyrptodata_message (void *cls)
778 gcry_mpi_t a; 775 gcry_mpi_t a;
779 776
780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
781 _ ("Successfully created new channel to peer (%s)!\n"), 778 "Successfully created new channel to peer (%s)!\n",
782 GNUNET_i2s (&s->peer)); 779 GNUNET_i2s (&s->peer));
783 780
784 msg_length = sizeof (struct AliceCryptodataMessage) 781 msg_length = sizeof (struct AliceCryptodataMessage)
785 +s->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 782 + s->used_element_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
786 783
787 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > msg_length) { 784 if (GNUNET_SERVER_MAX_MESSAGE_SIZE > msg_length)
785 {
788 s->transferred_element_count = s->used_element_count; 786 s->transferred_element_count = s->used_element_count;
789 } 787 }
790 else 788 else
@@ -814,8 +812,8 @@ prepare_alices_cyrptodata_message (void *cls)
814 gcry_mpi_release (a); 812 gcry_mpi_release (a);
815 813
816 s->msg = (struct GNUNET_MessageHeader *) msg; 814 s->msg = (struct GNUNET_MessageHeader *) msg;
817 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
818 _("Transmitting service request.\n")); 816 "Transmitting service request.\n");
819 817
820 //transmit via cadet messaging 818 //transmit via cadet messaging
821 s->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (s->channel, 819 s->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (s->channel,
@@ -873,8 +871,12 @@ prepare_bobs_cryptodata_message_multipart (void *cls)
873 for (i = s->transferred_element_count, j = 0; i < s->transferred_element_count + todo_count; i++) 871 for (i = s->transferred_element_count, j = 0; i < s->transferred_element_count + todo_count; i++)
874 { 872 {
875 //r[i][p] and r[i][q] 873 //r[i][p] and r[i][q]
876 memcpy (&payload[j++], &s->r[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 874 memcpy (&payload[j++],
877 memcpy (&payload[j++], &s->r_prime[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 875 &s->r[i],
876 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
877 memcpy (&payload[j++],
878 &s->r_prime[i],
879 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
878 } 880 }
879 s->transferred_element_count += todo_count; 881 s->transferred_element_count += todo_count;
880 s->msg = (struct GNUNET_MessageHeader *) msg; 882 s->msg = (struct GNUNET_MessageHeader *) msg;
@@ -895,11 +897,13 @@ prepare_bobs_cryptodata_message_multipart (void *cls)
895 GNUNET_CADET_channel_destroy(s->channel); 897 GNUNET_CADET_channel_destroy(s->channel);
896 s->response->active = GNUNET_SYSERR; 898 s->response->active = GNUNET_SYSERR;
897 899
898 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 900 GNUNET_CONTAINER_DLL_remove (from_service_head,
901 from_service_tail,
902 s);
899 903
900 s->response->client_notification_task = 904 s->response->client_notification_task
901 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 905 = GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
902 s->response); 906 s->response);
903 free_session_variables(s); 907 free_session_variables(s);
904 GNUNET_free(s); 908 GNUNET_free(s);
905 return; 909 return;
@@ -933,7 +937,7 @@ prepare_bobs_cryptodata_message (void *cls,
933 * tc) 937 * tc)
934{ 938{
935 struct ServiceSession * s = cls; 939 struct ServiceSession * s = cls;
936 struct ServiceResponseMessage * msg; 940 struct ServiceResponseMessage *msg;
937 uint32_t msg_length = 0; 941 uint32_t msg_length = 0;
938 struct GNUNET_CRYPTO_PaillierCiphertext * payload; 942 struct GNUNET_CRYPTO_PaillierCiphertext * payload;
939 int i; 943 int i;
@@ -972,18 +976,22 @@ prepare_bobs_cryptodata_message (void *cls,
972 for (i = 0; i < s->transferred_element_count; i++) 976 for (i = 0; i < s->transferred_element_count; i++)
973 { 977 {
974 //k[i][p] and k[i][q] 978 //k[i][p] and k[i][q]
975 memcpy (&payload[i * 2], &s->r[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 979 memcpy (&payload[i * 2],
976 memcpy (&payload[i * 2 + 1], &s->r_prime[i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 980 &s->r[i],
981 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
982 memcpy (&payload[i * 2 + 1],
983 &s->r_prime[i],
984 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
977 } 985 }
978 986
979 s->msg = (struct GNUNET_MessageHeader *) msg; 987 s->msg = (struct GNUNET_MessageHeader *) msg;
980 s->service_transmit_handle = 988 s->service_transmit_handle
981 GNUNET_CADET_notify_transmit_ready (s->channel, 989 = GNUNET_CADET_notify_transmit_ready (s->channel,
982 GNUNET_YES, 990 GNUNET_YES,
983 GNUNET_TIME_UNIT_FOREVER_REL, 991 GNUNET_TIME_UNIT_FOREVER_REL,
984 msg_length, 992 msg_length,
985 &cb_transfer_message, 993 &cb_transfer_message,
986 s); 994 s);
987 if (NULL == s->service_transmit_handle) 995 if (NULL == s->service_transmit_handle)
988 { 996 {
989 //disconnect our client 997 //disconnect our client
@@ -992,7 +1000,9 @@ prepare_bobs_cryptodata_message (void *cls,
992 1000
993 GNUNET_free (msg); 1001 GNUNET_free (msg);
994 s->msg = NULL; 1002 s->msg = NULL;
995 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 1003 GNUNET_CONTAINER_DLL_remove (from_service_head,
1004 from_service_tail,
1005 s);
996 GNUNET_CADET_channel_destroy(s->channel); 1006 GNUNET_CADET_channel_destroy(s->channel);
997 s->response->active = GNUNET_SYSERR; 1007 s->response->active = GNUNET_SYSERR;
998 1008
@@ -1062,7 +1072,8 @@ compute_service_response (struct ServiceSession *session)
1062 { 1072 {
1063 int32_t svalue; 1073 int32_t svalue;
1064 1074
1065 svalue = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 1075 svalue = (int32_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1076 UINT32_MAX);
1066 1077
1067 // long to gcry_mpi_t 1078 // long to gcry_mpi_t
1068 if (svalue < 0) 1079 if (svalue < 0)
@@ -1079,17 +1090,18 @@ compute_service_response (struct ServiceSession *session)
1079 // vectors, which get rid of all the lookups in p/q. 1090 // vectors, which get rid of all the lookups in p/q.
1080 // however, ap/aq are not absolutely necessary but are just abstraction 1091 // however, ap/aq are not absolutely necessary but are just abstraction
1081 // Calculate Kp = E(S + a_pi) (+) E(S - r_pi - b_pi) 1092 // Calculate Kp = E(S + a_pi) (+) E(S - r_pi - b_pi)
1082 for (i = 0; i < count; i++) { 1093 for (i = 0; i < count; i++)
1094 {
1083 // E(S - r_pi - b_pi) 1095 // E(S - r_pi - b_pi)
1084 gcry_mpi_sub (tmp, my_offset, rand[p[i]]); 1096 gcry_mpi_sub (tmp, my_offset, rand[p[i]]);
1085 gcry_mpi_sub (tmp, tmp, b[p[i]]); 1097 gcry_mpi_sub (tmp, tmp, b[p[i]]);
1086 GNUNET_CRYPTO_paillier_encrypt (session->remote_pubkey, 1098 GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
1087 tmp, 1099 tmp,
1088 2, 1100 2,
1089 &r[i]); 1101 &r[i]);
1090 1102
1091 // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b) 1103 // E(S - r_pi - b_pi) * E(S + a_pi) == E(2*S + a - r - b)
1092 GNUNET_CRYPTO_paillier_hom_add (session->remote_pubkey, 1104 GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey,
1093 &r[i], 1105 &r[i],
1094 &a[p[i]], 1106 &a[p[i]],
1095 &r[i]); 1107 &r[i]);
@@ -1099,13 +1111,13 @@ compute_service_response (struct ServiceSession *session)
1099 for (i = 0; i < count; i++) { 1111 for (i = 0; i < count; i++) {
1100 // E(S - r_qi) 1112 // E(S - r_qi)
1101 gcry_mpi_sub (tmp, my_offset, rand[q[i]]); 1113 gcry_mpi_sub (tmp, my_offset, rand[q[i]]);
1102 GNUNET_assert (2 == GNUNET_CRYPTO_paillier_encrypt (session->remote_pubkey, 1114 GNUNET_assert (2 == GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
1103 tmp, 1115 tmp,
1104 2, 1116 2,
1105 &r_prime[i])); 1117 &r_prime[i]));
1106 1118
1107 // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi) 1119 // E(S - r_qi) * E(S + a_qi) == E(2*S + a_qi - r_qi)
1108 GNUNET_assert (1 == GNUNET_CRYPTO_paillier_hom_add (session->remote_pubkey, 1120 GNUNET_assert (1 == GNUNET_CRYPTO_paillier_hom_add (&session->remote_pubkey,
1109 &r_prime[i], 1121 &r_prime[i],
1110 &a[q[i]], 1122 &a[q[i]],
1111 &r_prime[i])); 1123 &r_prime[i]));
@@ -1113,7 +1125,7 @@ compute_service_response (struct ServiceSession *session)
1113 1125
1114 // Calculate S' = E(SUM( r_i^2 )) 1126 // Calculate S' = E(SUM( r_i^2 ))
1115 tmp = compute_square_sum (rand, count); 1127 tmp = compute_square_sum (rand, count);
1116 GNUNET_CRYPTO_paillier_encrypt (session->remote_pubkey, 1128 GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
1117 tmp, 1129 tmp,
1118 1, 1130 1,
1119 s_prime); 1131 s_prime);
@@ -1122,7 +1134,7 @@ compute_service_response (struct ServiceSession *session)
1122 for (i = 0; i < count; i++) 1134 for (i = 0; i < count; i++)
1123 gcry_mpi_add (rand[i], rand[i], b[i]); 1135 gcry_mpi_add (rand[i], rand[i], b[i]);
1124 tmp = compute_square_sum (rand, count); 1136 tmp = compute_square_sum (rand, count);
1125 GNUNET_CRYPTO_paillier_encrypt (session->remote_pubkey, 1137 GNUNET_CRYPTO_paillier_encrypt (&session->remote_pubkey,
1126 tmp, 1138 tmp,
1127 1, 1139 1,
1128 s); 1140 s);
@@ -1161,12 +1173,12 @@ compute_service_response (struct ServiceSession *session)
1161 * iterate, 1173 * iterate,
1162 * #GNUNET_NO if not. 1174 * #GNUNET_NO if not.
1163 */ 1175 */
1164int 1176static int
1165cb_insert_element_sorted (void *cls, 1177cb_insert_element_sorted (void *cls,
1166 const struct GNUNET_HashCode *key, 1178 const struct GNUNET_HashCode *key,
1167 void *value) 1179 void *value)
1168{ 1180{
1169 struct ServiceSession * s = (struct ServiceSession*) cls; 1181 struct ServiceSession * s = cls;
1170 struct SortedValue * e = GNUNET_new (struct SortedValue); 1182 struct SortedValue * e = GNUNET_new (struct SortedValue);
1171 struct SortedValue * o = s->a_head; 1183 struct SortedValue * o = s->a_head;
1172 int64_t val; 1184 int64_t val;
@@ -1181,23 +1193,33 @@ cb_insert_element_sorted (void *cls,
1181 1193
1182 // insert as first element with the lowest key 1194 // insert as first element with the lowest key
1183 if (NULL == s->a_head 1195 if (NULL == s->a_head
1184 || (0 <= GNUNET_CRYPTO_hash_cmp (&s->a_head->elem->key, &e->elem->key))) 1196 || (0 <= GNUNET_CRYPTO_hash_cmp (&s->a_head->elem->key,
1197 &e->elem->key)))
1185 { 1198 {
1186 GNUNET_CONTAINER_DLL_insert (s->a_head, s->a_tail, e); 1199 GNUNET_CONTAINER_DLL_insert (s->a_head,
1200 s->a_tail,
1201 e);
1187 return GNUNET_YES; 1202 return GNUNET_YES;
1188 } 1203 }
1189 else if (0 > GNUNET_CRYPTO_hash_cmp (&s->a_tail->elem->key, &e->elem->key)) 1204 else if (0 > GNUNET_CRYPTO_hash_cmp (&s->a_tail->elem->key,
1205 &e->elem->key))
1190 { 1206 {
1191 // insert as last element with the highest key 1207 // insert as last element with the highest key
1192 GNUNET_CONTAINER_DLL_insert_tail (s->a_head, s->a_tail, e); 1208 GNUNET_CONTAINER_DLL_insert_tail (s->a_head,
1209 s->a_tail,
1210 e);
1193 return GNUNET_YES; 1211 return GNUNET_YES;
1194 } 1212 }
1195 // insert before the first higher/equal element 1213 // insert before the first higher/equal element
1196 do 1214 do
1197 { 1215 {
1198 if (0 <= GNUNET_CRYPTO_hash_cmp (&o->elem->key, &e->elem->key)) 1216 if (0 <= GNUNET_CRYPTO_hash_cmp (&o->elem->key,
1217 &e->elem->key))
1199 { 1218 {
1200 GNUNET_CONTAINER_DLL_insert_before (s->a_head, s->a_tail, o, e); 1219 GNUNET_CONTAINER_DLL_insert_before (s->a_head,
1220 s->a_tail,
1221 o,
1222 e);
1201 return GNUNET_YES; 1223 return GNUNET_YES;
1202 } 1224 }
1203 o = o->next; 1225 o = o->next;
@@ -1235,17 +1257,25 @@ cb_intersection_element_removed (void *cls,
1235 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, 1257 GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
1236 element->data, 1258 element->data,
1237 se); 1259 se);
1238 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: removed element with key %s value %d\n", s->role == ALICE ? "ALICE" : "BOB", GNUNET_h2s(&se->key), se->value); 1260 LOG (GNUNET_ERROR_TYPE_DEBUG,
1261 "%s: removed element with key %s value %d\n",
1262 s->role == ALICE ? "ALICE" : "BOB",
1263 GNUNET_h2s(&se->key),
1264 se->value);
1239 return; 1265 return;
1240 1266
1241 case GNUNET_SET_STATUS_DONE: 1267 case GNUNET_SET_STATUS_DONE:
1242 s->intersection_op = NULL; 1268 s->intersection_op = NULL;
1243 s->intersection_set = NULL; 1269 s->intersection_set = NULL;
1244 1270
1245 s->used_element_count = GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, 1271 s->used_element_count
1246 &cb_insert_element_sorted, 1272 = GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
1247 s); 1273 &cb_insert_element_sorted,
1248 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: Finished intersection, %d items remain\n", s->role == ALICE ? "ALICE" : "BOB", s->used_element_count); 1274 s);
1275 LOG (GNUNET_ERROR_TYPE_DEBUG,
1276 "%s: Finished intersection, %d items remain\n",
1277 s->role == ALICE ? "ALICE" : "BOB",
1278 s->used_element_count);
1249 if (2 > s->used_element_count) 1279 if (2 > s->used_element_count)
1250 { 1280 {
1251 // failed! do not leak information about our single remaining element! 1281 // failed! do not leak information about our single remaining element!
@@ -1414,7 +1444,9 @@ prepare_client_response (void *cls,
1414 &product_length, 1444 &product_length,
1415 value)))) 1445 value))))
1416 { 1446 {
1417 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); 1447 LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
1448 "gcry_mpi_scan",
1449 rc);
1418 product_length = 0; 1450 product_length = 0;
1419 range = -1; // signal error with product-length = 0 and range = -1 1451 range = -1; // signal error with product-length = 0 and range = -1
1420 } 1452 }
@@ -1423,9 +1455,11 @@ prepare_client_response (void *cls,
1423 1455
1424 msg_length = sizeof (struct ClientResponseMessage) + product_length; 1456 msg_length = sizeof (struct ClientResponseMessage) + product_length;
1425 msg = GNUNET_malloc (msg_length); 1457 msg = GNUNET_malloc (msg_length);
1426 if (product_exported != NULL) 1458 if (NULL != product_exported)
1427 { 1459 {
1428 memcpy (&msg[1], product_exported, product_length); 1460 memcpy (&msg[1],
1461 product_exported,
1462 product_length);
1429 GNUNET_free (product_exported); 1463 GNUNET_free (product_exported);
1430 } 1464 }
1431 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); 1465 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
@@ -1440,8 +1474,8 @@ prepare_client_response (void *cls,
1440 &cb_transfer_message, 1474 &cb_transfer_message,
1441 s); 1475 s);
1442 GNUNET_break (NULL != s->client_transmit_handle); 1476 GNUNET_break (NULL != s->client_transmit_handle);
1443 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1444 _ ("Sent result to client (%p), this session (%s) has ended!\n"), 1478 "Sent result to client (%p), this session (%s) has ended!\n",
1445 s->client, 1479 s->client,
1446 GNUNET_h2s (&s->session_id)); 1480 GNUNET_h2s (&s->session_id));
1447} 1481}
@@ -1477,7 +1511,7 @@ prepare_alices_computation_request (struct ServiceSession * s)
1477 sizeof (struct ServiceRequestMessage), 1511 sizeof (struct ServiceRequestMessage),
1478 &cb_transfer_message, 1512 &cb_transfer_message,
1479 s); 1513 s);
1480 if (!s->service_transmit_handle) 1514 if (! s->service_transmit_handle)
1481 { 1515 {
1482 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1516 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1483 _("Could not send message to channel!\n")); 1517 _("Could not send message to channel!\n"));
@@ -1538,14 +1572,17 @@ prepare_alices_cyrptodata_message_multipart (void *cls)
1538 s->transferred_element_count += todo_count; 1572 s->transferred_element_count += todo_count;
1539 1573
1540 s->msg = (struct GNUNET_MessageHeader *) msg; 1574 s->msg = (struct GNUNET_MessageHeader *) msg;
1541 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Transmitting service request.\n")); 1575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1576 "Transmitting service request.\n");
1542 1577
1543 //transmit via cadet messaging 1578 //transmit via cadet messaging
1544 s->service_transmit_handle = GNUNET_CADET_notify_transmit_ready (s->channel, GNUNET_YES, 1579 s->service_transmit_handle
1545 GNUNET_TIME_UNIT_FOREVER_REL, 1580 = GNUNET_CADET_notify_transmit_ready (s->channel,
1546 msg_length, 1581 GNUNET_YES,
1547 &cb_transfer_message, 1582 GNUNET_TIME_UNIT_FOREVER_REL,
1548 s); 1583 msg_length,
1584 &cb_transfer_message,
1585 s);
1549 if (!s->service_transmit_handle) 1586 if (!s->service_transmit_handle)
1550 { 1587 {
1551 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1588 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1553,9 +1590,9 @@ prepare_alices_cyrptodata_message_multipart (void *cls)
1553 GNUNET_free (msg); 1590 GNUNET_free (msg);
1554 s->msg = NULL; 1591 s->msg = NULL;
1555 s->active = GNUNET_SYSERR; 1592 s->active = GNUNET_SYSERR;
1556 s->client_notification_task = 1593 s->client_notification_task
1557 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 1594 = GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
1558 s); 1595 s);
1559 return; 1596 return;
1560 } 1597 }
1561} 1598}
@@ -1573,12 +1610,12 @@ client_request_complete_bob (struct ServiceSession * client_session)
1573 1610
1574 //check if service queue contains a matching request 1611 //check if service queue contains a matching request
1575 s = find_matching_session (from_service_tail, 1612 s = find_matching_session (from_service_tail,
1576 &client_session->session_id, 1613 &client_session->session_id,
1577 NULL); 1614 NULL);
1578 if (NULL != s) 1615 if (NULL != s)
1579 { 1616 {
1580 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1581 _ ("Got client-responder-session with key %s and a matching service-request-session set, processing.\n"), 1618 "Got client-responder-session with key %s and a matching service-request-session set, processing.\n",
1582 GNUNET_h2s (&client_session->session_id)); 1619 GNUNET_h2s (&client_session->session_id));
1583 1620
1584 s->response = client_session; 1621 s->response = client_session;
@@ -1598,8 +1635,8 @@ client_request_complete_bob (struct ServiceSession * client_session)
1598 } 1635 }
1599 else 1636 else
1600 { 1637 {
1601 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1602 _ ("Got client-responder-session with key %s but NO matching service-request-session set, queuing element for later use.\n"), 1639 "Got client-responder-session with key %s but NO matching service-request-session set, queuing element for later use.\n",
1603 GNUNET_h2s (&client_session->session_id)); 1640 GNUNET_h2s (&client_session->session_id));
1604 // no matching session exists yet, store the response 1641 // no matching session exists yet, store the response
1605 // for later processing by handle_service_request() 1642 // for later processing by handle_service_request()
@@ -1652,15 +1689,17 @@ handle_client_message_multipart (void *cls,
1652 struct GNUNET_SERVER_Client *client, 1689 struct GNUNET_SERVER_Client *client,
1653 const struct GNUNET_MessageHeader *message) 1690 const struct GNUNET_MessageHeader *message)
1654{ 1691{
1655 const struct ComputationMultipartMessage * msg = (const struct ComputationMultipartMessage *) message; 1692 const struct ComputationMultipartMessage * msg;
1656 struct ServiceSession *s; 1693 struct ServiceSession *s;
1657 uint32_t contained_count; 1694 uint32_t contained_count;
1658 struct GNUNET_SCALARPRODUCT_Element *elements; 1695 struct GNUNET_SCALARPRODUCT_Element *elements;
1659 uint32_t i; 1696 uint32_t i;
1660 1697
1698 msg = (const struct ComputationMultipartMessage *) message;
1661 // only one concurrent session per client connection allowed, simplifies logics a lot... 1699 // only one concurrent session per client connection allowed, simplifies logics a lot...
1662 s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); 1700 s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession);
1663 if (NULL == s) { 1701 if (NULL == s)
1702 {
1664 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1703 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1665 return; 1704 return;
1666 } 1705 }
@@ -1668,8 +1707,9 @@ handle_client_message_multipart (void *cls,
1668 contained_count = ntohl (msg->element_count_contained); 1707 contained_count = ntohl (msg->element_count_contained);
1669 1708
1670 //sanity check: is the message as long as the message_count fields suggests? 1709 //sanity check: is the message as long as the message_count fields suggests?
1671 if ((ntohs (msg->header.size) != (sizeof (struct ComputationMultipartMessage) +contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) 1710 if ( (ntohs (msg->header.size) != (sizeof (struct ComputationMultipartMessage) + contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
1672 || (0 == contained_count) || (s->total < s->transferred_element_count + contained_count)) 1711 (0 == contained_count) ||
1712 (s->total < s->transferred_element_count + contained_count))
1673 { 1713 {
1674 GNUNET_break_op (0); 1714 GNUNET_break_op (0);
1675 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1715 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -1753,7 +1793,8 @@ handle_client_message (void *cls,
1753 contained_count = ntohl (msg->element_count_contained); 1793 contained_count = ntohl (msg->element_count_contained);
1754 1794
1755 if ((GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) 1795 if ((GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type)
1756 && (!memcmp (&msg->peer, &me, sizeof (struct GNUNET_PeerIdentity)))) { 1796 && (!memcmp (&msg->peer, &me, sizeof (struct GNUNET_PeerIdentity))))
1797 {
1757 //session with ourself makes no sense! 1798 //session with ourself makes no sense!
1758 GNUNET_break_op (0); 1799 GNUNET_break_op (0);
1759 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1800 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -1773,7 +1814,8 @@ handle_client_message (void *cls,
1773 // do we have a duplicate session here already? 1814 // do we have a duplicate session here already?
1774 if (NULL != find_matching_session (from_client_tail, 1815 if (NULL != find_matching_session (from_client_tail,
1775 &msg->session_key, 1816 &msg->session_key,
1776 NULL)) { 1817 NULL))
1818 {
1777 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1819 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1778 _ ("Duplicate session information received, can not create new session with key `%s'\n"), 1820 _ ("Duplicate session information received, can not create new session with key `%s'\n"),
1779 GNUNET_h2s (&msg->session_key)); 1821 GNUNET_h2s (&msg->session_key));
@@ -1793,7 +1835,8 @@ handle_client_message (void *cls,
1793 elements = (struct GNUNET_SCALARPRODUCT_Element *) & msg[1]; 1835 elements = (struct GNUNET_SCALARPRODUCT_Element *) & msg[1];
1794 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_NO); 1836 s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_NO);
1795 s->intersection_set = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); 1837 s->intersection_set = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
1796 for (i = 0; i < contained_count; i++) { 1838 for (i = 0; i < contained_count; i++)
1839 {
1797 struct GNUNET_SET_Element set_elem; 1840 struct GNUNET_SET_Element set_elem;
1798 struct GNUNET_SCALARPRODUCT_Element * elem; 1841 struct GNUNET_SCALARPRODUCT_Element * elem;
1799 1842
@@ -1803,10 +1846,12 @@ handle_client_message (void *cls,
1803 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); 1846 elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
1804 memcpy (elem, &elements[i], sizeof (struct GNUNET_SCALARPRODUCT_Element)); 1847 memcpy (elem, &elements[i], sizeof (struct GNUNET_SCALARPRODUCT_Element));
1805 1848
1806 if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (s->intersected_elements, 1849 if (GNUNET_SYSERR ==
1807 &elem->key, 1850 GNUNET_CONTAINER_multihashmap_put (s->intersected_elements,
1808 elem, 1851 &elem->key,
1809 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) { 1852 elem,
1853 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
1854 {
1810 GNUNET_free (elem); 1855 GNUNET_free (elem);
1811 continue; 1856 continue;
1812 } 1857 }
@@ -1817,15 +1862,21 @@ handle_client_message (void *cls,
1817 s->used_element_count++; 1862 s->used_element_count++;
1818 } 1863 }
1819 1864
1820 if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type) { 1865 if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE == msg_type)
1866 {
1821 s->role = ALICE; 1867 s->role = ALICE;
1822 memcpy (&s->peer, &msg->peer, sizeof (struct GNUNET_PeerIdentity)); 1868 memcpy (&s->peer,
1869 &msg->peer,
1870 sizeof (struct GNUNET_PeerIdentity));
1823 } 1871 }
1824 else { 1872 else
1873 {
1825 s->role = BOB; 1874 s->role = BOB;
1826 } 1875 }
1827 1876
1828 GNUNET_CONTAINER_DLL_insert (from_client_head, from_client_tail, s); 1877 GNUNET_CONTAINER_DLL_insert (from_client_head,
1878 from_client_tail,
1879 s);
1829 GNUNET_SERVER_client_set_user_context (client, s); 1880 GNUNET_SERVER_client_set_user_context (client, s);
1830 GNUNET_SERVER_receive_done (client, GNUNET_YES); 1881 GNUNET_SERVER_receive_done (client, GNUNET_YES);
1831 1882
@@ -1852,16 +1903,17 @@ handle_client_message (void *cls,
1852 */ 1903 */
1853static void * 1904static void *
1854cb_channel_incoming (void *cls, 1905cb_channel_incoming (void *cls,
1855 struct GNUNET_CADET_Channel *channel, 1906 struct GNUNET_CADET_Channel *channel,
1856 const struct GNUNET_PeerIdentity *initiator, 1907 const struct GNUNET_PeerIdentity *initiator,
1857 uint32_t port, 1908 uint32_t port,
1858 enum GNUNET_CADET_ChannelOption options) 1909 enum GNUNET_CADET_ChannelOption options)
1859{ 1910{
1860 struct ServiceSession *s = GNUNET_new (struct ServiceSession); 1911 struct ServiceSession *s;
1861 1912
1862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1863 _ ("New incoming channel from peer %s.\n"), 1914 _ ("New incoming channel from peer %s.\n"),
1864 GNUNET_i2s (initiator)); 1915 GNUNET_i2s (initiator));
1916 s = GNUNET_new (struct ServiceSession);
1865 s->peer = *initiator; 1917 s->peer = *initiator;
1866 s->channel = channel; 1918 s->channel = channel;
1867 s->role = BOB; 1919 s->role = BOB;
@@ -1874,9 +1926,9 @@ cb_channel_incoming (void *cls,
1874 * Function called whenever a channel is destroyed. Should clean up 1926 * Function called whenever a channel is destroyed. Should clean up
1875 * any associated state. 1927 * any associated state.
1876 * 1928 *
1877 * It must NOT call GNUNET_CADET_channel_destroy on the channel. 1929 * It must NOT call #GNUNET_CADET_channel_destroy() on the channel.
1878 * 1930 *
1879 * @param cls closure (set from GNUNET_CADET_connect) 1931 * @param cls closure (set from #GNUNET_CADET_connect())
1880 * @param channel connection to the other end (henceforth invalid) 1932 * @param channel connection to the other end (henceforth invalid)
1881 * @param channel_ctx place where local state associated 1933 * @param channel_ctx place where local state associated
1882 * with the channel is stored 1934 * with the channel is stored
@@ -1890,14 +1942,16 @@ cb_channel_destruction (void *cls,
1890 struct ServiceSession * client_session; 1942 struct ServiceSession * client_session;
1891 1943
1892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1944 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1893 _ ("Peer disconnected, terminating session %s with peer (%s)\n"), 1945 "Peer disconnected, terminating session %s with peer (%s)\n",
1894 GNUNET_h2s (&s->session_id), 1946 GNUNET_h2s (&s->session_id),
1895 GNUNET_i2s (&s->peer)); 1947 GNUNET_i2s (&s->peer));
1896 1948
1897 // as we have only one peer connected in each session, just remove the session 1949 // as we have only one peer connected in each session, just remove the session
1898 s->channel = NULL; 1950 s->channel = NULL;
1899 1951
1900 if ((ALICE == s->role) && (GNUNET_YES == s->active) && (!do_shutdown)) 1952 if ( (ALICE == s->role) &&
1953 (GNUNET_YES == s->active) &&
1954 (! do_shutdown) )
1901 { 1955 {
1902 // if this happened before we received the answer, we must terminate the session 1956 // if this happened before we received the answer, we must terminate the session
1903 s->role = GNUNET_SYSERR; 1957 s->role = GNUNET_SYSERR;
@@ -1907,23 +1961,30 @@ cb_channel_destruction (void *cls,
1907 } 1961 }
1908 else if ((BOB == s->role) && (GNUNET_SYSERR != s->active)) 1962 else if ((BOB == s->role) && (GNUNET_SYSERR != s->active))
1909 { 1963 {
1910 if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) 1964 if ( (s == from_service_head) ||
1911 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 1965 ( (NULL != from_service_head) &&
1966 ( (NULL != s->next) ||
1967 (NULL != s->a_tail)) ) )
1968 GNUNET_CONTAINER_DLL_remove (from_service_head,
1969 from_service_tail,
1970 s);
1912 1971
1913 // there is a client waiting for this service session, terminate it, too! 1972 // there is a client waiting for this service session, terminate it, too!
1914 // i assume the tupel of key and element count is unique. if it was not the rest of the code would not work either. 1973 // i assume the tupel of key and element count is unique. if it was not the rest of the code would not work either.
1915 client_session = s->response; 1974 client_session = s->response;
1916 if ((NULL != s->response ) && (GNUNET_NO == s->active) && (GNUNET_YES == client_session->active)) 1975 if ( (NULL != s->response ) &&
1976 (GNUNET_NO == s->active) &&
1977 (GNUNET_YES == client_session->active) )
1917 client_session->active = GNUNET_NO; 1978 client_session->active = GNUNET_NO;
1918 free_session_variables (s); 1979 free_session_variables (s);
1919 1980
1920 // the client has to check if it was waiting for a result 1981 // the client has to check if it was waiting for a result
1921 // or if it was a responder, no point in adding more statefulness 1982 // or if it was a responder, no point in adding more statefulness
1922 if ((NULL != s->response ) && (!do_shutdown)) 1983 if ((NULL != s->response ) && (! do_shutdown))
1923 { 1984 {
1924 client_session->client_notification_task = 1985 client_session->client_notification_task
1925 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 1986 = GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
1926 client_session); 1987 client_session);
1927 } 1988 }
1928 GNUNET_free (s); 1989 GNUNET_free (s);
1929 } 1990 }
@@ -1958,12 +2019,16 @@ compute_scalar_product (struct ServiceSession *session)
1958 // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi) 2019 // the result is E((S + a_pi) + (S -b_pi-r_pi)) and E(S + a_qi + S - r_qi)
1959 for (i = 0; i < count; i++) 2020 for (i = 0; i < count; i++)
1960 { 2021 {
1961 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, 2022 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
1962 &session->r[i], r[i]); 2023 &my_pubkey,
2024 &session->r[i],
2025 r[i]);
1963 gcry_mpi_sub (r[i], r[i], my_offset); 2026 gcry_mpi_sub (r[i], r[i], my_offset);
1964 gcry_mpi_sub (r[i], r[i], my_offset); 2027 gcry_mpi_sub (r[i], r[i], my_offset);
1965 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, 2028 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
1966 &session->r_prime[i], r_prime[i]); 2029 &my_pubkey,
2030 &session->r_prime[i],
2031 r_prime[i]);
1967 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset); 2032 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset);
1968 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset); 2033 gcry_mpi_sub (r_prime[i], r_prime[i], my_offset);
1969 } 2034 }
@@ -1988,9 +2053,11 @@ compute_scalar_product (struct ServiceSession *session)
1988 GNUNET_assert (s_prime = gcry_mpi_new (0)); 2053 GNUNET_assert (s_prime = gcry_mpi_new (0));
1989 2054
1990 // compute P 2055 // compute P
1991 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, 2056 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
2057 &my_pubkey,
1992 session->s, s); 2058 session->s, s);
1993 GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, 2059 GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
2060 &my_pubkey,
1994 session->s_prime, s_prime); 2061 session->s_prime, s_prime);
1995 2062
1996 // compute P 2063 // compute P
@@ -2040,16 +2107,16 @@ compute_scalar_product (struct ServiceSession *session)
2040 * 2107 *
2041 * @param cls closure (set from #GNUNET_CADET_connect) 2108 * @param cls closure (set from #GNUNET_CADET_connect)
2042 * @param channel connection to the other end 2109 * @param channel connection to the other end
2043 * @param channel_ctx place to store local state associated with the channel 2110 * @param channel_ctx place to store local state associated with the @a channel
2044 * @param message the actual message 2111 * @param message the actual message
2045 * @return #GNUNET_OK to keep the connection open, 2112 * @return #GNUNET_OK to keep the connection open,
2046 * #GNUNET_SYSERR to close it (signal serious error) 2113 * #GNUNET_SYSERR to close it (signal serious error)
2047 */ 2114 */
2048static int 2115static int
2049handle_alices_cyrptodata_message_multipart (void *cls, 2116handle_alices_cyrptodata_message_multipart (void *cls,
2050 struct GNUNET_CADET_Channel * channel, 2117 struct GNUNET_CADET_Channel *channel,
2051 void **channel_ctx, 2118 void **channel_ctx,
2052 const struct GNUNET_MessageHeader * message) 2119 const struct GNUNET_MessageHeader *message)
2053{ 2120{
2054 struct ServiceSession * s; 2121 struct ServiceSession * s;
2055 const struct MultipartMessage * msg = (const struct MultipartMessage *) message; 2122 const struct MultipartMessage * msg = (const struct MultipartMessage *) message;
@@ -2117,8 +2184,13 @@ except:
2117 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 2184 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
2118 s->response); 2185 s->response);
2119 } 2186 }
2120 if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) 2187 if ( (s == from_service_head) ||
2121 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 2188 ( (NULL != from_service_head) &&
2189 ( (NULL != s->next) ||
2190 (NULL != s->a_tail)) ) )
2191 GNUNET_CONTAINER_DLL_remove (from_service_head,
2192 from_service_tail,
2193 s);
2122 GNUNET_free (s); 2194 GNUNET_free (s);
2123 } 2195 }
2124 return GNUNET_SYSERR; 2196 return GNUNET_SYSERR;
@@ -2137,12 +2209,12 @@ except:
2137 */ 2209 */
2138static int 2210static int
2139handle_alices_cyrptodata_message (void *cls, 2211handle_alices_cyrptodata_message (void *cls,
2140 struct GNUNET_CADET_Channel * channel, 2212 struct GNUNET_CADET_Channel *channel,
2141 void **channel_ctx, 2213 void **channel_ctx,
2142 const struct GNUNET_MessageHeader * message) 2214 const struct GNUNET_MessageHeader *message)
2143{ 2215{
2144 struct ServiceSession * s; 2216 struct ServiceSession * s;
2145 const struct AliceCryptodataMessage * msg = (const struct AliceCryptodataMessage *) message; 2217 const struct AliceCryptodataMessage *msg;
2146 struct GNUNET_CRYPTO_PaillierCiphertext *payload; 2218 struct GNUNET_CRYPTO_PaillierCiphertext *payload;
2147 uint32_t contained_elements = 0; 2219 uint32_t contained_elements = 0;
2148 uint32_t msg_length; 2220 uint32_t msg_length;
@@ -2162,11 +2234,12 @@ handle_alices_cyrptodata_message (void *cls,
2162 goto invalid_msg; 2234 goto invalid_msg;
2163 } 2235 }
2164 2236
2165 // shorter than minimum? 2237 if (ntohs (message->size) < sizeof (struct AliceCryptodataMessage))
2166 if (ntohs (msg->header.size) <= sizeof (struct MultipartMessage))
2167 { 2238 {
2239 GNUNET_break_op (0);
2168 goto invalid_msg; 2240 goto invalid_msg;
2169 } 2241 }
2242 msg = (const struct AliceCryptodataMessage *) message;
2170 2243
2171 contained_elements = ntohl (msg->contained_element_count); 2244 contained_elements = ntohl (msg->contained_element_count);
2172 msg_length = sizeof (struct AliceCryptodataMessage) 2245 msg_length = sizeof (struct AliceCryptodataMessage)
@@ -2184,7 +2257,9 @@ handle_alices_cyrptodata_message (void *cls,
2184 payload = (struct GNUNET_CRYPTO_PaillierCiphertext*) &msg[1]; 2257 payload = (struct GNUNET_CRYPTO_PaillierCiphertext*) &msg[1];
2185 2258
2186 s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count); 2259 s->e_a = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count);
2187 memcpy (&s->e_a[0], payload, contained_elements * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2260 memcpy (&s->e_a[0],
2261 payload,
2262 contained_elements * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2188 if (contained_elements == s->used_element_count) 2263 if (contained_elements == s->used_element_count)
2189 { 2264 {
2190 // single part finished 2265 // single part finished
@@ -2193,6 +2268,7 @@ handle_alices_cyrptodata_message (void *cls,
2193 compute_service_response (s); 2268 compute_service_response (s);
2194 } 2269 }
2195 return GNUNET_OK; 2270 return GNUNET_OK;
2271
2196invalid_msg: 2272invalid_msg:
2197 GNUNET_break_op (0); 2273 GNUNET_break_op (0);
2198 s->channel = NULL; 2274 s->channel = NULL;
@@ -2216,8 +2292,13 @@ invalid_msg:
2216 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 2292 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
2217 s->response); 2293 s->response);
2218 } 2294 }
2219 if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) 2295 if ( (s == from_service_head) ||
2220 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 2296 ( (NULL != from_service_head) &&
2297 ( (NULL != s->next) ||
2298 (NULL != s->a_tail)) ) )
2299 GNUNET_CONTAINER_DLL_remove (from_service_head,
2300 from_service_tail,
2301 s);
2221 GNUNET_free(s); 2302 GNUNET_free(s);
2222 } 2303 }
2223 return GNUNET_SYSERR; 2304 return GNUNET_SYSERR;
@@ -2236,66 +2317,59 @@ invalid_msg:
2236 */ 2317 */
2237static int 2318static int
2238handle_alices_computation_request (void *cls, 2319handle_alices_computation_request (void *cls,
2239 struct GNUNET_CADET_Channel * channel, 2320 struct GNUNET_CADET_Channel *channel,
2240 void **channel_ctx, 2321 void **channel_ctx,
2241 const struct GNUNET_MessageHeader * message) 2322 const struct GNUNET_MessageHeader *message)
2242{ 2323{
2243 struct ServiceSession * s; 2324 struct ServiceSession * s;
2244 struct ServiceSession * client_session; 2325 struct ServiceSession * client_session;
2245 const struct ServiceRequestMessage * msg = (const struct ServiceRequestMessage *) message; 2326 const struct ServiceRequestMessage *msg;
2246 2327
2328 msg = (const struct ServiceRequestMessage *) message;
2247 s = (struct ServiceSession *) * channel_ctx; 2329 s = (struct ServiceSession *) * channel_ctx;
2248 if ((BOB != s->role) || (s->total != 0)) 2330 if ((BOB != s->role) || (0 != s->total))
2249 { 2331 {
2250 // must be a fresh session 2332 // must be a fresh session
2251 goto invalid_msg; 2333 goto invalid_msg;
2252 } 2334 }
2253 // Check if message was sent by me, which would be bad! 2335 // Check if message was sent by me, which would be bad!
2254 if (!memcmp (&s->peer, &me, sizeof (struct GNUNET_PeerIdentity))) 2336 if (0 != memcmp (&s->peer,
2337 &me,
2338 sizeof (struct GNUNET_PeerIdentity)))
2255 { 2339 {
2256 GNUNET_free (s); 2340 GNUNET_free (s);
2257 GNUNET_break (0); 2341 GNUNET_break (0);
2258 return GNUNET_SYSERR; 2342 return GNUNET_SYSERR;
2259 } 2343 }
2260 // shorter than expected?
2261 if (ntohs (msg->header.size) != sizeof (struct ServiceRequestMessage))
2262 {
2263 GNUNET_free (s);
2264 GNUNET_break_op (0);
2265 return GNUNET_SYSERR;
2266 }
2267 if (find_matching_session (from_service_tail, 2344 if (find_matching_session (from_service_tail,
2268 &msg->session_id, 2345 &msg->session_id,
2269 NULL)) { 2346 NULL))
2347 {
2270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2348 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2271 _ ("Got message with duplicate session key (`%s'), ignoring service request.\n"), 2349 _("Got message with duplicate session key (`%s'), ignoring service request.\n"),
2272 (const char *) &(msg->session_id)); 2350 (const char *) &(msg->session_id));
2273 GNUNET_free (s); 2351 GNUNET_free (s);
2274 return GNUNET_SYSERR; 2352 return GNUNET_SYSERR;
2275 } 2353 }
2276 2354
2277 s->channel = channel; 2355 s->channel = channel;
2278 2356 s->session_id = msg->session_id;
2279 // session key 2357 s->remote_pubkey = msg->public_key;
2280 memcpy (&s->session_id, &msg->session_id, sizeof (struct GNUNET_HashCode));
2281
2282 // public key
2283 s->remote_pubkey = GNUNET_new (struct GNUNET_CRYPTO_PaillierPublicKey);
2284 memcpy (s->remote_pubkey, &msg->public_key, sizeof (struct GNUNET_CRYPTO_PaillierPublicKey));
2285 2358
2286 //check if service queue contains a matching request 2359 //check if service queue contains a matching request
2287 client_session = find_matching_session (from_client_tail, 2360 client_session = find_matching_session (from_client_tail,
2288 &s->session_id, 2361 &s->session_id,
2289 NULL); 2362 NULL);
2290 2363
2291 GNUNET_CONTAINER_DLL_insert (from_service_head, from_service_tail, s); 2364 GNUNET_CONTAINER_DLL_insert (from_service_head,
2365 from_service_tail,
2366 s);
2292 2367
2293 if ((NULL != client_session) 2368 if ( (NULL != client_session) &&
2294 && (client_session->transferred_element_count == client_session->total)) 2369 (client_session->transferred_element_count == client_session->total) )
2295 { 2370 {
2296 2371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2297 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2372 "Got session with key %s and a matching element set, processing.\n",
2298 _("Got session with key %s and a matching element set, processing.\n"),
2299 GNUNET_h2s (&s->session_id)); 2373 GNUNET_h2s (&s->session_id));
2300 2374
2301 s->response = client_session; 2375 s->response = client_session;
@@ -2304,18 +2378,21 @@ handle_alices_computation_request (void *cls,
2304 s->intersection_set = client_session->intersection_set; 2378 s->intersection_set = client_session->intersection_set;
2305 client_session->intersection_set = NULL; 2379 client_session->intersection_set = NULL;
2306 2380
2307 s->intersection_op = GNUNET_SET_prepare (&s->peer, 2381 s->intersection_op
2308 &s->session_id, 2382 = GNUNET_SET_prepare (&s->peer,
2309 NULL, 2383 &s->session_id,
2310 GNUNET_SET_RESULT_REMOVED, 2384 NULL,
2311 cb_intersection_element_removed, 2385 GNUNET_SET_RESULT_REMOVED,
2312 s); 2386 &cb_intersection_element_removed,
2313 2387 s);
2314 GNUNET_SET_commit (s->intersection_op, s->intersection_set); 2388 GNUNET_SET_commit (s->intersection_op,
2389 s->intersection_set);
2315 } 2390 }
2316 else 2391 else
2317 { 2392 {
2318 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Got session with key %s without a matching element set, queueing.\n"), GNUNET_h2s (&s->session_id)); 2393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2394 "Got session with key %s without a matching element set, queueing.\n",
2395 GNUNET_h2s (&s->session_id));
2319 } 2396 }
2320 2397
2321 return GNUNET_OK; 2398 return GNUNET_OK;
@@ -2341,8 +2418,13 @@ invalid_msg:
2341 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 2418 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
2342 s->response); 2419 s->response);
2343 } 2420 }
2344 if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) 2421 if ( (s == from_service_head) ||
2345 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 2422 ( (NULL != from_service_head) &&
2423 ( (NULL != s->next) ||
2424 (NULL != s->a_tail)) ) )
2425 GNUNET_CONTAINER_DLL_remove (from_service_head,
2426 from_service_tail,
2427 s);
2346 GNUNET_free(s); 2428 GNUNET_free(s);
2347 } 2429 }
2348 return GNUNET_SYSERR; 2430 return GNUNET_SYSERR;
@@ -2354,19 +2436,19 @@ invalid_msg:
2354 * 2436 *
2355 * @param cls closure (set from #GNUNET_CADET_connect) 2437 * @param cls closure (set from #GNUNET_CADET_connect)
2356 * @param channel connection to the other end 2438 * @param channel connection to the other end
2357 * @param channel_ctx place to store local state associated with the channel 2439 * @param channel_ctx place to store local state associated with the @a channel
2358 * @param message the actual message 2440 * @param message the actual message
2359 * @return #GNUNET_OK to keep the connection open, 2441 * @return #GNUNET_OK to keep the connection open,
2360 * #GNUNET_SYSERR to close it (signal serious error) 2442 * #GNUNET_SYSERR to close it (signal serious error)
2361 */ 2443 */
2362static int 2444static int
2363handle_bobs_cryptodata_multipart (void *cls, 2445handle_bobs_cryptodata_multipart (void *cls,
2364 struct GNUNET_CADET_Channel * channel, 2446 struct GNUNET_CADET_Channel *channel,
2365 void **channel_ctx, 2447 void **channel_ctx,
2366 const struct GNUNET_MessageHeader * message) 2448 const struct GNUNET_MessageHeader *message)
2367{ 2449{
2368 struct ServiceSession * s; 2450 struct ServiceSession * s;
2369 const struct MultipartMessage * msg = (const struct MultipartMessage *) message; 2451 const struct MultipartMessage *msg;
2370 struct GNUNET_CRYPTO_PaillierCiphertext * payload; 2452 struct GNUNET_CRYPTO_PaillierCiphertext * payload;
2371 size_t i; 2453 size_t i;
2372 uint32_t contained = 0; 2454 uint32_t contained = 0;
@@ -2380,27 +2462,32 @@ handle_bobs_cryptodata_multipart (void *cls,
2380 { 2462 {
2381 goto invalid_msg; 2463 goto invalid_msg;
2382 } 2464 }
2383 msg_size = ntohs (msg->header.size); 2465 msg_size = ntohs (message->size);
2384 required_size = sizeof (struct MultipartMessage) 2466 if (sizeof (struct MultipartMessage) > msg_size)
2385 + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
2386 // shorter than minimum?
2387 if (required_size > msg_size)
2388 { 2467 {
2468 GNUNET_break_op (0);
2389 goto invalid_msg; 2469 goto invalid_msg;
2390 } 2470 }
2471 msg = (const struct MultipartMessage *) message;
2391 contained = ntohl (msg->contained_element_count); 2472 contained = ntohl (msg->contained_element_count);
2392 required_size = sizeof (struct MultipartMessage) 2473 required_size = sizeof (struct MultipartMessage)
2393 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 2474 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
2394 //sanity check: is the message as long as the message_count fields suggests? 2475 //sanity check: is the message as long as the message_count fields suggests?
2395 if ((required_size != msg_size) || (s->used_element_count < s->transferred_element_count + contained)) 2476 if ( (required_size != msg_size) ||
2477 (s->used_element_count < s->transferred_element_count + contained) )
2396 { 2478 {
2397 goto invalid_msg; 2479 goto invalid_msg;
2398 } 2480 }
2399 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 2481 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
2400 // Convert each k[][perm] to its MPI_value 2482 // Convert each k[][perm] to its MPI_value
2401 for (i = 0; i < contained; i++) { 2483 for (i = 0; i < contained; i++)
2402 memcpy (&s->r[s->transferred_element_count + i], &payload[2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2484 {
2403 memcpy (&s->r_prime[s->transferred_element_count + i], &payload[2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2485 memcpy (&s->r[s->transferred_element_count + i],
2486 &payload[2 * i],
2487 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2488 memcpy (&s->r_prime[s->transferred_element_count + i],
2489 &payload[2 * i],
2490 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2404 } 2491 }
2405 s->transferred_element_count += contained; 2492 s->transferred_element_count += contained;
2406 if (s->transferred_element_count != s->used_element_count) 2493 if (s->transferred_element_count != s->used_element_count)
@@ -2431,8 +2518,13 @@ invalid_msg:
2431 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 2518 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
2432 s->response); 2519 s->response);
2433 } 2520 }
2434 if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) 2521 if ( (s == from_service_head) ||
2435 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 2522 ( (NULL != from_service_head) &&
2523 ( (NULL != s->next) ||
2524 (NULL != s->a_tail)) ) )
2525 GNUNET_CONTAINER_DLL_remove (from_service_head,
2526 from_service_tail,
2527 s);
2436 free_session_variables (s); 2528 free_session_variables (s);
2437 GNUNET_free(s); 2529 GNUNET_free(s);
2438 } 2530 }
@@ -2455,12 +2547,12 @@ invalid_msg:
2455 */ 2547 */
2456static int 2548static int
2457handle_bobs_cryptodata_message (void *cls, 2549handle_bobs_cryptodata_message (void *cls,
2458 struct GNUNET_CADET_Channel *channel, 2550 struct GNUNET_CADET_Channel *channel,
2459 void **channel_ctx, 2551 void **channel_ctx,
2460 const struct GNUNET_MessageHeader *message) 2552 const struct GNUNET_MessageHeader *message)
2461{ 2553{
2462 struct ServiceSession * s; 2554 struct ServiceSession *s;
2463 const struct ServiceResponseMessage *msg = (const struct ServiceResponseMessage *) message; 2555 const struct ServiceResponseMessage *msg;
2464 struct GNUNET_CRYPTO_PaillierCiphertext * payload; 2556 struct GNUNET_CRYPTO_PaillierCiphertext * payload;
2465 size_t i; 2557 size_t i;
2466 uint32_t contained = 0; 2558 uint32_t contained = 0;
@@ -2477,13 +2569,13 @@ handle_bobs_cryptodata_message (void *cls,
2477 goto invalid_msg; 2569 goto invalid_msg;
2478 } 2570 }
2479 //we need at least a full message without elements attached 2571 //we need at least a full message without elements attached
2480 msg_size = ntohs (msg->header.size); 2572 msg_size = ntohs (message->size);
2481 required_size = sizeof (struct ServiceResponseMessage) + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext); 2573 if (sizeof (struct ServiceResponseMessage) > msg_size)
2482
2483 if (required_size > msg_size)
2484 { 2574 {
2575 GNUNET_break_op (0);
2485 goto invalid_msg; 2576 goto invalid_msg;
2486 } 2577 }
2578 msg = (const struct ServiceResponseMessage *) message;
2487 contained = ntohl (msg->contained_element_count); 2579 contained = ntohl (msg->contained_element_count);
2488 required_size = sizeof (struct ServiceResponseMessage) 2580 required_size = sizeof (struct ServiceResponseMessage)
2489 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) 2581 + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)
@@ -2497,10 +2589,14 @@ handle_bobs_cryptodata_message (void *cls,
2497 //convert s 2589 //convert s
2498 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1]; 2590 payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
2499 2591
2500 s->s = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2592 s->s = GNUNET_new (struct GNUNET_CRYPTO_PaillierCiphertext);
2501 s->s_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2593 s->s_prime = GNUNET_new (struct GNUNET_CRYPTO_PaillierCiphertext);
2502 memcpy (s->s, &payload[0], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2594 memcpy (s->s,
2503 memcpy (s->s_prime, &payload[1], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2595 &payload[0],
2596 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2597 memcpy (s->s_prime,
2598 &payload[1],
2599 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2504 2600
2505 s->r = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count); 2601 s->r = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count);
2506 s->r_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count); 2602 s->r_prime = GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) * s->used_element_count);
@@ -2509,8 +2605,12 @@ handle_bobs_cryptodata_message (void *cls,
2509 // Convert each k[][perm] to its MPI_value 2605 // Convert each k[][perm] to its MPI_value
2510 for (i = 0; i < contained; i++) 2606 for (i = 0; i < contained; i++)
2511 { 2607 {
2512 memcpy (&s->r[i], &payload[2 * i], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2608 memcpy (&s->r[i],
2513 memcpy (&s->r_prime[i], &payload[2 * i + 1], sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)); 2609 &payload[2 * i],
2610 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2611 memcpy (&s->r_prime[i],
2612 &payload[2 * i + 1],
2613 sizeof (struct GNUNET_CRYPTO_PaillierCiphertext));
2514 } 2614 }
2515 if (s->transferred_element_count != s->used_element_count) 2615 if (s->transferred_element_count != s->used_element_count)
2516 return GNUNET_OK; //wait for the other multipart chunks 2616 return GNUNET_OK; //wait for the other multipart chunks
@@ -2533,12 +2633,17 @@ invalid_msg:
2533 if (NULL != s->response) 2633 if (NULL != s->response)
2534 { 2634 {
2535 s->response->active = GNUNET_SYSERR; 2635 s->response->active = GNUNET_SYSERR;
2536 s->response->client_notification_task = 2636 s->response->client_notification_task
2537 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 2637 = GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
2538 s->response); 2638 s->response);
2539 } 2639 }
2540 if ((s == from_service_head) || ((NULL != from_service_head) && ((NULL != s->next) || (NULL != s->a_tail)))) 2640 if ( (s == from_service_head) ||
2541 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 2641 ( (NULL != from_service_head) &&
2642 ( (NULL != s->next) ||
2643 (NULL != s->a_tail)) ) )
2644 GNUNET_CONTAINER_DLL_remove (from_service_head,
2645 from_service_tail,
2646 s);
2542 free_session_variables (s); 2647 free_session_variables (s);
2543 GNUNET_free(s); 2648 GNUNET_free(s);
2544 } 2649 }
@@ -2561,8 +2666,8 @@ shutdown_task (void *cls,
2561{ 2666{
2562 struct ServiceSession * s; 2667 struct ServiceSession * s;
2563 2668
2564 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2565 _("Shutting down, initiating cleanup.\n")); 2670 "Shutting down, initiating cleanup.\n");
2566 2671
2567 do_shutdown = GNUNET_YES; 2672 do_shutdown = GNUNET_YES;
2568 2673
@@ -2613,18 +2718,34 @@ run (void *cls,
2613 const struct GNUNET_CONFIGURATION_Handle *c) 2718 const struct GNUNET_CONFIGURATION_Handle *c)
2614{ 2719{
2615 static const struct GNUNET_SERVER_MessageHandler server_handlers[] = { 2720 static const struct GNUNET_SERVER_MessageHandler server_handlers[] = {
2616 {&handle_client_message, NULL, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, 0}, 2721 { &handle_client_message, NULL,
2617 {&handle_client_message, NULL, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB, 0}, 2722 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
2618 {&handle_client_message_multipart, NULL, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MUTLIPART, 0}, 2723 0},
2619 {NULL, NULL, 0, 0} 2724 { &handle_client_message, NULL,
2725 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB,
2726 0},
2727 { &handle_client_message_multipart, NULL,
2728 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MUTLIPART,
2729 0},
2730 { NULL, NULL, 0, 0}
2620 }; 2731 };
2621 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = { 2732 static const struct GNUNET_CADET_MessageHandler cadet_handlers[] = {
2622 { &handle_alices_computation_request, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION, 0}, 2733 { &handle_alices_computation_request,
2623 { &handle_alices_cyrptodata_message, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA, 0}, 2734 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION,
2624 { &handle_alices_cyrptodata_message_multipart, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA_MULTIPART, 0}, 2735 sizeof (struct ServiceRequestMessage) },
2625 { &handle_bobs_cryptodata_message, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA, 0}, 2736 { &handle_alices_cyrptodata_message,
2626 { &handle_bobs_cryptodata_multipart, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART, 0}, 2737 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA,
2627 {NULL, 0, 0} 2738 0},
2739 { &handle_alices_cyrptodata_message_multipart,
2740 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA_MULTIPART,
2741 0},
2742 { &handle_bobs_cryptodata_message,
2743 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
2744 0},
2745 { &handle_bobs_cryptodata_multipart,
2746 GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
2747 0},
2748 { NULL, 0, 0}
2628 }; 2749 };
2629 static const uint32_t ports[] = { 2750 static const uint32_t ports[] = {
2630 GNUNET_APPLICATION_TYPE_SCALARPRODUCT, 2751 GNUNET_APPLICATION_TYPE_SCALARPRODUCT,
@@ -2633,7 +2754,8 @@ run (void *cls,
2633 cfg = c; 2754 cfg = c;
2634 2755
2635 //generate private/public key set 2756 //generate private/public key set
2636 GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey); 2757 GNUNET_CRYPTO_paillier_create (&my_pubkey,
2758 &my_privkey);
2637 2759
2638 // offset has to be sufficiently small to allow computation of: 2760 // offset has to be sufficiently small to allow computation of:
2639 // m1+m2 mod n == (S + a) + (S + b) mod n, 2761 // m1+m2 mod n == (S + a) + (S + b) mod n,
@@ -2650,9 +2772,10 @@ run (void *cls,
2650 GNUNET_CRYPTO_get_peer_identity (cfg, 2772 GNUNET_CRYPTO_get_peer_identity (cfg,
2651 &me)); 2773 &me));
2652 my_cadet = GNUNET_CADET_connect (cfg, NULL, 2774 my_cadet = GNUNET_CADET_connect (cfg, NULL,
2653 &cb_channel_incoming, 2775 &cb_channel_incoming,
2654 &cb_channel_destruction, 2776 &cb_channel_destruction,
2655 cadet_handlers, ports); 2777 cadet_handlers,
2778 ports);
2656 if (!my_cadet) 2779 if (!my_cadet)
2657 { 2780 {
2658 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2781 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -2660,8 +2783,8 @@ run (void *cls,
2660 GNUNET_SCHEDULER_shutdown (); 2783 GNUNET_SCHEDULER_shutdown ();
2661 return; 2784 return;
2662 } 2785 }
2663 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2664 _("CADET initialized\n")); 2787 "Connection to CADET initialized\n");
2665 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 2788 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
2666 &shutdown_task, 2789 &shutdown_task,
2667 NULL); 2790 NULL);
diff --git a/src/scalarproduct/scalarproduct_api.c b/src/scalarproduct/scalarproduct_api.c
index 26c69dd13..6672e0e8f 100644
--- a/src/scalarproduct/scalarproduct_api.c
+++ b/src/scalarproduct/scalarproduct_api.c
@@ -149,7 +149,7 @@ process_result_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
149 const struct ClientResponseMessage *msg, 149 const struct ClientResponseMessage *msg,
150 enum GNUNET_SCALARPRODUCT_ResponseStatus status) 150 enum GNUNET_SCALARPRODUCT_ResponseStatus status)
151{ 151{
152 size_t product_len = ntohl (msg->product_length); 152 size_t product_len;
153 gcry_mpi_t result = NULL; 153 gcry_mpi_t result = NULL;
154 gcry_error_t rc; 154 gcry_error_t rc;
155 gcry_mpi_t num; 155 gcry_mpi_t num;
@@ -158,7 +158,7 @@ process_result_message (struct GNUNET_SCALARPRODUCT_ComputationHandle *h,
158 if ( (GNUNET_SCALARPRODUCT_Status_Success == status) && 158 if ( (GNUNET_SCALARPRODUCT_Status_Success == status) &&
159 ( (NULL == msg) || 159 ( (NULL == msg) ||
160 ( (ntohs (msg->header.size) - sizeof (struct ClientResponseMessage) 160 ( (ntohs (msg->header.size) - sizeof (struct ClientResponseMessage)
161 != product_len) ) ) ) 161 != (product_len = ntohl (msg->product_length))) ) ) )
162 { 162 {
163 GNUNET_break (0); 163 GNUNET_break (0);
164 status = GNUNET_SCALARPRODUCT_Status_InvalidResponse; 164 status = GNUNET_SCALARPRODUCT_Status_InvalidResponse;