diff options
author | Markus Teich <markus.teich@stusta.mhn.de> | 2016-07-13 14:01:24 +0200 |
---|---|---|
committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-07-13 14:01:24 +0200 |
commit | 99e5a11de13a3283c07f353471e08df241511d19 (patch) | |
tree | a92cce7ff2f96bbd0e096f6a3a267dacaa362a3d /brandt.c | |
parent | 8c7bd0fda283f8c529e5a582182b08150d875736 (diff) | |
download | libbrandt-99e5a11de13a3283c07f353471e08df241511d19.tar.gz libbrandt-99e5a11de13a3283c07f353471e08df241511d19.zip |
major random stuff
Diffstat (limited to 'brandt.c')
-rw-r--r-- | brandt.c | 83 |
1 files changed, 51 insertions, 32 deletions
@@ -16,9 +16,12 @@ | |||
16 | 16 | ||
17 | /** | 17 | /** |
18 | * @file brandt.c | 18 | * @file brandt.c |
19 | * @brief \todo | 19 | * @brief Implementation of the high level libbrandt interface. |
20 | * @author Markus Teich | 20 | * @author Markus Teich |
21 | */ | 21 | */ |
22 | |||
23 | #include "brandt_config.h" | ||
24 | |||
22 | #include <gcrypt.h> | 25 | #include <gcrypt.h> |
23 | 26 | ||
24 | #include "crypto.h" | 27 | #include "crypto.h" |
@@ -33,6 +36,20 @@ typedef int | |||
33 | uint16_t sender); | 36 | uint16_t sender); |
34 | 37 | ||
35 | 38 | ||
39 | enum { | ||
40 | auction_firstPrice, | ||
41 | auction_mPlusFirstPrice, | ||
42 | auction_last | ||
43 | }; | ||
44 | |||
45 | |||
46 | enum { | ||
47 | outcome_private, | ||
48 | outcome_public, | ||
49 | outcome_last | ||
50 | }; | ||
51 | |||
52 | |||
36 | /** | 53 | /** |
37 | * stores the function pointers to receive functions for each state. | 54 | * stores the function pointers to receive functions for each state. |
38 | * | 55 | * |
@@ -43,43 +60,43 @@ typedef int | |||
43 | * The second index denotes if the outcome should be public or private. A value | 60 | * The second index denotes if the outcome should be public or private. A value |
44 | * of 0 means a private outcome, while a value of 1 means public outcome. | 61 | * of 0 means a private outcome, while a value of 1 means public outcome. |
45 | */ | 62 | */ |
46 | static msg_recv handler_in[2][2][msg_last] = | 63 | static msg_recv handler_in[auction_last][outcome_last][msg_last] = |
47 | { | 64 | { |
48 | [0] = | 65 | [auction_firstPrice] = |
49 | { | 66 | { |
50 | [0] = | 67 | [outcome_private] = |
51 | { | 68 | { |
52 | [msg_init] = smc_recv_keyshare, | 69 | [msg_init] = &smc_recv_keyshare, |
53 | [msg_bid] = smc_recv_encrypted_bid, | 70 | [msg_bid] = &smc_recv_encrypted_bid, |
54 | [msg_outcome] = fp_priv_recv_outcome, | 71 | [msg_outcome] = &fp_priv_recv_outcome, |
55 | [msg_decrypt] = fp_priv_recv_decryption, | 72 | [msg_decrypt] = &fp_priv_recv_decryption, |
56 | }, | 73 | }, |
57 | [1] = | 74 | [outcome_public] = |
58 | { | 75 | { |
59 | [msg_init] = smc_recv_keyshare, | 76 | [msg_init] = &smc_recv_keyshare, |
60 | [msg_bid] = smc_recv_encrypted_bid, | 77 | [msg_bid] = &smc_recv_encrypted_bid, |
61 | [msg_outcome] = fp_pub_recv_outcome, | 78 | [msg_outcome] = &fp_pub_recv_outcome, |
62 | [msg_decrypt] = fp_pub_recv_decryption, | 79 | [msg_decrypt] = &fp_pub_recv_decryption, |
63 | } | 80 | } |
64 | }, | 81 | }, |
65 | [1] = | 82 | [auction_mPlusFirstPrice] = |
66 | { | 83 | { |
67 | [0] = | 84 | [outcome_private] = |
68 | { | 85 | { |
69 | [msg_init] = smc_recv_keyshare, | 86 | [msg_init] = &smc_recv_keyshare, |
70 | [msg_bid] = smc_recv_encrypted_bid, | 87 | [msg_bid] = &smc_recv_encrypted_bid, |
71 | }, | 88 | }, |
72 | [1] = | 89 | [outcome_public] = |
73 | { | 90 | { |
74 | [msg_init] = smc_recv_keyshare, | 91 | [msg_init] = &smc_recv_keyshare, |
75 | [msg_bid] = smc_recv_encrypted_bid, | 92 | [msg_bid] = &smc_recv_encrypted_bid, |
76 | } | 93 | } |
77 | } | 94 | } |
78 | }; | 95 | }; |
79 | 96 | ||
80 | 97 | ||
81 | void | 98 | void |
82 | BRANDT_init () | 99 | BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx) |
83 | { | 100 | { |
84 | gcry_error_t err = 0; | 101 | gcry_error_t err = 0; |
85 | 102 | ||
@@ -97,7 +114,7 @@ BRANDT_init () | |||
97 | gcry_strerror (err)); | 114 | gcry_strerror (err)); |
98 | 115 | ||
99 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 116 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
100 | brandt_crypto_init (); | 117 | brandt_crypto_init (dlogctx); |
101 | } | 118 | } |
102 | 119 | ||
103 | 120 | ||
@@ -107,21 +124,23 @@ BRANDT_got_message (struct BRANDT_Auction *auction, | |||
107 | const unsigned char *msg, | 124 | const unsigned char *msg, |
108 | size_t msg_len) | 125 | size_t msg_len) |
109 | { | 126 | { |
110 | uint16_t type = *(uint16_t *)msg; | 127 | uint16_t mtype = *(uint16_t *)msg; |
111 | int m = !!auction->desc->m; | 128 | int atype; |
112 | int pub = !!auction->desc->outcome_public; | 129 | int outcome; |
113 | enum rounds round = auction->cur_round; | 130 | enum rounds round = auction->cur_round; |
114 | 131 | ||
115 | /** todo: cache out of order messages */ | 132 | atype = auction->desc->m > 0 ? auction_mPlusFirstPrice : auction_firstPrice; |
133 | outcome = auction->desc->outcome_public ? outcome_public : outcome_private; | ||
134 | |||
135 | /** \todo: cache out of order messages */ | ||
116 | 136 | ||
117 | if (!handler_in[m][pub][round] || | 137 | if (!handler_in[atype][outcome][round] || |
118 | !handler_in[m][pub][round](auction, | 138 | !handler_in[atype][outcome][round](auction, |
119 | msg + sizeof (type), | 139 | msg + sizeof (mtype), |
120 | msg_len - sizeof (type), | 140 | msg_len - sizeof (mtype), |
121 | sender)) | 141 | sender)) |
122 | { | 142 | { |
123 | /** \todo */ | 143 | /** \todo */ |
124 | weprintf ("wow fail"); | 144 | weprintf ("wow fail"); |
125 | } | 145 | } |
126 | msg + sizeof (type); | ||
127 | } | 146 | } |