diff options
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct.c')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index e17a3a4d1..b2a84fdb6 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -66,7 +66,7 @@ enum PeerRole | |||
66 | 66 | ||
67 | /** | 67 | /** |
68 | * A scalarproduct session which tracks: | 68 | * A scalarproduct session which tracks: |
69 | * | 69 | * |
70 | * a request form the client to our final response. | 70 | * a request form the client to our final response. |
71 | * or | 71 | * or |
72 | * a request from a service to us(service). | 72 | * a request from a service to us(service). |
@@ -93,7 +93,7 @@ struct ServiceSession | |||
93 | */ | 93 | */ |
94 | struct GNUNET_HashCode key; | 94 | struct GNUNET_HashCode key; |
95 | 95 | ||
96 | /** | 96 | /** |
97 | * state of the session | 97 | * state of the session |
98 | */ | 98 | */ |
99 | enum SessionState state; | 99 | enum SessionState state; |
@@ -127,9 +127,9 @@ struct ServiceSession | |||
127 | * already transferred elements (sent/received) for multipart messages, less or equal than used_element_count for | 127 | * already transferred elements (sent/received) for multipart messages, less or equal than used_element_count for |
128 | */ | 128 | */ |
129 | uint32_t transferred_element_count; | 129 | uint32_t transferred_element_count; |
130 | 130 | ||
131 | /** | 131 | /** |
132 | * how many bytes the mask is long. | 132 | * how many bytes the mask is long. |
133 | * just for convenience so we don't have to re-re-re calculate it each time | 133 | * just for convenience so we don't have to re-re-re calculate it each time |
134 | */ | 134 | */ |
135 | uint32_t mask_length; | 135 | uint32_t mask_length; |
@@ -158,14 +158,14 @@ struct ServiceSession | |||
158 | * Bob's permutation p of R | 158 | * Bob's permutation p of R |
159 | */ | 159 | */ |
160 | gcry_mpi_t * r; | 160 | gcry_mpi_t * r; |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * Bob's permutation q of R | 163 | * Bob's permutation q of R |
164 | */ | 164 | */ |
165 | gcry_mpi_t * r_prime; | 165 | gcry_mpi_t * r_prime; |
166 | 166 | ||
167 | /** | 167 | /** |
168 | * The computed scalar | 168 | * The computed scalar |
169 | */ | 169 | */ |
170 | gcry_mpi_t product; | 170 | gcry_mpi_t product; |
171 | 171 | ||
@@ -245,27 +245,27 @@ static gcry_mpi_t my_lambda; | |||
245 | static gcry_mpi_t my_offset; | 245 | static gcry_mpi_t my_offset; |
246 | 246 | ||
247 | /** | 247 | /** |
248 | * Head of our double linked list for client-requests sent to us. | 248 | * Head of our double linked list for client-requests sent to us. |
249 | * for all of these elements we calculate a scalar product with a remote peer | 249 | * for all of these elements we calculate a scalar product with a remote peer |
250 | * split between service->service and client->service for simplicity | 250 | * split between service->service and client->service for simplicity |
251 | */ | 251 | */ |
252 | static struct ServiceSession * from_client_head; | 252 | static struct ServiceSession * from_client_head; |
253 | /** | 253 | /** |
254 | * Tail of our double linked list for client-requests sent to us. | 254 | * Tail of our double linked list for client-requests sent to us. |
255 | * for all of these elements we calculate a scalar product with a remote peer | 255 | * for all of these elements we calculate a scalar product with a remote peer |
256 | * split between service->service and client->service for simplicity | 256 | * split between service->service and client->service for simplicity |
257 | */ | 257 | */ |
258 | static struct ServiceSession * from_client_tail; | 258 | static struct ServiceSession * from_client_tail; |
259 | 259 | ||
260 | /** | 260 | /** |
261 | * Head of our double linked list for service-requests sent to us. | 261 | * Head of our double linked list for service-requests sent to us. |
262 | * for all of these elements we help the requesting service in calculating a scalar product | 262 | * for all of these elements we help the requesting service in calculating a scalar product |
263 | * split between service->service and client->service for simplicity | 263 | * split between service->service and client->service for simplicity |
264 | */ | 264 | */ |
265 | static struct ServiceSession * from_service_head; | 265 | static struct ServiceSession * from_service_head; |
266 | 266 | ||
267 | /** | 267 | /** |
268 | * Tail of our double linked list for service-requests sent to us. | 268 | * Tail of our double linked list for service-requests sent to us. |
269 | * for all of these elements we help the requesting service in calculating a scalar product | 269 | * for all of these elements we help the requesting service in calculating a scalar product |
270 | * split between service->service and client->service for simplicity | 270 | * split between service->service and client->service for simplicity |
271 | */ | 271 | */ |
@@ -306,7 +306,7 @@ generate_keyset () | |||
306 | GNUNET_assert (0 == gcry_pk_genkey (&key, gen_params)); | 306 | GNUNET_assert (0 == gcry_pk_genkey (&key, gen_params)); |
307 | gcry_sexp_release (gen_params); | 307 | gcry_sexp_release (gen_params); |
308 | 308 | ||
309 | // get n and d of our publickey as MPI | 309 | // get n and d of our publickey as MPI |
310 | tmp_sexp = gcry_sexp_find_token (key, "n", 0); | 310 | tmp_sexp = gcry_sexp_find_token (key, "n", 0); |
311 | GNUNET_assert (tmp_sexp); | 311 | GNUNET_assert (tmp_sexp); |
312 | my_n = gcry_sexp_nth_mpi (tmp_sexp, 1, GCRYMPI_FMT_USG); | 312 | my_n = gcry_sexp_nth_mpi (tmp_sexp, 1, GCRYMPI_FMT_USG); |
@@ -389,7 +389,7 @@ generate_keyset () | |||
389 | gcry_sexp_release (key); | 389 | gcry_sexp_release (key); |
390 | 390 | ||
391 | // offset has to be sufficiently small to allow computation of: | 391 | // offset has to be sufficiently small to allow computation of: |
392 | // m1+m2 mod n == (S + a) + (S + b) mod n, | 392 | // m1+m2 mod n == (S + a) + (S + b) mod n, |
393 | // if we have more complex operations, this factor needs to be lowered | 393 | // if we have more complex operations, this factor needs to be lowered |
394 | my_offset = gcry_mpi_new (KEYBITS / 3); | 394 | my_offset = gcry_mpi_new (KEYBITS / 3); |
395 | gcry_mpi_set_bit (my_offset, KEYBITS / 3); | 395 | gcry_mpi_set_bit (my_offset, KEYBITS / 3); |
@@ -420,7 +420,7 @@ adjust (unsigned char *buf, size_t size, size_t target) | |||
420 | 420 | ||
421 | /** | 421 | /** |
422 | * encrypts an element using the paillier crypto system | 422 | * encrypts an element using the paillier crypto system |
423 | * | 423 | * |
424 | * @param c ciphertext (output) | 424 | * @param c ciphertext (output) |
425 | * @param m plaintext | 425 | * @param m plaintext |
426 | * @param g the public base | 426 | * @param g the public base |
@@ -450,7 +450,7 @@ encrypt_element (gcry_mpi_t c, gcry_mpi_t m, gcry_mpi_t g, gcry_mpi_t n, gcry_mp | |||
450 | 450 | ||
451 | /** | 451 | /** |
452 | * decrypts an element using the paillier crypto system | 452 | * decrypts an element using the paillier crypto system |
453 | * | 453 | * |
454 | * @param m plaintext (output) | 454 | * @param m plaintext (output) |
455 | * @param c the ciphertext | 455 | * @param c the ciphertext |
456 | * @param mu the modifier to correct encryption | 456 | * @param mu the modifier to correct encryption |
@@ -470,7 +470,7 @@ decrypt_element (gcry_mpi_t m, gcry_mpi_t c, gcry_mpi_t mu, gcry_mpi_t lambda, g | |||
470 | 470 | ||
471 | /** | 471 | /** |
472 | * computes the square sum over a vector of a given length. | 472 | * computes the square sum over a vector of a given length. |
473 | * | 473 | * |
474 | * @param vector the vector to encrypt | 474 | * @param vector the vector to encrypt |
475 | * @param length the length of the vector | 475 | * @param length the length of the vector |
476 | * @return an MPI value containing the calculated sum, never NULL | 476 | * @return an MPI value containing the calculated sum, never NULL |
@@ -501,7 +501,7 @@ compute_square_sum (gcry_mpi_t * vector, uint32_t length) | |||
501 | * Primitive callback for copying over a message, as they | 501 | * Primitive callback for copying over a message, as they |
502 | * usually are too complex to be handled in the callback itself. | 502 | * usually are too complex to be handled in the callback itself. |
503 | * clears a session-callback, if a session was handed over and the transmit handle was stored | 503 | * clears a session-callback, if a session was handed over and the transmit handle was stored |
504 | * | 504 | * |
505 | * @param cls the message object | 505 | * @param cls the message object |
506 | * @param size the size of the buffer we got | 506 | * @param size the size of the buffer we got |
507 | * @param buf the buffer to copy the message to | 507 | * @param buf the buffer to copy the message to |
@@ -559,7 +559,7 @@ do_send_message (void *cls, size_t size, void *buf) | |||
559 | 559 | ||
560 | /** | 560 | /** |
561 | * initializes a new vector with fresh MPI values (=0) of a given length | 561 | * initializes a new vector with fresh MPI values (=0) of a given length |
562 | * | 562 | * |
563 | * @param length of the vector to create | 563 | * @param length of the vector to create |
564 | * @return the initialized vector, never NULL | 564 | * @return the initialized vector, never NULL |
565 | */ | 565 | */ |
@@ -577,7 +577,7 @@ initialize_mpi_vector (uint32_t length) | |||
577 | 577 | ||
578 | /** | 578 | /** |
579 | * permutes an MPI vector according to the given permutation vector | 579 | * permutes an MPI vector according to the given permutation vector |
580 | * | 580 | * |
581 | * @param vector the vector to permuted | 581 | * @param vector the vector to permuted |
582 | * @param perm the permutation to use | 582 | * @param perm the permutation to use |
583 | * @param length the length of the vectors | 583 | * @param length the length of the vectors |
@@ -596,7 +596,7 @@ permute_vector (gcry_mpi_t * vector, | |||
596 | // backup old layout | 596 | // backup old layout |
597 | memcpy (tmp, vector, length * sizeof (gcry_mpi_t)); | 597 | memcpy (tmp, vector, length * sizeof (gcry_mpi_t)); |
598 | 598 | ||
599 | // permute vector according to given | 599 | // permute vector according to given |
600 | for (i = 0; i < length; i++) | 600 | for (i = 0; i < length; i++) |
601 | vector[i] = tmp[perm[i]]; | 601 | vector[i] = tmp[perm[i]]; |
602 | 602 | ||
@@ -605,8 +605,8 @@ permute_vector (gcry_mpi_t * vector, | |||
605 | 605 | ||
606 | 606 | ||
607 | /** | 607 | /** |
608 | * Populate a vector with random integer values and convert them to | 608 | * Populate a vector with random integer values and convert them to |
609 | * | 609 | * |
610 | * @param length the length of the vector we must generate | 610 | * @param length the length of the vector we must generate |
611 | * @return an array of MPI values with random values | 611 | * @return an array of MPI values with random values |
612 | */ | 612 | */ |
@@ -636,12 +636,12 @@ generate_random_vector (uint32_t length) | |||
636 | 636 | ||
637 | 637 | ||
638 | /** | 638 | /** |
639 | * Finds a not terminated client/service session in the | 639 | * Finds a not terminated client/service session in the |
640 | * given DLL based on session key, element count and state. | 640 | * given DLL based on session key, element count and state. |
641 | * | 641 | * |
642 | * @param tail - the tail of the DLL | 642 | * @param tail - the tail of the DLL |
643 | * @param my - the session to compare it to | 643 | * @param my - the session to compare it to |
644 | * @return a pointer to a matching session, | 644 | * @return a pointer to a matching session, |
645 | * else NULL | 645 | * else NULL |
646 | */ | 646 | */ |
647 | static struct ServiceSession * | 647 | static struct ServiceSession * |
@@ -702,9 +702,9 @@ free_session (struct ServiceSession * session) | |||
702 | 702 | ||
703 | 703 | ||
704 | /** | 704 | /** |
705 | * A client disconnected. | 705 | * A client disconnected. |
706 | * | 706 | * |
707 | * Remove the associated session(s), release datastructures | 707 | * Remove the associated session(s), release datastructures |
708 | * and cancel pending outgoing transmissions to the client. | 708 | * and cancel pending outgoing transmissions to the client. |
709 | * if the session has not yet completed, we also cancel Alice's request to Bob. | 709 | * if the session has not yet completed, we also cancel Alice's request to Bob. |
710 | * | 710 | * |
@@ -755,10 +755,10 @@ handle_client_disconnect (void *cls, | |||
755 | 755 | ||
756 | /** | 756 | /** |
757 | * Notify the client that the session has succeeded or failed completely. | 757 | * Notify the client that the session has succeeded or failed completely. |
758 | * This message gets sent to | 758 | * This message gets sent to |
759 | * * alice's client if bob disconnected or to | 759 | * * alice's client if bob disconnected or to |
760 | * * bob's client if the operation completed or alice disconnected | 760 | * * bob's client if the operation completed or alice disconnected |
761 | * | 761 | * |
762 | * @param client_session the associated client session | 762 | * @param client_session the associated client session |
763 | * @return GNUNET_NO, if we could not notify the client | 763 | * @return GNUNET_NO, if we could not notify the client |
764 | * GNUNET_YES if we notified it. | 764 | * GNUNET_YES if we notified it. |
@@ -777,7 +777,7 @@ prepare_client_end_notification (void * cls, | |||
777 | memcpy (&msg->key, &session->key, sizeof (struct GNUNET_HashCode)); | 777 | memcpy (&msg->key, &session->key, sizeof (struct GNUNET_HashCode)); |
778 | memcpy (&msg->peer, &session->peer, sizeof ( struct GNUNET_PeerIdentity)); | 778 | memcpy (&msg->peer, &session->peer, sizeof ( struct GNUNET_PeerIdentity)); |
779 | msg->header.size = htons (sizeof (struct GNUNET_SCALARPRODUCT_client_response)); | 779 | msg->header.size = htons (sizeof (struct GNUNET_SCALARPRODUCT_client_response)); |
780 | // signal error if not signalized, positive result-range field but zero length. | 780 | // signal error if not signalized, positive result-range field but zero length. |
781 | msg->product_length = htonl (0); | 781 | msg->product_length = htonl (0); |
782 | msg->range = (session->state == FINALIZED) ? 0 : -1; | 782 | msg->range = (session->state == FINALIZED) ? 0 : -1; |
783 | 783 | ||
@@ -807,13 +807,13 @@ prepare_client_end_notification (void * cls, | |||
807 | 807 | ||
808 | /** | 808 | /** |
809 | * Bob executes: | 809 | * Bob executes: |
810 | * generates the response message to be sent to alice after computing | 810 | * generates the response message to be sent to alice after computing |
811 | * the values (1), (2), S and S' | 811 | * the values (1), (2), S and S' |
812 | * (1)[]: $E_A(a_{pi(i)}) times E_A(- r_{pi(i)} - b_{pi(i)}) &= E_A(a_{pi(i)} - r_{pi(i)} - b_{pi(i)})$ | 812 | * (1)[]: $E_A(a_{pi(i)}) times E_A(- r_{pi(i)} - b_{pi(i)}) &= E_A(a_{pi(i)} - r_{pi(i)} - b_{pi(i)})$ |
813 | * (2)[]: $E_A(a_{pi'(i)}) times E_A(- r_{pi'(i)}) &= E_A(a_{pi'(i)} - r_{pi'(i)})$ | 813 | * (2)[]: $E_A(a_{pi'(i)}) times E_A(- r_{pi'(i)}) &= E_A(a_{pi'(i)} - r_{pi'(i)})$ |
814 | * S: $S := E_A(sum (r_i + b_i)^2)$ | 814 | * S: $S := E_A(sum (r_i + b_i)^2)$ |
815 | * S': $S' := E_A(sum r_i^2)$ | 815 | * S': $S' := E_A(sum r_i^2)$ |
816 | * | 816 | * |
817 | * @param r (1)[]: $E_A(a_{pi(i)}) times E_A(- r_{pi(i)} - b_{pi(i)}) &= E_A(a_{pi(i)} - r_{pi(i)} - b_{pi(i)})$ | 817 | * @param r (1)[]: $E_A(a_{pi(i)}) times E_A(- r_{pi(i)} - b_{pi(i)}) &= E_A(a_{pi(i)} - r_{pi(i)} - b_{pi(i)})$ |
818 | * @param r_prime (2)[]: $E_A(a_{pi'(i)}) times E_A(- r_{pi'(i)}) &= E_A(a_{pi'(i)} - r_{pi'(i)})$ | 818 | * @param r_prime (2)[]: $E_A(a_{pi'(i)}) times E_A(- r_{pi'(i)}) &= E_A(a_{pi'(i)} - r_{pi'(i)})$ |
819 | * @param s S: $S := E_A(sum (r_i + b_i)^2)$ | 819 | * @param s S: $S := E_A(sum (r_i + b_i)^2)$ |
@@ -847,7 +847,7 @@ prepare_service_response (gcry_mpi_t s, | |||
847 | else { | 847 | else { |
848 | request->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - msg_length) / (PAILLIER_ELEMENT_LENGTH * 2); | 848 | request->transferred_element_count = (GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - msg_length) / (PAILLIER_ELEMENT_LENGTH * 2); |
849 | } | 849 | } |
850 | 850 | ||
851 | msg = GNUNET_malloc (msg_length); | 851 | msg = GNUNET_malloc (msg_length); |
852 | 852 | ||
853 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_TO_ALICE); | 853 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_TO_ALICE); |
@@ -861,7 +861,7 @@ prepare_service_response (gcry_mpi_t s, | |||
861 | element_exported = GNUNET_malloc (PAILLIER_ELEMENT_LENGTH); | 861 | element_exported = GNUNET_malloc (PAILLIER_ELEMENT_LENGTH); |
862 | // 4 times the same logics with slight variations. | 862 | // 4 times the same logics with slight variations. |
863 | // doesn't really justify having 2 functions for that | 863 | // doesn't really justify having 2 functions for that |
864 | // so i put it into blocks to enhance readability | 864 | // so i put it into blocks to enhance readability |
865 | // convert s | 865 | // convert s |
866 | memset (element_exported, 0, PAILLIER_ELEMENT_LENGTH); | 866 | memset (element_exported, 0, PAILLIER_ELEMENT_LENGTH); |
867 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, | 867 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, |
@@ -907,7 +907,7 @@ prepare_service_response (gcry_mpi_t s, | |||
907 | memcpy (current, element_exported, PAILLIER_ELEMENT_LENGTH); | 907 | memcpy (current, element_exported, PAILLIER_ELEMENT_LENGTH); |
908 | current += PAILLIER_ELEMENT_LENGTH; | 908 | current += PAILLIER_ELEMENT_LENGTH; |
909 | } | 909 | } |
910 | 910 | ||
911 | GNUNET_free (element_exported); | 911 | GNUNET_free (element_exported); |
912 | for (i = 0; i < request->transferred_element_count; i++) | 912 | for (i = 0; i < request->transferred_element_count; i++) |
913 | { | 913 | { |
@@ -916,7 +916,7 @@ prepare_service_response (gcry_mpi_t s, | |||
916 | } | 916 | } |
917 | gcry_mpi_release (s); | 917 | gcry_mpi_release (s); |
918 | gcry_mpi_release (s_prime); | 918 | gcry_mpi_release (s_prime); |
919 | 919 | ||
920 | request->msg = (struct GNUNET_MessageHeader *) msg; | 920 | request->msg = (struct GNUNET_MessageHeader *) msg; |
921 | request->service_transmit_handle = | 921 | request->service_transmit_handle = |
922 | GNUNET_MESH_notify_transmit_ready (request->tunnel, | 922 | GNUNET_MESH_notify_transmit_ready (request->tunnel, |
@@ -942,19 +942,19 @@ prepare_service_response (gcry_mpi_t s, | |||
942 | else | 942 | else |
943 | //singlepart | 943 | //singlepart |
944 | request->state = FINALIZED; | 944 | request->state = FINALIZED; |
945 | 945 | ||
946 | return GNUNET_OK; | 946 | return GNUNET_OK; |
947 | } | 947 | } |
948 | 948 | ||
949 | 949 | ||
950 | /** | 950 | /** |
951 | * executed by bob: | 951 | * executed by bob: |
952 | * compute the values | 952 | * compute the values |
953 | * (1)[]: $E_A(a_{\pi(i)}) \otimes E_A(- r_{\pi(i)} - b_{\pi(i)}) &= E_A(a_{\pi(i)} - r_{\pi(i)} - b_{\pi(i)})$ | 953 | * (1)[]: $E_A(a_{\pi(i)}) \otimes E_A(- r_{\pi(i)} - b_{\pi(i)}) &= E_A(a_{\pi(i)} - r_{\pi(i)} - b_{\pi(i)})$ |
954 | * (2)[]: $E_A(a_{\pi'(i)}) \otimes E_A(- r_{\pi'(i)}) &= E_A(a_{\pi'(i)} - r_{\pi'(i)})$ | 954 | * (2)[]: $E_A(a_{\pi'(i)}) \otimes E_A(- r_{\pi'(i)}) &= E_A(a_{\pi'(i)} - r_{\pi'(i)})$ |
955 | * S: $S := E_A(\sum (r_i + b_i)^2)$ | 955 | * S: $S := E_A(\sum (r_i + b_i)^2)$ |
956 | * S': $S' := E_A(\sum r_i^2)$ | 956 | * S': $S' := E_A(\sum r_i^2)$ |
957 | * | 957 | * |
958 | * @param request the requesting session + bob's requesting peer | 958 | * @param request the requesting session + bob's requesting peer |
959 | * @param response the responding session + bob's client handle | 959 | * @param response the responding session + bob's client handle |
960 | * @return GNUNET_SYSERR if the computation failed | 960 | * @return GNUNET_SYSERR if the computation failed |
@@ -1063,7 +1063,7 @@ compute_service_response (struct ServiceSession * request, | |||
1063 | r = initialize_mpi_vector (count); | 1063 | r = initialize_mpi_vector (count); |
1064 | r_prime = initialize_mpi_vector (count); | 1064 | r_prime = initialize_mpi_vector (count); |
1065 | 1065 | ||
1066 | // copy the REFERNCES of a, b and r into aq and bq. we will not change | 1066 | // copy the REFERNCES of a, b and r into aq and bq. we will not change |
1067 | // those values, thus we can work with the references | 1067 | // those values, thus we can work with the references |
1068 | memcpy (a_pi, request->a, sizeof (gcry_mpi_t) * count); | 1068 | memcpy (a_pi, request->a, sizeof (gcry_mpi_t) * count); |
1069 | memcpy (a_pi_prime, request->a, sizeof (gcry_mpi_t) * count); | 1069 | memcpy (a_pi_prime, request->a, sizeof (gcry_mpi_t) * count); |
@@ -1080,7 +1080,7 @@ compute_service_response (struct ServiceSession * request, | |||
1080 | 1080 | ||
1081 | // encrypt the element | 1081 | // encrypt the element |
1082 | // for the sake of readability I decided to have dedicated permutation | 1082 | // for the sake of readability I decided to have dedicated permutation |
1083 | // vectors, which get rid of all the lookups in p/q. | 1083 | // vectors, which get rid of all the lookups in p/q. |
1084 | // however, ap/aq are not absolutely necessary but are just abstraction | 1084 | // however, ap/aq are not absolutely necessary but are just abstraction |
1085 | // Calculate Kp = E(S + a_pi) (+) E(S - r_pi - b_pi) | 1085 | // Calculate Kp = E(S + a_pi) (+) E(S - r_pi - b_pi) |
1086 | for (i = 0; i < count; i++) | 1086 | for (i = 0; i < count; i++) |
@@ -1109,7 +1109,7 @@ compute_service_response (struct ServiceSession * request, | |||
1109 | } | 1109 | } |
1110 | GNUNET_free (a_pi_prime); | 1110 | GNUNET_free (a_pi_prime); |
1111 | GNUNET_free (rand_pi_prime); | 1111 | GNUNET_free (rand_pi_prime); |
1112 | 1112 | ||
1113 | request->r = r; | 1113 | request->r = r; |
1114 | request->r_prime = r_prime; | 1114 | request->r_prime = r_prime; |
1115 | 1115 | ||
@@ -1157,7 +1157,7 @@ except: | |||
1157 | 1157 | ||
1158 | /** | 1158 | /** |
1159 | * Executed by Alice, fills in a service-request message and sends it to the given peer | 1159 | * Executed by Alice, fills in a service-request message and sends it to the given peer |
1160 | * | 1160 | * |
1161 | * @param session the session associated with this request, then also holds the CORE-handle | 1161 | * @param session the session associated with this request, then also holds the CORE-handle |
1162 | * @return #GNUNET_SYSERR if we could not send the message | 1162 | * @return #GNUNET_SYSERR if we could not send the message |
1163 | * #GNUNET_NO if the message was too large | 1163 | * #GNUNET_NO if the message was too large |
@@ -1226,7 +1226,7 @@ prepare_service_request (void *cls, | |||
1226 | { | 1226 | { |
1227 | if (session->transferred_element_count <= j) | 1227 | if (session->transferred_element_count <= j) |
1228 | break; //reached end of this message, can't include more | 1228 | break; //reached end of this message, can't include more |
1229 | 1229 | ||
1230 | memset(element_exported, 0, PAILLIER_ELEMENT_LENGTH); | 1230 | memset(element_exported, 0, PAILLIER_ELEMENT_LENGTH); |
1231 | value = session->vector[i] >= 0 ? session->vector[i] : -session->vector[i]; | 1231 | value = session->vector[i] >= 0 ? session->vector[i] : -session->vector[i]; |
1232 | 1232 | ||
@@ -1287,10 +1287,10 @@ prepare_service_request (void *cls, | |||
1287 | 1287 | ||
1288 | 1288 | ||
1289 | /** | 1289 | /** |
1290 | * Handler for a client request message. | 1290 | * Handler for a client request message. |
1291 | * Can either be type A or B | 1291 | * Can either be type A or B |
1292 | * A: request-initiation to compute a scalar product with a peer | 1292 | * A: request-initiation to compute a scalar product with a peer |
1293 | * B: response role, keep the values + session and wait for a matching session or process a waiting request | 1293 | * B: response role, keep the values + session and wait for a matching session or process a waiting request |
1294 | * | 1294 | * |
1295 | * @param cls closure | 1295 | * @param cls closure |
1296 | * @param client identification of the client | 1296 | * @param client identification of the client |
@@ -1454,7 +1454,7 @@ handle_client_request (void *cls, | |||
1454 | GNUNET_SERVER_client_set_user_context (client, session); | 1454 | GNUNET_SERVER_client_set_user_context (client, session); |
1455 | GNUNET_CONTAINER_DLL_insert (from_client_head, from_client_tail, session); | 1455 | GNUNET_CONTAINER_DLL_insert (from_client_head, from_client_tail, session); |
1456 | 1456 | ||
1457 | //check if service queue contains a matching request | 1457 | //check if service queue contains a matching request |
1458 | requesting_session = find_matching_session (from_service_tail, | 1458 | requesting_session = find_matching_session (from_service_tail, |
1459 | &session->key, | 1459 | &session->key, |
1460 | session->element_count, | 1460 | session->element_count, |
@@ -1480,7 +1480,7 @@ handle_client_request (void *cls, | |||
1480 | 1480 | ||
1481 | 1481 | ||
1482 | /** | 1482 | /** |
1483 | * Function called for inbound tunnels. | 1483 | * Function called for inbound tunnels. |
1484 | * | 1484 | * |
1485 | * @param cls closure | 1485 | * @param cls closure |
1486 | * @param tunnel new handle to the tunnel | 1486 | * @param tunnel new handle to the tunnel |
@@ -1507,8 +1507,8 @@ tunnel_incoming_handler (void *cls, | |||
1507 | 1507 | ||
1508 | /** | 1508 | /** |
1509 | * Function called whenever a tunnel is destroyed. Should clean up | 1509 | * Function called whenever a tunnel is destroyed. Should clean up |
1510 | * any associated state. | 1510 | * any associated state. |
1511 | * | 1511 | * |
1512 | * It must NOT call GNUNET_MESH_tunnel_destroy on the tunnel. | 1512 | * It must NOT call GNUNET_MESH_tunnel_destroy on the tunnel. |
1513 | * | 1513 | * |
1514 | * @param cls closure (set from GNUNET_MESH_connect) | 1514 | * @param cls closure (set from GNUNET_MESH_connect) |
@@ -1561,7 +1561,7 @@ tunnel_destruction_handler (void *cls, | |||
1561 | NULL, NULL); | 1561 | NULL, NULL); |
1562 | free_session (session); | 1562 | free_session (session); |
1563 | 1563 | ||
1564 | // the client has to check if it was waiting for a result | 1564 | // the client has to check if it was waiting for a result |
1565 | // or if it was a responder, no point in adding more statefulness | 1565 | // or if it was a responder, no point in adding more statefulness |
1566 | if (client_session && (!do_shutdown)) | 1566 | if (client_session && (!do_shutdown)) |
1567 | { | 1567 | { |
@@ -1576,15 +1576,15 @@ tunnel_destruction_handler (void *cls, | |||
1576 | 1576 | ||
1577 | /** | 1577 | /** |
1578 | * Compute our scalar product, done by Alice | 1578 | * Compute our scalar product, done by Alice |
1579 | * | 1579 | * |
1580 | * @param session - the session associated with this computation | 1580 | * @param session - the session associated with this computation |
1581 | * @param kp - (1) from the protocol definition: | 1581 | * @param kp - (1) from the protocol definition: |
1582 | * $E_A(a_{\pi(i)}) \otimes E_A(- r_{\pi(i)} - b_{\pi(i)}) &= E_A(a_{\pi(i)} - r_{\pi(i)} - b_{\pi(i)})$ | 1582 | * $E_A(a_{\pi(i)}) \otimes E_A(- r_{\pi(i)} - b_{\pi(i)}) &= E_A(a_{\pi(i)} - r_{\pi(i)} - b_{\pi(i)})$ |
1583 | * @param kq - (2) from the protocol definition: | 1583 | * @param kq - (2) from the protocol definition: |
1584 | * $E_A(a_{\pi'(i)}) \otimes E_A(- r_{\pi'(i)}) &= E_A(a_{\pi'(i)} - r_{\pi'(i)})$ | 1584 | * $E_A(a_{\pi'(i)}) \otimes E_A(- r_{\pi'(i)}) &= E_A(a_{\pi'(i)} - r_{\pi'(i)})$ |
1585 | * @param s - S from the protocol definition: | 1585 | * @param s - S from the protocol definition: |
1586 | * $S := E_A(\sum (r_i + b_i)^2)$ | 1586 | * $S := E_A(\sum (r_i + b_i)^2)$ |
1587 | * @param stick - S' from the protocol definition: | 1587 | * @param stick - S' from the protocol definition: |
1588 | * $S' := E_A(\sum r_i^2)$ | 1588 | * $S' := E_A(\sum r_i^2)$ |
1589 | * @return product as MPI, never NULL | 1589 | * @return product as MPI, never NULL |
1590 | */ | 1590 | */ |
@@ -1667,8 +1667,8 @@ compute_scalar_product (struct ServiceSession * session, | |||
1667 | 1667 | ||
1668 | /** | 1668 | /** |
1669 | * prepare the response we will send to alice or bobs' clients. | 1669 | * prepare the response we will send to alice or bobs' clients. |
1670 | * in Bobs case the product will be NULL. | 1670 | * in Bobs case the product will be NULL. |
1671 | * | 1671 | * |
1672 | * @param session the session associated with our client. | 1672 | * @param session the session associated with our client. |
1673 | */ | 1673 | */ |
1674 | static void | 1674 | static void |
@@ -1873,7 +1873,7 @@ handle_service_request (void *cls, | |||
1873 | 1873 | ||
1874 | current += pk_length; | 1874 | current += pk_length; |
1875 | 1875 | ||
1876 | //check if service queue contains a matching request | 1876 | //check if service queue contains a matching request |
1877 | needed_state = CLIENT_RESPONSE_RECEIVED; | 1877 | needed_state = CLIENT_RESPONSE_RECEIVED; |
1878 | responder_session = find_matching_session (from_client_tail, | 1878 | responder_session = find_matching_session (from_client_tail, |
1879 | &session->key, | 1879 | &session->key, |