diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-09-08 19:17:15 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-09-08 19:17:15 +0200 |
commit | 14546eccb205aa844657d2c350c83f6be1289b67 (patch) | |
tree | 8d081850e2ca5dd44b1e03d7ed39a61c487c9725 /brandt.c | |
parent | f294cd3a85c084490a10ae6ac9c1dab4c60a7678 (diff) |
test_brandt nearly done
Diffstat (limited to 'brandt.c')
-rw-r--r-- | brandt.c | 95 |
1 files changed, 57 insertions, 38 deletions
@@ -287,6 +287,7 @@ BRANDT_destroy (struct BRANDT_Auction *auction) smc_free3 (auction->delta3, auction->n, auction->n, auction->k); smc_free2 (auction->phi2, auction->n, auction->k); smc_free3 (auction->phi3, auction->n, auction->n, auction->k); + free (auction->phiproofs3); smc_free1 (auction->tmpa1, auction->k); smc_free1 (auction->tmpb1, auction->k); } @@ -304,56 +305,75 @@ advance_round (struct BRANDT_Auction *ad, /* if we did not got the current round message from all participants, don't * advance to the next round yet. Early return, since we have to wait for - * the other participants messages. */ + * the other participants messages. In the msg_decrypt round as a bidder we + * only need the one message from the seller. */ for (uint16_t i = 0; i < ad->n; i++) - if (!gcry_mpi_test_bit (ad->round_progress, i)) + if (!gcry_mpi_test_bit (ad->round_progress, i) && + (ad->seller_mode || msg_decrypt != ad->cur_round)) return; - /* current round finished, clear round progress and advance to next one */ - gcry_mpi_clear_highbit (ad->round_progress, 0); - if (msg_last == ++(ad->cur_round)) + /* Do not advance to the next round if we are the seller and got all + * msg_decrypt messages from the bidders. We need to broadcast our combined + * msg_decrypt message back to the sellers first */ + if (!ad->seller_mode || msg_decrypt != ad->cur_round) { - /* done with all rounds, determine outcome here */ - if (!handler_res[atype][outcome] || - !(res = handler_res[atype][outcome] (ad, &reslen))) - { - /** \todo */ - weprintf ("wow fail result"); - /** \todo: call result with null pointer here? */ - return; - } + /* clear old round progress and advance to next one */ + gcry_mpi_clear_highbit (ad->round_progress, 0); + ad->cur_round++; - ad->result (ad->closure, res, reslen); - return; - } + /* prepare next round. */ + if (handler_prep[atype][outcome][ad->cur_round]) + handler_prep[atype][outcome][ad->cur_round] (ad); - if (handler_prep[atype][outcome][ad->cur_round]) - handler_prep[atype][outcome][ad->cur_round] (ad); - - if (ad->seller_mode) - { /** \todo: setup round timeout trigger */ - return; + if (ad->seller_mode) + { + } } - if (!handler_out[atype][outcome][ad->cur_round] || - !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) + /* send next message if we are not done yet */ + if ((!ad->seller_mode && msg_last > ad->cur_round) || + (ad->seller_mode && msg_decrypt == ad->cur_round && + gcry_mpi_test_bit (ad->round_progress, 0))) { - /** \todo */ - weprintf ("wow fail out"); - return; - } + if (!handler_out[atype][outcome][ad->cur_round] || + !(buf = handler_out[atype][outcome][ad->cur_round](ad, &buflen))) + { + weprintf ("failed to create message %d buffer", ad->cur_round); + return; + } - /* last message only sent to seller, others are broadcasted */ - if (msg_decrypt == ad->cur_round) - { - if (0 == ad->ucast (ad->closure, buf, buflen)) - gcry_mpi_set_bit (ad->round_progress, ad->i); + /* msg_decrypt unicast to seller or broadcast from seller. + * All other messages are broadcasted */ + if (msg_decrypt == ad->cur_round && !ad->seller_mode) + { + if (0 == ad->ucast (ad->closure, buf, buflen)) + gcry_mpi_set_bit (ad->round_progress, ad->i); + } + else + { + if (!ad->seller_mode && 0 == ad->bcast (ad->closure, buf, buflen)) + gcry_mpi_set_bit (ad->round_progress, ad->i); + } } - else + + if (msg_last == ad->cur_round || + (msg_decrypt == ad->cur_round && ad->seller_mode && + gcry_mpi_test_bit (ad->round_progress, 0))) { - if (0 == ad->bcast (ad->closure, buf, buflen)) - gcry_mpi_set_bit (ad->round_progress, ad->i); + /* done with all rounds, determine outcome here */ + if (!handler_res[atype][outcome] || + !(res = handler_res[atype][outcome] (ad, &reslen))) + { + weprintf ("failed to determine result"); + /** \todo: call result with null pointer here? */ + return; + } + + ad->result (ad->closure, res, reslen); + /* seller still needs to broadcast the decryption to all bidders */ + if (!ad->seller_mode) + return; } } @@ -400,6 +420,5 @@ BRANDT_got_message (struct BRANDT_Auction *auction, gcry_mpi_set_bit (auction->round_progress, sender); DM(auction->round_progress); - /** \todo: seller_mode and new task for round timing */ advance_round (auction, atype, outcome); } |