diff options
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | 973 |
1 files changed, 487 insertions, 486 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c index dc2763943..9671c46f6 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #include "gnunet-service-scalarproduct-ecc.h" | 37 | #include "gnunet-service-scalarproduct-ecc.h" |
38 | 38 | ||
39 | #define LOG(kind, ...) \ | 39 | #define LOG(kind, ...) \ |
40 | GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__) | 40 | GNUNET_log_from(kind, "scalarproduct-alice", __VA_ARGS__) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Maximum allowed result value for the scalarproduct computation. | 43 | * Maximum allowed result value for the scalarproduct computation. |
@@ -57,8 +57,7 @@ | |||
57 | /** | 57 | /** |
58 | * An encrypted element key-value pair. | 58 | * An encrypted element key-value pair. |
59 | */ | 59 | */ |
60 | struct MpiElement | 60 | struct MpiElement { |
61 | { | ||
62 | /** | 61 | /** |
63 | * Key used to identify matching pairs of values to multiply. | 62 | * Key used to identify matching pairs of values to multiply. |
64 | * Points into an existing data structure, to avoid copying | 63 | * Points into an existing data structure, to avoid copying |
@@ -77,9 +76,7 @@ struct MpiElement | |||
77 | * A scalarproduct session which tracks | 76 | * A scalarproduct session which tracks |
78 | * a request form the client to our final response. | 77 | * a request form the client to our final response. |
79 | */ | 78 | */ |
80 | struct AliceServiceSession | 79 | struct AliceServiceSession { |
81 | { | ||
82 | |||
83 | /** | 80 | /** |
84 | * (hopefully) unique transaction ID | 81 | * (hopefully) unique transaction ID |
85 | */ | 82 | */ |
@@ -213,11 +210,11 @@ static struct GNUNET_CADET_Handle *my_cadet; | |||
213 | * @return #GNUNET_OK (continue to iterate) | 210 | * @return #GNUNET_OK (continue to iterate) |
214 | */ | 211 | */ |
215 | static int | 212 | static int |
216 | free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | 213 | free_element_cb(void *cls, const struct GNUNET_HashCode *key, void *value) |
217 | { | 214 | { |
218 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 215 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
219 | 216 | ||
220 | GNUNET_free (e); | 217 | GNUNET_free(e); |
221 | return GNUNET_OK; | 218 | return GNUNET_OK; |
222 | } | 219 | } |
223 | 220 | ||
@@ -228,7 +225,7 @@ free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
228 | * @param s the session to free elements from | 225 | * @param s the session to free elements from |
229 | */ | 226 | */ |
230 | static void | 227 | static void |
231 | destroy_service_session (struct AliceServiceSession *s) | 228 | destroy_service_session(struct AliceServiceSession *s) |
232 | { | 229 | { |
233 | unsigned int i; | 230 | unsigned int i; |
234 | 231 | ||
@@ -236,54 +233,54 @@ destroy_service_session (struct AliceServiceSession *s) | |||
236 | return; | 233 | return; |
237 | s->in_destroy = GNUNET_YES; | 234 | s->in_destroy = GNUNET_YES; |
238 | if (NULL != s->client) | 235 | if (NULL != s->client) |
239 | { | 236 | { |
240 | struct GNUNET_SERVICE_Client *c = s->client; | 237 | struct GNUNET_SERVICE_Client *c = s->client; |
241 | 238 | ||
242 | s->client = NULL; | 239 | s->client = NULL; |
243 | GNUNET_SERVICE_client_drop (c); | 240 | GNUNET_SERVICE_client_drop(c); |
244 | } | 241 | } |
245 | if (NULL != s->channel) | 242 | if (NULL != s->channel) |
246 | { | 243 | { |
247 | GNUNET_CADET_channel_destroy (s->channel); | 244 | GNUNET_CADET_channel_destroy(s->channel); |
248 | s->channel = NULL; | 245 | s->channel = NULL; |
249 | } | 246 | } |
250 | if (NULL != s->intersected_elements) | 247 | if (NULL != s->intersected_elements) |
251 | { | 248 | { |
252 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 249 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, |
253 | &free_element_cb, | 250 | &free_element_cb, |
254 | s); | 251 | s); |
255 | GNUNET_CONTAINER_multihashmap_destroy (s->intersected_elements); | 252 | GNUNET_CONTAINER_multihashmap_destroy(s->intersected_elements); |
256 | s->intersected_elements = NULL; | 253 | s->intersected_elements = NULL; |
257 | } | 254 | } |
258 | if (NULL != s->intersection_listen) | 255 | if (NULL != s->intersection_listen) |
259 | { | 256 | { |
260 | GNUNET_SET_listen_cancel (s->intersection_listen); | 257 | GNUNET_SET_listen_cancel(s->intersection_listen); |
261 | s->intersection_listen = NULL; | 258 | s->intersection_listen = NULL; |
262 | } | 259 | } |
263 | if (NULL != s->intersection_op) | 260 | if (NULL != s->intersection_op) |
264 | { | 261 | { |
265 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection, op still ongoing!\n"); | 262 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Set intersection, op still ongoing!\n"); |
266 | GNUNET_SET_operation_cancel (s->intersection_op); | 263 | GNUNET_SET_operation_cancel(s->intersection_op); |
267 | s->intersection_op = NULL; | 264 | s->intersection_op = NULL; |
268 | } | 265 | } |
269 | if (NULL != s->intersection_set) | 266 | if (NULL != s->intersection_set) |
270 | { | 267 | { |
271 | GNUNET_SET_destroy (s->intersection_set); | 268 | GNUNET_SET_destroy(s->intersection_set); |
272 | s->intersection_set = NULL; | 269 | s->intersection_set = NULL; |
273 | } | 270 | } |
274 | if (NULL != s->sorted_elements) | 271 | if (NULL != s->sorted_elements) |
275 | { | 272 | { |
276 | for (i = 0; i < s->used_element_count; i++) | 273 | for (i = 0; i < s->used_element_count; i++) |
277 | gcry_mpi_release (s->sorted_elements[i].value); | 274 | gcry_mpi_release(s->sorted_elements[i].value); |
278 | GNUNET_free (s->sorted_elements); | 275 | GNUNET_free(s->sorted_elements); |
279 | s->sorted_elements = NULL; | 276 | s->sorted_elements = NULL; |
280 | } | 277 | } |
281 | if (NULL != s->product) | 278 | if (NULL != s->product) |
282 | { | 279 | { |
283 | gcry_mpi_release (s->product); | 280 | gcry_mpi_release(s->product); |
284 | s->product = NULL; | 281 | s->product = NULL; |
285 | } | 282 | } |
286 | GNUNET_free (s); | 283 | GNUNET_free(s); |
287 | } | 284 | } |
288 | 285 | ||
289 | 286 | ||
@@ -294,22 +291,22 @@ destroy_service_session (struct AliceServiceSession *s) | |||
294 | * @param session the associated client session to fail or succeed | 291 | * @param session the associated client session to fail or succeed |
295 | */ | 292 | */ |
296 | static void | 293 | static void |
297 | prepare_client_end_notification (struct AliceServiceSession *session) | 294 | prepare_client_end_notification(struct AliceServiceSession *session) |
298 | { | 295 | { |
299 | struct ClientResponseMessage *msg; | 296 | struct ClientResponseMessage *msg; |
300 | struct GNUNET_MQ_Envelope *e; | 297 | struct GNUNET_MQ_Envelope *e; |
301 | 298 | ||
302 | if (NULL == session->client_mq) | 299 | if (NULL == session->client_mq) |
303 | return; /* no client left to be notified */ | 300 | return; /* no client left to be notified */ |
304 | GNUNET_log ( | 301 | GNUNET_log( |
305 | GNUNET_ERROR_TYPE_DEBUG, | 302 | GNUNET_ERROR_TYPE_DEBUG, |
306 | "Sending session-end notification with status %d to client for session %s\n", | 303 | "Sending session-end notification with status %d to client for session %s\n", |
307 | session->status, | 304 | session->status, |
308 | GNUNET_h2s (&session->session_id)); | 305 | GNUNET_h2s(&session->session_id)); |
309 | e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 306 | e = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
310 | msg->product_length = htonl (0); | 307 | msg->product_length = htonl(0); |
311 | msg->status = htonl (session->status); | 308 | msg->status = htonl(session->status); |
312 | GNUNET_MQ_send (session->client_mq, e); | 309 | GNUNET_MQ_send(session->client_mq, e); |
313 | } | 310 | } |
314 | 311 | ||
315 | 312 | ||
@@ -320,7 +317,7 @@ prepare_client_end_notification (struct AliceServiceSession *session) | |||
320 | * @param s the session associated with our client. | 317 | * @param s the session associated with our client. |
321 | */ | 318 | */ |
322 | static void | 319 | static void |
323 | transmit_client_response (struct AliceServiceSession *s) | 320 | transmit_client_response(struct AliceServiceSession *s) |
324 | { | 321 | { |
325 | struct ClientResponseMessage *msg; | 322 | struct ClientResponseMessage *msg; |
326 | struct GNUNET_MQ_Envelope *e; | 323 | struct GNUNET_MQ_Envelope *e; |
@@ -332,56 +329,56 @@ transmit_client_response (struct AliceServiceSession *s) | |||
332 | gcry_mpi_t value; | 329 | gcry_mpi_t value; |
333 | 330 | ||
334 | if (NULL == s->product) | 331 | if (NULL == s->product) |
335 | { | 332 | { |
336 | GNUNET_break (0); | 333 | GNUNET_break(0); |
337 | prepare_client_end_notification (s); | 334 | prepare_client_end_notification(s); |
338 | return; | 335 | return; |
339 | } | 336 | } |
340 | value = gcry_mpi_new (0); | 337 | value = gcry_mpi_new(0); |
341 | sign = gcry_mpi_cmp_ui (s->product, 0); | 338 | sign = gcry_mpi_cmp_ui(s->product, 0); |
342 | if (0 > sign) | 339 | if (0 > sign) |
343 | { | 340 | { |
344 | range = -1; | 341 | range = -1; |
345 | gcry_mpi_sub (value, value, s->product); | 342 | gcry_mpi_sub(value, value, s->product); |
346 | } | 343 | } |
347 | else if (0 < sign) | 344 | else if (0 < sign) |
348 | { | 345 | { |
349 | range = 1; | 346 | range = 1; |
350 | gcry_mpi_add (value, value, s->product); | 347 | gcry_mpi_add(value, value, s->product); |
351 | } | 348 | } |
352 | else | 349 | else |
353 | { | 350 | { |
354 | /* result is exactly zero */ | 351 | /* result is exactly zero */ |
355 | range = 0; | 352 | range = 0; |
356 | } | 353 | } |
357 | gcry_mpi_release (s->product); | 354 | gcry_mpi_release(s->product); |
358 | s->product = NULL; | 355 | s->product = NULL; |
359 | 356 | ||
360 | if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, | 357 | if ((0 != range) && (0 != (rc = gcry_mpi_aprint(GCRYMPI_FMT_STD, |
361 | &product_exported, | 358 | &product_exported, |
362 | &product_length, | 359 | &product_length, |
363 | value)))) | 360 | value)))) |
364 | { | 361 | { |
365 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 362 | LOG_GCRY(GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); |
366 | prepare_client_end_notification (s); | 363 | prepare_client_end_notification(s); |
367 | return; | 364 | return; |
368 | } | 365 | } |
369 | gcry_mpi_release (value); | 366 | gcry_mpi_release(value); |
370 | e = GNUNET_MQ_msg_extra (msg, | 367 | e = GNUNET_MQ_msg_extra(msg, |
371 | product_length, | 368 | product_length, |
372 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 369 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); |
373 | msg->status = htonl (GNUNET_SCALARPRODUCT_STATUS_SUCCESS); | 370 | msg->status = htonl(GNUNET_SCALARPRODUCT_STATUS_SUCCESS); |
374 | msg->range = htonl (range); | 371 | msg->range = htonl(range); |
375 | msg->product_length = htonl (product_length); | 372 | msg->product_length = htonl(product_length); |
376 | if (NULL != product_exported) | 373 | if (NULL != product_exported) |
377 | { | 374 | { |
378 | GNUNET_memcpy (&msg[1], product_exported, product_length); | 375 | GNUNET_memcpy(&msg[1], product_exported, product_length); |
379 | GNUNET_free (product_exported); | 376 | GNUNET_free(product_exported); |
380 | } | 377 | } |
381 | GNUNET_MQ_send (s->client_mq, e); | 378 | GNUNET_MQ_send(s->client_mq, e); |
382 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 379 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
383 | "Sent result to client, session %s has ended!\n", | 380 | "Sent result to client, session %s has ended!\n", |
384 | GNUNET_h2s (&s->session_id)); | 381 | GNUNET_h2s(&s->session_id)); |
385 | } | 382 | } |
386 | 383 | ||
387 | 384 | ||
@@ -395,21 +392,21 @@ transmit_client_response (struct AliceServiceSession *s) | |||
395 | * @param channel connection to the other end (henceforth invalid) | 392 | * @param channel connection to the other end (henceforth invalid) |
396 | */ | 393 | */ |
397 | static void | 394 | static void |
398 | cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) | 395 | cb_channel_destruction(void *cls, const struct GNUNET_CADET_Channel *channel) |
399 | { | 396 | { |
400 | struct AliceServiceSession *s = cls; | 397 | struct AliceServiceSession *s = cls; |
401 | 398 | ||
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 399 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
403 | "Peer disconnected, terminating session %s with peer %s\n", | 400 | "Peer disconnected, terminating session %s with peer %s\n", |
404 | GNUNET_h2s (&s->session_id), | 401 | GNUNET_h2s(&s->session_id), |
405 | GNUNET_i2s (&s->peer)); | 402 | GNUNET_i2s(&s->peer)); |
406 | s->channel = NULL; | 403 | s->channel = NULL; |
407 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) | 404 | if (GNUNET_SCALARPRODUCT_STATUS_ACTIVE == s->status) |
408 | { | 405 | { |
409 | /* We didn't get an answer yet, fail with error */ | 406 | /* We didn't get an answer yet, fail with error */ |
410 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 407 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
411 | prepare_client_end_notification (s); | 408 | prepare_client_end_notification(s); |
412 | } | 409 | } |
413 | } | 410 | } |
414 | 411 | ||
415 | 412 | ||
@@ -422,9 +419,9 @@ cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) | |||
422 | * @return product as MPI, never NULL | 419 | * @return product as MPI, never NULL |
423 | */ | 420 | */ |
424 | static gcry_mpi_t | 421 | static gcry_mpi_t |
425 | compute_scalar_product (struct AliceServiceSession *session, | 422 | compute_scalar_product(struct AliceServiceSession *session, |
426 | gcry_mpi_point_t prod_g_i_b_i, | 423 | gcry_mpi_point_t prod_g_i_b_i, |
427 | gcry_mpi_point_t prod_h_i_b_i) | 424 | gcry_mpi_point_t prod_h_i_b_i) |
428 | { | 425 | { |
429 | gcry_mpi_point_t g_i_b_i_a_inv; | 426 | gcry_mpi_point_t g_i_b_i_a_inv; |
430 | gcry_mpi_point_t g_ai_bi; | 427 | gcry_mpi_point_t g_ai_bi; |
@@ -432,28 +429,28 @@ compute_scalar_product (struct AliceServiceSession *session, | |||
432 | gcry_mpi_t ret; | 429 | gcry_mpi_t ret; |
433 | 430 | ||
434 | g_i_b_i_a_inv = | 431 | g_i_b_i_a_inv = |
435 | GNUNET_CRYPTO_ecc_pmul_mpi (edc, prod_g_i_b_i, my_privkey_inv); | 432 | GNUNET_CRYPTO_ecc_pmul_mpi(edc, prod_g_i_b_i, my_privkey_inv); |
436 | g_ai_bi = GNUNET_CRYPTO_ecc_add (edc, g_i_b_i_a_inv, prod_h_i_b_i); | 433 | g_ai_bi = GNUNET_CRYPTO_ecc_add(edc, g_i_b_i_a_inv, prod_h_i_b_i); |
437 | gcry_mpi_point_release (g_i_b_i_a_inv); | 434 | gcry_mpi_point_release(g_i_b_i_a_inv); |
438 | ai_bi = GNUNET_CRYPTO_ecc_dlog (edc, g_ai_bi); | 435 | ai_bi = GNUNET_CRYPTO_ecc_dlog(edc, g_ai_bi); |
439 | gcry_mpi_point_release (g_ai_bi); | 436 | gcry_mpi_point_release(g_ai_bi); |
440 | if (INT_MAX == ai_bi) | 437 | if (INT_MAX == ai_bi) |
441 | { | 438 | { |
442 | /* result too big */ | 439 | /* result too big */ |
443 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 440 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
444 | "Scalar product result out of range\n"); | 441 | "Scalar product result out of range\n"); |
445 | return NULL; | 442 | return NULL; |
446 | } | 443 | } |
447 | ret = gcry_mpi_new (0); | 444 | ret = gcry_mpi_new(0); |
448 | if (ai_bi > 0) | 445 | if (ai_bi > 0) |
449 | { | 446 | { |
450 | gcry_mpi_set_ui (ret, ai_bi); | 447 | gcry_mpi_set_ui(ret, ai_bi); |
451 | } | 448 | } |
452 | else | 449 | else |
453 | { | 450 | { |
454 | gcry_mpi_set_ui (ret, -ai_bi); | 451 | gcry_mpi_set_ui(ret, -ai_bi); |
455 | gcry_mpi_neg (ret, ret); | 452 | gcry_mpi_neg(ret, ret); |
456 | } | 453 | } |
457 | return ret; | 454 | return ret; |
458 | } | 455 | } |
459 | 456 | ||
@@ -466,46 +463,46 @@ compute_scalar_product (struct AliceServiceSession *session, | |||
466 | * @param msg the actual message | 463 | * @param msg the actual message |
467 | */ | 464 | */ |
468 | static void | 465 | static void |
469 | handle_bobs_cryptodata_message (void *cls, | 466 | handle_bobs_cryptodata_message(void *cls, |
470 | const struct EccBobCryptodataMessage *msg) | 467 | const struct EccBobCryptodataMessage *msg) |
471 | { | 468 | { |
472 | struct AliceServiceSession *s = cls; | 469 | struct AliceServiceSession *s = cls; |
473 | gcry_mpi_point_t prod_g_i_b_i; | 470 | gcry_mpi_point_t prod_g_i_b_i; |
474 | gcry_mpi_point_t prod_h_i_b_i; | 471 | gcry_mpi_point_t prod_h_i_b_i; |
475 | uint32_t contained; | 472 | uint32_t contained; |
476 | 473 | ||
477 | contained = ntohl (msg->contained_element_count); | 474 | contained = ntohl(msg->contained_element_count); |
478 | if (2 != contained) | 475 | if (2 != contained) |
479 | { | 476 | { |
480 | GNUNET_break_op (0); | 477 | GNUNET_break_op(0); |
481 | destroy_service_session (s); | 478 | destroy_service_session(s); |
482 | return; | 479 | return; |
483 | } | 480 | } |
484 | if (NULL == s->sorted_elements) | 481 | if (NULL == s->sorted_elements) |
485 | { | 482 | { |
486 | /* we're not ready yet, how can Bob be? */ | 483 | /* we're not ready yet, how can Bob be? */ |
487 | GNUNET_break_op (0); | 484 | GNUNET_break_op(0); |
488 | destroy_service_session (s); | 485 | destroy_service_session(s); |
489 | return; | 486 | return; |
490 | } | 487 | } |
491 | if (s->total != s->client_received_element_count) | 488 | if (s->total != s->client_received_element_count) |
492 | { | 489 | { |
493 | /* we're not ready yet, how can Bob be? */ | 490 | /* we're not ready yet, how can Bob be? */ |
494 | GNUNET_break_op (0); | 491 | GNUNET_break_op(0); |
495 | destroy_service_session (s); | 492 | destroy_service_session(s); |
496 | return; | 493 | return; |
497 | } | 494 | } |
498 | 495 | ||
499 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 496 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
500 | "Received %u crypto values from Bob\n", | 497 | "Received %u crypto values from Bob\n", |
501 | (unsigned int) contained); | 498 | (unsigned int)contained); |
502 | GNUNET_CADET_receive_done (s->channel); | 499 | GNUNET_CADET_receive_done(s->channel); |
503 | prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_g_i_b_i); | 500 | prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point(edc, &msg->prod_g_i_b_i); |
504 | prod_h_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_h_i_b_i); | 501 | prod_h_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point(edc, &msg->prod_h_i_b_i); |
505 | s->product = compute_scalar_product (s, prod_g_i_b_i, prod_h_i_b_i); | 502 | s->product = compute_scalar_product(s, prod_g_i_b_i, prod_h_i_b_i); |
506 | gcry_mpi_point_release (prod_g_i_b_i); | 503 | gcry_mpi_point_release(prod_g_i_b_i); |
507 | gcry_mpi_point_release (prod_h_i_b_i); | 504 | gcry_mpi_point_release(prod_h_i_b_i); |
508 | transmit_client_response (s); | 505 | transmit_client_response(s); |
509 | } | 506 | } |
510 | 507 | ||
511 | 508 | ||
@@ -518,19 +515,19 @@ handle_bobs_cryptodata_message (void *cls, | |||
518 | * @param value the `struct GNUNET_SCALARPRODUCT_Element *` | 515 | * @param value the `struct GNUNET_SCALARPRODUCT_Element *` |
519 | */ | 516 | */ |
520 | static int | 517 | static int |
521 | copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | 518 | copy_element_cb(void *cls, const struct GNUNET_HashCode *key, void *value) |
522 | { | 519 | { |
523 | struct AliceServiceSession *s = cls; | 520 | struct AliceServiceSession *s = cls; |
524 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 521 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
525 | gcry_mpi_t mval; | 522 | gcry_mpi_t mval; |
526 | int64_t val; | 523 | int64_t val; |
527 | 524 | ||
528 | mval = gcry_mpi_new (0); | 525 | mval = gcry_mpi_new(0); |
529 | val = (int64_t) GNUNET_ntohll (e->value); | 526 | val = (int64_t)GNUNET_ntohll(e->value); |
530 | if (0 > val) | 527 | if (0 > val) |
531 | gcry_mpi_sub_ui (mval, mval, -val); | 528 | gcry_mpi_sub_ui(mval, mval, -val); |
532 | else | 529 | else |
533 | gcry_mpi_add_ui (mval, mval, val); | 530 | gcry_mpi_add_ui(mval, mval, val); |
534 | s->sorted_elements[s->used_element_count].value = mval; | 531 | s->sorted_elements[s->used_element_count].value = mval; |
535 | s->sorted_elements[s->used_element_count].key = &e->key; | 532 | s->sorted_elements[s->used_element_count].key = &e->key; |
536 | s->used_element_count++; | 533 | s->used_element_count++; |
@@ -546,12 +543,12 @@ copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
546 | * @return -1 for a < b, 0 for a=b, 1 for a > b. | 543 | * @return -1 for a < b, 0 for a=b, 1 for a > b. |
547 | */ | 544 | */ |
548 | static int | 545 | static int |
549 | element_cmp (const void *a, const void *b) | 546 | element_cmp(const void *a, const void *b) |
550 | { | 547 | { |
551 | const struct MpiElement *ma = a; | 548 | const struct MpiElement *ma = a; |
552 | const struct MpiElement *mb = b; | 549 | const struct MpiElement *mb = b; |
553 | 550 | ||
554 | return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key); | 551 | return GNUNET_CRYPTO_hash_cmp(ma->key, mb->key); |
555 | } | 552 | } |
556 | 553 | ||
557 | 554 | ||
@@ -561,8 +558,8 @@ element_cmp (const void *a, const void *b) | |||
561 | */ | 558 | */ |
562 | #define ELEMENT_CAPACITY \ | 559 | #define ELEMENT_CAPACITY \ |
563 | ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \ | 560 | ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \ |
564 | sizeof (struct EccAliceCryptodataMessage)) / \ | 561 | sizeof(struct EccAliceCryptodataMessage)) / \ |
565 | sizeof (struct GNUNET_CRYPTO_EccPoint)) | 562 | sizeof(struct GNUNET_CRYPTO_EccPoint)) |
566 | 563 | ||
567 | 564 | ||
568 | /** | 565 | /** |
@@ -572,7 +569,7 @@ element_cmp (const void *a, const void *b) | |||
572 | * @param s the associated service session | 569 | * @param s the associated service session |
573 | */ | 570 | */ |
574 | static void | 571 | static void |
575 | send_alices_cryptodata_message (struct AliceServiceSession *s) | 572 | send_alices_cryptodata_message(struct AliceServiceSession *s) |
576 | { | 573 | { |
577 | struct EccAliceCryptodataMessage *msg; | 574 | struct EccAliceCryptodataMessage *msg; |
578 | struct GNUNET_MQ_Envelope *e; | 575 | struct GNUNET_MQ_Envelope *e; |
@@ -583,64 +580,64 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
583 | unsigned int off; | 580 | unsigned int off; |
584 | unsigned int todo_count; | 581 | unsigned int todo_count; |
585 | 582 | ||
586 | s->sorted_elements = GNUNET_new_array (GNUNET_CONTAINER_multihashmap_size ( | 583 | s->sorted_elements = GNUNET_new_array(GNUNET_CONTAINER_multihashmap_size( |
587 | s->intersected_elements), | 584 | s->intersected_elements), |
588 | struct MpiElement); | 585 | struct MpiElement); |
589 | s->used_element_count = 0; | 586 | s->used_element_count = 0; |
590 | GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements, | 587 | GNUNET_CONTAINER_multihashmap_iterate(s->intersected_elements, |
591 | ©_element_cb, | 588 | ©_element_cb, |
592 | s); | 589 | s); |
593 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 590 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
594 | "Finished intersection, %d items remain\n", | 591 | "Finished intersection, %d items remain\n", |
595 | s->used_element_count); | 592 | s->used_element_count); |
596 | qsort (s->sorted_elements, | 593 | qsort(s->sorted_elements, |
597 | s->used_element_count, | 594 | s->used_element_count, |
598 | sizeof (struct MpiElement), | 595 | sizeof(struct MpiElement), |
599 | &element_cmp); | 596 | &element_cmp); |
600 | off = 0; | 597 | off = 0; |
601 | while (off < s->used_element_count) | 598 | while (off < s->used_element_count) |
602 | { | ||
603 | todo_count = s->used_element_count - off; | ||
604 | if (todo_count > ELEMENT_CAPACITY) | ||
605 | todo_count = ELEMENT_CAPACITY; | ||
606 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
607 | "Sending %u/%u crypto values to Bob\n", | ||
608 | (unsigned int) todo_count, | ||
609 | (unsigned int) s->used_element_count); | ||
610 | |||
611 | e = | ||
612 | GNUNET_MQ_msg_extra (msg, | ||
613 | todo_count * 2 * | ||
614 | sizeof (struct GNUNET_CRYPTO_EccPoint), | ||
615 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA); | ||
616 | msg->contained_element_count = htonl (todo_count); | ||
617 | payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1]; | ||
618 | r_ia = gcry_mpi_new (0); | ||
619 | r_ia_ai = gcry_mpi_new (0); | ||
620 | for (i = off; i < off + todo_count; i++) | ||
621 | { | 599 | { |
622 | gcry_mpi_t r_i; | 600 | todo_count = s->used_element_count - off; |
623 | gcry_mpi_point_t g_i; | 601 | if (todo_count > ELEMENT_CAPACITY) |
624 | gcry_mpi_point_t h_i; | 602 | todo_count = ELEMENT_CAPACITY; |
625 | 603 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | |
626 | r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc); | 604 | "Sending %u/%u crypto values to Bob\n", |
627 | g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_i); | 605 | (unsigned int)todo_count, |
628 | /* r_ia = r_i * a */ | 606 | (unsigned int)s->used_element_count); |
629 | gcry_mpi_mul (r_ia, r_i, my_privkey); | 607 | |
630 | gcry_mpi_release (r_i); | 608 | e = |
631 | /* r_ia_ai = r_ia + a_i */ | 609 | GNUNET_MQ_msg_extra(msg, |
632 | gcry_mpi_add (r_ia_ai, r_ia, s->sorted_elements[i].value); | 610 | todo_count * 2 * |
633 | h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_ia_ai); | 611 | sizeof(struct GNUNET_CRYPTO_EccPoint), |
634 | GNUNET_CRYPTO_ecc_point_to_bin (edc, g_i, &payload[(i - off) * 2]); | 612 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA); |
635 | GNUNET_CRYPTO_ecc_point_to_bin (edc, h_i, &payload[(i - off) * 2 + 1]); | 613 | msg->contained_element_count = htonl(todo_count); |
636 | gcry_mpi_point_release (g_i); | 614 | payload = (struct GNUNET_CRYPTO_EccPoint *)&msg[1]; |
637 | gcry_mpi_point_release (h_i); | 615 | r_ia = gcry_mpi_new(0); |
616 | r_ia_ai = gcry_mpi_new(0); | ||
617 | for (i = off; i < off + todo_count; i++) | ||
618 | { | ||
619 | gcry_mpi_t r_i; | ||
620 | gcry_mpi_point_t g_i; | ||
621 | gcry_mpi_point_t h_i; | ||
622 | |||
623 | r_i = GNUNET_CRYPTO_ecc_random_mod_n(edc); | ||
624 | g_i = GNUNET_CRYPTO_ecc_dexp_mpi(edc, r_i); | ||
625 | /* r_ia = r_i * a */ | ||
626 | gcry_mpi_mul(r_ia, r_i, my_privkey); | ||
627 | gcry_mpi_release(r_i); | ||
628 | /* r_ia_ai = r_ia + a_i */ | ||
629 | gcry_mpi_add(r_ia_ai, r_ia, s->sorted_elements[i].value); | ||
630 | h_i = GNUNET_CRYPTO_ecc_dexp_mpi(edc, r_ia_ai); | ||
631 | GNUNET_CRYPTO_ecc_point_to_bin(edc, g_i, &payload[(i - off) * 2]); | ||
632 | GNUNET_CRYPTO_ecc_point_to_bin(edc, h_i, &payload[(i - off) * 2 + 1]); | ||
633 | gcry_mpi_point_release(g_i); | ||
634 | gcry_mpi_point_release(h_i); | ||
635 | } | ||
636 | gcry_mpi_release(r_ia); | ||
637 | gcry_mpi_release(r_ia_ai); | ||
638 | off += todo_count; | ||
639 | GNUNET_MQ_send(s->cadet_mq, e); | ||
638 | } | 640 | } |
639 | gcry_mpi_release (r_ia); | ||
640 | gcry_mpi_release (r_ia_ai); | ||
641 | off += todo_count; | ||
642 | GNUNET_MQ_send (s->cadet_mq, e); | ||
643 | } | ||
644 | } | 641 | } |
645 | 642 | ||
646 | 643 | ||
@@ -655,66 +652,70 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
655 | * @param status what has happened with the set intersection? | 652 | * @param status what has happened with the set intersection? |
656 | */ | 653 | */ |
657 | static void | 654 | static void |
658 | cb_intersection_element_removed (void *cls, | 655 | cb_intersection_element_removed(void *cls, |
659 | const struct GNUNET_SET_Element *element, | 656 | const struct GNUNET_SET_Element *element, |
660 | uint64_t current_size, | 657 | uint64_t current_size, |
661 | enum GNUNET_SET_Status status) | 658 | enum GNUNET_SET_Status status) |
662 | { | 659 | { |
663 | struct AliceServiceSession *s = cls; | 660 | struct AliceServiceSession *s = cls; |
664 | struct GNUNET_SCALARPRODUCT_Element *se; | 661 | struct GNUNET_SCALARPRODUCT_Element *se; |
665 | 662 | ||
666 | switch (status) | 663 | switch (status) |
667 | { | ||
668 | case GNUNET_SET_STATUS_OK: | ||
669 | /* this element has been removed from the set */ | ||
670 | se = GNUNET_CONTAINER_multihashmap_get (s->intersected_elements, | ||
671 | element->data); | ||
672 | GNUNET_assert (NULL != se); | ||
673 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
674 | "Intersection removed element with key %s and value %lld\n", | ||
675 | GNUNET_h2s (&se->key), | ||
676 | (long long) GNUNET_ntohll (se->value)); | ||
677 | GNUNET_assert ( | ||
678 | GNUNET_YES == | ||
679 | GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements, | ||
680 | element->data, | ||
681 | se)); | ||
682 | GNUNET_free (se); | ||
683 | return; | ||
684 | case GNUNET_SET_STATUS_DONE: | ||
685 | s->intersection_op = NULL; | ||
686 | if (NULL != s->intersection_set) | ||
687 | { | 664 | { |
688 | GNUNET_SET_destroy (s->intersection_set); | 665 | case GNUNET_SET_STATUS_OK: |
689 | s->intersection_set = NULL; | 666 | /* this element has been removed from the set */ |
667 | se = GNUNET_CONTAINER_multihashmap_get(s->intersected_elements, | ||
668 | element->data); | ||
669 | GNUNET_assert(NULL != se); | ||
670 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
671 | "Intersection removed element with key %s and value %lld\n", | ||
672 | GNUNET_h2s(&se->key), | ||
673 | (long long)GNUNET_ntohll(se->value)); | ||
674 | GNUNET_assert( | ||
675 | GNUNET_YES == | ||
676 | GNUNET_CONTAINER_multihashmap_remove(s->intersected_elements, | ||
677 | element->data, | ||
678 | se)); | ||
679 | GNUNET_free(se); | ||
680 | return; | ||
681 | |||
682 | case GNUNET_SET_STATUS_DONE: | ||
683 | s->intersection_op = NULL; | ||
684 | if (NULL != s->intersection_set) | ||
685 | { | ||
686 | GNUNET_SET_destroy(s->intersection_set); | ||
687 | s->intersection_set = NULL; | ||
688 | } | ||
689 | send_alices_cryptodata_message(s); | ||
690 | return; | ||
691 | |||
692 | case GNUNET_SET_STATUS_HALF_DONE: | ||
693 | /* unexpected for intersection */ | ||
694 | GNUNET_break(0); | ||
695 | return; | ||
696 | |||
697 | case GNUNET_SET_STATUS_FAILURE: | ||
698 | /* unhandled status code */ | ||
699 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n"); | ||
700 | if (NULL != s->intersection_listen) | ||
701 | { | ||
702 | GNUNET_SET_listen_cancel(s->intersection_listen); | ||
703 | s->intersection_listen = NULL; | ||
704 | } | ||
705 | s->intersection_op = NULL; | ||
706 | if (NULL != s->intersection_set) | ||
707 | { | ||
708 | GNUNET_SET_destroy(s->intersection_set); | ||
709 | s->intersection_set = NULL; | ||
710 | } | ||
711 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
712 | prepare_client_end_notification(s); | ||
713 | return; | ||
714 | |||
715 | default: | ||
716 | GNUNET_break(0); | ||
717 | return; | ||
690 | } | 718 | } |
691 | send_alices_cryptodata_message (s); | ||
692 | return; | ||
693 | case GNUNET_SET_STATUS_HALF_DONE: | ||
694 | /* unexpected for intersection */ | ||
695 | GNUNET_break (0); | ||
696 | return; | ||
697 | case GNUNET_SET_STATUS_FAILURE: | ||
698 | /* unhandled status code */ | ||
699 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n"); | ||
700 | if (NULL != s->intersection_listen) | ||
701 | { | ||
702 | GNUNET_SET_listen_cancel (s->intersection_listen); | ||
703 | s->intersection_listen = NULL; | ||
704 | } | ||
705 | s->intersection_op = NULL; | ||
706 | if (NULL != s->intersection_set) | ||
707 | { | ||
708 | GNUNET_SET_destroy (s->intersection_set); | ||
709 | s->intersection_set = NULL; | ||
710 | } | ||
711 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | ||
712 | prepare_client_end_notification (s); | ||
713 | return; | ||
714 | default: | ||
715 | GNUNET_break (0); | ||
716 | return; | ||
717 | } | ||
718 | } | 719 | } |
719 | 720 | ||
720 | 721 | ||
@@ -734,40 +735,40 @@ cb_intersection_element_removed (void *cls, | |||
734 | * message. It's necessary to specify the timeout. | 735 | * message. It's necessary to specify the timeout. |
735 | */ | 736 | */ |
736 | static void | 737 | static void |
737 | cb_intersection_request_alice (void *cls, | 738 | cb_intersection_request_alice(void *cls, |
738 | const struct GNUNET_PeerIdentity *other_peer, | 739 | const struct GNUNET_PeerIdentity *other_peer, |
739 | const struct GNUNET_MessageHeader *context_msg, | 740 | const struct GNUNET_MessageHeader *context_msg, |
740 | struct GNUNET_SET_Request *request) | 741 | struct GNUNET_SET_Request *request) |
741 | { | 742 | { |
742 | struct AliceServiceSession *s = cls; | 743 | struct AliceServiceSession *s = cls; |
743 | 744 | ||
744 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 745 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
745 | "Received intersection request from %s!\n", | 746 | "Received intersection request from %s!\n", |
746 | GNUNET_i2s (other_peer)); | 747 | GNUNET_i2s(other_peer)); |
747 | if (0 != GNUNET_memcmp (other_peer, &s->peer)) | 748 | if (0 != GNUNET_memcmp(other_peer, &s->peer)) |
748 | { | 749 | { |
749 | GNUNET_break_op (0); | 750 | GNUNET_break_op(0); |
750 | return; | 751 | return; |
751 | } | 752 | } |
752 | s->intersection_op = GNUNET_SET_accept (request, | 753 | s->intersection_op = GNUNET_SET_accept(request, |
753 | GNUNET_SET_RESULT_REMOVED, | 754 | GNUNET_SET_RESULT_REMOVED, |
754 | (struct GNUNET_SET_Option[]){{0}}, | 755 | (struct GNUNET_SET_Option[]){ { 0 } }, |
755 | &cb_intersection_element_removed, | 756 | &cb_intersection_element_removed, |
756 | s); | 757 | s); |
757 | if (NULL == s->intersection_op) | 758 | if (NULL == s->intersection_op) |
758 | { | 759 | { |
759 | GNUNET_break (0); | 760 | GNUNET_break(0); |
760 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 761 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
761 | prepare_client_end_notification (s); | 762 | prepare_client_end_notification(s); |
762 | return; | 763 | return; |
763 | } | 764 | } |
764 | if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set)) | 765 | if (GNUNET_OK != GNUNET_SET_commit(s->intersection_op, s->intersection_set)) |
765 | { | 766 | { |
766 | GNUNET_break (0); | 767 | GNUNET_break(0); |
767 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 768 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
768 | prepare_client_end_notification (s); | 769 | prepare_client_end_notification(s); |
769 | return; | 770 | return; |
770 | } | 771 | } |
771 | } | 772 | } |
772 | 773 | ||
773 | 774 | ||
@@ -777,58 +778,58 @@ cb_intersection_request_alice (void *cls, | |||
777 | * @param session the service session context | 778 | * @param session the service session context |
778 | */ | 779 | */ |
779 | static void | 780 | static void |
780 | client_request_complete_alice (struct AliceServiceSession *s) | 781 | client_request_complete_alice(struct AliceServiceSession *s) |
781 | { | 782 | { |
782 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 783 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = |
783 | {GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, | 784 | { GNUNET_MQ_hd_fixed_size(bobs_cryptodata_message, |
784 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, | 785 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, |
785 | struct EccBobCryptodataMessage, | 786 | struct EccBobCryptodataMessage, |
786 | s), | 787 | s), |
787 | GNUNET_MQ_handler_end ()}; | 788 | GNUNET_MQ_handler_end() }; |
788 | struct EccServiceRequestMessage *msg; | 789 | struct EccServiceRequestMessage *msg; |
789 | struct GNUNET_MQ_Envelope *e; | 790 | struct GNUNET_MQ_Envelope *e; |
790 | struct GNUNET_HashCode set_sid; | 791 | struct GNUNET_HashCode set_sid; |
791 | 792 | ||
792 | GNUNET_CRYPTO_hash (&s->session_id, | 793 | GNUNET_CRYPTO_hash(&s->session_id, |
793 | sizeof (struct GNUNET_HashCode), | 794 | sizeof(struct GNUNET_HashCode), |
794 | &set_sid); | 795 | &set_sid); |
795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 796 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
796 | "Creating new channel for session with key %s.\n", | 797 | "Creating new channel for session with key %s.\n", |
797 | GNUNET_h2s (&s->session_id)); | 798 | GNUNET_h2s(&s->session_id)); |
798 | s->channel = GNUNET_CADET_channel_create (my_cadet, | 799 | s->channel = GNUNET_CADET_channel_create(my_cadet, |
799 | s, | 800 | s, |
800 | &s->peer, | 801 | &s->peer, |
801 | &s->session_id, | 802 | &s->session_id, |
802 | NULL, | 803 | NULL, |
803 | &cb_channel_destruction, | 804 | &cb_channel_destruction, |
804 | cadet_handlers); | 805 | cadet_handlers); |
805 | if (NULL == s->channel) | 806 | if (NULL == s->channel) |
806 | { | 807 | { |
807 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 808 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
808 | prepare_client_end_notification (s); | 809 | prepare_client_end_notification(s); |
809 | return; | 810 | return; |
810 | } | 811 | } |
811 | s->cadet_mq = GNUNET_CADET_get_mq (s->channel); | 812 | s->cadet_mq = GNUNET_CADET_get_mq(s->channel); |
812 | s->intersection_listen = GNUNET_SET_listen (cfg, | 813 | s->intersection_listen = GNUNET_SET_listen(cfg, |
813 | GNUNET_SET_OPERATION_INTERSECTION, | 814 | GNUNET_SET_OPERATION_INTERSECTION, |
814 | &set_sid, | 815 | &set_sid, |
815 | &cb_intersection_request_alice, | 816 | &cb_intersection_request_alice, |
816 | s); | 817 | s); |
817 | if (NULL == s->intersection_listen) | 818 | if (NULL == s->intersection_listen) |
818 | { | 819 | { |
819 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 820 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
820 | GNUNET_CADET_channel_destroy (s->channel); | 821 | GNUNET_CADET_channel_destroy(s->channel); |
821 | s->channel = NULL; | 822 | s->channel = NULL; |
822 | prepare_client_end_notification (s); | 823 | prepare_client_end_notification(s); |
823 | return; | 824 | return; |
824 | } | 825 | } |
825 | 826 | ||
826 | e = | 827 | e = |
827 | GNUNET_MQ_msg (msg, | 828 | GNUNET_MQ_msg(msg, |
828 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION); | 829 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_SESSION_INITIALIZATION); |
829 | GNUNET_MQ_env_set_options (e, GNUNET_MQ_PRIO_CRITICAL_CONTROL); | 830 | GNUNET_MQ_env_set_options(e, GNUNET_MQ_PRIO_CRITICAL_CONTROL); |
830 | msg->session_id = s->session_id; | 831 | msg->session_id = s->session_id; |
831 | GNUNET_MQ_send (s->cadet_mq, e); | 832 | GNUNET_MQ_send(s->cadet_mq, e); |
832 | } | 833 | } |
833 | 834 | ||
834 | 835 | ||
@@ -841,7 +842,7 @@ client_request_complete_alice (struct AliceServiceSession *s) | |||
841 | * @return #GNUNET_OK if @a msg is well-formed | 842 | * @return #GNUNET_OK if @a msg is well-formed |
842 | */ | 843 | */ |
843 | static int | 844 | static int |
844 | check_alice_client_message_multipart ( | 845 | check_alice_client_message_multipart( |
845 | void *cls, | 846 | void *cls, |
846 | const struct ComputationBobCryptodataMultipartMessage *msg) | 847 | const struct ComputationBobCryptodataMultipartMessage *msg) |
847 | { | 848 | { |
@@ -849,18 +850,18 @@ check_alice_client_message_multipart ( | |||
849 | uint32_t contained_count; | 850 | uint32_t contained_count; |
850 | uint16_t msize; | 851 | uint16_t msize; |
851 | 852 | ||
852 | msize = ntohs (msg->header.size); | 853 | msize = ntohs(msg->header.size); |
853 | contained_count = ntohl (msg->element_count_contained); | 854 | contained_count = ntohl(msg->element_count_contained); |
854 | if ((msize != | 855 | if ((msize != |
855 | (sizeof (struct ComputationBobCryptodataMultipartMessage) + | 856 | (sizeof(struct ComputationBobCryptodataMultipartMessage) + |
856 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) || | 857 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element))) || |
857 | (0 == contained_count) || | 858 | (0 == contained_count) || |
858 | (s->total == s->client_received_element_count) || | 859 | (s->total == s->client_received_element_count) || |
859 | (s->total < s->client_received_element_count + contained_count)) | 860 | (s->total < s->client_received_element_count + contained_count)) |
860 | { | 861 | { |
861 | GNUNET_break_op (0); | 862 | GNUNET_break_op(0); |
862 | return GNUNET_SYSERR; | 863 | return GNUNET_SYSERR; |
863 | } | 864 | } |
864 | return GNUNET_OK; | 865 | return GNUNET_OK; |
865 | } | 866 | } |
866 | 867 | ||
@@ -873,7 +874,7 @@ check_alice_client_message_multipart ( | |||
873 | * @param msg the actual message | 874 | * @param msg the actual message |
874 | */ | 875 | */ |
875 | static void | 876 | static void |
876 | handle_alice_client_message_multipart ( | 877 | handle_alice_client_message_multipart( |
877 | void *cls, | 878 | void *cls, |
878 | const struct ComputationBobCryptodataMultipartMessage *msg) | 879 | const struct ComputationBobCryptodataMultipartMessage *msg) |
879 | { | 880 | { |
@@ -883,41 +884,41 @@ handle_alice_client_message_multipart ( | |||
883 | struct GNUNET_SET_Element set_elem; | 884 | struct GNUNET_SET_Element set_elem; |
884 | struct GNUNET_SCALARPRODUCT_Element *elem; | 885 | struct GNUNET_SCALARPRODUCT_Element *elem; |
885 | 886 | ||
886 | contained_count = ntohl (msg->element_count_contained); | 887 | contained_count = ntohl(msg->element_count_contained); |
887 | s->client_received_element_count += contained_count; | 888 | s->client_received_element_count += contained_count; |
888 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 889 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; |
889 | for (uint32_t i = 0; i < contained_count; i++) | 890 | for (uint32_t i = 0; i < contained_count; i++) |
890 | { | ||
891 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
892 | GNUNET_memcpy (elem, | ||
893 | &elements[i], | ||
894 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | ||
895 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( | ||
896 | s->intersected_elements, | ||
897 | &elem->key, | ||
898 | elem, | ||
899 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
900 | { | 891 | { |
901 | GNUNET_break (0); | 892 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); |
902 | GNUNET_free (elem); | 893 | GNUNET_memcpy(elem, |
903 | continue; | 894 | &elements[i], |
895 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
896 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put( | ||
897 | s->intersected_elements, | ||
898 | &elem->key, | ||
899 | elem, | ||
900 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
901 | { | ||
902 | GNUNET_break(0); | ||
903 | GNUNET_free(elem); | ||
904 | continue; | ||
905 | } | ||
906 | set_elem.data = &elem->key; | ||
907 | set_elem.size = sizeof(elem->key); | ||
908 | set_elem.element_type = 0; | ||
909 | GNUNET_SET_add_element(s->intersection_set, &set_elem, NULL, NULL); | ||
910 | s->used_element_count++; | ||
904 | } | 911 | } |
905 | set_elem.data = &elem->key; | 912 | GNUNET_SERVICE_client_continue(s->client); |
906 | set_elem.size = sizeof (elem->key); | ||
907 | set_elem.element_type = 0; | ||
908 | GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); | ||
909 | s->used_element_count++; | ||
910 | } | ||
911 | GNUNET_SERVICE_client_continue (s->client); | ||
912 | if (s->total != s->client_received_element_count) | 913 | if (s->total != s->client_received_element_count) |
913 | { | 914 | { |
914 | /* more to come */ | 915 | /* more to come */ |
915 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 916 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
916 | "Received client multipart data, waiting for more!\n"); | 917 | "Received client multipart data, waiting for more!\n"); |
917 | return; | 918 | return; |
918 | } | 919 | } |
919 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); | 920 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); |
920 | client_request_complete_alice (s); | 921 | client_request_complete_alice(s); |
921 | } | 922 | } |
922 | 923 | ||
923 | 924 | ||
@@ -930,8 +931,8 @@ handle_alice_client_message_multipart ( | |||
930 | * @return #GNUNET_OK if @a msg is well-formed | 931 | * @return #GNUNET_OK if @a msg is well-formed |
931 | */ | 932 | */ |
932 | static int | 933 | static int |
933 | check_alice_client_message (void *cls, | 934 | check_alice_client_message(void *cls, |
934 | const struct AliceComputationMessage *msg) | 935 | const struct AliceComputationMessage *msg) |
935 | { | 936 | { |
936 | struct AliceServiceSession *s = cls; | 937 | struct AliceServiceSession *s = cls; |
937 | uint16_t msize; | 938 | uint16_t msize; |
@@ -939,23 +940,23 @@ check_alice_client_message (void *cls, | |||
939 | uint32_t contained_count; | 940 | uint32_t contained_count; |
940 | 941 | ||
941 | if (NULL != s->intersected_elements) | 942 | if (NULL != s->intersected_elements) |
942 | { | 943 | { |
943 | /* only one concurrent session per client connection allowed, | 944 | /* only one concurrent session per client connection allowed, |
944 | simplifies logic a lot... */ | 945 | simplifies logic a lot... */ |
945 | GNUNET_break (0); | 946 | GNUNET_break(0); |
946 | return GNUNET_SYSERR; | 947 | return GNUNET_SYSERR; |
947 | } | 948 | } |
948 | msize = ntohs (msg->header.size); | 949 | msize = ntohs(msg->header.size); |
949 | total_count = ntohl (msg->element_count_total); | 950 | total_count = ntohl(msg->element_count_total); |
950 | contained_count = ntohl (msg->element_count_contained); | 951 | contained_count = ntohl(msg->element_count_contained); |
951 | if ((0 == total_count) || (0 == contained_count) || | 952 | if ((0 == total_count) || (0 == contained_count) || |
952 | (msize != | 953 | (msize != |
953 | (sizeof (struct AliceComputationMessage) + | 954 | (sizeof(struct AliceComputationMessage) + |
954 | contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element)))) | 955 | contained_count * sizeof(struct GNUNET_SCALARPRODUCT_Element)))) |
955 | { | 956 | { |
956 | GNUNET_break_op (0); | 957 | GNUNET_break_op(0); |
957 | return GNUNET_SYSERR; | 958 | return GNUNET_SYSERR; |
958 | } | 959 | } |
959 | return GNUNET_OK; | 960 | return GNUNET_OK; |
960 | } | 961 | } |
961 | 962 | ||
@@ -968,8 +969,8 @@ check_alice_client_message (void *cls, | |||
968 | * @param msg the actual message | 969 | * @param msg the actual message |
969 | */ | 970 | */ |
970 | static void | 971 | static void |
971 | handle_alice_client_message (void *cls, | 972 | handle_alice_client_message(void *cls, |
972 | const struct AliceComputationMessage *msg) | 973 | const struct AliceComputationMessage *msg) |
973 | { | 974 | { |
974 | struct AliceServiceSession *s = cls; | 975 | struct AliceServiceSession *s = cls; |
975 | uint32_t contained_count; | 976 | uint32_t contained_count; |
@@ -978,53 +979,53 @@ handle_alice_client_message (void *cls, | |||
978 | struct GNUNET_SET_Element set_elem; | 979 | struct GNUNET_SET_Element set_elem; |
979 | struct GNUNET_SCALARPRODUCT_Element *elem; | 980 | struct GNUNET_SCALARPRODUCT_Element *elem; |
980 | 981 | ||
981 | total_count = ntohl (msg->element_count_total); | 982 | total_count = ntohl(msg->element_count_total); |
982 | contained_count = ntohl (msg->element_count_contained); | 983 | contained_count = ntohl(msg->element_count_contained); |
983 | s->peer = msg->peer; | 984 | s->peer = msg->peer; |
984 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; | 985 | s->status = GNUNET_SCALARPRODUCT_STATUS_ACTIVE; |
985 | s->total = total_count; | 986 | s->total = total_count; |
986 | s->client_received_element_count = contained_count; | 987 | s->client_received_element_count = contained_count; |
987 | s->session_id = msg->session_key; | 988 | s->session_id = msg->session_key; |
988 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 989 | elements = (const struct GNUNET_SCALARPRODUCT_Element *)&msg[1]; |
989 | s->intersected_elements = | 990 | s->intersected_elements = |
990 | GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES); | 991 | GNUNET_CONTAINER_multihashmap_create(s->total, GNUNET_YES); |
991 | s->intersection_set = | 992 | s->intersection_set = |
992 | GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); | 993 | GNUNET_SET_create(cfg, GNUNET_SET_OPERATION_INTERSECTION); |
993 | for (uint32_t i = 0; i < contained_count; i++) | 994 | for (uint32_t i = 0; i < contained_count; i++) |
994 | { | ||
995 | if (0 == GNUNET_ntohll (elements[i].value)) | ||
996 | continue; | ||
997 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | ||
998 | GNUNET_memcpy (elem, | ||
999 | &elements[i], | ||
1000 | sizeof (struct GNUNET_SCALARPRODUCT_Element)); | ||
1001 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( | ||
1002 | s->intersected_elements, | ||
1003 | &elem->key, | ||
1004 | elem, | ||
1005 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1006 | { | 995 | { |
1007 | /* element with same key encountered twice! */ | 996 | if (0 == GNUNET_ntohll(elements[i].value)) |
1008 | GNUNET_break (0); | 997 | continue; |
1009 | GNUNET_free (elem); | 998 | elem = GNUNET_new(struct GNUNET_SCALARPRODUCT_Element); |
1010 | continue; | 999 | GNUNET_memcpy(elem, |
1000 | &elements[i], | ||
1001 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | ||
1002 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put( | ||
1003 | s->intersected_elements, | ||
1004 | &elem->key, | ||
1005 | elem, | ||
1006 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
1007 | { | ||
1008 | /* element with same key encountered twice! */ | ||
1009 | GNUNET_break(0); | ||
1010 | GNUNET_free(elem); | ||
1011 | continue; | ||
1012 | } | ||
1013 | set_elem.data = &elem->key; | ||
1014 | set_elem.size = sizeof(elem->key); | ||
1015 | set_elem.element_type = 0; | ||
1016 | GNUNET_SET_add_element(s->intersection_set, &set_elem, NULL, NULL); | ||
1017 | s->used_element_count++; | ||
1011 | } | 1018 | } |
1012 | set_elem.data = &elem->key; | 1019 | GNUNET_SERVICE_client_continue(s->client); |
1013 | set_elem.size = sizeof (elem->key); | ||
1014 | set_elem.element_type = 0; | ||
1015 | GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL); | ||
1016 | s->used_element_count++; | ||
1017 | } | ||
1018 | GNUNET_SERVICE_client_continue (s->client); | ||
1019 | if (s->total != s->client_received_element_count) | 1020 | if (s->total != s->client_received_element_count) |
1020 | { | 1021 | { |
1021 | /* wait for multipart msg */ | 1022 | /* wait for multipart msg */ |
1022 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1023 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1023 | "Received partial client request, waiting for more!\n"); | 1024 | "Received partial client request, waiting for more!\n"); |
1024 | return; | 1025 | return; |
1025 | } | 1026 | } |
1026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); | 1027 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); |
1027 | client_request_complete_alice (s); | 1028 | client_request_complete_alice(s); |
1028 | } | 1029 | } |
1029 | 1030 | ||
1030 | 1031 | ||
@@ -1035,20 +1036,20 @@ handle_alice_client_message (void *cls, | |||
1035 | * @param tc unused | 1036 | * @param tc unused |
1036 | */ | 1037 | */ |
1037 | static void | 1038 | static void |
1038 | shutdown_task (void *cls) | 1039 | shutdown_task(void *cls) |
1039 | { | 1040 | { |
1040 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n"); | 1041 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n"); |
1041 | // FIXME: we have to cut our connections to CADET first! | 1042 | // FIXME: we have to cut our connections to CADET first! |
1042 | if (NULL != my_cadet) | 1043 | if (NULL != my_cadet) |
1043 | { | 1044 | { |
1044 | GNUNET_CADET_disconnect (my_cadet); | 1045 | GNUNET_CADET_disconnect(my_cadet); |
1045 | my_cadet = NULL; | 1046 | my_cadet = NULL; |
1046 | } | 1047 | } |
1047 | if (NULL != edc) | 1048 | if (NULL != edc) |
1048 | { | 1049 | { |
1049 | GNUNET_CRYPTO_ecc_dlog_release (edc); | 1050 | GNUNET_CRYPTO_ecc_dlog_release(edc); |
1050 | edc = NULL; | 1051 | edc = NULL; |
1051 | } | 1052 | } |
1052 | } | 1053 | } |
1053 | 1054 | ||
1054 | 1055 | ||
@@ -1063,13 +1064,13 @@ shutdown_task (void *cls) | |||
1063 | * @return our `struct AliceServiceSession` | 1064 | * @return our `struct AliceServiceSession` |
1064 | */ | 1065 | */ |
1065 | static void * | 1066 | static void * |
1066 | client_connect_cb (void *cls, | 1067 | client_connect_cb(void *cls, |
1067 | struct GNUNET_SERVICE_Client *client, | 1068 | struct GNUNET_SERVICE_Client *client, |
1068 | struct GNUNET_MQ_Handle *mq) | 1069 | struct GNUNET_MQ_Handle *mq) |
1069 | { | 1070 | { |
1070 | struct AliceServiceSession *s; | 1071 | struct AliceServiceSession *s; |
1071 | 1072 | ||
1072 | s = GNUNET_new (struct AliceServiceSession); | 1073 | s = GNUNET_new(struct AliceServiceSession); |
1073 | s->client = client; | 1074 | s->client = client; |
1074 | s->client_mq = mq; | 1075 | s->client_mq = mq; |
1075 | return s; | 1076 | return s; |
@@ -1087,18 +1088,18 @@ client_connect_cb (void *cls, | |||
1087 | * @param app_cls our `struct AliceServiceSession` | 1088 | * @param app_cls our `struct AliceServiceSession` |
1088 | */ | 1089 | */ |
1089 | static void | 1090 | static void |
1090 | client_disconnect_cb (void *cls, | 1091 | client_disconnect_cb(void *cls, |
1091 | struct GNUNET_SERVICE_Client *client, | 1092 | struct GNUNET_SERVICE_Client *client, |
1092 | void *app_cls) | 1093 | void *app_cls) |
1093 | { | 1094 | { |
1094 | struct AliceServiceSession *s = app_cls; | 1095 | struct AliceServiceSession *s = app_cls; |
1095 | 1096 | ||
1096 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1097 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1097 | "Client %p disconnected from us.\n", | 1098 | "Client %p disconnected from us.\n", |
1098 | client); | 1099 | client); |
1099 | s->client = NULL; | 1100 | s->client = NULL; |
1100 | s->client_mq = NULL; | 1101 | s->client_mq = NULL; |
1101 | destroy_service_session (s); | 1102 | destroy_service_session(s); |
1102 | } | 1103 | } |
1103 | 1104 | ||
1104 | 1105 | ||
@@ -1110,45 +1111,45 @@ client_disconnect_cb (void *cls, | |||
1110 | * @param service the initialized service | 1111 | * @param service the initialized service |
1111 | */ | 1112 | */ |
1112 | static void | 1113 | static void |
1113 | run (void *cls, | 1114 | run(void *cls, |
1114 | const struct GNUNET_CONFIGURATION_Handle *c, | 1115 | const struct GNUNET_CONFIGURATION_Handle *c, |
1115 | struct GNUNET_SERVICE_Handle *service) | 1116 | struct GNUNET_SERVICE_Handle *service) |
1116 | { | 1117 | { |
1117 | cfg = c; | 1118 | cfg = c; |
1118 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, MAX_RAM); | 1119 | edc = GNUNET_CRYPTO_ecc_dlog_prepare(MAX_RESULT, MAX_RAM); |
1119 | /* Select a random 'a' value for Alice */ | 1120 | /* Select a random 'a' value for Alice */ |
1120 | GNUNET_CRYPTO_ecc_rnd_mpi (edc, &my_privkey, &my_privkey_inv); | 1121 | GNUNET_CRYPTO_ecc_rnd_mpi(edc, &my_privkey, &my_privkey_inv); |
1121 | my_cadet = GNUNET_CADET_connect (cfg); | 1122 | my_cadet = GNUNET_CADET_connect(cfg); |
1122 | if (NULL == my_cadet) | 1123 | if (NULL == my_cadet) |
1123 | { | 1124 | { |
1124 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n")); | 1125 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Connect to CADET failed\n")); |
1125 | GNUNET_SCHEDULER_shutdown (); | 1126 | GNUNET_SCHEDULER_shutdown(); |
1126 | return; | 1127 | return; |
1127 | } | 1128 | } |
1128 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1129 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
1129 | } | 1130 | } |
1130 | 1131 | ||
1131 | 1132 | ||
1132 | /** | 1133 | /** |
1133 | * Define "main" method using service macro. | 1134 | * Define "main" method using service macro. |
1134 | */ | 1135 | */ |
1135 | GNUNET_SERVICE_MAIN ( | 1136 | GNUNET_SERVICE_MAIN( |
1136 | "scalarproduct-alice", | 1137 | "scalarproduct-alice", |
1137 | GNUNET_SERVICE_OPTION_NONE, | 1138 | GNUNET_SERVICE_OPTION_NONE, |
1138 | &run, | 1139 | &run, |
1139 | &client_connect_cb, | 1140 | &client_connect_cb, |
1140 | &client_disconnect_cb, | 1141 | &client_disconnect_cb, |
1141 | NULL, | 1142 | NULL, |
1142 | GNUNET_MQ_hd_var_size (alice_client_message, | 1143 | GNUNET_MQ_hd_var_size(alice_client_message, |
1143 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, | 1144 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE, |
1144 | struct AliceComputationMessage, | 1145 | struct AliceComputationMessage, |
1145 | NULL), | 1146 | NULL), |
1146 | GNUNET_MQ_hd_var_size ( | 1147 | GNUNET_MQ_hd_var_size( |
1147 | alice_client_message_multipart, | 1148 | alice_client_message_multipart, |
1148 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, | 1149 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE, |
1149 | struct ComputationBobCryptodataMultipartMessage, | 1150 | struct ComputationBobCryptodataMultipartMessage, |
1150 | NULL), | 1151 | NULL), |
1151 | GNUNET_MQ_handler_end ()); | 1152 | GNUNET_MQ_handler_end()); |
1152 | 1153 | ||
1153 | 1154 | ||
1154 | /* end of gnunet-service-scalarproduct-ecc_alice.c */ | 1155 | /* end of gnunet-service-scalarproduct-ecc_alice.c */ |