diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-07-06 14:56:14 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-07-06 14:56:14 +0200 |
commit | 4deee5eb1247b46d04c4ab8eeba52ca4e4db0567 (patch) | |
tree | 0ce15be1f4ca4bd52a62d6418fd6b1e7f5f5f5b8 /brandt.c | |
parent | 39ff8cfaa4c0d90bfcd1f2a4a21f6bd498faec93 (diff) |
start with brandt.c
Diffstat (limited to 'brandt.c')
-rw-r--r-- | brandt.c | 82 |
1 files changed, 81 insertions, 1 deletions
@@ -22,8 +22,62 @@ #include <gcrypt.h> #include "crypto.h" +#include "internals.h" #include "util.h" + +typedef int +(*msg_recv)(struct BRANDT_Auction *ad, + const unsigned char *buf, + size_t buflen, + uint16_t sender); + + +/** + * stores the function pointers to receive functions for each state. + * + * The first index denotes if a first price auction or a M+1st price auction is + * used. If it is 0, it is a first price auction, if it is 1, it is a M+1st + * price auction. + * + * The second index denotes if the outcome should be public or private. A value + * of 0 means a private outcome, while a value of 1 means public outcome. + */ +static msg_recv handler_in[2][2][msg_last] = +{ + [0] = + { + [0] = + { + [msg_init] = smc_recv_keyshare, + [msg_bid] = smc_recv_encrypted_bid, + [msg_outcome] = fp_priv_recv_outcome, + [msg_decrypt] = fp_priv_recv_decryption, + }, + [1] = + { + [msg_init] = smc_recv_keyshare, + [msg_bid] = smc_recv_encrypted_bid, + [msg_outcome] = fp_pub_recv_outcome, + [msg_decrypt] = fp_pub_recv_decryption, + } + }, + [1] = + { + [0] = + { + [msg_init] = smc_recv_keyshare, + [msg_bid] = smc_recv_encrypted_bid, + }, + [1] = + { + [msg_init] = smc_recv_keyshare, + [msg_bid] = smc_recv_encrypted_bid, + } + } +}; + + void BRANDT_init () { @@ -37,7 +91,7 @@ BRANDT_init () weprintf ("failed to set libgcrypt option DISABLE_SECMEM: %s", gcry_strerror (err)); - /* ecc is slow otherwise. */ + /* ecc is slow otherwise and we don't create long term keys anyway. */ if ((err = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) weprintf ("failed to set libgcrypt option ENABLE_QUICK_RANDOM: %s", gcry_strerror (err)); @@ -45,3 +99,29 @@ BRANDT_init () gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); brandt_crypto_init (); } + + +void +BRANDT_got_message (struct BRANDT_Auction *auction, + uint16_t sender, + const unsigned char *msg, + size_t msg_len) +{ + uint16_t type = *(uint16_t *)msg; + int m = !!auction->desc->m; + int pub = !!auction->desc->outcome_public; + enum rounds round = auction->cur_round; + + /** todo: cache out of order messages */ + + if (!handler_in[m][pub][round] || + !handler_in[m][pub][round](auction, + msg + sizeof (type), + msg_len - sizeof (type), + sender)) + { + /** \todo */ + weprintf ("wow fail"); + } + msg + sizeof (type); +} |