diff --git a/brandt.c b/brandt.c index 2e6a5ed..dd66e0c 100644 --- a/brandt.c +++ b/brandt.c @@ -77,7 +77,6 @@ BRANDT_bidder_start (struct BRANDT_Auction *auction, return; } - weprintf("broadcasting msg_init %p from bidder %d", buf, i); auction->bcast (auction->closure, buf, buflen); gcry_mpi_set_bit (auction->round_progress, auction->i); free (buf); @@ -88,8 +87,8 @@ static void seller_start (void *arg) { struct BRANDT_Auction *ad = (struct BRANDT_Auction *)arg; - enum auction_type atype; - enum outcome_type outcome; + enum auction_type atype; + enum outcome_type outcome; ad->task = NULL; @@ -302,7 +301,7 @@ report_outcome (struct BRANDT_Auction *ad, uint16_t reslen = 0; if (!handler_res[atype][outcome] || - !(res = handler_res[atype][outcome] (ad, &reslen))) + !(res = handler_res[atype][outcome] (ad, &reslen))) ad->result (ad->closure, NULL, 0); else ad->result (ad->closure, res, reslen); @@ -341,7 +340,7 @@ advance_round (struct BRANDT_Auction *ad, { /* all bidders msg_decrypt received, broadcast combined msg_decrypt */ 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", ad->cur_round); @@ -371,7 +370,7 @@ advance_round (struct BRANDT_Auction *ad, /* create next message buffer */ 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); return; @@ -404,7 +403,6 @@ BRANDT_got_message (struct BRANDT_Auction *auction, /** \todo: cache out of order messages instead of discarding */ if (ntohl (head->msg_type) != round || ntohl (head->prot_version) != 0) { - weprintf ("%d", auction->i); weprintf ("got unexpected message, ignoring..."); return; } @@ -427,7 +425,6 @@ BRANDT_got_message (struct BRANDT_Auction *auction, return; } gcry_mpi_set_bit (auction->round_progress, sender); - DM(auction->round_progress); advance_round (auction, atype, outcome); } diff --git a/brandt.h b/brandt.h index 3ed48b6..2017a6b 100644 --- a/brandt.h +++ b/brandt.h @@ -29,8 +29,7 @@ #include /** Enumeration of all possible status reports for a single bidder */ -enum BRANDT_BidderStatus -{ +enum BRANDT_BidderStatus { BRANDT_bidder_won, }; @@ -41,8 +40,7 @@ struct BRANDT_Auction; * An array of this struct is given to the application by the BRANDT_CbResult() * callback. One instance represents the status of a single bidder. */ -struct BRANDT_Result -{ +struct BRANDT_Result { /** Id of the bidder this instance refers to */ uint16_t bidder; diff --git a/crypto.c b/crypto.c index eb7e944..600fbb8 100644 --- a/crypto.c +++ b/crypto.c @@ -816,12 +816,12 @@ quit: void fp_pub_prep_outcome (struct BRANDT_Auction *ad) { - gcry_mpi_t coeff = gcry_mpi_copy (GCRYMPI_CONST_ONE); - gcry_mpi_point_t tmp = gcry_mpi_point_new (0); - gcry_mpi_point_t *tlta1; - gcry_mpi_point_t *tltb1; - gcry_mpi_point_t **tlta2; - gcry_mpi_point_t **tltb2; + gcry_mpi_t coeff = gcry_mpi_copy (GCRYMPI_CONST_ONE); + gcry_mpi_point_t tmp = gcry_mpi_point_new (0); + gcry_mpi_point_t *tlta1; + gcry_mpi_point_t *tltb1; + gcry_mpi_point_t **tlta2; + gcry_mpi_point_t **tltb2; ad->gamma2 = smc_init2 (ad->n, ad->k); brandt_assert (ad->gamma2); @@ -1045,7 +1045,7 @@ quit: void fp_pub_prep_decryption (struct BRANDT_Auction *ad) { - gcry_mpi_point_t tmp = gcry_mpi_point_new (0); + gcry_mpi_point_t tmp = gcry_mpi_point_new (0); ad->phi2 = smc_init2 (ad->n, ad->k); brandt_assert (ad->phi2); @@ -1162,15 +1162,16 @@ quit: } -struct BRANDT_Result *fp_pub_determine_outcome (struct BRANDT_Auction *ad, - uint16_t *len) +struct BRANDT_Result * +fp_pub_determine_outcome (struct BRANDT_Auction *ad, + uint16_t *len) { struct BRANDT_Result *ret; - int32_t price = -1; - int32_t winner = -1; - int dlogi = -1; - gcry_mpi_point_t sum_gamma = gcry_mpi_point_new (0); - gcry_mpi_point_t sum_phi = gcry_mpi_point_new (0); + int32_t price = -1; + int32_t winner = -1; + int dlogi = -1; + gcry_mpi_point_t sum_gamma = gcry_mpi_point_new (0); + gcry_mpi_point_t sum_phi = gcry_mpi_point_new (0); brandt_assert (ad); @@ -1208,7 +1209,7 @@ struct BRANDT_Result *fp_pub_determine_outcome (struct BRANDT_Auction *ad, if (-1 == winner || -1 == price) return NULL; - ret = GNUNET_new(struct BRANDT_Result); + ret = GNUNET_new (struct BRANDT_Result); ret->bidder = winner; ret->price = price; ret->status = BRANDT_bidder_won; @@ -1221,14 +1222,14 @@ struct BRANDT_Result *fp_pub_determine_outcome (struct BRANDT_Auction *ad, void fp_priv_prep_outcome (struct BRANDT_Auction *ad) { - gcry_mpi_point_t tmpa = gcry_mpi_point_new (0); - gcry_mpi_point_t tmpb = gcry_mpi_point_new (0); - gcry_mpi_point_t *tlta1; - gcry_mpi_point_t *tltb1; - gcry_mpi_point_t **tlta2; - gcry_mpi_point_t **tltb2; - gcry_mpi_point_t **tlta3; - gcry_mpi_point_t **tltb3; + gcry_mpi_point_t tmpa = gcry_mpi_point_new (0); + gcry_mpi_point_t tmpb = gcry_mpi_point_new (0); + gcry_mpi_point_t *tlta1; + gcry_mpi_point_t *tltb1; + gcry_mpi_point_t **tlta2; + gcry_mpi_point_t **tltb2; + gcry_mpi_point_t **tlta3; + gcry_mpi_point_t **tltb3; ad->gamma3 = smc_init3 (ad->n, ad->n, ad->k); brandt_assert (ad->gamma3); @@ -1452,7 +1453,7 @@ quit: void fp_priv_prep_decryption (struct BRANDT_Auction *ad) { - gcry_mpi_point_t tmp = gcry_mpi_point_new (0); + gcry_mpi_point_t tmp = gcry_mpi_point_new (0); ad->phi3 = smc_init3 (ad->n, ad->n, ad->k); brandt_assert (ad->phi3); @@ -1682,10 +1683,10 @@ fp_priv_recv_decryption_bidder (struct BRANDT_Auction *ad, ec_point_parse (phi, (struct ec_mpi *)cur); proof2 = (struct proof_2dle *)(cur + sizeof (struct ec_mpi)); if (smc_zkp_2dle_check (phi, - ad->y[h], - ad->phi3[h][i][j], - ec_gen, - proof2)) + ad->y[h], + ad->phi3[h][i][j], + ec_gen, + proof2)) { weprintf ("wrong zkp2 for phi, y received from seller"); goto quit; @@ -1717,8 +1718,9 @@ fp_priv_recv_decryption (struct BRANDT_Auction *ad, } -struct BRANDT_Result *fp_priv_determine_outcome (struct BRANDT_Auction *ad, - uint16_t *len) +struct BRANDT_Result * +fp_priv_determine_outcome (struct BRANDT_Auction *ad, + uint16_t *len) { struct BRANDT_Result *ret; int32_t price = -1; @@ -1762,7 +1764,7 @@ struct BRANDT_Result *fp_priv_determine_outcome (struct BRANDT_Auction *ad, if (-1 == winner || -1 == price) return NULL; - ret = GNUNET_new(struct BRANDT_Result); + ret = GNUNET_new (struct BRANDT_Result); ret->bidder = winner; ret->price = price; ret->status = BRANDT_bidder_won; diff --git a/crypto.h b/crypto.h index 16aa536..e9338f4 100644 --- a/crypto.h +++ b/crypto.h @@ -176,14 +176,14 @@ typedef void typedef int (*MsgIn)(struct BRANDT_Auction *ad, - const unsigned char *buf, - size_t buflen, - uint16_t sender); + const unsigned char *buf, + size_t buflen, + uint16_t sender); typedef unsigned char * (*MsgOut)(struct BRANDT_Auction *ad, - size_t *buflen); + size_t *buflen); /** @@ -317,9 +317,9 @@ static const MsgOut handler_out[auction_last][outcome_last][msg_last] = { * of 0 means a private outcome, while a value of 1 means public outcome. */ static const Result handler_res[auction_last][outcome_last] = { - [auction_firstPrice] = { + [auction_firstPrice] = { [outcome_private] = &fp_priv_determine_outcome, - [outcome_public] = &fp_pub_determine_outcome, + [outcome_public] = &fp_pub_determine_outcome, }, // [auction_mPlusFirstPrice] = { // [outcome_private] = , diff --git a/test_brandt.c b/test_brandt.c index fb0f2c9..077f6f1 100644 --- a/test_brandt.c +++ b/test_brandt.c @@ -30,19 +30,18 @@ #include "util.h" -struct msg -{ - uint16_t sender; - uint16_t receiver; - void *buf; - size_t buf_len; +struct msg { + uint16_t sender; + uint16_t receiver; + void *buf; + size_t buf_len; }; -static uint16_t *id; +static uint16_t *id; static struct BRANDT_Auction **ad; -static uint16_t bidders = 3; -static uint16_t prizes = 8; +static uint16_t bidders = 3; +static uint16_t prizes = 8; static void @@ -50,7 +49,7 @@ bidder_start (void *arg) { uint16_t i = *(uint16_t *)arg; - weprintf("starting bidder %d", i); + weprintf ("starting bidder %d", i); BRANDT_bidder_start (ad[i], i, bidders); } @@ -58,10 +57,11 @@ bidder_start (void *arg) static void transfer_message (void *arg) { - struct msg *m = (struct msg *)arg; + struct msg *m = (struct msg *)arg; struct msg_head *h = (struct msg_head *)m->buf; - weprintf("xfer msg %d %x from %d to %d", ntohl(h->msg_type), arg, m->sender, m->receiver); + weprintf ("xfer msg %d %x from %d to %d", ntohl ( + h->msg_type), arg, m->sender, m->receiver); BRANDT_got_message (ad[m->receiver], m->sender, m->buf, m->buf_len); free (arg); } @@ -71,6 +71,7 @@ static uint16_t cb_start (void *auction_closure) { uint16_t *s = (uint16_t *)auction_closure; + if (!s || bidders != *s) { weprintf ("start callback called from bidder"); @@ -89,7 +90,7 @@ cb_broadcast (void *auction_closure, const void *msg, size_t msg_len) { - uint16_t *s = (uint16_t *)auction_closure; + uint16_t *s = (uint16_t *)auction_closure; struct msg *m; for (uint16_t i = 0; i <= bidders; i++) @@ -113,7 +114,7 @@ cb_unicast (void *auction_closure, const void *msg, size_t msg_len) { - uint16_t *s = (uint16_t *)auction_closure; + uint16_t *s = (uint16_t *)auction_closure; struct msg *m; m = GNUNET_new (struct msg); @@ -139,37 +140,38 @@ cb_result (void *auction_closure, weprintf ("result determined by agent %d: none", *s); for (uint16_t i = 0; i < results_len; i++) - weprintf ("result determined by agent %d: bidder %d got status %d with price %d", - *s, - results[i].bidder, - results[i].status, - results[i].price); + weprintf ( + "result determined by agent %d: bidder %d got status %d with price %d", + *s, + results[i].bidder, + results[i].status, + results[i].price); } static void run_new_join (void *arg) { - int *ret = arg; - const char description[] = "test description for test_new_join"; - void *desc; - size_t desc_len; + int *ret = arg; + const char description[] = "test description for test_new_join"; + void *desc; + size_t desc_len; ad = GNUNET_new_array (bidders + 1, struct BRANDT_Auction *); ad[bidders] = BRANDT_new (&cb_result, - &cb_broadcast, - &cb_start, - &id[bidders], - &desc, - &desc_len, - description, - sizeof (description), - GNUNET_TIME_absolute_get (), - GNUNET_TIME_UNIT_MINUTES, - prizes, /* amount of possible prizes */ - 0, /* m */ - 1); /* outcome public */ + &cb_broadcast, + &cb_start, + &id[bidders], + &desc, + &desc_len, + description, + sizeof (description), + GNUNET_TIME_absolute_get (), + GNUNET_TIME_UNIT_MINUTES, + prizes, /* amount of possible prizes */ + 0, /* m */ + 1); /* outcome public */ if (!ad[bidders]) { weprintf ("BRANDT_new() failed."); @@ -179,14 +181,14 @@ run_new_join (void *arg) for (uint16_t i = 0; i < bidders; i++) { ad[i] = BRANDT_join (&cb_result, - &cb_broadcast, - &cb_unicast, - &id[i], - desc, - desc_len, - description, - sizeof (description), - 3); /* bid */ + &cb_broadcast, + &cb_unicast, + &id[i], + desc, + desc_len, + description, + sizeof (description), + 3); /* bid */ if (!ad[i]) { weprintf ("BRANDT_join() failed."); @@ -194,14 +196,14 @@ run_new_join (void *arg) } if (ad[bidders]->k != ad[i]->k || - ad[bidders]->m != ad[i]->m || - ad[bidders]->outcome_public != ad[i]->outcome_public || - ad[bidders]->time_start.abs_value_us - != ad[i]->time_start.abs_value_us || - ad[bidders]->time_round.rel_value_us - != ad[i]->time_round.rel_value_us || - !ad[bidders]->seller_mode || /* todo: split out */ - ad[i]->seller_mode) + ad[bidders]->m != ad[i]->m || + ad[bidders]->outcome_public != ad[i]->outcome_public || + ad[bidders]->time_start.abs_value_us + != ad[i]->time_start.abs_value_us || + ad[bidders]->time_round.rel_value_us + != ad[i]->time_round.rel_value_us || + !ad[bidders]->seller_mode || /* todo: split out */ + ad[i]->seller_mode) { weprintf ("error/mismatch in basic auction data"); _exit (1); diff --git a/test_crypto.c b/test_crypto.c index 2a04c1d..cfc6160 100644 --- a/test_crypto.c +++ b/test_crypto.c @@ -199,7 +199,7 @@ test_setup_auction_data () /** * 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 @@ -310,7 +310,7 @@ test_all_auctions () for (size_t oc = 0; oc < outcome_last; oc++) { - if (!test_setup_auction_data() || !test_auction (atype, oc)) + if (!test_setup_auction_data () || !test_auction (atype, oc)) { cleanup_auction_data (); return 0;