diff options
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | 297 |
1 files changed, 149 insertions, 148 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c index 447451aef..e33d589be 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c +++ b/src/scalarproduct/gnunet-service-scalarproduct-ecc_alice.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013-2017 GNUnet e.V. | 3 | Copyright (C) 2013-2017, 2021 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -69,7 +69,7 @@ struct MpiElement | |||
69 | /** | 69 | /** |
70 | * a_i value, not disclosed to Bob. | 70 | * a_i value, not disclosed to Bob. |
71 | */ | 71 | */ |
72 | gcry_mpi_t value; | 72 | int64_t value; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
@@ -138,9 +138,9 @@ struct AliceServiceSession | |||
138 | struct MpiElement *sorted_elements; | 138 | struct MpiElement *sorted_elements; |
139 | 139 | ||
140 | /** | 140 | /** |
141 | * The computed scalar | 141 | * The computed scalar product. INT_MAX if the computation failed. |
142 | */ | 142 | */ |
143 | gcry_mpi_t product; | 143 | int product; |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * How many elements we were supplied with from the client (total | 146 | * How many elements we were supplied with from the client (total |
@@ -190,12 +190,12 @@ static struct GNUNET_CRYPTO_EccDlogContext *edc; | |||
190 | /** | 190 | /** |
191 | * Alice's private key ('a'). | 191 | * Alice's private key ('a'). |
192 | */ | 192 | */ |
193 | static gcry_mpi_t my_privkey; | 193 | static struct GNUNET_CRYPTO_EccScalar my_privkey; |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * Inverse of Alice's private key ('a_inv'). | 196 | * Inverse of Alice's private key ('a_inv'). |
197 | */ | 197 | */ |
198 | static gcry_mpi_t my_privkey_inv; | 198 | static struct GNUNET_CRYPTO_EccScalar my_privkey_inv; |
199 | 199 | ||
200 | /** | 200 | /** |
201 | * Handle to the CADET service. | 201 | * Handle to the CADET service. |
@@ -212,7 +212,9 @@ static struct GNUNET_CADET_Handle *my_cadet; | |||
212 | * @return #GNUNET_OK (continue to iterate) | 212 | * @return #GNUNET_OK (continue to iterate) |
213 | */ | 213 | */ |
214 | static int | 214 | static int |
215 | free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | 215 | free_element_cb (void *cls, |
216 | const struct GNUNET_HashCode *key, | ||
217 | void *value) | ||
216 | { | 218 | { |
217 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 219 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
218 | 220 | ||
@@ -229,8 +231,6 @@ free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
229 | static void | 231 | static void |
230 | destroy_service_session (struct AliceServiceSession *s) | 232 | destroy_service_session (struct AliceServiceSession *s) |
231 | { | 233 | { |
232 | unsigned int i; | ||
233 | |||
234 | if (GNUNET_YES == s->in_destroy) | 234 | if (GNUNET_YES == s->in_destroy) |
235 | return; | 235 | return; |
236 | s->in_destroy = GNUNET_YES; | 236 | s->in_destroy = GNUNET_YES; |
@@ -261,7 +261,8 @@ destroy_service_session (struct AliceServiceSession *s) | |||
261 | } | 261 | } |
262 | if (NULL != s->intersection_op) | 262 | if (NULL != s->intersection_op) |
263 | { | 263 | { |
264 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection, op still ongoing!\n"); | 264 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
265 | "Set intersection, op still ongoing!\n"); | ||
265 | GNUNET_SETI_operation_cancel (s->intersection_op); | 266 | GNUNET_SETI_operation_cancel (s->intersection_op); |
266 | s->intersection_op = NULL; | 267 | s->intersection_op = NULL; |
267 | } | 268 | } |
@@ -272,16 +273,9 @@ destroy_service_session (struct AliceServiceSession *s) | |||
272 | } | 273 | } |
273 | if (NULL != s->sorted_elements) | 274 | if (NULL != s->sorted_elements) |
274 | { | 275 | { |
275 | for (i = 0; i < s->used_element_count; i++) | ||
276 | gcry_mpi_release (s->sorted_elements[i].value); | ||
277 | GNUNET_free (s->sorted_elements); | 276 | GNUNET_free (s->sorted_elements); |
278 | s->sorted_elements = NULL; | 277 | s->sorted_elements = NULL; |
279 | } | 278 | } |
280 | if (NULL != s->product) | ||
281 | { | ||
282 | gcry_mpi_release (s->product); | ||
283 | s->product = NULL; | ||
284 | } | ||
285 | GNUNET_free (s); | 279 | GNUNET_free (s); |
286 | } | 280 | } |
287 | 281 | ||
@@ -305,10 +299,12 @@ prepare_client_end_notification (struct AliceServiceSession *session) | |||
305 | "Sending session-end notification with status %d to client for session %s\n", | 299 | "Sending session-end notification with status %d to client for session %s\n", |
306 | session->status, | 300 | session->status, |
307 | GNUNET_h2s (&session->session_id)); | 301 | GNUNET_h2s (&session->session_id)); |
308 | e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | 302 | e = GNUNET_MQ_msg (msg, |
303 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT); | ||
309 | msg->product_length = htonl (0); | 304 | msg->product_length = htonl (0); |
310 | msg->status = htonl (session->status); | 305 | msg->status = htonl (session->status); |
311 | GNUNET_MQ_send (session->client_mq, e); | 306 | GNUNET_MQ_send (session->client_mq, |
307 | e); | ||
312 | } | 308 | } |
313 | 309 | ||
314 | 310 | ||
@@ -327,41 +323,41 @@ transmit_client_response (struct AliceServiceSession *s) | |||
327 | size_t product_length = 0; | 323 | size_t product_length = 0; |
328 | int32_t range; | 324 | int32_t range; |
329 | gcry_error_t rc; | 325 | gcry_error_t rc; |
330 | int sign; | ||
331 | gcry_mpi_t value; | 326 | gcry_mpi_t value; |
332 | 327 | ||
333 | if (NULL == s->product) | 328 | if (INT_MAX == s->product) |
334 | { | 329 | { |
335 | GNUNET_break (0); | 330 | GNUNET_break (0); |
336 | prepare_client_end_notification (s); | 331 | prepare_client_end_notification (s); |
337 | return; | 332 | return; |
338 | } | 333 | } |
339 | value = gcry_mpi_new (0); | 334 | value = gcry_mpi_new (32); |
340 | sign = gcry_mpi_cmp_ui (s->product, 0); | 335 | if (0 > s->product) |
341 | if (0 > sign) | ||
342 | { | 336 | { |
343 | range = -1; | 337 | range = -1; |
344 | gcry_mpi_sub (value, value, s->product); | 338 | gcry_mpi_set_ui (value, |
339 | -s->product); | ||
345 | } | 340 | } |
346 | else if (0 < sign) | 341 | else if (0 < s->product) |
347 | { | 342 | { |
348 | range = 1; | 343 | range = 1; |
349 | gcry_mpi_add (value, value, s->product); | 344 | gcry_mpi_set_ui (value, |
345 | s->product); | ||
350 | } | 346 | } |
351 | else | 347 | else |
352 | { | 348 | { |
353 | /* result is exactly zero */ | 349 | /* result is exactly zero */ |
354 | range = 0; | 350 | range = 0; |
355 | } | 351 | } |
356 | gcry_mpi_release (s->product); | 352 | if ( (0 != range) && |
357 | s->product = NULL; | 353 | (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, |
358 | 354 | &product_exported, | |
359 | if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD, | 355 | &product_length, |
360 | &product_exported, | 356 | value)))) |
361 | &product_length, | ||
362 | value)))) | ||
363 | { | 357 | { |
364 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc); | 358 | LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, |
359 | "gcry_mpi_scan", | ||
360 | rc); | ||
365 | prepare_client_end_notification (s); | 361 | prepare_client_end_notification (s); |
366 | return; | 362 | return; |
367 | } | 363 | } |
@@ -374,10 +370,13 @@ transmit_client_response (struct AliceServiceSession *s) | |||
374 | msg->product_length = htonl (product_length); | 370 | msg->product_length = htonl (product_length); |
375 | if (NULL != product_exported) | 371 | if (NULL != product_exported) |
376 | { | 372 | { |
377 | GNUNET_memcpy (&msg[1], product_exported, product_length); | 373 | GNUNET_memcpy (&msg[1], |
374 | product_exported, | ||
375 | product_length); | ||
378 | GNUNET_free (product_exported); | 376 | GNUNET_free (product_exported); |
379 | } | 377 | } |
380 | GNUNET_MQ_send (s->client_mq, e); | 378 | GNUNET_MQ_send (s->client_mq, |
379 | e); | ||
381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 380 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
382 | "Sent result to client, session %s has ended!\n", | 381 | "Sent result to client, session %s has ended!\n", |
383 | GNUNET_h2s (&s->session_id)); | 382 | GNUNET_h2s (&s->session_id)); |
@@ -394,7 +393,8 @@ transmit_client_response (struct AliceServiceSession *s) | |||
394 | * @param channel connection to the other end (henceforth invalid) | 393 | * @param channel connection to the other end (henceforth invalid) |
395 | */ | 394 | */ |
396 | static void | 395 | static void |
397 | cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) | 396 | cb_channel_destruction (void *cls, |
397 | const struct GNUNET_CADET_Channel *channel) | ||
398 | { | 398 | { |
399 | struct AliceServiceSession *s = cls; | 399 | struct AliceServiceSession *s = cls; |
400 | 400 | ||
@@ -413,51 +413,6 @@ cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel) | |||
413 | 413 | ||
414 | 414 | ||
415 | /** | 415 | /** |
416 | * Compute our scalar product, done by Alice | ||
417 | * | ||
418 | * @param session the session associated with this computation | ||
419 | * @param prod_g_i_b_i value from Bob | ||
420 | * @param prod_h_i_b_i value from Bob | ||
421 | * @return product as MPI, never NULL | ||
422 | */ | ||
423 | static gcry_mpi_t | ||
424 | compute_scalar_product (struct AliceServiceSession *session, | ||
425 | gcry_mpi_point_t prod_g_i_b_i, | ||
426 | gcry_mpi_point_t prod_h_i_b_i) | ||
427 | { | ||
428 | gcry_mpi_point_t g_i_b_i_a_inv; | ||
429 | gcry_mpi_point_t g_ai_bi; | ||
430 | int ai_bi; | ||
431 | gcry_mpi_t ret; | ||
432 | |||
433 | g_i_b_i_a_inv = | ||
434 | GNUNET_CRYPTO_ecc_pmul_mpi (edc, prod_g_i_b_i, my_privkey_inv); | ||
435 | g_ai_bi = GNUNET_CRYPTO_ecc_add (edc, g_i_b_i_a_inv, prod_h_i_b_i); | ||
436 | gcry_mpi_point_release (g_i_b_i_a_inv); | ||
437 | ai_bi = GNUNET_CRYPTO_ecc_dlog (edc, g_ai_bi); | ||
438 | gcry_mpi_point_release (g_ai_bi); | ||
439 | if (INT_MAX == ai_bi) | ||
440 | { | ||
441 | /* result too big */ | ||
442 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
443 | "Scalar product result out of range\n"); | ||
444 | return NULL; | ||
445 | } | ||
446 | ret = gcry_mpi_new (0); | ||
447 | if (ai_bi > 0) | ||
448 | { | ||
449 | gcry_mpi_set_ui (ret, ai_bi); | ||
450 | } | ||
451 | else | ||
452 | { | ||
453 | gcry_mpi_set_ui (ret, -ai_bi); | ||
454 | gcry_mpi_neg (ret, ret); | ||
455 | } | ||
456 | return ret; | ||
457 | } | ||
458 | |||
459 | |||
460 | /** | ||
461 | * Handle a response we got from another service we wanted to | 416 | * Handle a response we got from another service we wanted to |
462 | * calculate a scalarproduct with. | 417 | * calculate a scalarproduct with. |
463 | * | 418 | * |
@@ -469,8 +424,6 @@ handle_bobs_cryptodata_message (void *cls, | |||
469 | const struct EccBobCryptodataMessage *msg) | 424 | const struct EccBobCryptodataMessage *msg) |
470 | { | 425 | { |
471 | struct AliceServiceSession *s = cls; | 426 | struct AliceServiceSession *s = cls; |
472 | gcry_mpi_point_t prod_g_i_b_i; | ||
473 | gcry_mpi_point_t prod_h_i_b_i; | ||
474 | uint32_t contained; | 427 | uint32_t contained; |
475 | 428 | ||
476 | contained = ntohl (msg->contained_element_count); | 429 | contained = ntohl (msg->contained_element_count); |
@@ -494,16 +447,33 @@ handle_bobs_cryptodata_message (void *cls, | |||
494 | destroy_service_session (s); | 447 | destroy_service_session (s); |
495 | return; | 448 | return; |
496 | } | 449 | } |
497 | |||
498 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 450 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
499 | "Received %u crypto values from Bob\n", | 451 | "Received %u crypto values from Bob\n", |
500 | (unsigned int) contained); | 452 | (unsigned int) contained); |
501 | GNUNET_CADET_receive_done (s->channel); | 453 | GNUNET_CADET_receive_done (s->channel); |
502 | prod_g_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_g_i_b_i); | 454 | { |
503 | prod_h_i_b_i = GNUNET_CRYPTO_ecc_bin_to_point (edc, &msg->prod_h_i_b_i); | 455 | struct GNUNET_CRYPTO_EccPoint g_i_b_i_a_inv; |
504 | s->product = compute_scalar_product (s, prod_g_i_b_i, prod_h_i_b_i); | 456 | struct GNUNET_CRYPTO_EccPoint g_ai_bi; |
505 | gcry_mpi_point_release (prod_g_i_b_i); | 457 | |
506 | gcry_mpi_point_release (prod_h_i_b_i); | 458 | GNUNET_assert ( |
459 | GNUNET_OK == | ||
460 | GNUNET_CRYPTO_ecc_pmul_mpi (&msg->prod_g_i_b_i, | ||
461 | &my_privkey_inv, | ||
462 | &g_i_b_i_a_inv)); | ||
463 | GNUNET_assert ( | ||
464 | GNUNET_OK == | ||
465 | GNUNET_CRYPTO_ecc_add (&g_i_b_i_a_inv, | ||
466 | &msg->prod_h_i_b_i, | ||
467 | &g_ai_bi)); | ||
468 | s->product = GNUNET_CRYPTO_ecc_dlog (edc, | ||
469 | &g_ai_bi); | ||
470 | if (INT_MAX == s->product) | ||
471 | { | ||
472 | /* result too big */ | ||
473 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
474 | "Scalar product result out of range\n"); | ||
475 | } | ||
476 | } | ||
507 | transmit_client_response (s); | 477 | transmit_client_response (s); |
508 | } | 478 | } |
509 | 479 | ||
@@ -517,20 +487,15 @@ handle_bobs_cryptodata_message (void *cls, | |||
517 | * @param value the `struct GNUNET_SCALARPRODUCT_Element *` | 487 | * @param value the `struct GNUNET_SCALARPRODUCT_Element *` |
518 | */ | 488 | */ |
519 | static int | 489 | static int |
520 | copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | 490 | copy_element_cb (void *cls, |
491 | const struct GNUNET_HashCode *key, | ||
492 | void *value) | ||
521 | { | 493 | { |
522 | struct AliceServiceSession *s = cls; | 494 | struct AliceServiceSession *s = cls; |
523 | struct GNUNET_SCALARPRODUCT_Element *e = value; | 495 | struct GNUNET_SCALARPRODUCT_Element *e = value; |
524 | gcry_mpi_t mval; | ||
525 | int64_t val; | ||
526 | 496 | ||
527 | mval = gcry_mpi_new (0); | 497 | s->sorted_elements[s->used_element_count].value = (int64_t) GNUNET_ntohll ( |
528 | val = (int64_t) GNUNET_ntohll (e->value); | 498 | e->value); |
529 | if (0 > val) | ||
530 | gcry_mpi_sub_ui (mval, mval, -val); | ||
531 | else | ||
532 | gcry_mpi_add_ui (mval, mval, val); | ||
533 | s->sorted_elements[s->used_element_count].value = mval; | ||
534 | s->sorted_elements[s->used_element_count].key = &e->key; | 499 | s->sorted_elements[s->used_element_count].key = &e->key; |
535 | s->used_element_count++; | 500 | s->used_element_count++; |
536 | return GNUNET_OK; | 501 | return GNUNET_OK; |
@@ -545,12 +510,14 @@ copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value) | |||
545 | * @return -1 for a < b, 0 for a=b, 1 for a > b. | 510 | * @return -1 for a < b, 0 for a=b, 1 for a > b. |
546 | */ | 511 | */ |
547 | static int | 512 | static int |
548 | element_cmp (const void *a, const void *b) | 513 | element_cmp (const void *a, |
514 | const void *b) | ||
549 | { | 515 | { |
550 | const struct MpiElement *ma = a; | 516 | const struct MpiElement *ma = a; |
551 | const struct MpiElement *mb = b; | 517 | const struct MpiElement *mb = b; |
552 | 518 | ||
553 | return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key); | 519 | return GNUNET_CRYPTO_hash_cmp (ma->key, |
520 | mb->key); | ||
554 | } | 521 | } |
555 | 522 | ||
556 | 523 | ||
@@ -576,9 +543,8 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
576 | struct EccAliceCryptodataMessage *msg; | 543 | struct EccAliceCryptodataMessage *msg; |
577 | struct GNUNET_MQ_Envelope *e; | 544 | struct GNUNET_MQ_Envelope *e; |
578 | struct GNUNET_CRYPTO_EccPoint *payload; | 545 | struct GNUNET_CRYPTO_EccPoint *payload; |
579 | gcry_mpi_t r_ia; | 546 | struct GNUNET_CRYPTO_EccScalar r_ia; |
580 | gcry_mpi_t r_ia_ai; | 547 | struct GNUNET_CRYPTO_EccScalar r_ia_ai; |
581 | unsigned int i; | ||
582 | unsigned int off; | 548 | unsigned int off; |
583 | unsigned int todo_count; | 549 | unsigned int todo_count; |
584 | 550 | ||
@@ -614,31 +580,53 @@ send_alices_cryptodata_message (struct AliceServiceSession *s) | |||
614 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA); | 580 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_ALICE_CRYPTODATA); |
615 | msg->contained_element_count = htonl (todo_count); | 581 | msg->contained_element_count = htonl (todo_count); |
616 | payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1]; | 582 | payload = (struct GNUNET_CRYPTO_EccPoint *) &msg[1]; |
617 | r_ia = gcry_mpi_new (0); | 583 | for (unsigned int i = off; i < off + todo_count; i++) |
618 | r_ia_ai = gcry_mpi_new (0); | ||
619 | for (i = off; i < off + todo_count; i++) | ||
620 | { | 584 | { |
621 | gcry_mpi_t r_i; | 585 | struct GNUNET_CRYPTO_EccScalar r_i; |
622 | gcry_mpi_point_t g_i; | 586 | struct GNUNET_CRYPTO_EccPoint g_i; |
623 | gcry_mpi_point_t h_i; | 587 | struct GNUNET_CRYPTO_EccPoint h_i; |
624 | 588 | ||
625 | r_i = GNUNET_CRYPTO_ecc_random_mod_n (edc); | 589 | /* r_i = random() mod n */ |
626 | g_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_i); | 590 | GNUNET_CRYPTO_ecc_random_mod_n (&r_i); |
591 | /* g_i = g^{r_i} */ | ||
592 | GNUNET_assert (GNUNET_OK == | ||
593 | GNUNET_CRYPTO_ecc_dexp_mpi (&r_i, | ||
594 | &g_i)); | ||
627 | /* r_ia = r_i * a */ | 595 | /* r_ia = r_i * a */ |
628 | gcry_mpi_mul (r_ia, r_i, my_privkey); | 596 | crypto_core_ed25519_scalar_mul (r_ia.v, |
629 | gcry_mpi_release (r_i); | 597 | r_i.v, |
598 | my_privkey.v); | ||
630 | /* r_ia_ai = r_ia + a_i */ | 599 | /* r_ia_ai = r_ia + a_i */ |
631 | gcry_mpi_add (r_ia_ai, r_ia, s->sorted_elements[i].value); | 600 | { |
632 | h_i = GNUNET_CRYPTO_ecc_dexp_mpi (edc, r_ia_ai); | 601 | int64_t val = s->sorted_elements[i].value; |
633 | GNUNET_CRYPTO_ecc_point_to_bin (edc, g_i, &payload[(i - off) * 2]); | 602 | struct GNUNET_CRYPTO_EccScalar vali; |
634 | GNUNET_CRYPTO_ecc_point_to_bin (edc, h_i, &payload[(i - off) * 2 + 1]); | 603 | |
635 | gcry_mpi_point_release (g_i); | 604 | GNUNET_assert (INT64_MIN != val); |
636 | gcry_mpi_point_release (h_i); | 605 | GNUNET_CRYPTO_ecc_scalar_from_int (val > 0 ? val : -val, |
606 | &vali); | ||
607 | if (val > 0) | ||
608 | crypto_core_ed25519_scalar_add (r_ia_ai.v, | ||
609 | r_ia.v, | ||
610 | vali.v); | ||
611 | else | ||
612 | crypto_core_ed25519_scalar_sub (r_ia_ai.v, | ||
613 | r_ia.v, | ||
614 | vali.v); | ||
615 | } | ||
616 | /* h_i = g^{r_ia_ai} */ | ||
617 | GNUNET_assert (GNUNET_OK == | ||
618 | GNUNET_CRYPTO_ecc_dexp_mpi (&r_ia_ai, | ||
619 | &h_i)); | ||
620 | memcpy (&payload[(i - off) * 2], | ||
621 | &g_i, | ||
622 | sizeof (g_i)); | ||
623 | memcpy (&payload[(i - off) * 2 + 1], | ||
624 | &h_i, | ||
625 | sizeof (h_i)); | ||
637 | } | 626 | } |
638 | gcry_mpi_release (r_ia); | ||
639 | gcry_mpi_release (r_ia_ai); | ||
640 | off += todo_count; | 627 | off += todo_count; |
641 | GNUNET_MQ_send (s->cadet_mq, e); | 628 | GNUNET_MQ_send (s->cadet_mq, |
629 | e); | ||
642 | } | 630 | } |
643 | } | 631 | } |
644 | 632 | ||
@@ -740,16 +728,17 @@ cb_intersection_request_alice (void *cls, | |||
740 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 728 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
741 | "Received intersection request from %s!\n", | 729 | "Received intersection request from %s!\n", |
742 | GNUNET_i2s (other_peer)); | 730 | GNUNET_i2s (other_peer)); |
743 | if (0 != GNUNET_memcmp (other_peer, &s->peer)) | 731 | if (0 != GNUNET_memcmp (other_peer, |
732 | &s->peer)) | ||
744 | { | 733 | { |
745 | GNUNET_break_op (0); | 734 | GNUNET_break_op (0); |
746 | return; | 735 | return; |
747 | } | 736 | } |
748 | s->intersection_op = GNUNET_SETI_accept (request, | 737 | s->intersection_op |
749 | (struct | 738 | = GNUNET_SETI_accept (request, |
750 | GNUNET_SETI_Option[]){ { 0 } }, | 739 | (struct GNUNET_SETI_Option[]){ { 0 } }, |
751 | &cb_intersection_element_removed, | 740 | &cb_intersection_element_removed, |
752 | s); | 741 | s); |
753 | if (NULL == s->intersection_op) | 742 | if (NULL == s->intersection_op) |
754 | { | 743 | { |
755 | GNUNET_break (0); | 744 | GNUNET_break (0); |
@@ -757,7 +746,9 @@ cb_intersection_request_alice (void *cls, | |||
757 | prepare_client_end_notification (s); | 746 | prepare_client_end_notification (s); |
758 | return; | 747 | return; |
759 | } | 748 | } |
760 | if (GNUNET_OK != GNUNET_SETI_commit (s->intersection_op, s->intersection_set)) | 749 | if (GNUNET_OK != |
750 | GNUNET_SETI_commit (s->intersection_op, | ||
751 | s->intersection_set)) | ||
761 | { | 752 | { |
762 | GNUNET_break (0); | 753 | GNUNET_break (0); |
763 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; | 754 | s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE; |
@@ -775,12 +766,13 @@ cb_intersection_request_alice (void *cls, | |||
775 | static void | 766 | static void |
776 | client_request_complete_alice (struct AliceServiceSession *s) | 767 | client_request_complete_alice (struct AliceServiceSession *s) |
777 | { | 768 | { |
778 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = | 769 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
779 | { GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, | 770 | GNUNET_MQ_hd_fixed_size (bobs_cryptodata_message, |
780 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, | 771 | GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ECC_BOB_CRYPTODATA, |
781 | struct EccBobCryptodataMessage, | 772 | struct EccBobCryptodataMessage, |
782 | s), | 773 | s), |
783 | GNUNET_MQ_handler_end () }; | 774 | GNUNET_MQ_handler_end () |
775 | }; | ||
784 | struct EccServiceRequestMessage *msg; | 776 | struct EccServiceRequestMessage *msg; |
785 | struct GNUNET_MQ_Envelope *e; | 777 | struct GNUNET_MQ_Envelope *e; |
786 | struct GNUNET_HashCode set_sid; | 778 | struct GNUNET_HashCode set_sid; |
@@ -982,17 +974,17 @@ handle_alice_client_message (void *cls, | |||
982 | s->session_id = msg->session_key; | 974 | s->session_id = msg->session_key; |
983 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; | 975 | elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1]; |
984 | s->intersected_elements = | 976 | s->intersected_elements = |
985 | GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES); | 977 | GNUNET_CONTAINER_multihashmap_create (s->total, |
978 | GNUNET_YES); | ||
986 | s->intersection_set = GNUNET_SETI_create (cfg); | 979 | s->intersection_set = GNUNET_SETI_create (cfg); |
987 | for (uint32_t i = 0; i < contained_count; i++) | 980 | for (uint32_t i = 0; i < contained_count; i++) |
988 | { | 981 | { |
989 | if (0 == GNUNET_ntohll (elements[i].value)) | 982 | if (0 == GNUNET_ntohll (elements[i].value)) |
990 | continue; | 983 | continue; |
991 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); | 984 | elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element); |
992 | GNUNET_memcpy (elem, | 985 | *elem = elements[i]; |
993 | &elements[i], | 986 | if (GNUNET_SYSERR == |
994 | sizeof(struct GNUNET_SCALARPRODUCT_Element)); | 987 | GNUNET_CONTAINER_multihashmap_put ( |
995 | if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put ( | ||
996 | s->intersected_elements, | 988 | s->intersected_elements, |
997 | &elem->key, | 989 | &elem->key, |
998 | elem, | 990 | elem, |
@@ -1006,7 +998,10 @@ handle_alice_client_message (void *cls, | |||
1006 | set_elem.data = &elem->key; | 998 | set_elem.data = &elem->key; |
1007 | set_elem.size = sizeof(elem->key); | 999 | set_elem.size = sizeof(elem->key); |
1008 | set_elem.element_type = 0; | 1000 | set_elem.element_type = 0; |
1009 | GNUNET_SETI_add_element (s->intersection_set, &set_elem, NULL, NULL); | 1001 | GNUNET_SETI_add_element (s->intersection_set, |
1002 | &set_elem, | ||
1003 | NULL, | ||
1004 | NULL); | ||
1010 | s->used_element_count++; | 1005 | s->used_element_count++; |
1011 | } | 1006 | } |
1012 | GNUNET_SERVICE_client_continue (s->client); | 1007 | GNUNET_SERVICE_client_continue (s->client); |
@@ -1017,7 +1012,8 @@ handle_alice_client_message (void *cls, | |||
1017 | "Received partial client request, waiting for more!\n"); | 1012 | "Received partial client request, waiting for more!\n"); |
1018 | return; | 1013 | return; |
1019 | } | 1014 | } |
1020 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Launching computation\n"); | 1015 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1016 | "Launching computation\n"); | ||
1021 | client_request_complete_alice (s); | 1017 | client_request_complete_alice (s); |
1022 | } | 1018 | } |
1023 | 1019 | ||
@@ -1031,7 +1027,8 @@ handle_alice_client_message (void *cls, | |||
1031 | static void | 1027 | static void |
1032 | shutdown_task (void *cls) | 1028 | shutdown_task (void *cls) |
1033 | { | 1029 | { |
1034 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n"); | 1030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1031 | "Shutting down, initiating cleanup.\n"); | ||
1035 | // FIXME: we have to cut our connections to CADET first! | 1032 | // FIXME: we have to cut our connections to CADET first! |
1036 | if (NULL != my_cadet) | 1033 | if (NULL != my_cadet) |
1037 | { | 1034 | { |
@@ -1109,17 +1106,21 @@ run (void *cls, | |||
1109 | struct GNUNET_SERVICE_Handle *service) | 1106 | struct GNUNET_SERVICE_Handle *service) |
1110 | { | 1107 | { |
1111 | cfg = c; | 1108 | cfg = c; |
1112 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, MAX_RAM); | 1109 | edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_RESULT, |
1110 | MAX_RAM); | ||
1113 | /* Select a random 'a' value for Alice */ | 1111 | /* Select a random 'a' value for Alice */ |
1114 | GNUNET_CRYPTO_ecc_rnd_mpi (edc, &my_privkey, &my_privkey_inv); | 1112 | GNUNET_CRYPTO_ecc_rnd_mpi (&my_privkey, |
1113 | &my_privkey_inv); | ||
1115 | my_cadet = GNUNET_CADET_connect (cfg); | 1114 | my_cadet = GNUNET_CADET_connect (cfg); |
1116 | if (NULL == my_cadet) | 1115 | if (NULL == my_cadet) |
1117 | { | 1116 | { |
1118 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n")); | 1117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1118 | _ ("Connect to CADET failed\n")); | ||
1119 | GNUNET_SCHEDULER_shutdown (); | 1119 | GNUNET_SCHEDULER_shutdown (); |
1120 | return; | 1120 | return; |
1121 | } | 1121 | } |
1122 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 1122 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
1123 | NULL); | ||
1123 | } | 1124 | } |
1124 | 1125 | ||
1125 | 1126 | ||