summaryrefslogtreecommitdiff
path: root/src/scalarproduct/gnunet-service-scalarproduct_alice.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalarproduct/gnunet-service-scalarproduct_alice.c')
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct_alice.c379
1 files changed, 168 insertions, 211 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct_alice.c b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
index 18c5cc49a..e138876f5 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct_alice.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct_alice.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -36,7 +36,8 @@
#include "scalarproduct.h"
#include "gnunet-service-scalarproduct.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__)
+#define LOG(kind, ...) \
+ GNUNET_log_from (kind, "scalarproduct-alice", __VA_ARGS__)
/**
* An encrypted element key-value pair.
@@ -185,7 +186,6 @@ struct AliceServiceSession
* doing harm.
*/
int in_destroy;
-
};
@@ -224,9 +224,7 @@ static struct GNUNET_CADET_Handle *my_cadet;
* @return #GNUNET_OK (continue to iterate)
*/
static int
-free_element_cb (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+free_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct GNUNET_SCALARPRODUCT_Element *e = value;
@@ -283,7 +281,7 @@ destroy_service_session (struct AliceServiceSession *s)
}
if (NULL != s->sorted_elements)
{
- for (unsigned int i=0;i<s->used_element_count;i++)
+ for (unsigned int i = 0; i < s->used_element_count; i++)
gcry_mpi_release (s->sorted_elements[i].value);
GNUNET_free (s->sorted_elements);
s->sorted_elements = NULL;
@@ -321,16 +319,15 @@ prepare_client_end_notification (struct AliceServiceSession *session)
if (NULL == session->client_mq)
return; /* no client left to be notified */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending session-end notification with status %d to client for session %s\n",
- session->status,
- GNUNET_h2s (&session->session_id));
- e = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Sending session-end notification with status %d to client for session %s\n",
+ session->status,
+ GNUNET_h2s (&session->session_id));
+ e = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SCALARPRODUCT_RESULT);
msg->product_length = htonl (0);
msg->status = htonl (session->status);
- GNUNET_MQ_send (session->client_mq,
- e);
+ GNUNET_MQ_send (session->client_mq, e);
}
@@ -363,9 +360,7 @@ transmit_client_response (struct AliceServiceSession *s)
if (0 > sign)
{
range = -1;
- gcry_mpi_sub (value,
- value,
- s->product);
+ gcry_mpi_sub (value, value, s->product);
}
else if (0 < sign)
{
@@ -380,15 +375,12 @@ transmit_client_response (struct AliceServiceSession *s)
gcry_mpi_release (s->product);
s->product = NULL;
- if ( (0 != range) &&
- (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD,
- &product_exported,
- &product_length,
- value))))
+ if ((0 != range) && (0 != (rc = gcry_mpi_aprint (GCRYMPI_FMT_STD,
+ &product_exported,
+ &product_length,
+ value))))
{
- LOG_GCRY (GNUNET_ERROR_TYPE_ERROR,
- "gcry_mpi_scan",
- rc);
+ LOG_GCRY (GNUNET_ERROR_TYPE_ERROR, "gcry_mpi_scan", rc);
prepare_client_end_notification (s);
return;
}
@@ -401,20 +393,16 @@ transmit_client_response (struct AliceServiceSession *s)
msg->product_length = htonl (product_length);
if (NULL != product_exported)
{
- GNUNET_memcpy (&msg[1],
- product_exported,
- product_length);
+ GNUNET_memcpy (&msg[1], product_exported, product_length);
GNUNET_free (product_exported);
}
- GNUNET_MQ_send (s->client_mq,
- e);
+ GNUNET_MQ_send (s->client_mq, e);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sent result to client, session %s has ended!\n",
GNUNET_h2s (&s->session_id));
}
-
/**
* Function called whenever a channel is destroyed. Should clean up
* any associated state.
@@ -425,8 +413,7 @@ transmit_client_response (struct AliceServiceSession *s)
* @param channel connection to the other end (henceforth invalid)
*/
static void
-cb_channel_destruction (void *cls,
- const struct GNUNET_CADET_Channel *channel)
+cb_channel_destruction (void *cls, const struct GNUNET_CADET_Channel *channel)
{
struct AliceServiceSession *s = cls;
@@ -479,8 +466,7 @@ compute_square_sum_mpi_elements (const struct MpiElement *vector,
* @return an MPI value containing the calculated sum, never NULL
*/
static gcry_mpi_t
-compute_square_sum (const gcry_mpi_t *vector,
- uint32_t length)
+compute_square_sum (const gcry_mpi_t *vector, uint32_t length)
{
gcry_mpi_t elem;
gcry_mpi_t sum;
@@ -531,28 +517,19 @@ compute_scalar_product (struct AliceServiceSession *session)
&my_pubkey,
&session->r[i],
r[i]);
- gcry_mpi_sub (r[i],
- r[i],
- my_offset);
- gcry_mpi_sub (r[i],
- r[i],
- my_offset);
+ gcry_mpi_sub (r[i], r[i], my_offset);
+ gcry_mpi_sub (r[i], r[i], my_offset);
r_prime[i] = gcry_mpi_new (0);
GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
&my_pubkey,
&session->r_prime[i],
r_prime[i]);
- gcry_mpi_sub (r_prime[i],
- r_prime[i],
- my_offset);
- gcry_mpi_sub (r_prime[i],
- r_prime[i],
- my_offset);
+ gcry_mpi_sub (r_prime[i], r_prime[i], my_offset);
+ gcry_mpi_sub (r_prime[i], r_prime[i], my_offset);
}
// calculate t = sum(ai)
- t = compute_square_sum_mpi_elements (session->sorted_elements,
- count);
+ t = compute_square_sum_mpi_elements (session->sorted_elements, count);
// calculate U
u = gcry_mpi_new (0);
tmp = compute_square_sum (r, count);
@@ -570,10 +547,7 @@ compute_scalar_product (struct AliceServiceSession *session)
GNUNET_assert (s_prime = gcry_mpi_new (0));
// compute P
- GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
- &my_pubkey,
- &session->s,
- s);
+ GNUNET_CRYPTO_paillier_decrypt (&my_privkey, &my_pubkey, &session->s, s);
GNUNET_CRYPTO_paillier_decrypt (&my_privkey,
&my_pubkey,
&session->s_prime,
@@ -627,8 +601,9 @@ compute_scalar_product (struct AliceServiceSession *session)
* #GNUNET_SYSERR to close it (signal serious error)
*/
static int
-check_bobs_cryptodata_multipart (void *cls,
- const struct BobCryptodataMultipartMessage *msg)
+check_bobs_cryptodata_multipart (
+ void *cls,
+ const struct BobCryptodataMultipartMessage *msg)
{
struct AliceServiceSession *s = cls;
uint32_t contained;
@@ -637,10 +612,11 @@ check_bobs_cryptodata_multipart (void *cls,
msg_size = ntohs (msg->header.size);
contained = ntohl (msg->contained_element_count);
- required_size = sizeof (struct BobCryptodataMultipartMessage)
- + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
- if ( (required_size != msg_size) ||
- (s->cadet_received_element_count + contained > s->used_element_count) )
+ required_size =
+ sizeof (struct BobCryptodataMultipartMessage) +
+ 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
+ if ((required_size != msg_size) ||
+ (s->cadet_received_element_count + contained > s->used_element_count))
{
GNUNET_break (0);
return GNUNET_SYSERR;
@@ -656,8 +632,9 @@ check_bobs_cryptodata_multipart (void *cls,
* @param msg the actual message
*/
static void
-handle_bobs_cryptodata_multipart (void *cls,
- const struct BobCryptodataMultipartMessage *msg)
+handle_bobs_cryptodata_multipart (
+ void *cls,
+ const struct BobCryptodataMultipartMessage *msg)
{
struct AliceServiceSession *s = cls;
const struct GNUNET_CRYPTO_PaillierCiphertext *payload;
@@ -710,12 +687,12 @@ check_bobs_cryptodata_message (void *cls,
msg_size = ntohs (msg->header.size);
contained = ntohl (msg->contained_element_count);
- required_size = sizeof (struct BobCryptodataMessage)
- + 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext)
- + 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
- if ( (msg_size != required_size) ||
- (contained > UINT16_MAX) ||
- (s->used_element_count < contained) )
+ required_size =
+ sizeof (struct BobCryptodataMessage) +
+ 2 * contained * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext) +
+ 2 * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext);
+ if ((msg_size != required_size) || (contained > UINT16_MAX) ||
+ (s->used_element_count < contained))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -800,9 +777,7 @@ handle_bobs_cryptodata_message (void *cls,
* @param value the `struct GNUNET_SCALARPRODUCT_Element *`
*/
static int
-copy_element_cb (void *cls,
- const struct GNUNET_HashCode *key,
- void *value)
+copy_element_cb (void *cls, const struct GNUNET_HashCode *key, void *value)
{
struct AliceServiceSession *s = cls;
struct GNUNET_SCALARPRODUCT_Element *e = value;
@@ -815,8 +790,8 @@ copy_element_cb (void *cls,
gcry_mpi_sub_ui (mval, mval, -val);
else
gcry_mpi_add_ui (mval, mval, val);
- s->sorted_elements [s->used_element_count].value = mval;
- s->sorted_elements [s->used_element_count].key = &e->key;
+ s->sorted_elements[s->used_element_count].value = mval;
+ s->sorted_elements[s->used_element_count].key = &e->key;
s->used_element_count++;
return GNUNET_OK;
}
@@ -830,14 +805,12 @@ copy_element_cb (void *cls,
* @return -1 for a < b, 0 for a=b, 1 for a > b.
*/
static int
-element_cmp (const void *a,
- const void *b)
+element_cmp (const void *a, const void *b)
{
const struct MpiElement *ma = a;
const struct MpiElement *mb = b;
- return GNUNET_CRYPTO_hash_cmp (ma->key,
- mb->key);
+ return GNUNET_CRYPTO_hash_cmp (ma->key, mb->key);
}
@@ -845,7 +818,10 @@ element_cmp (const void *a,
* Maximum number of elements we can put into a single cryptodata
* message
*/
-#define ELEMENT_CAPACITY ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - sizeof (struct AliceCryptodataMessage)) / sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
+#define ELEMENT_CAPACITY \
+ ((GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - 1 - \
+ sizeof (struct AliceCryptodataMessage)) / \
+ sizeof (struct GNUNET_CRYPTO_PaillierCiphertext))
/**
@@ -865,9 +841,9 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
gcry_mpi_t a;
uint32_t off;
- s->sorted_elements
- = GNUNET_malloc (GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) *
- sizeof (struct MpiElement));
+ s->sorted_elements = GNUNET_malloc (
+ GNUNET_CONTAINER_multihashmap_size (s->intersected_elements) *
+ sizeof (struct MpiElement));
s->used_element_count = 0;
GNUNET_CONTAINER_multihashmap_iterate (s->intersected_elements,
&copy_element_cb,
@@ -890,29 +866,24 @@ send_alices_cryptodata_message (struct AliceServiceSession *s)
(unsigned int) todo_count,
(unsigned int) s->used_element_count);
- e = GNUNET_MQ_msg_extra (msg,
- todo_count * sizeof (struct GNUNET_CRYPTO_PaillierCiphertext),
- GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA);
- GNUNET_MQ_env_set_options(e,
- GNUNET_MQ_PREF_RELIABLE);
+ e =
+ GNUNET_MQ_msg_extra (msg,
+ todo_count *
+ sizeof (struct GNUNET_CRYPTO_PaillierCiphertext),
+ GNUNET_MESSAGE_TYPE_SCALARPRODUCT_ALICE_CRYPTODATA);
msg->contained_element_count = htonl (todo_count);
payload = (struct GNUNET_CRYPTO_PaillierCiphertext *) &msg[1];
a = gcry_mpi_new (0);
for (i = off; i < off + todo_count; i++)
{
- gcry_mpi_add (a,
- s->sorted_elements[i].value,
- my_offset);
- GNUNET_assert (3 ==
- GNUNET_CRYPTO_paillier_encrypt (&my_pubkey,
- a,
- 3,
- &payload[i - off]));
+ gcry_mpi_add (a, s->sorted_elements[i].value, my_offset);
+ GNUNET_assert (
+ 3 ==
+ GNUNET_CRYPTO_paillier_encrypt (&my_pubkey, a, 3, &payload[i - off]));
}
gcry_mpi_release (a);
off += todo_count;
- GNUNET_MQ_send (s->cadet_mq,
- e);
+ GNUNET_MQ_send (s->cadet_mq, e);
}
}
@@ -947,10 +918,11 @@ cb_intersection_element_removed (void *cls,
"Intersection removed element with key %s and value %lld\n",
GNUNET_h2s (&se->key),
(long long) GNUNET_ntohll (se->value));
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
- element->data,
- se));
+ GNUNET_assert (
+ GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (s->intersected_elements,
+ element->data,
+ se));
GNUNET_free (se);
return;
case GNUNET_SET_STATUS_DONE:
@@ -968,8 +940,7 @@ cb_intersection_element_removed (void *cls,
return;
case GNUNET_SET_STATUS_FAILURE:
/* unhandled status code */
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Set intersection failed!\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Set intersection failed!\n");
if (NULL != s->intersection_listen)
{
GNUNET_SET_listen_cancel (s->intersection_listen);
@@ -1014,18 +985,16 @@ cb_intersection_request_alice (void *cls,
{
struct AliceServiceSession *s = cls;
- if (0 != GNUNET_memcmp (other_peer,
- &s->peer))
+ if (0 != GNUNET_memcmp (other_peer, &s->peer))
{
GNUNET_break_op (0);
return;
}
- s->intersection_op
- = GNUNET_SET_accept (request,
- GNUNET_SET_RESULT_REMOVED,
- (struct GNUNET_SET_Option[]) {{ 0 }},
- &cb_intersection_element_removed,
- s);
+ s->intersection_op = GNUNET_SET_accept (request,
+ GNUNET_SET_RESULT_REMOVED,
+ (struct GNUNET_SET_Option[]){{0}},
+ &cb_intersection_element_removed,
+ s);
if (NULL == s->intersection_op)
{
GNUNET_break (0);
@@ -1033,9 +1002,7 @@ cb_intersection_request_alice (void *cls,
prepare_client_end_notification (s);
return;
}
- if (GNUNET_OK !=
- GNUNET_SET_commit (s->intersection_op,
- s->intersection_set))
+ if (GNUNET_OK != GNUNET_SET_commit (s->intersection_op, s->intersection_set))
{
GNUNET_break (0);
s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1053,31 +1020,30 @@ cb_intersection_request_alice (void *cls,
static void
client_request_complete_alice (struct AliceServiceSession *s)
{
- struct GNUNET_MQ_MessageHandler cadet_handlers[] = {
- GNUNET_MQ_hd_var_size (bobs_cryptodata_message,
- GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
- struct BobCryptodataMessage,
- s),
- GNUNET_MQ_hd_var_size (bobs_cryptodata_multipart,
- GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
- struct BobCryptodataMultipartMessage,
- s),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler cadet_handlers[] =
+ {GNUNET_MQ_hd_var_size (bobs_cryptodata_message,
+ GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA,
+ struct BobCryptodataMessage,
+ s),
+ GNUNET_MQ_hd_var_size (
+ bobs_cryptodata_multipart,
+ GNUNET_MESSAGE_TYPE_SCALARPRODUCT_BOB_CRYPTODATA_MULTIPART,
+ struct BobCryptodataMultipartMessage,
+ s),
+ GNUNET_MQ_handler_end ()};
struct ServiceRequestMessage *msg;
struct GNUNET_MQ_Envelope *e;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Creating new channel for session with key %s.\n",
GNUNET_h2s (&s->session_id));
- s->channel
- = GNUNET_CADET_channel_create (my_cadet,
- s,
- &s->peer,
- &s->session_id,
- NULL,
- &cb_channel_destruction,
- cadet_handlers);
+ s->channel = GNUNET_CADET_channel_create (my_cadet,
+ s,
+ &s->peer,
+ &s->session_id,
+ NULL,
+ &cb_channel_destruction,
+ cadet_handlers);
if (NULL == s->channel)
{
s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1085,12 +1051,11 @@ client_request_complete_alice (struct AliceServiceSession *s)
return;
}
s->cadet_mq = GNUNET_CADET_get_mq (s->channel);
- s->intersection_listen
- = GNUNET_SET_listen (cfg,
- GNUNET_SET_OPERATION_INTERSECTION,
- &s->session_id,
- &cb_intersection_request_alice,
- s);
+ s->intersection_listen = GNUNET_SET_listen (cfg,
+ GNUNET_SET_OPERATION_INTERSECTION,
+ &s->session_id,
+ &cb_intersection_request_alice,
+ s);
if (NULL == s->intersection_listen)
{
s->status = GNUNET_SCALARPRODUCT_STATUS_FAILURE;
@@ -1102,12 +1067,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
e = GNUNET_MQ_msg (msg,
GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SESSION_INITIALIZATION);
- GNUNET_MQ_env_set_options(e,
- GNUNET_MQ_PREF_RELIABLE);
msg->session_id = s->session_id;
msg->public_key = my_pubkey;
- GNUNET_MQ_send (s->cadet_mq,
- e);
+ GNUNET_MQ_send (s->cadet_mq, e);
}
@@ -1120,8 +1082,9 @@ client_request_complete_alice (struct AliceServiceSession *s)
* @return #GNUNET_OK if @a msg is well-formed
*/
static int
-check_alice_client_message_multipart (void *cls,
- const struct ComputationBobCryptodataMultipartMessage *msg)
+check_alice_client_message_multipart (
+ void *cls,
+ const struct ComputationBobCryptodataMultipartMessage *msg)
{
struct AliceServiceSession *s = cls;
uint32_t contained_count;
@@ -1129,11 +1092,12 @@ check_alice_client_message_multipart (void *cls,
msize = ntohs (msg->header.size);
contained_count = ntohl (msg->element_count_contained);
- if ( (msize != (sizeof (struct ComputationBobCryptodataMultipartMessage) +
- contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
- (0 == contained_count) ||
- (s->total == s->client_received_element_count) ||
- (s->total < s->client_received_element_count + contained_count) )
+ if ((msize !=
+ (sizeof (struct ComputationBobCryptodataMultipartMessage) +
+ contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) ||
+ (0 == contained_count) ||
+ (s->total == s->client_received_element_count) ||
+ (s->total < s->client_received_element_count + contained_count))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -1150,8 +1114,9 @@ check_alice_client_message_multipart (void *cls,
* @param msg the actual message
*/
static void
-handle_alice_client_message_multipart (void *cls,
- const struct ComputationBobCryptodataMultipartMessage *msg)
+handle_alice_client_message_multipart (
+ void *cls,
+ const struct ComputationBobCryptodataMultipartMessage *msg)
{
struct AliceServiceSession *s = cls;
uint32_t contained_count;
@@ -1166,13 +1131,13 @@ handle_alice_client_message_multipart (void *cls,
{
elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
GNUNET_memcpy (elem,
- &elements[i],
- sizeof (struct GNUNET_SCALARPRODUCT_Element));
- if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_put (s->intersected_elements,
- &elem->key,
- elem,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ &elements[i],
+ sizeof (struct GNUNET_SCALARPRODUCT_Element));
+ if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
+ s->intersected_elements,
+ &elem->key,
+ elem,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
GNUNET_break (0);
GNUNET_free (elem);
@@ -1181,9 +1146,7 @@ handle_alice_client_message_multipart (void *cls,
set_elem.data = &elem->key;
set_elem.size = sizeof (elem->key);
set_elem.element_type = 0;
- GNUNET_SET_add_element (s->intersection_set,
- &set_elem,
- NULL, NULL);
+ GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
s->used_element_count++;
}
GNUNET_SERVICE_client_continue (s->client);
@@ -1206,7 +1169,7 @@ handle_alice_client_message_multipart (void *cls,
*/
static int
check_alice_client_message (void *cls,
- const struct AliceComputationMessage *msg)
+ const struct AliceComputationMessage *msg)
{
struct AliceServiceSession *s = cls;
uint16_t msize;
@@ -1223,10 +1186,10 @@ check_alice_client_message (void *cls,
msize = ntohs (msg->header.size);
total_count = ntohl (msg->element_count_total);
contained_count = ntohl (msg->element_count_contained);
- if ( (0 == total_count) ||
- (0 == contained_count) ||
- (msize != (sizeof (struct AliceComputationMessage) +
- contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))) )
+ if ((0 == total_count) || (0 == contained_count) ||
+ (msize !=
+ (sizeof (struct AliceComputationMessage) +
+ contained_count * sizeof (struct GNUNET_SCALARPRODUCT_Element))))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -1244,7 +1207,7 @@ check_alice_client_message (void *cls,
*/
static void
handle_alice_client_message (void *cls,
- const struct AliceComputationMessage *msg)
+ const struct AliceComputationMessage *msg)
{
struct AliceServiceSession *s = cls;
uint32_t contained_count;
@@ -1261,10 +1224,10 @@ handle_alice_client_message (void *cls,
s->client_received_element_count = contained_count;
s->session_id = msg->session_key;
elements = (const struct GNUNET_SCALARPRODUCT_Element *) &msg[1];
- s->intersected_elements = GNUNET_CONTAINER_multihashmap_create (s->total,
- GNUNET_YES);
- s->intersection_set = GNUNET_SET_create (cfg,
- GNUNET_SET_OPERATION_INTERSECTION);
+ s->intersected_elements =
+ GNUNET_CONTAINER_multihashmap_create (s->total, GNUNET_YES);
+ s->intersection_set =
+ GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION);
for (uint32_t i = 0; i < contained_count; i++)
{
@@ -1272,13 +1235,13 @@ handle_alice_client_message (void *cls,
continue;
elem = GNUNET_new (struct GNUNET_SCALARPRODUCT_Element);
GNUNET_memcpy (elem,
- &elements[i],
- sizeof (struct GNUNET_SCALARPRODUCT_Element));
- if (GNUNET_SYSERR ==
- GNUNET_CONTAINER_multihashmap_put (s->intersected_elements,
- &elem->key,
- elem,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ &elements[i],
+ sizeof (struct GNUNET_SCALARPRODUCT_Element));
+ if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (
+ s->intersected_elements,
+ &elem->key,
+ elem,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
{
/* element with same key encountered twice! */
GNUNET_break (0);
@@ -1288,9 +1251,7 @@ handle_alice_client_message (void *cls,
set_elem.data = &elem->key;
set_elem.size = sizeof (elem->key);
set_elem.element_type = 0;
- GNUNET_SET_add_element (s->intersection_set,
- &set_elem,
- NULL, NULL);
+ GNUNET_SET_add_element (s->intersection_set, &set_elem, NULL, NULL);
s->used_element_count++;
}
GNUNET_SERVICE_client_continue (s->client);
@@ -1311,8 +1272,7 @@ handle_alice_client_message (void *cls,
static void
shutdown_task (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutting down, initiating cleanup.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down, initiating cleanup.\n");
// FIXME: we have to cut our connections to CADET first!
if (NULL != my_cadet)
{
@@ -1334,8 +1294,8 @@ shutdown_task (void *cls)
*/
static void *
client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- struct GNUNET_MQ_Handle *mq)
+ struct GNUNET_SERVICE_Client *client,
+ struct GNUNET_MQ_Handle *mq)
{
struct AliceServiceSession *s;
@@ -1358,8 +1318,8 @@ client_connect_cb (void *cls,
*/
static void
client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
- void *app_cls)
+ struct GNUNET_SERVICE_Client *client,
+ void *app_cls)
{
struct AliceServiceSession *s = app_cls;
@@ -1390,17 +1350,13 @@ run (void *cls,
m1+m2 mod n == (S + a) + (S + b) mod n,
if we have more complex operations, this factor needs to be lowered */
my_offset = gcry_mpi_new (GNUNET_CRYPTO_PAILLIER_BITS / 3);
- gcry_mpi_set_bit (my_offset,
- GNUNET_CRYPTO_PAILLIER_BITS / 3);
- GNUNET_CRYPTO_paillier_create (&my_pubkey,
- &my_privkey);
+ gcry_mpi_set_bit (my_offset, GNUNET_CRYPTO_PAILLIER_BITS / 3);
+ GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey);
my_cadet = GNUNET_CADET_connect (cfg);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
if (NULL == my_cadet)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Connect to CADET failed\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Connect to CADET failed\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -1410,22 +1366,23 @@ run (void *cls,
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("scalarproduct-alice",
- GNUNET_SERVICE_OPTION_NONE,
- &run,
- &client_connect_cb,
- &client_disconnect_cb,
- NULL,
- GNUNET_MQ_hd_var_size (alice_client_message,
- GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
- struct AliceComputationMessage,
- NULL),
- GNUNET_MQ_hd_var_size (alice_client_message_multipart,
- GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
- struct ComputationBobCryptodataMultipartMessage,
- NULL),
- GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN (
+ "scalarproduct-alice",
+ GNUNET_SERVICE_OPTION_NONE,
+ &run,
+ &client_connect_cb,
+ &client_disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_var_size (alice_client_message,
+ GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE,
+ struct AliceComputationMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (
+ alice_client_message_multipart,
+ GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_MULTIPART_ALICE,
+ struct ComputationBobCryptodataMultipartMessage,
+ NULL),
+ GNUNET_MQ_handler_end ());
/* end of gnunet-service-scalarproduct_alice.c */