aboutsummaryrefslogtreecommitdiff
path: root/brandt.c
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-07-13 14:01:24 +0200
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-07-13 14:01:24 +0200
commit99e5a11de13a3283c07f353471e08df241511d19 (patch)
treea92cce7ff2f96bbd0e096f6a3a267dacaa362a3d /brandt.c
parent8c7bd0fda283f8c529e5a582182b08150d875736 (diff)
major random stuff
Diffstat (limited to 'brandt.c')
-rw-r--r--brandt.c83
1 files changed, 51 insertions, 32 deletions
diff --git a/brandt.c b/brandt.c
index d56a607..1f53b43 100644
--- a/brandt.c
+++ b/brandt.c
@@ -16,9 +16,12 @@
/**
* @file brandt.c
- * @brief \todo
+ * @brief Implementation of the high level libbrandt interface.
* @author Markus Teich
*/
+
+#include "brandt_config.h"
+
#include <gcrypt.h>
#include "crypto.h"
@@ -33,6 +36,20 @@ typedef int
uint16_t sender);
+enum {
+ auction_firstPrice,
+ auction_mPlusFirstPrice,
+ auction_last
+};
+
+
+enum {
+ outcome_private,
+ outcome_public,
+ outcome_last
+};
+
+
/**
* stores the function pointers to receive functions for each state.
*
@@ -43,43 +60,43 @@ typedef int
* 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] =
+static msg_recv handler_in[auction_last][outcome_last][msg_last] =
{
- [0] =
+ [auction_firstPrice] =
{
- [0] =
+ [outcome_private] =
{
- [msg_init] = smc_recv_keyshare,
- [msg_bid] = smc_recv_encrypted_bid,
- [msg_outcome] = fp_priv_recv_outcome,
- [msg_decrypt] = fp_priv_recv_decryption,
+ [msg_init] = &smc_recv_keyshare,
+ [msg_bid] = &smc_recv_encrypted_bid,
+ [msg_outcome] = &fp_priv_recv_outcome,
+ [msg_decrypt] = &fp_priv_recv_decryption,
},
- [1] =
+ [outcome_public] =
{
- [msg_init] = smc_recv_keyshare,
- [msg_bid] = smc_recv_encrypted_bid,
- [msg_outcome] = fp_pub_recv_outcome,
- [msg_decrypt] = fp_pub_recv_decryption,
+ [msg_init] = &smc_recv_keyshare,
+ [msg_bid] = &smc_recv_encrypted_bid,
+ [msg_outcome] = &fp_pub_recv_outcome,
+ [msg_decrypt] = &fp_pub_recv_decryption,
}
},
- [1] =
+ [auction_mPlusFirstPrice] =
{
- [0] =
+ [outcome_private] =
{
- [msg_init] = smc_recv_keyshare,
- [msg_bid] = smc_recv_encrypted_bid,
+ [msg_init] = &smc_recv_keyshare,
+ [msg_bid] = &smc_recv_encrypted_bid,
},
- [1] =
+ [outcome_public] =
{
- [msg_init] = smc_recv_keyshare,
- [msg_bid] = smc_recv_encrypted_bid,
+ [msg_init] = &smc_recv_keyshare,
+ [msg_bid] = &smc_recv_encrypted_bid,
}
}
};
void
-BRANDT_init ()
+BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx)
{
gcry_error_t err = 0;
@@ -97,7 +114,7 @@ BRANDT_init ()
gcry_strerror (err));
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
- brandt_crypto_init ();
+ brandt_crypto_init (dlogctx);
}
@@ -107,21 +124,23 @@ BRANDT_got_message (struct BRANDT_Auction *auction,
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;
+ uint16_t mtype = *(uint16_t *)msg;
+ int atype;
+ int outcome;
enum rounds round = auction->cur_round;
- /** todo: cache out of order messages */
+ atype = auction->desc->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice;
+ outcome = auction->desc->outcome_public ? outcome_public : outcome_private;
+
+ /** \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))
+ if (!handler_in[atype][outcome][round] ||
+ !handler_in[atype][outcome][round](auction,
+ msg + sizeof (mtype),
+ msg_len - sizeof (mtype),
+ sender))
{
/** \todo */
weprintf ("wow fail");
}
- msg + sizeof (type);
}