From 56b43dab7ff80acc4cd0e7ad3057abd5e6bad680 Mon Sep 17 00:00:00 2001 From: Markus Teich Date: Fri, 2 Dec 2016 09:34:25 +0100 Subject: migrate to GNUNET_log --- test_crypto.c | 154 +--------------------------------------------------------- 1 file changed, 2 insertions(+), 152 deletions(-) (limited to 'test_crypto.c') 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 @@ #include "test.h" -static uint16_t bidders; -static uint16_t prizes; -static struct BRANDT_Auction *ad; - static int 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 main (int argc, char *argv[]) { int repeat = 1; struct GNUNET_CRYPTO_EccDlogContext *edc; - bidders = 3; - prizes = 3; + if (GNUNET_OK != GNUNET_log_setup ("test_crypto", "WARNING", NULL)) + return 1; edc = GNUNET_CRYPTO_ecc_dlog_prepare (1024, 16); BRANDT_init (edc); @@ -303,8 +155,6 @@ main (int argc, char *argv[]) RUN (test_smc_zkp_0og); } - RUN (test_all_auctions); - GNUNET_CRYPTO_ecc_dlog_release (edc); return ret; } -- cgit v1.2.3