migrate to GNUNET_log

This commit is contained in:
Markus Teich 2016-12-02 09:34:25 +01:00
parent aee7167739
commit 56b43dab7f
7 changed files with 149 additions and 205 deletions

View File

@ -37,12 +37,17 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
/* SECMEM cannot be resized dynamically. We do not know how much we need */ /* SECMEM cannot be resized dynamically. We do not know how much we need */
if ((err = gcry_control (GCRYCTL_DISABLE_SECMEM, 0))) if ((err = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
weprintf ("failed to set libgcrypt option DISABLE_SECMEM: %s", GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"failed to set libgcrypt option DISABLE_SECMEM: %s\n",
gcry_strerror (err)); gcry_strerror (err));
/* ecc is slow otherwise and we don't create long term keys anyway. */ /* ecc is slow otherwise and we don't create long term keys anyway. */
if ((err = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) if ((err = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0)))
weprintf ("failed to set libgcrypt option ENABLE_QUICK_RANDOM: %s", GNUNET_log_from (
GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"failed to set libgcrypt option ENABLE_QUICK_RANDOM: %s\n",
gcry_strerror (err)); gcry_strerror (err));
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
@ -110,7 +115,9 @@ BRANDT_bidder_start (struct BRANDT_Auction *auction,
!(buf = handler_out[atype][outcome][msg_init](auction, &buflen))) !(buf = handler_out[atype][outcome][msg_init](auction, &buflen)))
{ {
/** \todo */ /** \todo */
weprintf ("wow fail out"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"wow fail out\n");
return; return;
} }
@ -132,7 +139,9 @@ seller_start (void *arg)
ad->n = ad->start (ad->closure); ad->n = ad->start (ad->closure);
if (0 == ad->n) if (0 == ad->n)
{ {
weprintf ("no bidders registered for auction"); GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
"libbrandt",
"no bidders registered for auction\n");
ad->result (ad->closure, NULL, 0); ad->result (ad->closure, NULL, 0);
return; return;
} }
@ -141,7 +150,9 @@ seller_start (void *arg)
struct BRANDT_Result *res = GNUNET_new_array (ad->n, struct BRANDT_Result *res = GNUNET_new_array (ad->n,
struct BRANDT_Result); struct BRANDT_Result);
weprintf ("less bidders than needed, selling for lowest price"); GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
"libbrandt",
"less bidders than needed, selling for lowest price\n");
for (uint16_t i = 0; i < ad->n; i++) for (uint16_t i = 0; i < ad->n; i++)
{ {
res[i].bidder = i; res[i].bidder = i;
@ -237,13 +248,17 @@ BRANDT_parse_desc (const void *auction_desc,
if (sizeof (struct BRANDT_DescrP) != auction_desc_len) if (sizeof (struct BRANDT_DescrP) != auction_desc_len)
{ {
weprintf ("auction desc struct size mismatch"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"auction desc struct size mismatch\n");
return -1; return -1;
} }
if (0 != memcmp (&desc->reserved, &zero, sizeof (desc->reserved))) if (0 != memcmp (&desc->reserved, &zero, sizeof (desc->reserved)))
{ {
weprintf ("reserved field in auction description must be zero"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"reserved field in auction description must be zero\n");
return -1; return -1;
} }
@ -282,7 +297,9 @@ BRANDT_join (BRANDT_CbResult result,
&ret->outcome_public)) &ret->outcome_public))
{ {
GNUNET_free (ret); GNUNET_free (ret);
weprintf ("failed to parse auction description blob"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"failed to parse auction description blob\n");
return NULL; return NULL;
} }
ret->cur_round = msg_init; ret->cur_round = msg_init;
@ -378,7 +395,9 @@ advance_round (struct BRANDT_Auction *ad,
if (!handler_out[atype][outcome][ad->cur_round] || if (!handler_out[atype][outcome][ad->cur_round] ||
!(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen)))
{ {
weprintf ("failed to create msg %d buffer as seller", GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"failed to create msg %d buffer as seller\n",
ad->cur_round); ad->cur_round);
return; return;
} }
@ -410,7 +429,10 @@ advance_round (struct BRANDT_Auction *ad,
if (!handler_out[atype][outcome][ad->cur_round] || if (!handler_out[atype][outcome][ad->cur_round] ||
!(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen)))
{ {
weprintf ("failed to create msg %d buffer as bidder", ad->cur_round); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"failed to create msg %d buffer as bidder\n",
ad->cur_round);
return; return;
} }
@ -441,14 +463,18 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
/** \todo: cache out of order messages instead of discarding */ /** \todo: cache out of order messages instead of discarding */
if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0) if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0)
{ {
weprintf ("got unexpected message, ignoring..."); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"got unexpected message, ignoring...\n");
return; return;
} }
/* check if we already got that round message from the same user */ /* check if we already got that round message from the same user */
if (gcry_mpi_test_bit (auction->round_progress, sender)) if (gcry_mpi_test_bit (auction->round_progress, sender))
{ {
weprintf ("got a duplicate message from user %d", sender); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"got a duplicate message from user %d\n", sender);
return; return;
} }
@ -459,7 +485,9 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
sender)) sender))
{ {
/** \todo */ /** \todo */
weprintf ("wow fail in"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"wow fail in\n");
return; return;
} }
gcry_mpi_set_bit (auction->round_progress, sender); gcry_mpi_set_bit (auction->round_progress, sender);

View File

@ -219,7 +219,9 @@ ec_point_cmp (const gcry_mpi_point_t a, const gcry_mpi_point_t b)
brandt_assert (a && b); brandt_assert (a && b);
if (!ax || !bx || !ay || !by) if (!ax || !bx || !ay || !by)
{ {
weprintf ("could not init point in point_cmp"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"could not init point in point_cmp\n");
return 1; return 1;
} }
@ -410,8 +412,10 @@ smc_init1 (uint16_t size1)
{ {
if (NULL == (ret[i] = gcry_mpi_point_new (0))) if (NULL == (ret[i] = gcry_mpi_point_new (0)))
{ {
weprintf ("could not init point in 1 dimensional array. " GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"out of memory?"); "libbrandt",
"could not init point in 1 dimensional array. "
"out of memory?\n");
smc_free1 (ret, size1); smc_free1 (ret, size1);
return NULL; return NULL;
} }
@ -464,8 +468,11 @@ smc_init2 (uint16_t size1, uint16_t size2)
{ {
if (NULL == (ret[i][j] = gcry_mpi_point_new (0))) if (NULL == (ret[i][j] = gcry_mpi_point_new (0)))
{ {
weprintf ("could not init point in 2 dimensional array. " GNUNET_log_from (
"out of memory?"); GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"could not init point in 2 dimensional array. "
"out of memory?\n");
smc_free2 (ret, size1, size2); smc_free2 (ret, size1, size2);
GNUNET_assert (0); GNUNET_assert (0);
} }
@ -527,8 +534,11 @@ smc_init3 (uint16_t size1, uint16_t size2, uint16_t size3)
{ {
if (NULL == (ret[i][j][k] = gcry_mpi_point_new (0))) if (NULL == (ret[i][j][k] = gcry_mpi_point_new (0)))
{ {
weprintf ("could not init point in 2 dimensional array. " GNUNET_log_from (
"out of memory?"); GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"could not init point in 2 dimensional array. "
"out of memory?\n");
smc_free3 (ret, size1, size2, size3); smc_free3 (ret, size1, size2, size3);
GNUNET_assert (0); GNUNET_assert (0);
} }
@ -651,7 +661,9 @@ smc_recv_keyshare (struct BRANDT_Auction *ad,
if (buflen != (sizeof (struct ec_mpi) + sizeof (*proof1))) if (buflen != (sizeof (struct ec_mpi) + sizeof (*proof1)))
{ {
weprintf ("wrong size of received key share"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong size of received key share\n");
goto quit; goto quit;
} }
@ -659,7 +671,9 @@ smc_recv_keyshare (struct BRANDT_Auction *ad,
ec_point_parse (y, (struct ec_mpi *)buf); ec_point_parse (y, (struct ec_mpi *)buf);
if (smc_zkp_dl_check (y, proof1)) if (smc_zkp_dl_check (y, proof1))
{ {
weprintf ("wrong zkp1 for public key share received"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong zkp1 for public key share received\n");
goto quit; goto quit;
} }
@ -785,7 +799,9 @@ smc_recv_encrypted_bid (struct BRANDT_Auction *ad,
(0 < ad->m ? 2 : 1) * sizeof (struct proof_2dle)) || (0 < ad->m ? 2 : 1) * sizeof (struct proof_2dle)) ||
NULL == (ct = smc_init2 (2, ad->k))) NULL == (ct = smc_init2 (2, ad->k)))
{ {
weprintf ("wrong size of received encrypted bid"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong size of received encrypted bid\n");
goto quit; goto quit;
} }
@ -801,7 +817,9 @@ smc_recv_encrypted_bid (struct BRANDT_Auction *ad,
proof3 = (struct proof_0og *)(cur + 2 * sizeof (struct ec_mpi)); proof3 = (struct proof_0og *)(cur + 2 * sizeof (struct ec_mpi));
if (smc_zkp_0og_check (ad->Y, ct[0][j], ct[1][j], proof3)) if (smc_zkp_0og_check (ad->Y, ct[0][j], ct[1][j], proof3))
{ {
weprintf ("wrong zkp3 for alpha, beta received"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong zkp3 for alpha, beta received\n");
goto quit; goto quit;
} }
gcry_mpi_ec_add (alpha_sum, alpha_sum, ct[0][j], ec_ctx); 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,
ec_gen, ec_gen,
(struct proof_2dle *)cur)) (struct proof_2dle *)cur))
{ {
weprintf ("wrong zkp2 for alpha, beta received"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong zkp2 for alpha, beta received\n");
goto quit; goto quit;
} }
@ -841,8 +861,11 @@ smc_recv_encrypted_bid (struct BRANDT_Auction *ad,
ec_gen, ec_gen,
(struct proof_2dle *)cur)) (struct proof_2dle *)cur))
{ {
weprintf ("wrong second zkp2 for alpha, beta received. " GNUNET_log_from (
"bid not allowed for this user in M+1st price auctions."); GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong second zkp2 for alpha, beta received. "
"bid not allowed for this user in M+1st price auctions.\n");
goto quit; goto quit;
} }
} }
@ -1381,7 +1404,5 @@ smc_zkp_0og_check (const gcry_mpi_point_t y,
gcry_mpi_point_release (right); gcry_mpi_point_release (right);
gcry_mpi_point_release (tmp); gcry_mpi_point_release (tmp);
if (ret)
weprintf ("ret: 0x%x", ret);
return ret; return ret;
} }

View File

@ -226,7 +226,9 @@ fp_priv_recv_outcome (struct BRANDT_Auction *ad,
if (buflen != (ad->n * ad->k * if (buflen != (ad->n * ad->k *
(2 * sizeof (struct ec_mpi) + sizeof (*proof2)))) (2 * sizeof (struct ec_mpi) + sizeof (*proof2))))
{ {
weprintf ("wrong size of received outcome"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong size of received outcome\n");
goto quit; goto quit;
} }
@ -243,7 +245,9 @@ fp_priv_recv_outcome (struct BRANDT_Auction *ad,
ad->delta3[sender][i][j], ad->delta3[sender][i][j],
proof2)) proof2))
{ {
weprintf ("wrong zkp2 for gamma, delta received"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong zkp2 for gamma, delta received\n");
goto quit; goto quit;
} }
ec_point_copy (ad->gamma3[sender][i][j], gamma); ec_point_copy (ad->gamma3[sender][i][j], gamma);
@ -420,7 +424,10 @@ fp_priv_recv_decryption_seller (struct BRANDT_Auction *ad,
if (buflen != (ad->n * ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2)))) if (buflen != (ad->n * ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2))))
{ {
weprintf ("wrong size of received outcome decryption from bidder"); GNUNET_log_from (
GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong size of received outcome decryption from bidder\n");
goto quit; goto quit;
} }
@ -436,7 +443,9 @@ fp_priv_recv_decryption_seller (struct BRANDT_Auction *ad,
ec_gen, ec_gen,
proof2)) proof2))
{ {
weprintf ("wrong zkp2 for phi, y received from bidder"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong zkp2 for phi, y received from bidder\n");
goto quit; goto quit;
} }
@ -469,7 +478,10 @@ fp_priv_recv_decryption_bidder (struct BRANDT_Auction *ad,
if (buflen != ((ad->n - 1) * ad->n * ad->k * (sizeof (struct ec_mpi) + if (buflen != ((ad->n - 1) * ad->n * ad->k * (sizeof (struct ec_mpi) +
sizeof (*proof2)))) sizeof (*proof2))))
{ {
weprintf ("wrong size of received outcome decryption from seller"); GNUNET_log_from (
GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong size of received outcome decryption from seller\n");
goto quit; goto quit;
} }
@ -498,7 +510,10 @@ fp_priv_recv_decryption_bidder (struct BRANDT_Auction *ad,
ec_gen, ec_gen,
proof2)) proof2))
{ {
weprintf ("wrong zkp2 for phi, y received from seller"); GNUNET_log_from (
GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong zkp2 for phi, y received from seller\n");
goto quit; goto quit;
} }
ec_point_copy (ad->phi3[h][i][j], phi); ec_point_copy (ad->phi3[h][i][j], phi);
@ -554,12 +569,16 @@ fp_priv_determine_outcome (struct BRANDT_Auction *ad,
{ {
if (-1 != price) if (-1 != price)
{ {
weprintf ("multiple winning prices detected"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"multiple winning prices detected\n");
return NULL; return NULL;
} }
if (-1 != winner) if (-1 != winner)
{ {
weprintf ("multiple winners detected"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"multiple winners detected\n");
return NULL; return NULL;
} }
price = j; price = j;

View File

@ -216,7 +216,9 @@ fp_pub_recv_outcome (struct BRANDT_Auction *ad,
if (buflen != (ad->k * (2 * sizeof (struct ec_mpi) + sizeof (*proof2)))) if (buflen != (ad->k * (2 * sizeof (struct ec_mpi) + sizeof (*proof2))))
{ {
weprintf ("wrong size of received outcome"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong size of received outcome\n");
goto quit; goto quit;
} }
@ -231,7 +233,9 @@ fp_pub_recv_outcome (struct BRANDT_Auction *ad,
ad->delta2[sender][j], ad->delta2[sender][j],
proof2)) proof2))
{ {
weprintf ("wrong zkp2 for gamma, delta received"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong zkp2 for gamma, delta received\n");
goto quit; goto quit;
} }
ec_point_copy (ad->gamma2[sender][j], gamma); ec_point_copy (ad->gamma2[sender][j], gamma);
@ -350,7 +354,9 @@ fp_pub_recv_decryption (struct BRANDT_Auction *ad,
if (buflen != (ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2)))) if (buflen != (ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2))))
{ {
weprintf ("wrong size of received outcome decryption"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong size of received outcome decryption\n");
goto quit; goto quit;
} }
@ -364,7 +370,9 @@ fp_pub_recv_decryption (struct BRANDT_Auction *ad,
ec_gen, ec_gen,
proof2)) proof2))
{ {
weprintf ("wrong zkp2 for phi, y received"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong zkp2 for phi, y received\n");
goto quit; goto quit;
} }
ec_point_copy (ad->phi2[sender][j], phi); ec_point_copy (ad->phi2[sender][j], phi);

View File

@ -179,12 +179,16 @@ mp_priv_determine_outcome (struct BRANDT_Auction *ad,
{ {
if (winners >= max_winners) if (winners >= max_winners)
{ {
weprintf ("too many winners detected"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"too many winners detected\n");
goto fail; goto fail;
} }
if (-1 != price && j != price) if (-1 != price && j != price)
{ {
weprintf ("multiple winning prices detected"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"multiple winning prices detected\n");
goto fail; goto fail;
} }
price = j; price = j;
@ -201,7 +205,9 @@ mp_priv_determine_outcome (struct BRANDT_Auction *ad,
gcry_mpi_point_release (sum_phi); gcry_mpi_point_release (sum_phi);
if (ad->m <= ad->n && winners < max_winners && -1 != price) if (ad->m <= ad->n && winners < max_winners && -1 != price)
weprintf ("too few winners detected"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"too few winners detected\n");
if (0 == winners) if (0 == winners)
goto fail; goto fail;

View File

@ -267,7 +267,9 @@ mp_pub_recv_outcome (struct BRANDT_Auction *ad,
if (buflen != (ad->k * (2 * sizeof (struct ec_mpi) + sizeof (*proof2)))) if (buflen != (ad->k * (2 * sizeof (struct ec_mpi) + sizeof (*proof2))))
{ {
weprintf ("wrong size of received outcome"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"wrong size of received outcome\n");
goto quit; goto quit;
} }
@ -282,7 +284,9 @@ mp_pub_recv_outcome (struct BRANDT_Auction *ad,
ad->delta3[sender][0][j], ad->delta3[sender][0][j],
proof2)) proof2))
{ {
weprintf ("wrong zkp2 for gamma, delta received"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"wrong zkp2 for gamma, delta received\n");
goto quit; goto quit;
} }
ec_point_copy (ad->gamma3[sender][0][j], gamma); ec_point_copy (ad->gamma3[sender][0][j], gamma);
@ -411,7 +415,9 @@ mp_pub_recv_decryption (struct BRANDT_Auction *ad,
if (buflen != (2 * ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2)))) if (buflen != (2 * ad->k * (sizeof (struct ec_mpi) + sizeof (*proof2))))
{ {
weprintf ("wrong size of received outcome decryption"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong size of received outcome decryption\n");
goto quit; goto quit;
} }
@ -429,7 +435,9 @@ mp_pub_recv_decryption (struct BRANDT_Auction *ad,
ec_gen, ec_gen,
proof2)) proof2))
{ {
weprintf ("wrong zkp2 for phi, y received"); GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
"libbrandt",
"wrong zkp2 for phi, y received\n");
goto quit; goto quit;
} }
ec_point_copy (ad->phi3[sender][comp][j], phi); ec_point_copy (ad->phi3[sender][comp][j], phi);
@ -496,7 +504,9 @@ mp_pub_determine_outcome (struct BRANDT_Auction *ad,
{ {
if (cur_winner >= ad->m) if (cur_winner >= ad->m)
{ {
weprintf ("too many winners detected"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"too many winners detected\n");
GNUNET_free (ret); GNUNET_free (ret);
ret = NULL; ret = NULL;
goto quit; goto quit;
@ -511,7 +521,9 @@ mp_pub_determine_outcome (struct BRANDT_Auction *ad,
if (cur_winner != ad->m) if (cur_winner != ad->m)
{ {
weprintf ("too few winners detected"); GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
"libbrandt",
"too few winners detected\n");
GNUNET_free (ret); GNUNET_free (ret);
ret = NULL; ret = NULL;
goto quit; goto quit;

View File

@ -28,10 +28,6 @@
#include "test.h" #include "test.h"
static uint16_t bidders;
static uint16_t prizes;
static struct BRANDT_Auction *ad;
static int static int
test_serialization () test_serialization ()
{ {
@ -137,158 +133,14 @@ test_smc_zkp_0og ()
} }
static int
test_setup_auction_data ()
{
uint16_t i;
ad = GNUNET_new_array (bidders, struct BRANDT_Auction);
for (i = 0; i < bidders; i++)
{
ad[i].n = bidders;
ad[i].i = i;
ad[i].k = prizes;
ad[i].b = i;
}
return 1;
}
/**
* compute round @a index of the protocol specified by @a type and @a oc
*
* @param[in] type auction type
* @param[in] oc outcome type
* @param[in] index round index
*/
#define ROUND(type, oc, index) do { \
for (uint16_t i = 0; i < bidders; i++) \
{ \
handler_prep[type][oc][index] (&ad[i]); \
bufs[i] = handler_out[type][oc][index] (&ad[i], &lens[i]); \
CHECK (bufs[i], "failed to gen message buffer"); \
} \
\
for (uint16_t i = 0; i < bidders; i++) \
{ \
/* enable seller mode for receiving decryption messages */ \
if (msg_decrypt == index) \
ad[i].seller_mode = 1; \
for (uint16_t s = 0; s < bidders; s++) \
{ \
if (s == i) \
continue; \
CHECK (handler_in[type][oc][index] (&ad[i], \
bufs[s] + \
sizeof (struct msg_head), \
lens[s] - \
sizeof (struct msg_head), \
s), \
"failed to parse message buffer"); \
} \
/* disable seller mode again */ \
if (msg_decrypt == index) \
ad[i].seller_mode = 0; \
} \
\
for (uint16_t i = 0; i < bidders; i++) \
free (bufs[i]); \
} while (0)
static int
test_auction (enum auction_type atype, enum outcome_type oc)
{
unsigned char *bufs[bidders];
size_t lens[bidders];
int32_t winner = -1;
int32_t price = -1;
weprintf ("testing auction type %d and outcome format %d...", atype, oc);
ROUND (atype, oc, msg_init);
ROUND (atype, oc, msg_bid);
ROUND (atype, oc, msg_outcome);
ROUND (atype, oc, msg_decrypt);
/* outcome */
for (uint16_t i = 0; i < ad->n; i++)
{
struct BRANDT_Result *res;
uint16_t reslen;
res = handler_res[atype][oc] (&ad[i], &reslen);
if (res && -1 == price && -1 != res->price)
price = res->price;
if (res)
weprintf ("price: %d", res->price);
CHECK (!res || res->price == price, "different prices detected");
if (res && -1 == winner && -1 != res->bidder)
winner = res->bidder;
CHECK (!res || res->bidder == winner, "different winners detected");
}
CHECK (-1 != winner, "no winner detected");
CHECK (-1 != price, "no price detected");
fputs ("good: one winner detected\n", stderr);
return 1;
}
static void
cleanup_auction_data ()
{
for (uint16_t i = 0; i < bidders; i++)
{
gcry_mpi_point_release (ad[i].Y);
gcry_mpi_release (ad[i].x);
smc_free1 (ad[i].y, ad[i].n);
smc_free2 (ad[i].alpha, ad[i].n, ad[i].k);
smc_free2 (ad[i].beta, ad[i].n, ad[i].k);
smc_free2 (ad[i].gamma2, ad[i].n, ad[i].k);
smc_free2 (ad[i].delta2, ad[i].n, ad[i].k);
smc_free2 (ad[i].phi2, ad[i].n, ad[i].k);
smc_free3 (ad[i].gamma3, ad[i].n, ad[i].n, ad[i].k);
smc_free3 (ad[i].delta3, ad[i].n, ad[i].n, ad[i].k);
smc_free3 (ad[i].phi3, ad[i].n, ad[i].n, ad[i].k);
smc_free1 (ad[i].tmpa1, ad[i].k);
smc_free1 (ad[i].tmpb1, ad[i].k);
}
free (ad);
}
static int
test_all_auctions ()
{
for (size_t atype = 0; atype < auction_last; atype++)
{
if (auction_firstPrice != atype) /* others not yet implemented */
continue;
for (size_t oc = 0; oc < outcome_last; oc++)
{
if (!test_setup_auction_data () || !test_auction (atype, oc))
{
cleanup_auction_data ();
return 0;
}
cleanup_auction_data ();
}
}
return 1;
}
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
int repeat = 1; int repeat = 1;
struct GNUNET_CRYPTO_EccDlogContext *edc; struct GNUNET_CRYPTO_EccDlogContext *edc;
bidders = 3; if (GNUNET_OK != GNUNET_log_setup ("test_crypto", "WARNING", NULL))
prizes = 3; return 1;
edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16); edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16);
BRANDT_init (edc); BRANDT_init (edc);
@ -303,8 +155,6 @@ main (int argc, char *argv[])
RUN (test_smc_zkp_0og); RUN (test_smc_zkp_0og);
} }
RUN (test_all_auctions);
GNUNET_CRYPTO_ecc_dlog_release (edc); GNUNET_CRYPTO_ecc_dlog_release (edc);
return ret; return ret;
} }