diff options
author | Florian Dold <florian.dold@gmail.com> | 2013-12-03 11:38:14 +0000 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2013-12-03 11:38:14 +0000 |
commit | 32b0ff1774ca5e76485be047ae693398163e0e68 (patch) | |
tree | 85de5403d4e7c71378155fe02684d7bcdbc9365e /src/secretsharing/gnunet-service-secretsharing.c | |
parent | 06b98ce26989dd42cad35f91ae9d8e757b602383 (diff) | |
download | gnunet-32b0ff1774ca5e76485be047ae693398163e0e68.tar.gz gnunet-32b0ff1774ca5e76485be047ae693398163e0e68.zip |
- work on secretsharing
Diffstat (limited to 'src/secretsharing/gnunet-service-secretsharing.c')
-rw-r--r-- | src/secretsharing/gnunet-service-secretsharing.c | 589 |
1 files changed, 584 insertions, 5 deletions
diff --git a/src/secretsharing/gnunet-service-secretsharing.c b/src/secretsharing/gnunet-service-secretsharing.c index a16f88079..c7b1f2d0d 100644 --- a/src/secretsharing/gnunet-service-secretsharing.c +++ b/src/secretsharing/gnunet-service-secretsharing.c | |||
@@ -25,6 +25,353 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_time_lib.h" | ||
29 | #include "gnunet_consensus_service.h" | ||
30 | #include "secretsharing.h" | ||
31 | #include "secretsharing_protocol.h" | ||
32 | #include <gcrypt.h> | ||
33 | |||
34 | |||
35 | |||
36 | /** | ||
37 | * Info about a peer in a key generation session. | ||
38 | */ | ||
39 | struct KeygenPeerInfo | ||
40 | { | ||
41 | /** | ||
42 | * Peer identity of the peer. | ||
43 | */ | ||
44 | struct GNUNET_PeerIdentity peer; | ||
45 | |||
46 | /** | ||
47 | * g-component of the peer's paillier public key. | ||
48 | */ | ||
49 | gcry_mpi_t paillier_g; | ||
50 | |||
51 | /** | ||
52 | * mu-component of the peer's paillier public key. | ||
53 | */ | ||
54 | gcry_mpi_t paillier_mu; | ||
55 | |||
56 | /** | ||
57 | * The peer's commitment to his presecret. | ||
58 | */ | ||
59 | gcry_mpi_t presecret_commitment; | ||
60 | |||
61 | /** | ||
62 | * GNUNET_YES if the peer has been disqualified, | ||
63 | * GNUNET_NO otherwise. | ||
64 | */ | ||
65 | int disqualified; | ||
66 | }; | ||
67 | |||
68 | |||
69 | /** | ||
70 | * Session to establish a threshold-shared secret. | ||
71 | */ | ||
72 | struct KeygenSession | ||
73 | { | ||
74 | /** | ||
75 | * Keygen sessions are held in a linked list. | ||
76 | */ | ||
77 | struct KeygenSession *next; | ||
78 | |||
79 | /** | ||
80 | * Keygen sessions are held in a linked list. | ||
81 | */ | ||
82 | struct KeygenSession *prev; | ||
83 | |||
84 | /** | ||
85 | * Current consensus, used for both DKG rounds. | ||
86 | */ | ||
87 | struct GNUNET_CONSENSUS_Handle *consensus; | ||
88 | |||
89 | /** | ||
90 | * Client that is interested in the result | ||
91 | * of this key generation session. | ||
92 | */ | ||
93 | struct GNUNET_SERVER_Client *client; | ||
94 | |||
95 | /** | ||
96 | * Randomly generated coefficients of the polynomial for sharing our | ||
97 | * pre-secret, where 'preshares[0]' is our pre-secret. Contains 'threshold' | ||
98 | * elements, thus represents a polynomial of degree 'threshold-1', which can | ||
99 | * be interpolated with 'threshold' data points. | ||
100 | * | ||
101 | * The pre-secret-shares 'i=1,...,num_peers' are given by evaluating this | ||
102 | * polyomial at 'i' for share i. | ||
103 | */ | ||
104 | gcry_mpi_t *presecret_polynomial; | ||
105 | |||
106 | /** | ||
107 | * Minimum number of shares required to restore the secret. | ||
108 | */ | ||
109 | unsigned int threshold; | ||
110 | |||
111 | /** | ||
112 | * Total number of peers. | ||
113 | */ | ||
114 | unsigned int num_peers; | ||
115 | |||
116 | /** | ||
117 | * Index of the local peer. | ||
118 | */ | ||
119 | unsigned int local_peer; | ||
120 | |||
121 | /** | ||
122 | * Information about all participating peers. | ||
123 | */ | ||
124 | struct KeygenPeerInfo *info; | ||
125 | |||
126 | /** | ||
127 | * List of all peers involved in the secret sharing session. | ||
128 | */ | ||
129 | struct GNUNET_PeerIdentity *peers; | ||
130 | |||
131 | /** | ||
132 | * Identifier for this session. | ||
133 | */ | ||
134 | struct GNUNET_HashCode session_id; | ||
135 | |||
136 | /** | ||
137 | * g-component of our peer's paillier private key. | ||
138 | */ | ||
139 | gcry_mpi_t paillier_g; | ||
140 | |||
141 | /** | ||
142 | * g-component of our peer's paillier private key. | ||
143 | */ | ||
144 | gcry_mpi_t paillier_mu; | ||
145 | |||
146 | struct GNUNET_TIME_Absolute deadline; | ||
147 | |||
148 | /** | ||
149 | * Index of the local peer in the ordered list | ||
150 | * of peers in the session. | ||
151 | */ | ||
152 | unsigned int local_peer_idx; | ||
153 | }; | ||
154 | |||
155 | |||
156 | struct DecryptSession | ||
157 | { | ||
158 | struct DecryptSession *next; | ||
159 | struct DecryptSession *prev; | ||
160 | |||
161 | struct GNUNET_CONSENSUS_Handle *consensus; | ||
162 | |||
163 | struct GNUNET_SERVER_Client *client; | ||
164 | }; | ||
165 | |||
166 | /** | ||
167 | * Decrypt sessions are held in a linked list. | ||
168 | */ | ||
169 | static struct DecryptSession *decrypt_sessions_head; | ||
170 | |||
171 | /** | ||
172 | * Decrypt sessions are held in a linked list. | ||
173 | */ | ||
174 | static struct DecryptSession *decrypt_sessions_tail; | ||
175 | |||
176 | /** | ||
177 | * Decrypt sessions are held in a linked list. | ||
178 | */ | ||
179 | static struct KeygenSession *keygen_sessions_head; | ||
180 | |||
181 | /** | ||
182 | * Decrypt sessions are held in a linked list. | ||
183 | */ | ||
184 | static struct KeygenSession *keygen_sessions_tail; | ||
185 | |||
186 | /** | ||
187 | * The ElGamal prime field order as libgcrypt mpi. | ||
188 | * Will be initialized to 'ELGAMAL_Q_DATA'. | ||
189 | */ | ||
190 | static gcry_mpi_t elgamal_q; | ||
191 | |||
192 | /** | ||
193 | * Modulus of the prime field used for ElGamal. | ||
194 | * Will be initialized to 'ELGAMAL_P_DATA'. | ||
195 | */ | ||
196 | static gcry_mpi_t elgamal_p; | ||
197 | |||
198 | /** | ||
199 | * Generator for prime field of order 'elgamal_q'. | ||
200 | * Will be initialized to 'ELGAMAL_G_DATA'. | ||
201 | */ | ||
202 | static gcry_mpi_t elgamal_g; | ||
203 | |||
204 | /** | ||
205 | * Peer that runs this service. | ||
206 | */ | ||
207 | static struct GNUNET_PeerIdentity my_peer; | ||
208 | |||
209 | /** | ||
210 | * Configuration of this service. | ||
211 | */ | ||
212 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
213 | |||
214 | /** | ||
215 | * Server for this service. | ||
216 | */ | ||
217 | static struct GNUNET_SERVER_Handle *srv; | ||
218 | |||
219 | |||
220 | /** | ||
221 | * Although GNUNET_CRYPTO_hash_cmp exisits, it does not have | ||
222 | * the correct signature to be used with e.g. qsort. | ||
223 | * We use this function instead. | ||
224 | * | ||
225 | * @param h1 some hash code | ||
226 | * @param h2 some hash code | ||
227 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. | ||
228 | */ | ||
229 | static int | ||
230 | hash_cmp (const void *h1, const void *h2) | ||
231 | { | ||
232 | return GNUNET_CRYPTO_hash_cmp ((struct GNUNET_HashCode *) h1, (struct GNUNET_HashCode *) h2); | ||
233 | } | ||
234 | |||
235 | |||
236 | /** | ||
237 | * Normalize the given list of peers, by including the local peer | ||
238 | * (if it is missing) and sorting the peers by their identity. | ||
239 | * | ||
240 | * @param listed peers in the unnormalized list | ||
241 | * @param num_listed peers in the un-normalized list | ||
242 | * @param num_normalized[out] number of peers in the normalized list | ||
243 | * @param my_peer_idx[out] index of the local peer in the normalized list | ||
244 | * @return normalized list, must be free'd by the caller | ||
245 | */ | ||
246 | static struct GNUNET_PeerIdentity * | ||
247 | normalize_peers (struct GNUNET_PeerIdentity *listed, | ||
248 | unsigned int num_listed, | ||
249 | unsigned int *num_normalized, | ||
250 | unsigned int *my_peer_idx) | ||
251 | { | ||
252 | unsigned int local_peer_in_list; | ||
253 | unsigned int n; | ||
254 | unsigned int i; | ||
255 | struct GNUNET_PeerIdentity *normalized; | ||
256 | |||
257 | local_peer_in_list = GNUNET_NO; | ||
258 | for (i = 0; i < num_listed; i++) | ||
259 | { | ||
260 | if (0 == memcmp (&listed[i], &my_peer, sizeof (struct GNUNET_PeerIdentity))) | ||
261 | { | ||
262 | local_peer_in_list = GNUNET_YES; | ||
263 | break; | ||
264 | } | ||
265 | } | ||
266 | |||
267 | n = num_listed; | ||
268 | if (GNUNET_NO == local_peer_in_list) | ||
269 | n++; | ||
270 | |||
271 | normalized = GNUNET_malloc (n * sizeof (struct GNUNET_PeerIdentity)); | ||
272 | |||
273 | if (GNUNET_NO == local_peer_in_list) | ||
274 | normalized[n - 1] = my_peer; | ||
275 | |||
276 | memcpy (normalized, listed, num_listed * sizeof (struct GNUNET_PeerIdentity)); | ||
277 | qsort (normalized, n, sizeof (struct GNUNET_PeerIdentity), &hash_cmp); | ||
278 | |||
279 | if (NULL != my_peer_idx) | ||
280 | { | ||
281 | for (i = 0; i < num_listed; i++) | ||
282 | { | ||
283 | if (0 == memcmp (&normalized[i], &my_peer, sizeof (struct GNUNET_PeerIdentity))) | ||
284 | { | ||
285 | *my_peer_idx = i; | ||
286 | break; | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | |||
291 | *num_normalized = n; | ||
292 | return normalized; | ||
293 | } | ||
294 | |||
295 | |||
296 | /** | ||
297 | * Create a key pair for the paillier crypto system. | ||
298 | * | ||
299 | * Uses the simplified key generation of Jonathan Katz, Yehuda Lindell, | ||
300 | * "Introduction to Modern Cryptography: Principles and Protocols". | ||
301 | */ | ||
302 | static void | ||
303 | paillier_create (unsigned int s, gcry_mpi_t n, gcry_mpi_t g, gcry_mpi_t lambda, gcry_mpi_t mu) | ||
304 | { | ||
305 | gcry_mpi_t p; | ||
306 | gcry_mpi_t q; | ||
307 | gcry_mpi_t phi; | ||
308 | gcry_mpi_t tmp; | ||
309 | |||
310 | GNUNET_assert (0 != (phi = gcry_mpi_new (PAILLIER_BITS))); | ||
311 | GNUNET_assert (0 != (tmp = gcry_mpi_new (PAILLIER_BITS))); | ||
312 | |||
313 | // generate rsa modulus | ||
314 | GNUNET_assert (0 == gcry_prime_generate (&p, s, 0, NULL, NULL, NULL, | ||
315 | GCRY_WEAK_RANDOM, 0)); | ||
316 | GNUNET_assert (0 == gcry_prime_generate (&q, s, 0, NULL, NULL, NULL, | ||
317 | GCRY_WEAK_RANDOM, 0)); | ||
318 | gcry_mpi_mul (n, p, q); | ||
319 | gcry_mpi_add_ui (g, n, 1); | ||
320 | // compute phi(n) = (p-1)(q-1) | ||
321 | gcry_mpi_sub_ui (phi, p, 1); | ||
322 | gcry_mpi_sub_ui (tmp, q, 1); | ||
323 | gcry_mpi_mul (phi, phi, tmp); | ||
324 | gcry_mpi_set (lambda, phi); | ||
325 | // compute mu | ||
326 | GNUNET_assert (0 != gcry_mpi_invm (mu, phi, n)); | ||
327 | |||
328 | gcry_mpi_release (p); | ||
329 | gcry_mpi_release (q); | ||
330 | gcry_mpi_release (phi); | ||
331 | gcry_mpi_release (tmp); | ||
332 | } | ||
333 | |||
334 | |||
335 | static void | ||
336 | paillier_encrypt (gcry_mpi_t c, gcry_mpi_t m, gcry_mpi_t g, gcry_mpi_t n) | ||
337 | { | ||
338 | gcry_mpi_t n_square; | ||
339 | gcry_mpi_t r; | ||
340 | |||
341 | GNUNET_assert (0 != (n_square = gcry_mpi_new (0))); | ||
342 | GNUNET_assert (0 != (r = gcry_mpi_new (0))); | ||
343 | |||
344 | gcry_mpi_mul (n_square, n, n); | ||
345 | |||
346 | // generate r < n | ||
347 | do | ||
348 | { | ||
349 | gcry_mpi_randomize (r, PAILLIER_BITS, GCRY_WEAK_RANDOM); | ||
350 | } | ||
351 | while (gcry_mpi_cmp (r, n) > 0); | ||
352 | |||
353 | gcry_mpi_powm (c, g, m, n_square); | ||
354 | gcry_mpi_powm (r, r, n, n_square); | ||
355 | gcry_mpi_mulm (c, r, c, n_square); | ||
356 | |||
357 | gcry_mpi_release (n_square); | ||
358 | gcry_mpi_release (r); | ||
359 | } | ||
360 | |||
361 | |||
362 | static void | ||
363 | paillier_decrypt (gcry_mpi_t m, gcry_mpi_t c, gcry_mpi_t mu, gcry_mpi_t lambda, gcry_mpi_t n) | ||
364 | { | ||
365 | gcry_mpi_t n_square; | ||
366 | GNUNET_assert (0 != (n_square = gcry_mpi_new (0))); | ||
367 | gcry_mpi_mul (n_square, n, n); | ||
368 | gcry_mpi_powm (m, c, lambda, n_square); | ||
369 | gcry_mpi_sub_ui (m, m, 1); | ||
370 | // m = m/n | ||
371 | gcry_mpi_div (m, NULL, m, n, 0); | ||
372 | gcry_mpi_mulm (m, m, mu, n); | ||
373 | gcry_mpi_release (n_square); | ||
374 | } | ||
28 | 375 | ||
29 | 376 | ||
30 | /** | 377 | /** |
@@ -40,6 +387,230 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
40 | } | 387 | } |
41 | 388 | ||
42 | 389 | ||
390 | static void | ||
391 | generate_presecret_polynomial (struct KeygenSession *ks) | ||
392 | { | ||
393 | int i; | ||
394 | GNUNET_assert (NULL == ks->presecret_polynomial); | ||
395 | ks->presecret_polynomial = GNUNET_malloc (ks->threshold * sizeof (gcry_mpi_t)); | ||
396 | for (i = 0; i < ks->threshold; i++) | ||
397 | { | ||
398 | ks->presecret_polynomial[i] = gcry_mpi_new (PAILLIER_BITS); | ||
399 | gcry_mpi_randomize (ks->presecret_polynomial[i], PAILLIER_BITS, | ||
400 | GCRY_WEAK_RANDOM); | ||
401 | } | ||
402 | } | ||
403 | |||
404 | |||
405 | static void | ||
406 | keygen_round1_new_element (void *cls, | ||
407 | const struct GNUNET_SET_Element *element) | ||
408 | { | ||
409 | const struct GNUNET_SECRETSHARING_KeygenCommitData *d; | ||
410 | struct KeygenSession *ks = cls; | ||
411 | unsigned int i; | ||
412 | |||
413 | if (element->size != sizeof (struct GNUNET_SECRETSHARING_KeygenCommitData)) | ||
414 | { | ||
415 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "keygen commit data with wrong size in consensus\n"); | ||
416 | return; | ||
417 | } | ||
418 | |||
419 | d = element->data; | ||
420 | |||
421 | for (i = 0; i < ks->num_peers; i++) | ||
422 | { | ||
423 | if (0 == memcmp (&d->peer, &ks->info[i].peer, sizeof (struct GNUNET_PeerIdentity))) | ||
424 | { | ||
425 | // TODO: check signature and store key data | ||
426 | return; | ||
427 | } | ||
428 | } | ||
429 | |||
430 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "keygen commit data with wrong peer identity in consensus\n"); | ||
431 | |||
432 | } | ||
433 | |||
434 | |||
435 | /** | ||
436 | * Evaluate the polynomial with coefficients @a coeff at @a x. | ||
437 | * The i-th element in @coeff corresponds to the coefficient of x^i. | ||
438 | * | ||
439 | * @param[out] z result of the evaluation | ||
440 | * @param coeff array of coefficients | ||
441 | * @param num_coeff number of coefficients | ||
442 | * @param x where to evaluate the polynomial | ||
443 | * @param m what group are we operating in? | ||
444 | */ | ||
445 | static void | ||
446 | horner_eval (gcry_mpi_t z, gcry_mpi_t *coeff, unsigned int num_coeff, gcry_mpi_t x, gcry_mpi_t m) | ||
447 | { | ||
448 | unsigned int i; | ||
449 | |||
450 | gcry_mpi_set_ui (z, 0); | ||
451 | for (i = 0; i < num_coeff; i++) | ||
452 | { | ||
453 | // z <- zx + c | ||
454 | gcry_mpi_mul (z, z, x); | ||
455 | gcry_mpi_addm (z, z, coeff[num_coeff - i - 1], m); | ||
456 | } | ||
457 | } | ||
458 | |||
459 | |||
460 | static void | ||
461 | keygen_round2_conclude (void *cls) | ||
462 | { | ||
463 | // TODO: recombine shares and send to client | ||
464 | GNUNET_assert (0); | ||
465 | } | ||
466 | |||
467 | |||
468 | static void | ||
469 | insert_round2_element (struct KeygenSession *ks) | ||
470 | { | ||
471 | struct GNUNET_SET_Element *element; | ||
472 | unsigned int i; | ||
473 | uint16_t big_y_size; | ||
474 | gcry_mpi_t c; | ||
475 | gcry_mpi_t idx; | ||
476 | gcry_mpi_t preshare; | ||
477 | |||
478 | GNUNET_assert (0 != (c = gcry_mpi_new (PAILLIER_BITS))); | ||
479 | GNUNET_assert (0 != (preshare = gcry_mpi_new (PAILLIER_BITS))); | ||
480 | GNUNET_assert (0 != (idx = gcry_mpi_new (PAILLIER_BITS))); | ||
481 | |||
482 | big_y_size = PAILLIER_BITS / 8 * ks->num_peers; | ||
483 | |||
484 | element = GNUNET_malloc (sizeof (struct GNUNET_SET_Element) + big_y_size); | ||
485 | |||
486 | for (i = 0; i < ks->num_peers; i++) | ||
487 | { | ||
488 | gcry_mpi_set_ui (idx, i + 1); | ||
489 | horner_eval (preshare, ks->presecret_polynomial, ks->threshold, idx, elgamal_p); | ||
490 | // concat 'A', 'y' and 'Y' to the vector | ||
491 | } | ||
492 | |||
493 | for (i = 0; i < ks->threshold; i++) | ||
494 | { | ||
495 | // concat 'a' to the vector | ||
496 | } | ||
497 | |||
498 | GNUNET_CONSENSUS_insert (ks->consensus, element, NULL, NULL); | ||
499 | } | ||
500 | |||
501 | |||
502 | |||
503 | static void | ||
504 | keygen_round1_conclude (void *cls) | ||
505 | { | ||
506 | struct KeygenSession *ks = cls; | ||
507 | |||
508 | // TODO: destroy old consensus | ||
509 | |||
510 | ks->consensus = GNUNET_CONSENSUS_create (cfg, ks->num_peers, ks->peers, &ks->session_id, | ||
511 | keygen_round1_new_element, ks); | ||
512 | |||
513 | insert_round2_element (ks); | ||
514 | |||
515 | GNUNET_CONSENSUS_conclude (ks->consensus, GNUNET_TIME_UNIT_FOREVER_REL /* FIXME */, keygen_round2_conclude, ks); | ||
516 | } | ||
517 | |||
518 | |||
519 | static void | ||
520 | insert_round1_element (struct KeygenSession *ks) | ||
521 | { | ||
522 | struct GNUNET_SET_Element *element; | ||
523 | struct GNUNET_SECRETSHARING_KeygenCommitData *d; | ||
524 | gcry_mpi_t v; | ||
525 | unsigned char v_data[PAILLIER_BITS / 8]; | ||
526 | |||
527 | element = GNUNET_malloc (sizeof *element + sizeof *d); | ||
528 | d = (void *) &element[1]; | ||
529 | element->data = d; | ||
530 | element->size = sizeof *d; | ||
531 | |||
532 | GNUNET_assert (0 != (v = gcry_mpi_new (PAILLIER_BITS))); | ||
533 | |||
534 | gcry_mpi_powm (v, elgamal_g, ks->presecret_polynomial[0], elgamal_p); | ||
535 | |||
536 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, | ||
537 | v_data, PAILLIER_BITS / 8, NULL, | ||
538 | v)); | ||
539 | |||
540 | GNUNET_CRYPTO_hash (v_data, PAILLIER_BITS / 8, &d->commitment); | ||
541 | |||
542 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, | ||
543 | (unsigned char *) d->pubkey.g, PAILLIER_BITS / 8, NULL, | ||
544 | ks->paillier_g)); | ||
545 | |||
546 | GNUNET_assert (0 == gcry_mpi_print (GCRYMPI_FMT_USG, | ||
547 | (unsigned char *) d->pubkey.mu, PAILLIER_BITS / 8, NULL, | ||
548 | ks->paillier_mu)); | ||
549 | |||
550 | // FIXME: sign stuff | ||
551 | |||
552 | d->peer = my_peer; | ||
553 | |||
554 | GNUNET_CONSENSUS_insert (ks->consensus, element, NULL, NULL); | ||
555 | } | ||
556 | |||
557 | |||
558 | /** | ||
559 | * Functions with this signature are called whenever a message is | ||
560 | * received. | ||
561 | * | ||
562 | * @param cls closure | ||
563 | * @param client identification of the client | ||
564 | * @param message the actual message | ||
565 | */ | ||
566 | static void handle_client_keygen (void *cls, | ||
567 | struct GNUNET_SERVER_Client *client, | ||
568 | const struct GNUNET_MessageHeader | ||
569 | *message) | ||
570 | { | ||
571 | const struct GNUNET_SECRETSHARING_CreateMessage *msg = | ||
572 | (const struct GNUNET_SECRETSHARING_CreateMessage *) message; | ||
573 | struct KeygenSession *ks; | ||
574 | |||
575 | ks = GNUNET_new (struct KeygenSession); | ||
576 | |||
577 | GNUNET_CONTAINER_DLL_insert (keygen_sessions_head, keygen_sessions_tail, ks); | ||
578 | |||
579 | ks->deadline = GNUNET_TIME_absolute_ntoh (msg->deadline); | ||
580 | ks->threshold = ntohs (msg->threshold); | ||
581 | ks->num_peers = ntohs (msg->num_peers); | ||
582 | |||
583 | ks->peers = normalize_peers ((struct GNUNET_PeerIdentity *) &msg[1], ks->num_peers, | ||
584 | &ks->num_peers, &ks->local_peer_idx); | ||
585 | |||
586 | ks->consensus = GNUNET_CONSENSUS_create (cfg, ks->num_peers, ks->peers, &msg->session_id, | ||
587 | keygen_round1_new_element, ks); | ||
588 | |||
589 | generate_presecret_polynomial (ks); | ||
590 | |||
591 | insert_round1_element (ks); | ||
592 | |||
593 | GNUNET_CONSENSUS_conclude (ks->consensus, GNUNET_TIME_UNIT_FOREVER_REL /* FIXME */, keygen_round1_conclude, ks); | ||
594 | } | ||
595 | |||
596 | |||
597 | /** | ||
598 | * Functions with this signature are called whenever a message is | ||
599 | * received. | ||
600 | * | ||
601 | * @param cls closure | ||
602 | * @param client identification of the client | ||
603 | * @param message the actual message | ||
604 | */ | ||
605 | static void handle_client_decrypt (void *cls, | ||
606 | struct GNUNET_SERVER_Client *client, | ||
607 | const struct GNUNET_MessageHeader | ||
608 | *message) | ||
609 | { | ||
610 | GNUNET_assert (0); | ||
611 | } | ||
612 | |||
613 | |||
43 | /** | 614 | /** |
44 | * Process template requests. | 615 | * Process template requests. |
45 | * | 616 | * |
@@ -49,13 +620,22 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
49 | */ | 620 | */ |
50 | static void | 621 | static void |
51 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 622 | run (void *cls, struct GNUNET_SERVER_Handle *server, |
52 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 623 | const struct GNUNET_CONFIGURATION_Handle *c) |
53 | { | 624 | { |
54 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 625 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
55 | /* FIXME: add handlers here! */ | 626 | {handle_client_keygen, NULL, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_GENERATE, 0}, |
627 | {handle_client_decrypt, NULL, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT, 0}, | ||
56 | {NULL, NULL, 0, 0} | 628 | {NULL, NULL, 0, 0} |
57 | }; | 629 | }; |
58 | /* FIXME: do setup here */ | 630 | cfg = c; |
631 | srv = server; | ||
632 | if (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity (cfg, &my_peer)) | ||
633 | { | ||
634 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "could not retrieve host identity\n"); | ||
635 | GNUNET_break (0); | ||
636 | GNUNET_SCHEDULER_shutdown (); | ||
637 | return; | ||
638 | } | ||
59 | GNUNET_SERVER_add_handlers (server, handlers); | 639 | GNUNET_SERVER_add_handlers (server, handlers); |
60 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, | 640 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup_task, |
61 | NULL); | 641 | NULL); |
@@ -73,8 +653,7 @@ int | |||
73 | main (int argc, char *const *argv) | 653 | main (int argc, char *const *argv) |
74 | { | 654 | { |
75 | return (GNUNET_OK == | 655 | return (GNUNET_OK == |
76 | GNUNET_SERVICE_run (argc, argv, "template", | 656 | GNUNET_SERVICE_run (argc, argv, "secretsharing", |
77 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | 657 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; |
78 | } | 658 | } |
79 | 659 | ||
80 | /* end of gnunet-service-template.c */ | ||