aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Teich <markus.teich@stusta.mhn.de>2016-11-23 23:20:25 +0100
committerMarkus Teich <markus.teich@stusta.mhn.de>2016-11-23 23:26:01 +0100
commitf4932d94c07d7c0dd9992b6b2d5b562b567d49b0 (patch)
tree22fb1dee0c28a54957513d8fe09655c26a31b1c8
parentb0042a588a932883a8f03e58ffe930c6eb795d48 (diff)
downloadlibbrandt-f4932d94c07d7c0dd9992b6b2d5b562b567d49b0.tar.gz
libbrandt-f4932d94c07d7c0dd9992b6b2d5b562b567d49b0.zip
remove unnecessary description handling and hashing.
The hash is not needed since the sellers application is required to sign the description and the bidders application is required to check the signature. Since the arbitrary description used by the application was only used inside this hash, it can be removed as well.
-rw-r--r--brandt.c66
-rw-r--r--brandt.h38
-rw-r--r--internals.h22
-rw-r--r--test_brandt.c9
4 files changed, 37 insertions, 98 deletions
diff --git a/brandt.c b/brandt.c
index 5d134cc..5a75eda 100644
--- a/brandt.c
+++ b/brandt.c
@@ -174,8 +174,6 @@ BRANDT_new (BRANDT_CbResult result,
174 void *auction_closure, 174 void *auction_closure,
175 void **auction_desc, 175 void **auction_desc,
176 size_t *auction_desc_len, 176 size_t *auction_desc_len,
177 const void *description,
178 uint32_t description_len,
179 struct GNUNET_TIME_Absolute time_start, 177 struct GNUNET_TIME_Absolute time_start,
180 struct GNUNET_TIME_Relative time_round, 178 struct GNUNET_TIME_Relative time_round,
181 uint16_t num_prices, 179 uint16_t num_prices,
@@ -184,7 +182,6 @@ BRANDT_new (BRANDT_CbResult result,
184{ 182{
185 struct BRANDT_Auction *ret; 183 struct BRANDT_Auction *ret;
186 struct BRANDT_DescrP *desc; 184 struct BRANDT_DescrP *desc;
187 struct GNUNET_HashContext *hc;
188 struct GNUNET_TIME_Relative until_start; 185 struct GNUNET_TIME_Relative until_start;
189 186
190 if (0 == num_prices) 187 if (0 == num_prices)
@@ -193,18 +190,9 @@ BRANDT_new (BRANDT_CbResult result,
193 desc = GNUNET_new (struct BRANDT_DescrP); 190 desc = GNUNET_new (struct BRANDT_DescrP);
194 desc->time_start = GNUNET_TIME_absolute_hton (time_start); 191 desc->time_start = GNUNET_TIME_absolute_hton (time_start);
195 desc->time_round = GNUNET_TIME_relative_hton (time_round); 192 desc->time_round = GNUNET_TIME_relative_hton (time_round);
196 desc->description_len = htonl (description_len);
197 desc->k = htons (num_prices); 193 desc->k = htons (num_prices);
198 desc->m = htons (m); 194 desc->m = htons (m);
199 desc->outcome_public = htons (outcome_public); 195 desc->outcome_public = htons (outcome_public);
200 hc = GNUNET_CRYPTO_hash_context_start ();
201 GNUNET_CRYPTO_hash_context_read (hc,
202 &desc->time_start,
203 sizeof (*desc) - sizeof (desc->hash));
204 GNUNET_CRYPTO_hash_context_read (hc,
205 description,
206 description_len);
207 GNUNET_CRYPTO_hash_context_finish (hc, &desc->hash);
208 196
209 ret = GNUNET_new (struct BRANDT_Auction); 197 ret = GNUNET_new (struct BRANDT_Auction);
210 ret->time_start = time_start; 198 ret->time_start = time_start;
@@ -236,20 +224,16 @@ BRANDT_new (BRANDT_CbResult result,
236 224
237 225
238int 226int
239BRANDT_verify_desc (const void *auction_desc, 227BRANDT_parse_desc (const void *auction_desc,
240 size_t auction_desc_len, 228 size_t auction_desc_len,
241 const void *description, 229 struct GNUNET_TIME_Absolute *time_start,
242 uint32_t description_len, 230 struct GNUNET_TIME_Relative *time_round,
243 struct GNUNET_TIME_Absolute *time_start, 231 uint16_t *num_prices,
244 struct GNUNET_TIME_Relative *time_round, 232 uint16_t *m,
245 uint16_t *num_prices, 233 uint16_t *outcome_public)
246 uint16_t *m,
247 uint16_t *outcome_public)
248{ 234{
249 const struct BRANDT_DescrP *desc = auction_desc; 235 const struct BRANDT_DescrP *desc = auction_desc;
250 const uint32_t zero = 0; 236 const uint32_t zero = 0;
251 struct GNUNET_HashContext *hc = GNUNET_CRYPTO_hash_context_start ();
252 struct GNUNET_HashCode computed_hash;
253 237
254 if (sizeof (struct BRANDT_DescrP) != auction_desc_len) 238 if (sizeof (struct BRANDT_DescrP) != auction_desc_len)
255 { 239 {
@@ -257,23 +241,9 @@ BRANDT_verify_desc (const void *auction_desc,
257 return -1; 241 return -1;
258 } 242 }
259 243
260 GNUNET_CRYPTO_hash_context_read (hc, 244 if (0 != memcmp (&desc->reserved, &zero, sizeof (desc->reserved)))
261 &desc->time_start,
262 sizeof (*desc) - sizeof (desc->hash));
263 GNUNET_CRYPTO_hash_context_read (hc,
264 description,
265 description_len);
266 GNUNET_CRYPTO_hash_context_finish (hc, &computed_hash);
267 if (0 != memcmp (&desc->hash, &computed_hash, sizeof (computed_hash)))
268 { 245 {
269 weprintf ("auction description hash does not match"); 246 weprintf ("reserved field in auction description must be zero");
270 return -1;
271 }
272
273 if (0 != memcmp (&desc->reserved1, &zero, sizeof (desc->reserved1)) ||
274 0 != memcmp (&desc->reserved2, &zero, sizeof (desc->reserved2)))
275 {
276 weprintf ("unknown auction description format");
277 return -1; 247 return -1;
278 } 248 }
279 249
@@ -299,21 +269,17 @@ BRANDT_join (BRANDT_CbResult result,
299 void *auction_closure, 269 void *auction_closure,
300 const void *auction_desc, 270 const void *auction_desc,
301 size_t auction_desc_len, 271 size_t auction_desc_len,
302 const void *description,
303 uint32_t description_len,
304 uint16_t bid) 272 uint16_t bid)
305{ 273{
306 struct BRANDT_Auction *ret = GNUNET_new (struct BRANDT_Auction); 274 struct BRANDT_Auction *ret = GNUNET_new (struct BRANDT_Auction);
307 275
308 if (0 != BRANDT_verify_desc (auction_desc, 276 if (0 != BRANDT_parse_desc (auction_desc,
309 auction_desc_len, 277 auction_desc_len,
310 description, 278 &ret->time_start,
311 description_len, 279 &ret->time_round,
312 &ret->time_start, 280 &ret->k,
313 &ret->time_round, 281 &ret->m,
314 &ret->k, 282 &ret->outcome_public))
315 &ret->m,
316 &ret->outcome_public))
317 { 283 {
318 GNUNET_free (ret); 284 GNUNET_free (ret);
319 weprintf ("failed to parse auction description blob"); 285 weprintf ("failed to parse auction description blob");
diff --git a/brandt.h b/brandt.h
index 6d68f0a..fab8ebf 100644
--- a/brandt.h
+++ b/brandt.h
@@ -126,13 +126,11 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
126 126
127 127
128/** 128/**
129 * Verify an auction description blob and parse it's fields. See BRANDT_new() 129 * Parse an auction description data block. See BRANDT_new()
130 * for an explanation of the different auction description fields. 130 * for an explanation of the different auction description fields.
131 * 131 *
132 * @param[in] auction_desc The auction description blob published by the seller. 132 * @param[in] auction_desc The auction description blob published by the seller.
133 * @param[in] auction_desc_len Length of @a auction_desc in bytes. 133 * @param[in] auction_desc_len Length of @a auction_desc in bytes.
134 * @param[in] description The description text in application choosen format.
135 * @param[in] description_len Length of @a description in bytes.
136 * @param[out] time_start Starting time of the auction. May be NULL. 134 * @param[out] time_start Starting time of the auction. May be NULL.
137 * @param[out] time_round Maximum round time of the auction. May be NULL. 135 * @param[out] time_round Maximum round time of the auction. May be NULL.
138 * @param[out] num_prices Amount of possible prices. May be NULL. 136 * @param[out] num_prices Amount of possible prices. May be NULL.
@@ -140,15 +138,13 @@ BRANDT_init (struct GNUNET_CRYPTO_EccDlogContext *dlogctx);
140 * @param[out] outcome_public Outcome setting. May be NULL. 138 * @param[out] outcome_public Outcome setting. May be NULL.
141 */ 139 */
142int 140int
143BRANDT_verify_desc (const void *auction_desc, 141BRANDT_parse_desc (const void *auction_desc,
144 size_t auction_desc_len, 142 size_t auction_desc_len,
145 const void *description, 143 struct GNUNET_TIME_Absolute *time_start,
146 uint32_t description_len, 144 struct GNUNET_TIME_Relative *time_round,
147 struct GNUNET_TIME_Absolute *time_start, 145 uint16_t *num_prices,
148 struct GNUNET_TIME_Relative *time_round, 146 uint16_t *m,
149 uint16_t *num_prices, 147 uint16_t *outcome_public);
150 uint16_t *m,
151 uint16_t *outcome_public);
152 148
153 149
154/** 150/**
@@ -160,9 +156,10 @@ BRANDT_verify_desc (const void *auction_desc,
160 * @param[in] auction_closure Closure pointer representing the auction. This 156 * @param[in] auction_closure Closure pointer representing the auction. This
161 * will not be touched by libbrandt itself. It is only passed to the callbacks. 157 * will not be touched by libbrandt itself. It is only passed to the callbacks.
162 * @param[in] auction_desc The auction information data published by the seller. 158 * @param[in] auction_desc The auction information data published by the seller.
163 * This is an opaque data structure. It will be parsed and checked by 159 * This is opaque to the application. Its content will be parsed. The
164 * BRANDT_join(). 160 * application MUST check the signature on this data block before passing it to
165 * @param[in] auction_desc_len The length in bytes of the @a auction_desc 161 * libbrandt!
162 * @param[in] auction_desc_len The length in byte of the @a auction_desc
166 * structure. 163 * structure.
167 * @return A pointer, which should only be remembered and passed to 164 * @return A pointer, which should only be remembered and passed to
168 * libbrandt functions when the client needs to refer to this auction. This is a 165 * libbrandt functions when the client needs to refer to this auction. This is a
@@ -175,8 +172,6 @@ BRANDT_join (BRANDT_CbResult result,
175 void *auction_closure, 172 void *auction_closure,
176 const void *auction_desc, 173 const void *auction_desc,
177 size_t auction_desc_len, 174 size_t auction_desc_len,
178 const void *description,
179 uint32_t description_len,
180 uint16_t bid); 175 uint16_t bid);
181 176
182 177
@@ -196,9 +191,10 @@ BRANDT_join (BRANDT_CbResult result,
196 * @param[in] result Pointer to the result callback function 191 * @param[in] result Pointer to the result callback function
197 * @param[in] auction_closure Closure pointer representing the auction. This 192 * @param[in] auction_closure Closure pointer representing the auction. This
198 * will not be touched by libbrandt. It is only passed to the callbacks. 193 * will not be touched by libbrandt. It is only passed to the callbacks.
199 * @param[out] auction_desc The auction information data a an opaque data 194 * @param[out] auction_desc The auction information data as an opaque data
200 * structure. It will be generated by BRANDT_new() and should be distributed to 195 * structure. It is generated by this function and should be distributed to
201 * all possibly interested bidders. 196 * all possibly interested bidders. The seller MUST sign this data block before
197 * publishing it!
202 * @param[out] auction_desc_len The length in bytes of the @a auction_desc 198 * @param[out] auction_desc_len The length in bytes of the @a auction_desc
203 * structure. Will be filled by BRANDT_new(). 199 * structure. Will be filled by BRANDT_new().
204 * @param[in] num_prices The amount of possible valuations for the sold item(s). 200 * @param[in] num_prices The amount of possible valuations for the sold item(s).
@@ -223,8 +219,6 @@ BRANDT_new (BRANDT_CbResult result,
223 void *auction_closure, 219 void *auction_closure,
224 void **auction_desc, 220 void **auction_desc,
225 size_t *auction_desc_len, 221 size_t *auction_desc_len,
226 const void *description,
227 uint32_t description_len,
228 struct GNUNET_TIME_Absolute time_start, 222 struct GNUNET_TIME_Absolute time_start,
229 struct GNUNET_TIME_Relative time_round, 223 struct GNUNET_TIME_Relative time_round,
230 uint16_t num_prices, 224 uint16_t num_prices,
diff --git a/internals.h b/internals.h
index 373c3d4..d6de9db 100644
--- a/internals.h
+++ b/internals.h
@@ -60,20 +60,10 @@ struct msg_head {
60 60
61 61
62/** 62/**
63 * This struct describes an auction and is always linked to a description buffer 63 * This struct describes the parameters of an auction. All fields are stored in
64 * of #description_len bytes of arbitrary data where the description of the item
65 * to be sold is stored. This buffer should also contain information linking the
66 * auction to the payment system (which exact prices do the k possibilities
67 * refer to, payment system seller identity, …). All fields are stored in
68 * network byte order. 64 * network byte order.
69 * 65 */
70 * \todo: align to a multiple of 64bit
71 * \todo: versionsnummer */
72struct BRANDT_DescrP { 66struct BRANDT_DescrP {
73 /** Hash code over the remaining elements of this struct followed by the
74 * description buffer of #description_len bytes */
75 struct GNUNET_HashCode hash GNUNET_PACKED;
76
77 /** Starting time of the auction. Bidders have to join the auction via 67 /** Starting time of the auction. Bidders have to join the auction via
78 * BRANDT_join until this time */ 68 * BRANDT_join until this time */
79 struct GNUNET_TIME_AbsoluteNBO time_start; 69 struct GNUNET_TIME_AbsoluteNBO time_start;
@@ -81,12 +71,6 @@ struct BRANDT_DescrP {
81 /** The maximum duration the participants have to complete each round. */ 71 /** The maximum duration the participants have to complete each round. */
82 struct GNUNET_TIME_RelativeNBO time_round; 72 struct GNUNET_TIME_RelativeNBO time_round;
83 73
84 /** The length of the description in bytes */
85 uint32_t description_len GNUNET_PACKED;
86
87 /** reserved for future use. Must be zeroed out. */
88 uint32_t reserved1 GNUNET_PACKED;
89
90 /** The amount of possible prices */ 74 /** The amount of possible prices */
91 uint16_t k GNUNET_PACKED; 75 uint16_t k GNUNET_PACKED;
92 76
@@ -99,7 +83,7 @@ struct BRANDT_DescrP {
99 uint16_t outcome_public GNUNET_PACKED; 83 uint16_t outcome_public GNUNET_PACKED;
100 84
101 /** reserved for future use. Must be zeroed out. */ 85 /** reserved for future use. Must be zeroed out. */
102 uint16_t reserved2 GNUNET_PACKED; 86 uint16_t reserved GNUNET_PACKED;
103}; 87};
104 88
105GNUNET_NETWORK_STRUCT_END 89GNUNET_NETWORK_STRUCT_END
diff --git a/test_brandt.c b/test_brandt.c
index 1540583..9d91260 100644
--- a/test_brandt.c
+++ b/test_brandt.c
@@ -305,9 +305,8 @@ quit:
305static void 305static void
306run_auction (void *arg) 306run_auction (void *arg)
307{ 307{
308 const char description[] = "test description for test_auction"; 308 void *desc;
309 void *desc; 309 size_t desc_len;
310 size_t desc_len;
311 310
312 tcase.ad[tcase.n] = BRANDT_new (&cb_result, 311 tcase.ad[tcase.n] = BRANDT_new (&cb_result,
313 &cb_broadcast, 312 &cb_broadcast,
@@ -315,8 +314,6 @@ run_auction (void *arg)
315 &tcase.id[tcase.n], 314 &tcase.id[tcase.n],
316 &desc, 315 &desc,
317 &desc_len, 316 &desc_len,
318 description,
319 sizeof (description),
320 GNUNET_TIME_absolute_get (), 317 GNUNET_TIME_absolute_get (),
321 GNUNET_TIME_UNIT_MINUTES, 318 GNUNET_TIME_UNIT_MINUTES,
322 tcase.k, /* number of prizes */ 319 tcase.k, /* number of prizes */
@@ -336,8 +333,6 @@ run_auction (void *arg)
336 &tcase.id[i], 333 &tcase.id[i],
337 desc, 334 desc,
338 desc_len, 335 desc_len,
339 description,
340 sizeof (description),
341 tcase.bids[i]); /* bid */ 336 tcase.bids[i]); /* bid */
342 if (!tcase.ad[i]) 337 if (!tcase.ad[i])
343 { 338 {