diff options
Diffstat (limited to 'test_crypto.c')
-rw-r--r-- | test_crypto.c | 101 |
1 files changed, 53 insertions, 48 deletions
diff --git a/test_crypto.c b/test_crypto.c index 53e06fe..057754a 100644 --- a/test_crypto.c +++ b/test_crypto.c @@ -197,11 +197,17 @@ 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 */ #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 keyshare"); \ } \ @@ -228,63 +234,43 @@ test_setup_auction_data () static int -test_private_first_price () +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; - ROUND (auction_firstPrice, outcome_private, msg_init); - ROUND (auction_firstPrice, outcome_private, msg_bid); - ROUND (auction_firstPrice, outcome_private, msg_outcome); - ROUND (auction_firstPrice, outcome_private, msg_decrypt); + 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++) { - if (-1 != fp_priv_determine_outcome (&ad[i])) - { - CHECK (-1 == winner, "multiple winners detected"); - winner = 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 int -test_public_first_price () -{ - unsigned char *bufs[bidders]; - size_t lens[bidders]; - int32_t wret = -1; - int32_t pret = -1; - uint16_t winner = -1; - uint16_t price = -1; - - ROUND (auction_firstPrice, outcome_public, msg_init); - ROUND (auction_firstPrice, outcome_public, msg_bid); - ROUND (auction_firstPrice, outcome_public, msg_outcome); - ROUND (auction_firstPrice, outcome_public, msg_decrypt); - - /* outcome */ - for (uint16_t i = 0; i < ad->n; i++) - { - price = fp_pub_determine_outcome (&ad[i], &winner); - if (-1 == pret) - pret = price; - CHECK (price == pret, "different prices detected"); - if (-1 == wret) - wret = winner; - CHECK (winner == wret, "different winners detected"); - } - fputs ("good: same winner detected\n", stderr); - return 1; -} - - static void cleanup_auction_data () { @@ -308,6 +294,30 @@ cleanup_auction_data () } +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++) +// { + size_t oc = outcome_public; + if (!test_setup_auction_data() || !test_auction (atype, oc)) + { + cleanup_auction_data (); + return 0; + } + cleanup_auction_data (); +// } + } + + return 1; +} + + int main (int argc, char *argv[]) { @@ -332,12 +342,7 @@ main (int argc, char *argv[]) RUN (test_smc_zkp_0og); } - RUN (test_setup_auction_data); - RUN (test_private_first_price); - cleanup_auction_data (); - RUN (test_setup_auction_data); - RUN (test_public_first_price); - cleanup_auction_data (); + RUN (test_all_auctions); GNUNET_CRYPTO_ecc_dlog_release (edc); return ret; |