aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-05-24 18:06:44 +0000
committerChristian Grothoff <christian@grothoff.org>2014-05-24 18:06:44 +0000
commit152cd13768915399f9e5137d78a2f75296a1b93e (patch)
treedd7c1b41a053991eb64d62746a900b4614ef940d /src
parentc0d549b6ab07a951380b807f1a1c1a767bfd5be0 (diff)
downloadgnunet-152cd13768915399f9e5137d78a2f75296a1b93e.tar.gz
gnunet-152cd13768915399f9e5137d78a2f75296a1b93e.zip
-doxygen, some additional error checking
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_secretsharing_service.h12
-rw-r--r--src/scalarproduct/gnunet-service-scalarproduct.c73
-rw-r--r--src/secretsharing/secretsharing_api.c170
-rw-r--r--src/secretsharing/secretsharing_common.c12
4 files changed, 168 insertions, 99 deletions
diff --git a/src/include/gnunet_secretsharing_service.h b/src/include/gnunet_secretsharing_service.h
index 3673ca0fe..98e270e84 100644
--- a/src/include/gnunet_secretsharing_service.h
+++ b/src/include/gnunet_secretsharing_service.h
@@ -187,7 +187,7 @@ typedef void (*GNUNET_SECRETSHARING_DecryptCallback) (void *cls,
187 * with the other peers. 187 * with the other peers.
188 * 188 *
189 * @param cfg configuration to use 189 * @param cfg configuration to use
190 * @param num_peers number of peers in 'peers' 190 * @param num_peers number of peers in @a peers
191 * @param peers array of peers that we will share secrets with, can optionally contain the local peer 191 * @param peers array of peers that we will share secrets with, can optionally contain the local peer
192 * @param session_id unique session id 192 * @param session_id unique session id
193 * @param start When should all peers be available for sharing the secret? 193 * @param start When should all peers be available for sharing the secret?
@@ -196,7 +196,7 @@ typedef void (*GNUNET_SECRETSHARING_DecryptCallback) (void *cls,
196 * by underlying consensus sessions 196 * by underlying consensus sessions
197 * @param threshold minimum number of peers that must cooperate to decrypt a value 197 * @param threshold minimum number of peers that must cooperate to decrypt a value
198 * @param cb called when the secret has been established 198 * @param cb called when the secret has been established
199 * @param cls closure for cb 199 * @param cls closure for @a cb
200 */ 200 */
201struct GNUNET_SECRETSHARING_Session * 201struct GNUNET_SECRETSHARING_Session *
202GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *cfg, 202GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -214,10 +214,10 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c
214 * Destroy a secret sharing session. 214 * Destroy a secret sharing session.
215 * The secret ready callback will not be called. 215 * The secret ready callback will not be called.
216 * 216 *
217 * @param session session to destroy 217 * @param s session to destroy
218 */ 218 */
219void 219void
220GNUNET_SECRETSHARING_session_destroy (struct GNUNET_SECRETSHARING_Session *session); 220GNUNET_SECRETSHARING_session_destroy (struct GNUNET_SECRETSHARING_Session *s);
221 221
222 222
223/** 223/**
@@ -271,10 +271,10 @@ GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg,
271 * The decrypt_cb is not called anymore, but the calling 271 * The decrypt_cb is not called anymore, but the calling
272 * peer may already have irrevocably contributed his share for the decryption of the value. 272 * peer may already have irrevocably contributed his share for the decryption of the value.
273 * 273 *
274 * @param decryption_handle decryption to cancel 274 * @param dh to cancel
275 */ 275 */
276void 276void
277GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandle *decryption_handle); 277GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandle *dh);
278 278
279 279
280/** 280/**
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c
index b133bb325..568f68ffc 100644
--- a/src/scalarproduct/gnunet-service-scalarproduct.c
+++ b/src/scalarproduct/gnunet-service-scalarproduct.c
@@ -60,17 +60,17 @@ struct SortedValue
60 * Sorted Values are kept in a DLL 60 * Sorted Values are kept in a DLL
61 */ 61 */
62 struct SortedValue * next; 62 struct SortedValue * next;
63 63
64 /** 64 /**
65 * Sorted Values are kept in a DLL 65 * Sorted Values are kept in a DLL
66 */ 66 */
67 struct SortedValue * prev; 67 struct SortedValue * prev;
68 68
69 /** 69 /**
70 * The element's id+integer-value 70 * The element's id+integer-value
71 */ 71 */
72 struct GNUNET_SCALARPRODUCT_Element * elem; 72 struct GNUNET_SCALARPRODUCT_Element * elem;
73 73
74 /** 74 /**
75 * the element's value converted to MPI 75 * the element's value converted to MPI
76 */ 76 */
@@ -91,7 +91,7 @@ struct ServiceSession
91 * Is this session active(GNUNET_YES), Concluded(GNUNET_NO), (GNUNET_SYSERR) 91 * Is this session active(GNUNET_YES), Concluded(GNUNET_NO), (GNUNET_SYSERR)
92 */ 92 */
93 int32_t active; 93 int32_t active;
94 94
95 /** 95 /**
96 * the role this peer has 96 * the role this peer has
97 */ 97 */
@@ -116,7 +116,7 @@ struct ServiceSession
116 * Alice or Bob's peerID 116 * Alice or Bob's peerID
117 */ 117 */
118 struct GNUNET_PeerIdentity peer; 118 struct GNUNET_PeerIdentity peer;
119 119
120 /** 120 /**
121 * the client this request is related to 121 * the client this request is related to
122 */ 122 */
@@ -148,13 +148,13 @@ struct ServiceSession
148 uint32_t transferred_element_count; 148 uint32_t transferred_element_count;
149 149
150 /** 150 /**
151 * Set of elements for which will conduction an intersection. 151 * Set of elements for which will conduction an intersection.
152 * the resulting elements are then used for computing the scalar product. 152 * the resulting elements are then used for computing the scalar product.
153 */ 153 */
154 struct GNUNET_SET_Handle * intersection_set; 154 struct GNUNET_SET_Handle * intersection_set;
155 155
156 /** 156 /**
157 * Set of elements for which will conduction an intersection. 157 * Set of elements for which will conduction an intersection.
158 * the resulting elements are then used for computing the scalar product. 158 * the resulting elements are then used for computing the scalar product.
159 */ 159 */
160 struct GNUNET_SET_OperationHandle * intersection_op; 160 struct GNUNET_SET_OperationHandle * intersection_op;
@@ -561,7 +561,7 @@ cb_client_disconnect (void *cls,
561 s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession); 561 s = GNUNET_SERVER_client_get_user_context (client, struct ServiceSession);
562 if (NULL == s) 562 if (NULL == s)
563 return; 563 return;
564 564
565 GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, s); 565 GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, s);
566 566
567 if (NULL != s->service_transmit_handle){ 567 if (NULL != s->service_transmit_handle){
@@ -751,14 +751,14 @@ prepare_bobs_cryptodata_message_multipart (void *cls)
751 s); 751 s);
752 if (NULL == s->service_transmit_handle) { 752 if (NULL == s->service_transmit_handle) {
753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via cadet!)\n")); 753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-response message via cadet!)\n"));
754 754
755 GNUNET_free (msg); 755 GNUNET_free (msg);
756 s->msg = NULL; 756 s->msg = NULL;
757 GNUNET_CADET_channel_destroy(s->channel); 757 GNUNET_CADET_channel_destroy(s->channel);
758 s->response->active = GNUNET_SYSERR; 758 s->response->active = GNUNET_SYSERR;
759 759
760 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 760 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s);
761 761
762 s->response->client_notification_task = 762 s->response->client_notification_task =
763 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 763 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
764 s->response); 764 s->response);
@@ -852,7 +852,7 @@ prepare_bobs_cryptodata_message (void *cls,
852 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s); 852 GNUNET_CONTAINER_DLL_remove (from_service_head, from_service_tail, s);
853 GNUNET_CADET_channel_destroy(s->channel); 853 GNUNET_CADET_channel_destroy(s->channel);
854 s->response->active = GNUNET_SYSERR; 854 s->response->active = GNUNET_SYSERR;
855 855
856 s->response->client_notification_task = 856 s->response->client_notification_task =
857 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, 857 GNUNET_SCHEDULER_add_now (&prepare_client_end_notification,
858 s->response); 858 s->response);
@@ -1087,7 +1087,7 @@ cb_intersection_element_removed (void *cls,
1087 1087
1088 case GNUNET_SET_STATUS_DONE: 1088 case GNUNET_SET_STATUS_DONE:
1089 s->intersection_op = NULL; 1089 s->intersection_op = NULL;
1090 1090
1091 if (2 > s->used_element_count) { 1091 if (2 > s->used_element_count) {
1092 // failed! do not leak information about our single remaining element! 1092 // failed! do not leak information about our single remaining element!
1093 // continue after the loop 1093 // continue after the loop
@@ -1102,7 +1102,7 @@ cb_intersection_element_removed (void *cls,
1102 for (i = 0; NULL != s->a_head; i++) { 1102 for (i = 0; NULL != s->a_head; i++) {
1103 struct SortedValue* a = s->a_head; 1103 struct SortedValue* a = s->a_head;
1104 GNUNET_assert (i < s->used_element_count); 1104 GNUNET_assert (i < s->used_element_count);
1105 1105
1106 s->sorted_elements[i] = a->val; 1106 s->sorted_elements[i] = a->val;
1107 GNUNET_CONTAINER_DLL_remove (s->a_head, s->a_tail, a); 1107 GNUNET_CONTAINER_DLL_remove (s->a_head, s->a_tail, a);
1108 GNUNET_free (a->elem); 1108 GNUNET_free (a->elem);
@@ -1129,7 +1129,7 @@ cb_intersection_element_removed (void *cls,
1129 1129
1130 //failed if we go here 1130 //failed if we go here
1131 GNUNET_break_op (0); 1131 GNUNET_break_op (0);
1132 1132
1133 1133
1134 // and notify our client-session that we could not complete the session 1134 // and notify our client-session that we could not complete the session
1135 if (ALICE == s->role) { 1135 if (ALICE == s->role) {
@@ -1262,31 +1262,18 @@ prepare_client_response (void *cls,
1262 msg->header.size = htons (msg_length); 1262 msg->header.size = htons (msg_length);
1263 msg->range = range; 1263 msg->range = range;
1264 msg->product_length = htonl (product_length); 1264 msg->product_length = htonl (product_length);
1265
1266 s->msg = (struct GNUNET_MessageHeader *) msg; 1265 s->msg = (struct GNUNET_MessageHeader *) msg;
1267 //transmit this message to our client
1268 s->client_transmit_handle = 1266 s->client_transmit_handle =
1269 GNUNET_SERVER_notify_transmit_ready (s->client, 1267 GNUNET_SERVER_notify_transmit_ready (s->client,
1270 msg_length, 1268 msg_length,
1271 GNUNET_TIME_UNIT_FOREVER_REL, 1269 GNUNET_TIME_UNIT_FOREVER_REL,
1272 &cb_transfer_message, 1270 &cb_transfer_message,
1273 s); 1271 s);
1274 if (NULL == s->client_transmit_handle) { 1272 GNUNET_break (NULL != s->client_transmit_handle);
1275 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1273 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1276 _ ("Could not send message to client (%p)!\n"), 1274 _ ("Sent result to client (%p), this session (%s) has ended!\n"),
1277 s->client); 1275 s->client,
1278 GNUNET_SERVER_client_disconnect(s->client); 1276 GNUNET_h2s (&s->session_id));
1279 free_session_variables(s);
1280 GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, s);
1281 GNUNET_free(s);
1282 }
1283 else
1284 // gracefully sent message, just terminate session structure
1285 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1286 _ ("Sent result to client (%p), this session (%s) has ended!\n"),
1287 s->client,
1288 GNUNET_h2s (&s->session_id));
1289 free_session_variables (s);
1290} 1277}
1291 1278
1292 1279
@@ -1317,7 +1304,8 @@ prepare_alices_computation_request (struct ServiceSession * s)
1317 &cb_transfer_message, 1304 &cb_transfer_message,
1318 s); 1305 s);
1319 if (!s->service_transmit_handle) { 1306 if (!s->service_transmit_handle) {
1320 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send message to channel!\n")); 1307 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1308 _ ("Could not send message to channel!\n"));
1321 GNUNET_free (msg); 1309 GNUNET_free (msg);
1322 s->msg = NULL; 1310 s->msg = NULL;
1323 s->active = GNUNET_SYSERR; 1311 s->active = GNUNET_SYSERR;
@@ -1383,7 +1371,8 @@ prepare_alices_cyrptodata_message_multipart (void *cls)
1383 &cb_transfer_message, 1371 &cb_transfer_message,
1384 s); 1372 s);
1385 if (!s->service_transmit_handle) { 1373 if (!s->service_transmit_handle) {
1386 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ ("Could not send service-request multipart message to channel!\n")); 1374 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1375 _("Could not send service-request multipart message to channel!\n"));
1387 GNUNET_free (msg); 1376 GNUNET_free (msg);
1388 s->msg = NULL; 1377 s->msg = NULL;
1389 s->active = GNUNET_SYSERR; 1378 s->active = GNUNET_SYSERR;
@@ -1397,7 +1386,7 @@ prepare_alices_cyrptodata_message_multipart (void *cls)
1397 1386
1398/** 1387/**
1399 * Our client has finished sending us its multipart message. 1388 * Our client has finished sending us its multipart message.
1400 * 1389 *
1401 * @param session the service session context 1390 * @param session the service session context
1402 */ 1391 */
1403static void 1392static void
@@ -1442,7 +1431,7 @@ client_request_complete_bob (struct ServiceSession * client_session)
1442 1431
1443/** 1432/**
1444 * Our client has finished sending us its multipart message. 1433 * Our client has finished sending us its multipart message.
1445 * 1434 *
1446 * @param session the service session context 1435 * @param session the service session context
1447 */ 1436 */
1448static void 1437static void
@@ -1719,7 +1708,7 @@ cb_channel_destruction (void *cls,
1719 _ ("Peer disconnected, terminating session %s with peer (%s)\n"), 1708 _ ("Peer disconnected, terminating session %s with peer (%s)\n"),
1720 GNUNET_h2s (&s->session_id), 1709 GNUNET_h2s (&s->session_id),
1721 GNUNET_i2s (&s->peer)); 1710 GNUNET_i2s (&s->peer));
1722 1711
1723 // as we have only one peer connected in each session, just remove the session 1712 // as we have only one peer connected in each session, just remove the session
1724 s->channel = NULL; 1713 s->channel = NULL;
1725 1714
@@ -1881,7 +1870,7 @@ handle_alices_cyrptodata_message_multipart (void *cls,
1881 // are we in the correct state? 1870 // are we in the correct state?
1882 s = (struct ServiceSession *) * channel_ctx; 1871 s = (struct ServiceSession *) * channel_ctx;
1883 //we are not bob 1872 //we are not bob
1884 if ((NULL == s->e_a) || //or we did not expect this message yet 1873 if ((NULL == s->e_a) || //or we did not expect this message yet
1885 (s->used_element_count == s->transferred_element_count)) { //we are not expecting multipart messages 1874 (s->used_element_count == s->transferred_element_count)) { //we are not expecting multipart messages
1886 goto except; 1875 goto except;
1887 } 1876 }
@@ -2265,8 +2254,8 @@ handle_bobs_cryptodata_message (void *cls,
2265 GNUNET_assert (NULL != message); 2254 GNUNET_assert (NULL != message);
2266 s = (struct ServiceSession *) * channel_ctx; 2255 s = (struct ServiceSession *) * channel_ctx;
2267 // are we in the correct state? 2256 // are we in the correct state?
2268 if (NULL == s->sorted_elements 2257 if (NULL == s->sorted_elements
2269 || NULL != s->msg 2258 || NULL != s->msg
2270 || s->used_element_count != s->transferred_element_count) { 2259 || s->used_element_count != s->transferred_element_count) {
2271 goto invalid_msg; 2260 goto invalid_msg;
2272 } 2261 }
@@ -2411,7 +2400,7 @@ run (void *cls,
2411 0 2400 0
2412 }; 2401 };
2413 cfg = c; 2402 cfg = c;
2414 2403
2415 //generate private/public key set 2404 //generate private/public key set
2416 GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey); 2405 GNUNET_CRYPTO_paillier_create (&my_pubkey, &my_privkey);
2417 2406
diff --git a/src/secretsharing/secretsharing_api.c b/src/secretsharing/secretsharing_api.c
index 6e347f6da..a1f5c336e 100644
--- a/src/secretsharing/secretsharing_api.c
+++ b/src/secretsharing/secretsharing_api.c
@@ -44,7 +44,7 @@ struct GNUNET_SECRETSHARING_Session
44 struct GNUNET_CLIENT_Connection *client; 44 struct GNUNET_CLIENT_Connection *client;
45 45
46 /** 46 /**
47 * Message queue for 'client'. 47 * Message queue for @e client.
48 */ 48 */
49 struct GNUNET_MQ_Handle *mq; 49 struct GNUNET_MQ_Handle *mq;
50 50
@@ -54,12 +54,15 @@ struct GNUNET_SECRETSHARING_Session
54 GNUNET_SECRETSHARING_SecretReadyCallback secret_ready_cb; 54 GNUNET_SECRETSHARING_SecretReadyCallback secret_ready_cb;
55 55
56 /** 56 /**
57 * Closure for 'secret_ready_cb'. 57 * Closure for @e secret_ready_cb.
58 */ 58 */
59 void *secret_ready_cls; 59 void *secret_ready_cls;
60}; 60};
61 61
62 62
63/**
64 * Handle to cancel a cooperative decryption operation.
65 */
63struct GNUNET_SECRETSHARING_DecryptionHandle 66struct GNUNET_SECRETSHARING_DecryptionHandle
64{ 67{
65 /** 68 /**
@@ -68,7 +71,7 @@ struct GNUNET_SECRETSHARING_DecryptionHandle
68 struct GNUNET_CLIENT_Connection *client; 71 struct GNUNET_CLIENT_Connection *client;
69 72
70 /** 73 /**
71 * Message queue for 'client'. 74 * Message queue for @e client.
72 */ 75 */
73 struct GNUNET_MQ_Handle *mq; 76 struct GNUNET_MQ_Handle *mq;
74 77
@@ -78,7 +81,7 @@ struct GNUNET_SECRETSHARING_DecryptionHandle
78 GNUNET_SECRETSHARING_DecryptCallback decrypt_cb; 81 GNUNET_SECRETSHARING_DecryptCallback decrypt_cb;
79 82
80 /** 83 /**
81 * Closure for 'decrypt_cb'. 84 * Closure for @e decrypt_cb.
82 */ 85 */
83 void *decrypt_cls; 86 void *decrypt_cls;
84}; 87};
@@ -103,6 +106,9 @@ static gcry_mpi_t elgamal_p;
103static gcry_mpi_t elgamal_g; 106static gcry_mpi_t elgamal_g;
104 107
105 108
109/**
110 * Function to initialize #elgamal_q, #egamal_p and #elgamal_g.
111 */
106static void 112static void
107ensure_elgamal_initialized (void) 113ensure_elgamal_initialized (void)
108{ 114{
@@ -118,60 +124,117 @@ ensure_elgamal_initialized (void)
118} 124}
119 125
120 126
127/**
128 * Callback invoked when there is an error communicating with
129 * the service. Notifies the application about the error.
130 *
131 * @param cls the `struct GNUNET_SECRETSHARING_Session`
132 * @param error error code
133 */
121static void 134static void
122handle_session_client_error (void *cls, enum GNUNET_MQ_Error error) 135handle_session_client_error (void *cls,
136 enum GNUNET_MQ_Error error)
123{ 137{
124 struct GNUNET_SECRETSHARING_Session *s = cls; 138 struct GNUNET_SECRETSHARING_Session *s = cls;
125 139
126 s->secret_ready_cb (s->secret_ready_cls, NULL, NULL, 0, NULL); 140 s->secret_ready_cb (s->secret_ready_cls, NULL, NULL, 0, NULL);
141 GNUNET_SECRETSHARING_session_destroy (s);
127} 142}
128 143
129 144
145/**
146 * Callback invoked when there is an error communicating with
147 * the service. Notifies the application about the error.
148 *
149 * @param cls the `struct GNUNET_SECRETSHARING_DecryptionHandle`
150 * @param error error code
151 */
130static void 152static void
131handle_decrypt_client_error (void *cls, enum GNUNET_MQ_Error error) 153handle_decrypt_client_error (void *cls,
154 enum GNUNET_MQ_Error error)
132{ 155{
133 struct GNUNET_SECRETSHARING_DecryptionHandle *dh = cls; 156 struct GNUNET_SECRETSHARING_DecryptionHandle *dh = cls;
134 157
135 dh->decrypt_cb (dh->decrypt_cls, NULL); 158 dh->decrypt_cb (dh->decrypt_cls, NULL);
159 GNUNET_SECRETSHARING_decrypt_cancel (dh);
136} 160}
137 161
138 162
163/**
164 * Handler invoked with the final result message from
165 * secret sharing. Decodes the message and passes the
166 * result to the application.
167 *
168 * @param cls the `struct GNUNET_SECRETSHARING_Session`
169 * @param msg message with the result
170 */
139static void 171static void
140handle_secret_ready (void *cls, const struct GNUNET_MessageHeader *msg) 172handle_secret_ready (void *cls,
173 const struct GNUNET_MessageHeader *msg)
141{ 174{
142 struct GNUNET_SECRETSHARING_Session *session = cls; 175 struct GNUNET_SECRETSHARING_Session *s = cls;
176 const struct GNUNET_SECRETSHARING_SecretReadyMessage *m;
143 struct GNUNET_SECRETSHARING_Share *share; 177 struct GNUNET_SECRETSHARING_Share *share;
144 const struct GNUNET_SECRETSHARING_SecretReadyMessage *m = (const void *) msg;
145 size_t share_size; 178 size_t share_size;
146 179
147 LOG (GNUNET_ERROR_TYPE_DEBUG, "got secret ready message of size %u\n", 180 LOG (GNUNET_ERROR_TYPE_DEBUG,
148 ntohs (m->header.size)); 181 "Got secret ready message of size %u\n",
149 182 ntohs (msg->size));
150 share_size = ntohs (m->header.size) - sizeof *m; 183 if (ntohs (msg->size) < sizeof (struct GNUNET_SECRETSHARING_SecretReadyMessage))
151 184 {
152 share = GNUNET_SECRETSHARING_share_read (&m[1], share_size, NULL); 185 GNUNET_break (0);
186 s->secret_ready_cb (s->secret_ready_cls, NULL, NULL, 0, NULL);
187 GNUNET_SECRETSHARING_session_destroy (s);
188 return;
189 }
190 m = (const struct GNUNET_SECRETSHARING_SecretReadyMessage *) msg;
191 share_size = ntohs (m->header.size) - sizeof (struct GNUNET_SECRETSHARING_SecretReadyMessage);
153 192
154 session->secret_ready_cb (session->secret_ready_cls, 193 share = GNUNET_SECRETSHARING_share_read (&m[1],
194 share_size,
195 NULL);
196 s->secret_ready_cb (s->secret_ready_cls,
155 share, /* FIXME */ 197 share, /* FIXME */
156 &share->public_key, 198 &share->public_key,
157 share->num_peers, 199 share->num_peers,
158 (struct GNUNET_PeerIdentity *) &m[1]); 200 (struct GNUNET_PeerIdentity *) &m[1]);
159 201 GNUNET_SECRETSHARING_session_destroy (s);
160 GNUNET_SECRETSHARING_session_destroy (session);
161} 202}
162 203
163 204
205/**
206 * Destroy a secret sharing session.
207 * The secret ready callback will not be called.
208 *
209 * @param s session to destroy
210 */
164void 211void
165GNUNET_SECRETSHARING_session_destroy (struct GNUNET_SECRETSHARING_Session *session) 212GNUNET_SECRETSHARING_session_destroy (struct GNUNET_SECRETSHARING_Session *s)
166{ 213{
167 GNUNET_MQ_destroy (session->mq); 214 GNUNET_MQ_destroy (s->mq);
168 session->mq = NULL; 215 s->mq = NULL;
169 GNUNET_CLIENT_disconnect (session->client); 216 GNUNET_CLIENT_disconnect (s->client);
170 session->client = NULL; 217 s->client = NULL;
171 GNUNET_free (session); 218 GNUNET_free (s);
172} 219}
173 220
174 221
222/**
223 * Create a session that will eventually establish a shared secret
224 * with the other peers.
225 *
226 * @param cfg configuration to use
227 * @param num_peers number of peers in @a peers
228 * @param peers array of peers that we will share secrets with, can optionally contain the local peer
229 * @param session_id unique session id
230 * @param start When should all peers be available for sharing the secret?
231 * Random number generation can take place before the start time.
232 * @param deadline point in time where the session must be established; taken as hint
233 * by underlying consensus sessions
234 * @param threshold minimum number of peers that must cooperate to decrypt a value
235 * @param cb called when the secret has been established
236 * @param cls closure for @a cb
237 */
175struct GNUNET_SECRETSHARING_Session * 238struct GNUNET_SECRETSHARING_Session *
176GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *cfg, 239GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *cfg,
177 unsigned int num_peers, 240 unsigned int num_peers,
@@ -187,19 +250,25 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c
187 struct GNUNET_MQ_Envelope *ev; 250 struct GNUNET_MQ_Envelope *ev;
188 struct GNUNET_SECRETSHARING_CreateMessage *msg; 251 struct GNUNET_SECRETSHARING_CreateMessage *msg;
189 static const struct GNUNET_MQ_MessageHandler mq_handlers[] = { 252 static const struct GNUNET_MQ_MessageHandler mq_handlers[] = {
190 {handle_secret_ready, GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY, 0}, 253 { &handle_secret_ready,
254 GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY, 0},
191 GNUNET_MQ_HANDLERS_END 255 GNUNET_MQ_HANDLERS_END
192 }; 256 };
193 257
194
195 s = GNUNET_new (struct GNUNET_SECRETSHARING_Session); 258 s = GNUNET_new (struct GNUNET_SECRETSHARING_Session);
196 s->client = GNUNET_CLIENT_connect ("secretsharing", cfg); 259 s->client = GNUNET_CLIENT_connect ("secretsharing", cfg);
260 if (NULL == s->client)
261 {
262 /* secretsharing not configured correctly */
263 GNUNET_break (0);
264 GNUNET_free (s);
265 return NULL;
266 }
197 s->secret_ready_cb = cb; 267 s->secret_ready_cb = cb;
198 s->secret_ready_cls = cls; 268 s->secret_ready_cls = cls;
199 GNUNET_assert (NULL != s->client);
200
201 s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers, 269 s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers,
202 handle_session_client_error, s); 270 &handle_session_client_error,
271 s);
203 GNUNET_assert (NULL != s->mq); 272 GNUNET_assert (NULL != s->mq);
204 273
205 ev = GNUNET_MQ_msg_extra (msg, 274 ev = GNUNET_MQ_msg_extra (msg,
@@ -215,19 +284,20 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c
215 284
216 GNUNET_MQ_send (s->mq, ev); 285 GNUNET_MQ_send (s->mq, ev);
217 286
218 LOG (GNUNET_ERROR_TYPE_DEBUG, "secretsharing session created with %u peers\n", 287 LOG (GNUNET_ERROR_TYPE_DEBUG,
288 "Secretsharing session created with %u peers\n",
219 num_peers); 289 num_peers);
220 return s; 290 return s;
221} 291}
222 292
223 293
224static void 294static void
225handle_decrypt_done (void *cls, const struct GNUNET_MessageHeader *msg) 295handle_decrypt_done (void *cls,
296 const struct GNUNET_MessageHeader *msg)
226{ 297{
227 struct GNUNET_SECRETSHARING_DecryptionHandle *dh = cls; 298 struct GNUNET_SECRETSHARING_DecryptionHandle *dh = cls;
228 const struct GNUNET_SECRETSHARING_DecryptResponseMessage *m = 299 const struct GNUNET_SECRETSHARING_DecryptResponseMessage *m =
229 (const void *) msg; 300 (const void *) msg; // FIXME: size check!?
230
231 const struct GNUNET_SECRETSHARING_Plaintext *plaintext; 301 const struct GNUNET_SECRETSHARING_Plaintext *plaintext;
232 302
233 if (m->success == 0) 303 if (m->success == 0)
@@ -280,7 +350,8 @@ GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg,
280 GNUNET_assert (NULL != s->client); 350 GNUNET_assert (NULL != s->client);
281 351
282 s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers, 352 s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers,
283 handle_decrypt_client_error, s); 353 &handle_decrypt_client_error,
354 s);
284 GNUNET_assert (NULL != s->mq); 355 GNUNET_assert (NULL != s->mq);
285 356
286 GNUNET_assert (GNUNET_OK == GNUNET_SECRETSHARING_share_write (share, NULL, 0, &share_size)); 357 GNUNET_assert (GNUNET_OK == GNUNET_SECRETSHARING_share_write (share, NULL, 0, &share_size));
@@ -376,7 +447,7 @@ GNUNET_SECRETSHARING_encrypt (const struct GNUNET_SECRETSHARING_PublicKey *publi
376 447
377 // Randomize y such that 0 < y < elgamal_q. 448 // Randomize y such that 0 < y < elgamal_q.
378 // The '- 1' is necessary as bitlength(q) = bitlength(p) - 1. 449 // The '- 1' is necessary as bitlength(q) = bitlength(p) - 1.
379 do 450 do
380 { 451 {
381 gcry_mpi_randomize (y, GNUNET_SECRETSHARING_ELGAMAL_BITS - 1, GCRY_WEAK_RANDOM); 452 gcry_mpi_randomize (y, GNUNET_SECRETSHARING_ELGAMAL_BITS - 1, GCRY_WEAK_RANDOM);
382 } while ((gcry_mpi_cmp_ui (y, 0) == 0) || (gcry_mpi_cmp (y, elgamal_q) >= 0)); 453 } while ((gcry_mpi_cmp_ui (y, 0) == 0) || (gcry_mpi_cmp (y, elgamal_q) >= 0));
@@ -386,10 +457,10 @@ GNUNET_SECRETSHARING_encrypt (const struct GNUNET_SECRETSHARING_PublicKey *publi
386 // write tmp to c1 457 // write tmp to c1
387 GNUNET_CRYPTO_mpi_print_unsigned (&result_ciphertext->c1_bits, 458 GNUNET_CRYPTO_mpi_print_unsigned (&result_ciphertext->c1_bits,
388 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8, tmp); 459 GNUNET_SECRETSHARING_ELGAMAL_BITS / 8, tmp);
389 460
390 // tmp <- h^y 461 // tmp <- h^y
391 gcry_mpi_powm (tmp, h, y, elgamal_p); 462 gcry_mpi_powm (tmp, h, y, elgamal_p);
392 // tmp <- tmp * m 463 // tmp <- tmp * m
393 gcry_mpi_mulm (tmp, tmp, m, elgamal_p); 464 gcry_mpi_mulm (tmp, tmp, m, elgamal_p);
394 // write tmp to c2 465 // write tmp to c2
395 GNUNET_CRYPTO_mpi_print_unsigned (&result_ciphertext->c2_bits, 466 GNUNET_CRYPTO_mpi_print_unsigned (&result_ciphertext->c2_bits,
@@ -399,15 +470,22 @@ GNUNET_SECRETSHARING_encrypt (const struct GNUNET_SECRETSHARING_PublicKey *publi
399} 470}
400 471
401 472
473/**
474 * Cancel a decryption.
475 *
476 * The decrypt_cb is not called anymore, but the calling
477 * peer may already have irrevocably contributed his share for the decryption of the value.
478 *
479 * @param dh to cancel
480 */
402void 481void
403GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandle *h) 482GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandle *dh)
404{ 483{
405 GNUNET_MQ_destroy (h->mq); 484 GNUNET_MQ_destroy (dh->mq);
406 h->mq = NULL; 485 dh->mq = NULL;
407 GNUNET_CLIENT_disconnect (h->client); 486 GNUNET_CLIENT_disconnect (dh->client);
408 h->client = NULL; 487 dh->client = NULL;
409 GNUNET_free (h); 488 GNUNET_free (dh);
410} 489}
411 490
412 491/* end of secretsharing_api.c */
413
diff --git a/src/secretsharing/secretsharing_common.c b/src/secretsharing/secretsharing_common.c
index c1e5acb9c..5b5d13b62 100644
--- a/src/secretsharing/secretsharing_common.c
+++ b/src/secretsharing/secretsharing_common.c
@@ -30,7 +30,9 @@
30 * @return The share, or NULL on error. 30 * @return The share, or NULL on error.
31 */ 31 */
32struct GNUNET_SECRETSHARING_Share * 32struct GNUNET_SECRETSHARING_Share *
33GNUNET_SECRETSHARING_share_read (const void *data, size_t len, size_t *readlen) 33GNUNET_SECRETSHARING_share_read (const void *data,
34 size_t len,
35 size_t *readlen)
34{ 36{
35 struct GNUNET_SECRETSHARING_Share *share; 37 struct GNUNET_SECRETSHARING_Share *share;
36 const struct GNUNET_SECRETSHARING_ShareHeaderNBO *sh = data; 38 const struct GNUNET_SECRETSHARING_ShareHeaderNBO *sh = data;
@@ -38,8 +40,8 @@ GNUNET_SECRETSHARING_share_read (const void *data, size_t len, size_t *readlen)
38 size_t n; 40 size_t n;
39 uint16_t payload_size; 41 uint16_t payload_size;
40 42
41 payload_size = ntohs (sh->num_peers) * 43 payload_size = ntohs (sh->num_peers) *
42 (sizeof (uint16_t) + sizeof (struct GNUNET_SECRETSHARING_FieldElement) + 44 (sizeof (uint16_t) + sizeof (struct GNUNET_SECRETSHARING_FieldElement) +
43 sizeof (struct GNUNET_PeerIdentity)); 45 sizeof (struct GNUNET_PeerIdentity));
44 46
45 if (NULL != readlen) 47 if (NULL != readlen)
@@ -94,8 +96,8 @@ GNUNET_SECRETSHARING_share_write (const struct GNUNET_SECRETSHARING_Share *share
94 char *p; 96 char *p;
95 int n; 97 int n;
96 98
97 payload_size = share->num_peers * 99 payload_size = share->num_peers *
98 (sizeof (uint16_t) + sizeof (struct GNUNET_SECRETSHARING_FieldElement) + 100 (sizeof (uint16_t) + sizeof (struct GNUNET_SECRETSHARING_FieldElement) +
99 sizeof (struct GNUNET_PeerIdentity)); 101 sizeof (struct GNUNET_PeerIdentity));
100 102
101 if (NULL != writelen) 103 if (NULL != writelen)