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