aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-12-02 09:34:25 +0100
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-12-02 09:34:25 +0100
commit56b43dab7ff80acc4cd0e7ad3057abd5e6bad680 (patch)
tree74b6a5f1ff6f8994582926112b4102574784f524
parentaee7167739e666ea94c3b68c58a0f7aa1ede238e (diff)
downloadlibbrandt-56b43dab7ff80acc4cd0e7ad3057abd5e6bad680.tar.gz
libbrandt-56b43dab7ff80acc4cd0e7ad3057abd5e6bad680.zip
migrate to GNUNET_log
-rw-r--r--brandt.c60
-rw-r--r--crypto.c53
-rw-r--r--fp_priv.c35
-rw-r--r--fp_pub.c16
-rw-r--r--mp_priv.c12
-rw-r--r--mp_pub.c24
-rw-r--r--test_crypto.c154
7 files changed, 149 insertions, 205 deletions
diff --git a/brandt.c b/brandt.c
index 5a75eda..86239a8 100644
--- a/brandt.c
+++ b/brandt.c
@@ -37,13 +37,18 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
37 37
38 /* SECMEM cannot be resized dynamically. We do not know how much we need */ 38 /* SECMEM cannot be resized dynamically. We do not know how much we need */
39 if ((err = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) 39 if ((err = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
40 weprintf ("failed to set libgcrypt option DISABLE_SECMEM: %s", 40 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
41 gcry_strerror (err)); 41 "libbrandt",
42 "failed to set libgcrypt option DISABLE_SECMEM: %s\n",
43 gcry_strerror (err));
42 44
43 /* ecc is slow otherwise and we don't create long term keys anyway. */ 45 /* ecc is slow otherwise and we don't create long term keys anyway. */
44 if ((err = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) 46 if ((err = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0)))
45 weprintf ("failed to set libgcrypt option ENABLE_QUICK_RANDOM: %s", 47 GNUNET_log_from (
46 gcry_strerror (err)); 48 GNUNET_ERROR_TYPE_WARNING,
49 "libbrandt",
50 "failed to set libgcrypt option ENABLE_QUICK_RANDOM: %s\n",
51 gcry_strerror (err));
47 52
48 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); 53 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
49 brandt_crypto_init (dlogctx); 54 brandt_crypto_init (dlogctx);
@@ -110,7 +115,9 @@ BRANDT_bidder_start (struct BRANDT_Auction *auction,
110 !(buf = handler_out[atype][outcome][msg_init](auction, &buflen))) 115 !(buf = handler_out[atype][outcome][msg_init](auction, &buflen)))
111 { 116 {
112 /** \todo */ 117 /** \todo */
113 weprintf ("wow fail out"); 118 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
119 "libbrandt",
120 "wow fail out\n");
114 return; 121 return;
115 } 122 }
116 123
@@ -132,7 +139,9 @@ seller_start (void *arg)
132 ad->n = ad->start (ad->closure); 139 ad->n = ad->start (ad->closure);
133 if (0 == ad->n) 140 if (0 == ad->n)
134 { 141 {
135 weprintf ("no bidders registered for auction"); 142 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
143 "libbrandt",
144 "no bidders registered for auction\n");
136 ad->result (ad->closure, NULL, 0); 145 ad->result (ad->closure, NULL, 0);
137 return; 146 return;
138 } 147 }
@@ -141,7 +150,9 @@ seller_start (void *arg)
141 struct BRANDT_Result *res = GNUNET_new_array (ad->n, 150 struct BRANDT_Result *res = GNUNET_new_array (ad->n,
142 struct BRANDT_Result); 151 struct BRANDT_Result);
143 152
144 weprintf ("less bidders than needed, selling for lowest price"); 153 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
154 "libbrandt",
155 "less bidders than needed, selling for lowest price\n");
145 for (uint16_t i = 0; i < ad->n; i++) 156 for (uint16_t i = 0; i < ad->n; i++)
146 { 157 {
147 res[i].bidder = i; 158 res[i].bidder = i;
@@ -237,13 +248,17 @@ BRANDT_parse_desc (const void *auction_desc,
237 248
238 if (sizeof (struct BRANDT_DescrP) != auction_desc_len) 249 if (sizeof (struct BRANDT_DescrP) != auction_desc_len)
239 { 250 {
240 weprintf ("auction desc struct size mismatch"); 251 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
252 "libbrandt",
253 "auction desc struct size mismatch\n");
241 return -1; 254 return -1;
242 } 255 }
243 256
244 if (0 != memcmp (&desc->reserved, &zero, sizeof (desc->reserved))) 257 if (0 != memcmp (&desc->reserved, &zero, sizeof (desc->reserved)))
245 { 258 {
246 weprintf ("reserved field in auction description must be zero"); 259 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
260 "libbrandt",
261 "reserved field in auction description must be zero\n");
247 return -1; 262 return -1;
248 } 263 }
249 264
@@ -282,7 +297,9 @@ BRANDT_join (BRANDT_CbResult result,
282 &ret->outcome_public)) 297 &ret->outcome_public))
283 { 298 {
284 GNUNET_free (ret); 299 GNUNET_free (ret);
285 weprintf ("failed to parse auction description blob"); 300 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
301 "libbrandt",
302 "failed to parse auction description blob\n");
286 return NULL; 303 return NULL;
287 } 304 }
288 ret->cur_round = msg_init; 305 ret->cur_round = msg_init;
@@ -378,8 +395,10 @@ advance_round (struct BRANDT_Auction *ad,
378 if (!handler_out[atype][outcome][ad->cur_round] || 395 if (!handler_out[atype][outcome][ad->cur_round] ||
379 !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) 396 !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen)))
380 { 397 {
381 weprintf ("failed to create msg %d buffer as seller", 398 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
382 ad->cur_round); 399 "libbrandt",
400 "failed to create msg %d buffer as seller\n",
401 ad->cur_round);
383 return; 402 return;
384 } 403 }
385 ad->bcast (ad->closure, buf, buflen); 404 ad->bcast (ad->closure, buf, buflen);
@@ -410,7 +429,10 @@ advance_round (struct BRANDT_Auction *ad,
410 if (!handler_out[atype][outcome][ad->cur_round] || 429 if (!handler_out[atype][outcome][ad->cur_round] ||
411 !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) 430 !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen)))
412 { 431 {
413 weprintf ("failed to create msg %d buffer as bidder", ad->cur_round); 432 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
433 "libbrandt",
434 "failed to create msg %d buffer as bidder\n",
435 ad->cur_round);
414 return; 436 return;
415 } 437 }
416 438
@@ -441,14 +463,18 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
441 /** \todo: cache out of order messages instead of discarding */ 463 /** \todo: cache out of order messages instead of discarding */
442 if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0) 464 if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0)
443 { 465 {
444 weprintf ("got unexpected message, ignoring..."); 466 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
467 "libbrandt",
468 "got unexpected message, ignoring...\n");
445 return; 469 return;
446 } 470 }
447 471
448 /* check if we already got that round message from the same user */ 472 /* check if we already got that round message from the same user */
449 if (gcry_mpi_test_bit (auction->round_progress, sender)) 473 if (gcry_mpi_test_bit (auction->round_progress, sender))
450 { 474 {
451 weprintf ("got a duplicate message from user %d", sender); 475 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
476 "libbrandt",
477 "got a duplicate message from user %d\n", sender);
452 return; 478 return;
453 } 479 }
454 480
@@ -459,7 +485,9 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
459 sender)) 485 sender))
460 { 486 {
461 /** \todo */ 487 /** \todo */
462 weprintf ("wow fail in"); 488 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
489 "libbrandt",
490 "wow fail in\n");
463 return; 491 return;
464 } 492 }
465 gcry_mpi_set_bit (auction->round_progress, sender); 493 gcry_mpi_set_bit (auction->round_progress, sender);
diff --git a/crypto.c b/crypto.c
index e870f2b..6c1b501 100644
--- a/crypto.c
+++ b/crypto.c
@@ -219,7 +219,9 @@ ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b)
219 brandt_assert (a && b); 219 brandt_assert (a && b);
220 if (!ax || !bx || !ay || !by) 220 if (!ax || !bx || !ay || !by)
221 { 221 {
222 weprintf ("could not init point in point_cmp"); 222 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
223 "libbrandt",
224 "could not init point in point_cmp\n");
223 return 1; 225 return 1;
224 } 226 }
225 227
@@ -410,8 +412,10 @@ smc_init1 (uint16_t size1)
410 { 412 {
411 if (NULL == (ret[i] = gcry_mpi_point_new (0))) 413 if (NULL == (ret[i] = gcry_mpi_point_new (0)))
412 { 414 {
413 weprintf ("could not init point in 1 dimensional array. " 415 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
414 "out of memory?"); 416 "libbrandt",
417 "could not init point in 1 dimensional array. "
418 "out of memory?\n");
415 smc_free1 (ret, size1); 419 smc_free1 (ret, size1);
416 return NULL; 420 return NULL;
417 } 421 }
@@ -464,8 +468,11 @@ smc_init2 (uint16_t size1, uint16_t size2)
464 { 468 {
465 if (NULL == (ret[i][j] = gcry_mpi_point_new (0))) 469 if (NULL == (ret[i][j] = gcry_mpi_point_new (0)))
466 { 470 {
467 weprintf ("could not init point in 2 dimensional array. " 471 GNUNET_log_from (
468 "out of memory?"); 472 GNUNET_ERROR_TYPE_ERROR,
473 "libbrandt",
474 "could not init point in 2 dimensional array. "
475 "out of memory?\n");
469 smc_free2 (ret, size1, size2); 476 smc_free2 (ret, size1, size2);
470 GNUNET_assert (0); 477 GNUNET_assert (0);
471 } 478 }
@@ -527,8 +534,11 @@ smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3)
527 { 534 {
528 if (NULL == (ret[i][j][k] = gcry_mpi_point_new (0))) 535 if (NULL == (ret[i][j][k] = gcry_mpi_point_new (0)))
529 { 536 {
530 weprintf ("could not init point in 2 dimensional array. " 537 GNUNET_log_from (
531 "out of memory?"); 538 GNUNET_ERROR_TYPE_ERROR,
539 "libbrandt",
540 "could not init point in 2 dimensional array. "
541 "out of memory?\n");
532 smc_free3 (ret, size1, size2, size3); 542 smc_free3 (ret, size1, size2, size3);
533 GNUNET_assert (0); 543 GNUNET_assert (0);
534 } 544 }
@@ -651,7 +661,9 @@ smc_recv_keyshare (struct BRANDT_Auction *ad,
651 661
652 if (buflen != (sizeof (struct ec_mpi) + sizeof (*proof1))) 662 if (buflen != (sizeof (struct ec_mpi) + sizeof (*proof1)))
653 { 663 {
654 weprintf ("wrong size of received key share"); 664 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
665 "libbrandt",
666 "wrong size of received key share\n");
655 goto quit; 667 goto quit;
656 } 668 }
657 669
@@ -659,7 +671,9 @@ smc_recv_keyshare (struct BRANDT_Auction *ad,
659 ec_point_parse (y, (struct ec_mpi *)buf); 671 ec_point_parse (y, (struct ec_mpi *)buf);
660 if (smc_zkp_dl_check (y, proof1)) 672 if (smc_zkp_dl_check (y, proof1))
661 { 673 {
662 weprintf ("wrong zkp1 for public key share received"); 674 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
675 "libbrandt",
676 "wrong zkp1 for public key share received\n");
663 goto quit; 677 goto quit;
664 } 678 }
665 679
@@ -785,7 +799,9 @@ smc_recv_encrypted_bid (struct BRANDT_Auction *ad,
785 (0 < ad->m ? 2 : 1) * sizeof (struct proof_2dle)) || 799 (0 < ad->m ? 2 : 1) * sizeof (struct proof_2dle)) ||
786 NULL == (ct = smc_init2 (2, ad->k))) 800 NULL == (ct = smc_init2 (2, ad->k)))
787 { 801 {
788 weprintf ("wrong size of received encrypted bid"); 802 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
803 "libbrandt",
804 "wrong size of received encrypted bid\n");
789 goto quit; 805 goto quit;
790 } 806 }
791 807
@@ -801,7 +817,9 @@ smc_recv_encrypted_bid (struct BRANDT_Auction *ad,
801 proof3 = (struct proof_0og *)(cur + 2 * sizeof (struct ec_mpi)); 817 proof3 = (struct proof_0og *)(cur + 2 * sizeof (struct ec_mpi));
802 if (smc_zkp_0og_check (ad->Y, ct[0][j], ct[1][j], proof3)) 818 if (smc_zkp_0og_check (ad->Y, ct[0][j], ct[1][j], proof3))
803 { 819 {
804 weprintf ("wrong zkp3 for alpha, beta received"); 820 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
821 "libbrandt",
822 "wrong zkp3 for alpha, beta received\n");
805 goto quit; 823 goto quit;
806 } 824 }
807 gcry_mpi_ec_add (alpha_sum, alpha_sum, ct[0][j], ec_ctx); 825 gcry_mpi_ec_add (alpha_sum, alpha_sum, ct[0][j], ec_ctx);
@@ -825,7 +843,9 @@ smc_recv_encrypted_bid (struct BRANDT_Auction *ad,
825 ec_gen, 843 ec_gen,
826 (struct proof_2dle *)cur)) 844 (struct proof_2dle *)cur))
827 { 845 {
828 weprintf ("wrong zkp2 for alpha, beta received"); 846 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
847 "libbrandt",
848 "wrong zkp2 for alpha, beta received\n");
829 goto quit; 849 goto quit;
830 } 850 }
831 851
@@ -841,8 +861,11 @@ smc_recv_encrypted_bid (struct BRANDT_Auction *ad,
841 ec_gen, 861 ec_gen,
842 (struct proof_2dle *)cur)) 862 (struct proof_2dle *)cur))
843 { 863 {
844 weprintf ("wrong second zkp2 for alpha, beta received. " 864 GNUNET_log_from (
845 "bid not allowed for this user in M+1st price auctions."); 865 GNUNET_ERROR_TYPE_WARNING,
866 "libbrandt",
867 "wrong second zkp2 for alpha, beta received. "
868 "bid not allowed for this user in M+1st price auctions.\n");
846 goto quit; 869 goto quit;
847 } 870 }
848 } 871 }
@@ -1381,7 +1404,5 @@ smc_zkp_0og_check (const gcry_mpi_point_t y,
1381 gcry_mpi_point_release (right); 1404 gcry_mpi_point_release (right);
1382 gcry_mpi_point_release (tmp); 1405 gcry_mpi_point_release (tmp);
1383 1406
1384 if (ret)
1385 weprintf ("ret: 0x%x", ret);
1386 return ret; 1407 return ret;
1387} 1408}
diff --git a/fp_priv.c b/fp_priv.c
index 6be19eb..201e643 100644
--- a/fp_priv.c
+++ b/fp_priv.c
@@ -226,7 +226,9 @@ fp_priv_recv_outcome (struct BRANDT_Auction *ad,
226 if (buflen != (ad->n * ad->k * 226 if (buflen != (ad->n * ad->k *
227 (2 * sizeof (struct ec_mpi) + sizeof (*proof2)))) 227 (2 * sizeof (struct ec_mpi) + sizeof (*proof2))))
228 { 228 {
229 weprintf ("wrong size of received outcome"); 229 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
230 "libbrandt",
231 "wrong size of received outcome\n");
230 goto quit; 232 goto quit;
231 } 233 }
232 234
@@ -243,7 +245,9 @@ fp_priv_recv_outcome (struct BRANDT_Auction *ad,
243 ad->delta3[sender][i][j], 245 ad->delta3[sender][i][j],
244 proof2)) 246 proof2))
245 { 247 {
246 weprintf ("wrong zkp2 for gamma, delta received"); 248 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
249 "libbrandt",
250 "wrong zkp2 for gamma, delta received\n");
247 goto quit; 251 goto quit;
248 } 252 }
249 ec_point_copy (ad->gamma3[sender][i][j], gamma); 253 ec_point_copy (ad->gamma3[sender][i][j], gamma);
@@ -420,7 +424,10 @@ fp_priv_recv_decryption_seller (struct BRANDT_Auction *ad,
420 424
421 if (buflen != (ad->n * ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2)))) 425 if (buflen != (ad->n * ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2))))
422 { 426 {
423 weprintf ("wrong size of received outcome decryption from bidder"); 427 GNUNET_log_from (
428 GNUNET_ERROR_TYPE_WARNING,
429 "libbrandt",
430 "wrong size of received outcome decryption from bidder\n");
424 goto quit; 431 goto quit;
425 } 432 }
426 433
@@ -436,7 +443,9 @@ fp_priv_recv_decryption_seller (struct BRANDT_Auction *ad,
436 ec_gen, 443 ec_gen,
437 proof2)) 444 proof2))
438 { 445 {
439 weprintf ("wrong zkp2 for phi, y received from bidder"); 446 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
447 "libbrandt",
448 "wrong zkp2 for phi, y received from bidder\n");
440 goto quit; 449 goto quit;
441 } 450 }
442 451
@@ -469,7 +478,10 @@ fp_priv_recv_decryption_bidder (struct BRANDT_Auction *ad,
469 if (buflen != ((ad->n - 1) * ad->n * ad->k * (sizeof (struct ec_mpi) + 478 if (buflen != ((ad->n - 1) * ad->n * ad->k * (sizeof (struct ec_mpi) +
470 sizeof (*proof2)))) 479 sizeof (*proof2))))
471 { 480 {
472 weprintf ("wrong size of received outcome decryption from seller"); 481 GNUNET_log_from (
482 GNUNET_ERROR_TYPE_WARNING,
483 "libbrandt",
484 "wrong size of received outcome decryption from seller\n");
473 goto quit; 485 goto quit;
474 } 486 }
475 487
@@ -498,7 +510,10 @@ fp_priv_recv_decryption_bidder (struct BRANDT_Auction *ad,
498 ec_gen, 510 ec_gen,
499 proof2)) 511 proof2))
500 { 512 {
501 weprintf ("wrong zkp2 for phi, y received from seller"); 513 GNUNET_log_from (
514 GNUNET_ERROR_TYPE_WARNING,
515 "libbrandt",
516 "wrong zkp2 for phi, y received from seller\n");
502 goto quit; 517 goto quit;
503 } 518 }
504 ec_point_copy (ad->phi3[h][i][j], phi); 519 ec_point_copy (ad->phi3[h][i][j], phi);
@@ -554,12 +569,16 @@ fp_priv_determine_outcome (struct BRANDT_Auction *ad,
554 { 569 {
555 if (-1 != price) 570 if (-1 != price)
556 { 571 {
557 weprintf ("multiple winning prices detected"); 572 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
573 "libbrandt",
574 "multiple winning prices detected\n");
558 return NULL; 575 return NULL;
559 } 576 }
560 if (-1 != winner) 577 if (-1 != winner)
561 { 578 {
562 weprintf ("multiple winners detected"); 579 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
580 "libbrandt",
581 "multiple winners detected\n");
563 return NULL; 582 return NULL;
564 } 583 }
565 price = j; 584 price = j;
diff --git a/fp_pub.c b/fp_pub.c
index e4079cb..cc8cf28 100644
--- a/fp_pub.c
+++ b/fp_pub.c
@@ -216,7 +216,9 @@ fp_pub_recv_outcome (struct BRANDT_Auction *ad,
216 216
217 if (buflen != (ad->k * (2 * sizeof (struct ec_mpi) + sizeof (*proof2)))) 217 if (buflen != (ad->k * (2 * sizeof (struct ec_mpi) + sizeof (*proof2))))
218 { 218 {
219 weprintf ("wrong size of received outcome"); 219 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
220 "libbrandt",
221 "wrong size of received outcome\n");
220 goto quit; 222 goto quit;
221 } 223 }
222 224
@@ -231,7 +233,9 @@ fp_pub_recv_outcome (struct BRANDT_Auction *ad,
231 ad->delta2[sender][j], 233 ad->delta2[sender][j],
232 proof2)) 234 proof2))
233 { 235 {
234 weprintf ("wrong zkp2 for gamma, delta received"); 236 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
237 "libbrandt",
238 "wrong zkp2 for gamma, delta received\n");
235 goto quit; 239 goto quit;
236 } 240 }
237 ec_point_copy (ad->gamma2[sender][j], gamma); 241 ec_point_copy (ad->gamma2[sender][j], gamma);
@@ -350,7 +354,9 @@ fp_pub_recv_decryption (struct BRANDT_Auction *ad,
350 354
351 if (buflen != (ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2)))) 355 if (buflen != (ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2))))
352 { 356 {
353 weprintf ("wrong size of received outcome decryption"); 357 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
358 "libbrandt",
359 "wrong size of received outcome decryption\n");
354 goto quit; 360 goto quit;
355 } 361 }
356 362
@@ -364,7 +370,9 @@ fp_pub_recv_decryption (struct BRANDT_Auction *ad,
364 ec_gen, 370 ec_gen,
365 proof2)) 371 proof2))
366 { 372 {
367 weprintf ("wrong zkp2 for phi, y received"); 373 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
374 "libbrandt",
375 "wrong zkp2 for phi, y received\n");
368 goto quit; 376 goto quit;
369 } 377 }
370 ec_point_copy (ad->phi2[sender][j], phi); 378 ec_point_copy (ad->phi2[sender][j], phi);
diff --git a/mp_priv.c b/mp_priv.c
index 470d0b5..65b5cde 100644
--- a/mp_priv.c
+++ b/mp_priv.c
@@ -179,12 +179,16 @@ mp_priv_determine_outcome (struct BRANDT_Auction *ad,
179 { 179 {
180 if (winners >= max_winners) 180 if (winners >= max_winners)
181 { 181 {
182 weprintf ("too many winners detected"); 182 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
183 "libbrandt",
184 "too many winners detected\n");
183 goto fail; 185 goto fail;
184 } 186 }
185 if (-1 != price && j != price) 187 if (-1 != price && j != price)
186 { 188 {
187 weprintf ("multiple winning prices detected"); 189 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
190 "libbrandt",
191 "multiple winning prices detected\n");
188 goto fail; 192 goto fail;
189 } 193 }
190 price = j; 194 price = j;
@@ -201,7 +205,9 @@ mp_priv_determine_outcome (struct BRANDT_Auction *ad,
201 gcry_mpi_point_release (sum_phi); 205 gcry_mpi_point_release (sum_phi);
202 206
203 if (ad->m <= ad->n && winners < max_winners && -1 != price) 207 if (ad->m <= ad->n && winners < max_winners && -1 != price)
204 weprintf ("too few winners detected"); 208 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
209 "libbrandt",
210 "too few winners detected\n");
205 if (0 == winners) 211 if (0 == winners)
206 goto fail; 212 goto fail;
207 213
diff --git a/mp_pub.c b/mp_pub.c
index 7c2a373..68705cf 100644
--- a/mp_pub.c
+++ b/mp_pub.c
@@ -267,7 +267,9 @@ mp_pub_recv_outcome (struct BRANDT_Auction *ad,
267 267
268 if (buflen != (ad->k * (2 * sizeof (struct ec_mpi) + sizeof (*proof2)))) 268 if (buflen != (ad->k * (2 * sizeof (struct ec_mpi) + sizeof (*proof2))))
269 { 269 {
270 weprintf ("wrong size of received outcome"); 270 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
271 "libbrandt",
272 "wrong size of received outcome\n");
271 goto quit; 273 goto quit;
272 } 274 }
273 275
@@ -282,7 +284,9 @@ mp_pub_recv_outcome (struct BRANDT_Auction *ad,
282 ad->delta3[sender][0][j], 284 ad->delta3[sender][0][j],
283 proof2)) 285 proof2))
284 { 286 {
285 weprintf ("wrong zkp2 for gamma, delta received"); 287 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
288 "libbrandt",
289 "wrong zkp2 for gamma, delta received\n");
286 goto quit; 290 goto quit;
287 } 291 }
288 ec_point_copy (ad->gamma3[sender][0][j], gamma); 292 ec_point_copy (ad->gamma3[sender][0][j], gamma);
@@ -411,7 +415,9 @@ mp_pub_recv_decryption (struct BRANDT_Auction *ad,
411 415
412 if (buflen != (2 * ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2)))) 416 if (buflen != (2 * ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2))))
413 { 417 {
414 weprintf ("wrong size of received outcome decryption"); 418 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
419 "libbrandt",
420 "wrong size of received outcome decryption\n");
415 goto quit; 421 goto quit;
416 } 422 }
417 423
@@ -429,7 +435,9 @@ mp_pub_recv_decryption (struct BRANDT_Auction *ad,
429 ec_gen, 435 ec_gen,
430 proof2)) 436 proof2))
431 { 437 {
432 weprintf ("wrong zkp2 for phi, y received"); 438 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
439 "libbrandt",
440 "wrong zkp2 for phi, y received\n");
433 goto quit; 441 goto quit;
434 } 442 }
435 ec_point_copy (ad->phi3[sender][comp][j], phi); 443 ec_point_copy (ad->phi3[sender][comp][j], phi);
@@ -496,7 +504,9 @@ mp_pub_determine_outcome (struct BRANDT_Auction *ad,
496 { 504 {
497 if (cur_winner >= ad->m) 505 if (cur_winner >= ad->m)
498 { 506 {
499 weprintf ("too many winners detected"); 507 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
508 "libbrandt",
509 "too many winners detected\n");
500 GNUNET_free (ret); 510 GNUNET_free (ret);
501 ret = NULL; 511 ret = NULL;
502 goto quit; 512 goto quit;
@@ -511,7 +521,9 @@ mp_pub_determine_outcome (struct BRANDT_Auction *ad,
511 521
512 if (cur_winner != ad->m) 522 if (cur_winner != ad->m)
513 { 523 {
514 weprintf ("too few winners detected"); 524 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
525 "libbrandt",
526 "too few winners detected\n");
515 GNUNET_free (ret); 527 GNUNET_free (ret);
516 ret = NULL; 528 ret = NULL;
517 goto quit; 529 goto quit;
diff --git a/test_crypto.c b/test_crypto.c
index 6a49927..0517e52 100644
--- a/test_crypto.c
+++ b/test_crypto.c
@@ -28,10 +28,6 @@
28#include "test.h" 28#include "test.h"
29 29
30 30
31static uint16_t bidders;
32static uint16_t prizes;
33static struct BRANDT_Auction *ad;
34
35static int 31static int
36test_serialization () 32test_serialization ()
37{ 33{
@@ -137,158 +133,14 @@ test_smc_zkp_0og ()
137} 133}
138 134
139 135
140static int
141test_setup_auction_data ()
142{
143 uint16_t i;
144
145 ad = GNUNET_new_array (bidders, struct BRANDT_Auction);
146
147 for (i = 0; i < bidders; i++)
148 {
149 ad[i].n = bidders;
150 ad[i].i = i;
151 ad[i].k = prizes;
152 ad[i].b = i;
153 }
154 return 1;
155}
156
157
158/**
159 * compute round @a index of the protocol specified by @a type and @a oc
160 *
161 * @param[in] type auction type
162 * @param[in] oc outcome type
163 * @param[in] index round index
164 */
165#define ROUND(type, oc, index) do { \
166 for (uint16_t i = 0; i < bidders; i++) \
167 { \
168 handler_prep[type][oc][index] (&ad[i]); \
169 bufs[i] = handler_out[type][oc][index] (&ad[i], &lens[i]); \
170 CHECK (bufs[i], "failed to gen message buffer"); \
171 } \
172 \
173 for (uint16_t i = 0; i < bidders; i++) \
174 { \
175 /* enable seller mode for receiving decryption messages */ \
176 if (msg_decrypt == index) \
177 ad[i].seller_mode = 1; \
178 for (uint16_t s = 0; s < bidders; s++) \
179 { \
180 if (s == i) \
181 continue; \
182 CHECK (handler_in[type][oc][index] (&ad[i], \
183 bufs[s] + \
184 sizeof (struct msg_head), \
185 lens[s] - \
186 sizeof (struct msg_head), \
187 s), \
188 "failed to parse message buffer"); \
189 } \
190 /* disable seller mode again */ \
191 if (msg_decrypt == index) \
192 ad[i].seller_mode = 0; \
193 } \
194 \
195 for (uint16_t i = 0; i < bidders; i++) \
196 free (bufs[i]); \
197} while (0)
198
199
200static int
201test_auction (enum auction_type atype, enum outcome_type oc)
202{
203 unsigned char *bufs[bidders];
204 size_t lens[bidders];
205 int32_t winner = -1;
206 int32_t price = -1;
207
208 weprintf ("testing auction type %d and outcome format %d...", atype, oc);
209 ROUND (atype, oc, msg_init);
210 ROUND (atype, oc, msg_bid);
211 ROUND (atype, oc, msg_outcome);
212 ROUND (atype, oc, msg_decrypt);
213
214 /* outcome */
215 for (uint16_t i = 0; i < ad->n; i++)
216 {
217 struct BRANDT_Result *res;
218 uint16_t reslen;
219
220 res = handler_res[atype][oc] (&ad[i], &reslen);
221 if (res && -1 == price && -1 != res->price)
222 price = res->price;
223 if (res)
224 weprintf ("price: %d", res->price);
225 CHECK (!res || res->price == price, "different prices detected");
226 if (res && -1 == winner && -1 != res->bidder)
227 winner = res->bidder;
228 CHECK (!res || res->bidder == winner, "different winners detected");
229 }
230
231 CHECK (-1 != winner, "no winner detected");
232 CHECK (-1 != price, "no price detected");
233 fputs ("good: one winner detected\n", stderr);
234 return 1;
235}
236
237
238static void
239cleanup_auction_data ()
240{
241 for (uint16_t i = 0; i < bidders; i++)
242 {
243 gcry_mpi_point_release (ad[i].Y);
244 gcry_mpi_release (ad[i].x);
245 smc_free1 (ad[i].y, ad[i].n);
246 smc_free2 (ad[i].alpha, ad[i].n, ad[i].k);
247 smc_free2 (ad[i].beta, ad[i].n, ad[i].k);
248 smc_free2 (ad[i].gamma2, ad[i].n, ad[i].k);
249 smc_free2 (ad[i].delta2, ad[i].n, ad[i].k);
250 smc_free2 (ad[i].phi2, ad[i].n, ad[i].k);
251 smc_free3 (ad[i].gamma3, ad[i].n, ad[i].n, ad[i].k);
252 smc_free3 (ad[i].delta3, ad[i].n, ad[i].n, ad[i].k);
253 smc_free3 (ad[i].phi3, ad[i].n, ad[i].n, ad[i].k);
254 smc_free1 (ad[i].tmpa1, ad[i].k);
255 smc_free1 (ad[i].tmpb1, ad[i].k);
256 }
257 free (ad);
258}
259
260
261static int
262test_all_auctions ()
263{
264 for (size_t atype = 0; atype < auction_last; atype++)
265 {
266 if (auction_firstPrice != atype) /* others not yet implemented */
267 continue;
268
269 for (size_t oc = 0; oc < outcome_last; oc++)
270 {
271 if (!test_setup_auction_data () || !test_auction (atype, oc))
272 {
273 cleanup_auction_data ();
274 return 0;
275 }
276 cleanup_auction_data ();
277 }
278 }
279
280 return 1;
281}
282
283
284int 136int
285main (int argc, char *argv[]) 137main (int argc, char *argv[])
286{ 138{
287 int repeat = 1; 139 int repeat = 1;
288 struct GNUNET_CRYPTO_EccDlogContext *edc; 140 struct GNUNET_CRYPTO_EccDlogContext *edc;
289 141
290 bidders = 3; 142 if (GNUNET_OK != GNUNET_log_setup ("test_crypto", "WARNING", NULL))
291 prizes = 3; 143 return 1;
292 144
293 edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16); 145 edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
294 BRANDT_init (edc); 146 BRANDT_init (edc);
@@ -303,8 +155,6 @@ main (int argc, char *argv[])
303 RUN (test_smc_zkp_0og); 155 RUN (test_smc_zkp_0og);
304 } 156 }
305 157
306 RUN (test_all_auctions);
307
308 GNUNET_CRYPTO_ecc_dlog_release (edc); 158 GNUNET_CRYPTO_ecc_dlog_release (edc);
309 return ret; 159 return ret;
310} 160}