diff options
Diffstat (limited to 'test_crypto.c')
-rw-r--r-- | test_crypto.c | 177 |
1 files changed, 59 insertions, 118 deletions
diff --git a/test_crypto.c b/test_crypto.c index 09a0838..297ac69 100644 --- a/test_crypto.c +++ b/test_crypto.c @@ -30,8 +30,8 @@ #include "test.h" -static uint16_t bidders; -static uint16_t prizes; +static uint16_t bidders; +static uint16_t prizes; static struct BRANDT_Auction *ad; int @@ -199,141 +199,83 @@ test_setup_auction_data () } -int -test_prologue () -{ - uint16_t i, s; - unsigned char *bufs[bidders]; - size_t lens[bidders]; - - for (i = 0; i < bidders; i++) - { - bufs[i] = smc_gen_keyshare (&ad[i], &lens[i]); - check (bufs[i], "failed to gen keyshare"); - } - - for (i = 0; i < bidders; i++) - { - for (s = 0; s < bidders; s++) - { - if (s == i) - continue; - check (smc_recv_keyshare (&ad[i], bufs[s], lens[s], s), - "failed checking keyshare"); - } - } - - for (i = 0; i < bidders; i++) - free (bufs[i]); - return 1; -} +#define ROUND(type, oc, index) do { \ + for (uint16_t i = 0; i < bidders; i++) \ + { \ + bufs[i] = handler_out[type][oc][index] (&ad[i], &lens[i]); \ + check (bufs[i], "failed to gen keyshare"); \ + } \ + \ + for (uint16_t i = 0; i < bidders; i++) \ + { \ + for (uint16_t s = 0; s < bidders; s++) \ + { \ + if (s == i) \ + continue; \ + check (handler_in[type][oc][index] (&ad[i], bufs[s], lens[s], s), \ + "failed checking keyshare"); \ + } \ + } \ + \ + for (uint16_t i = 0; i < bidders; i++) \ + free (bufs[i]); \ +} while (0) int -test_round1 () +test_private_first_price () { - uint16_t i, s; unsigned char *bufs[bidders]; size_t lens[bidders]; + int32_t winner = -1; - for (i = 0; i < bidders; i++) - { - bufs[i] = smc_encrypt_bid (&ad[i], &lens[i]); - check (bufs[i], "failed to encrypt bid"); - } + 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); - for (i = 0; i < bidders; i++) + /* outcome */ + for (uint16_t i = 0; i < ad->n; i++) { - for (s = 0; s < bidders; s++) + if (-1 != fp_priv_determine_outcome (&ad[i])) { - if (s == i) - continue; - check (smc_recv_encrypted_bid (&ad[i], bufs[s], lens[s], s), - "failed checking encrypted bid"); + check (-1 == winner, "multiple winners detected"); + winner = i; } } - - for (i = 0; i < bidders; i++) - free (bufs[i]); + check (-1 != winner, "no winner detected"); + fputs ("good: one winner detected", stderr); return 1; } int -test_round2 () -{ - uint16_t i, s; - unsigned char *bufs[bidders]; - size_t lens[bidders]; - - for (i = 0; i < bidders; i++) - { - bufs[i] = fp_priv_compute_outcome (&ad[i], &lens[i]); - check (bufs[i], "failed to compute outcome"); - } - - for (i = 0; i < bidders; i++) - { - for (s = 0; s < bidders; s++) - { - if (s == i) - continue; - check (fp_priv_recv_outcome (&ad[i], bufs[s], lens[s], s), - "failed checking outcome"); - } - } - - for (i = 0; i < bidders; i++) - free (bufs[i]); - return 1; -} - - -static int -test_round3 () +test_public_first_price () { - uint16_t i, s; unsigned char *bufs[bidders]; size_t lens[bidders]; + int32_t wret = -1; + int32_t pret = -1; + uint16_t winner = -1; + uint16_t price = -1; - for (i = 0; i < bidders; i++) - { - bufs[i] = fp_priv_decrypt_outcome (&ad[i], &lens[i]); - check (bufs[i], "failed to decrypt outcome"); - } - - for (i = 0; i < bidders; i++) - { - for (s = 0; s < bidders; s++) - { - if (s == i) - continue; - check (fp_priv_recv_decryption (&ad[i], bufs[s], lens[s], s), - "failed checking decrypted outcome"); - } - } - - for (i = 0; i < bidders; i++) - free (bufs[i]); - return 1; -} - - -static int -test_outcome () -{ - int32_t ret = -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++) { - if (-1 != fp_priv_determine_outcome (&ad[i])) - { - check (-1 == ret, "multiple winners detected"); - ret = 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"); } - check (-1 != ret, "no winner detected"); - fputs ("winner detected", stderr); + fputs ("good: same winner detected", stderr); return 1; } @@ -364,7 +306,7 @@ cleanup_auction_data () int main (int argc, char *argv[]) { - int repeat = 1; + int repeat = 1; struct GNUNET_CRYPTO_EccDlogContext *edc; bidders = 2; @@ -386,11 +328,10 @@ main (int argc, char *argv[]) } run (test_setup_auction_data); - run (test_prologue); - run (test_round1); - run (test_round2); - run (test_round3); - run (test_outcome); + run (test_private_first_price); + cleanup_auction_data (); + run (test_setup_auction_data); + run (test_public_first_price); cleanup_auction_data (); GNUNET_CRYPTO_ecc_dlog_release (edc); |