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) | |
download | libbrandt-4deee5eb1247b46d04c4ab8eeba52ca4e4db0567.tar.gz libbrandt-4deee5eb1247b46d04c4ab8eeba52ca4e4db0567.zip |
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 @@ | |||
22 | #include <gcrypt.h> | 22 | #include <gcrypt.h> |
23 | 23 | ||
24 | #include "crypto.h" | 24 | #include "crypto.h" |
25 | #include "internals.h" | ||
25 | #include "util.h" | 26 | #include "util.h" |
26 | 27 | ||
28 | |||
29 | typedef int | ||
30 | (*msg_recv)(struct BRANDT_Auction *ad, | ||
31 | const unsigned char *buf, | ||
32 | size_t buflen, | ||
33 | uint16_t sender); | ||
34 | |||
35 | |||
36 | /** | ||
37 | * stores the function pointers to receive functions for each state. | ||
38 | * | ||
39 | * The first index denotes if a first price auction or a M+1st price auction is | ||
40 | * used. If it is 0, it is a first price auction, if it is 1, it is a M+1st | ||
41 | * price auction. | ||
42 | * | ||
43 | * 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. | ||
45 | */ | ||
46 | static msg_recv handler_in[2][2][msg_last] = | ||
47 | { | ||
48 | [0] = | ||
49 | { | ||
50 | [0] = | ||
51 | { | ||
52 | [msg_init] = smc_recv_keyshare, | ||
53 | [msg_bid] = smc_recv_encrypted_bid, | ||
54 | [msg_outcome] = fp_priv_recv_outcome, | ||
55 | [msg_decrypt] = fp_priv_recv_decryption, | ||
56 | }, | ||
57 | [1] = | ||
58 | { | ||
59 | [msg_init] = smc_recv_keyshare, | ||
60 | [msg_bid] = smc_recv_encrypted_bid, | ||
61 | [msg_outcome] = fp_pub_recv_outcome, | ||
62 | [msg_decrypt] = fp_pub_recv_decryption, | ||
63 | } | ||
64 | }, | ||
65 | [1] = | ||
66 | { | ||
67 | [0] = | ||
68 | { | ||
69 | [msg_init] = smc_recv_keyshare, | ||
70 | [msg_bid] = smc_recv_encrypted_bid, | ||
71 | }, | ||
72 | [1] = | ||
73 | { | ||
74 | [msg_init] = smc_recv_keyshare, | ||
75 | [msg_bid] = smc_recv_encrypted_bid, | ||
76 | } | ||
77 | } | ||
78 | }; | ||
79 | |||
80 | |||
27 | void | 81 | void |
28 | BRANDT_init () | 82 | BRANDT_init () |
29 | { | 83 | { |
@@ -37,7 +91,7 @@ BRANDT_init () | |||
37 | weprintf ("failed to set libgcrypt option DISABLE_SECMEM: %s", | 91 | weprintf ("failed to set libgcrypt option DISABLE_SECMEM: %s", |
38 | gcry_strerror (err)); | 92 | gcry_strerror (err)); |
39 | 93 | ||
40 | /* ecc is slow otherwise. */ | 94 | /* ecc is slow otherwise and we don't create long term keys anyway. */ |
41 | if ((err = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) | 95 | if ((err = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0))) |
42 | weprintf ("failed to set libgcrypt option ENABLE_QUICK_RANDOM: %s", | 96 | weprintf ("failed to set libgcrypt option ENABLE_QUICK_RANDOM: %s", |
43 | gcry_strerror (err)); | 97 | gcry_strerror (err)); |
@@ -45,3 +99,29 @@ BRANDT_init () | |||
45 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); | 99 | gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0); |
46 | brandt_crypto_init (); | 100 | brandt_crypto_init (); |
47 | } | 101 | } |
102 | |||
103 | |||
104 | void | ||
105 | BRANDT_got_message (struct BRANDT_Auction *auction, | ||
106 | uint16_t sender, | ||
107 | const unsigned char *msg, | ||
108 | size_t msg_len) | ||
109 | { | ||
110 | uint16_t type = *(uint16_t *)msg; | ||
111 | int m = !!auction->desc->m; | ||
112 | int pub = !!auction->desc->outcome_public; | ||
113 | enum rounds round = auction->cur_round; | ||
114 | |||
115 | /** todo: cache out of order messages */ | ||
116 | |||
117 | if (!handler_in[m][pub][round] || | ||
118 | !handler_in[m][pub][round](auction, | ||
119 | msg + sizeof (type), | ||
120 | msg_len - sizeof (type), | ||
121 | sender)) | ||
122 | { | ||
123 | /** \todo */ | ||
124 | weprintf ("wow fail"); | ||
125 | } | ||
126 | msg + sizeof (type); | ||
127 | } | ||