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/include/gnunet_secretsharing_service.h | |
parent | 06b98ce26989dd42cad35f91ae9d8e757b602383 (diff) | |
download | gnunet-32b0ff1774ca5e76485be047ae693398163e0e68.tar.gz gnunet-32b0ff1774ca5e76485be047ae693398163e0e68.zip |
- work on secretsharing
Diffstat (limited to 'src/include/gnunet_secretsharing_service.h')
-rw-r--r-- | src/include/gnunet_secretsharing_service.h | 104 |
1 files changed, 56 insertions, 48 deletions
diff --git a/src/include/gnunet_secretsharing_service.h b/src/include/gnunet_secretsharing_service.h index f30761486..7752bb2d2 100644 --- a/src/include/gnunet_secretsharing_service.h +++ b/src/include/gnunet_secretsharing_service.h | |||
@@ -43,6 +43,14 @@ extern "C" | |||
43 | 43 | ||
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Number of bits for secretsharing keys. | ||
47 | * Must be smaller than the Pallier key size used internally | ||
48 | * by the secretsharing service. | ||
49 | */ | ||
50 | #define GNUNET_SECRETSHARING_KEY_BITS 1024 | ||
51 | |||
52 | |||
53 | /** | ||
46 | * Session that will eventually establish a shared secred between | 54 | * Session that will eventually establish a shared secred between |
47 | * the involved peers and allow encryption and cooperative decryption. | 55 | * the involved peers and allow encryption and cooperative decryption. |
48 | */ | 56 | */ |
@@ -50,6 +58,8 @@ struct GNUNET_SECRETSHARING_Session; | |||
50 | 58 | ||
51 | /** | 59 | /** |
52 | * Share of a secret shared with a group of peers. | 60 | * Share of a secret shared with a group of peers. |
61 | * Contains both the share and information about the peers that have | ||
62 | * the other parts of the share. | ||
53 | */ | 63 | */ |
54 | struct GNUNET_SECRETSHARING_Share; | 64 | struct GNUNET_SECRETSHARING_Share; |
55 | 65 | ||
@@ -65,10 +75,7 @@ struct GNUNET_SECRETSHARING_DecryptionHandle; | |||
65 | */ | 75 | */ |
66 | struct GNUNET_SECRETSHARING_PublicKey | 76 | struct GNUNET_SECRETSHARING_PublicKey |
67 | { | 77 | { |
68 | /** | 78 | uint32_t bits[GNUNET_SECRETSHARING_KEY_BITS / 8 / sizeof (uint32_t)]; |
69 | * Value of the private key. | ||
70 | */ | ||
71 | gcry_mpi_t value; | ||
72 | }; | 79 | }; |
73 | 80 | ||
74 | 81 | ||
@@ -77,14 +84,7 @@ struct GNUNET_SECRETSHARING_PublicKey | |||
77 | */ | 84 | */ |
78 | struct GNUNET_SECRETSHARING_Ciphertext | 85 | struct GNUNET_SECRETSHARING_Ciphertext |
79 | { | 86 | { |
80 | /** | 87 | uint32_t bits[2 * GNUNET_SECRETSHARING_KEY_BITS / 8 / sizeof (uint32_t)]; |
81 | * First component. | ||
82 | */ | ||
83 | gcry_mpi_t c1; | ||
84 | /** | ||
85 | * Second component. | ||
86 | */ | ||
87 | gcry_mpi_t c2; | ||
88 | }; | 88 | }; |
89 | 89 | ||
90 | 90 | ||
@@ -104,10 +104,12 @@ struct GNUNET_SECRETSHARING_Message | |||
104 | /** | 104 | /** |
105 | * Called once the secret has been established with all peers, or the deadline is due. | 105 | * Called once the secret has been established with all peers, or the deadline is due. |
106 | * | 106 | * |
107 | * Note that the number of peers can be smaller that 'k' (this threshold parameter), which | 107 | * Note that the number of peers can be smaller than 'k' (this threshold parameter), which |
108 | * makes the threshold crypto system useless. However, in this case one can still determine which peers | 108 | * makes the threshold crypto system useless. However, in this case one can still determine which peers |
109 | * were able to participate in the secret sharing successfully. | 109 | * were able to participate in the secret sharing successfully. |
110 | * | 110 | * |
111 | * If the secret sharing failed, num_ready_peers is 0 and my_share and public_key is NULL. | ||
112 | * | ||
111 | * @param cls closure | 113 | * @param cls closure |
112 | * @param my_share the share of this peer | 114 | * @param my_share the share of this peer |
113 | * @param public_key public key of the session | 115 | * @param public_key public key of the session |
@@ -160,36 +162,6 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c | |||
160 | 162 | ||
161 | 163 | ||
162 | /** | 164 | /** |
163 | * Load a session from an existing share. | ||
164 | * | ||
165 | * @param cfg configuration to use for connecting to the secretsharing service | ||
166 | * @param share share to load the session from | ||
167 | */ | ||
168 | struct GNUNET_SECRETSHARING_Session * | ||
169 | GNUNET_SECRETSHARING_load_session_DEPRECATED (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
170 | const struct GNUNET_SECRETSHARING_Share *share); | ||
171 | |||
172 | /** | ||
173 | * Convert a secret share to a string. | ||
174 | * | ||
175 | * @param share share to serialize | ||
176 | * @return the serialized secret share, to be freed by the caller | ||
177 | */ | ||
178 | char * | ||
179 | GNUNET_SECRETSHARING_share_to_BIN (const struct GNUNET_SECRETSHARING_Share *share); | ||
180 | |||
181 | |||
182 | /** | ||
183 | * Convert a secret share to a string. | ||
184 | * | ||
185 | * @param str string to deserialize | ||
186 | * @return the serialized secret share, to be freed by the caller | ||
187 | */ | ||
188 | const struct GNUNET_SECRETSHARING_Share * | ||
189 | GNUNET_SECRETSHARING_share_from_BIN (const char *str); | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Destroy a secret share. | 165 | * Destroy a secret share. |
194 | * | 166 | * |
195 | * @param share secret share to destroy | 167 | * @param share secret share to destroy |
@@ -214,15 +186,14 @@ GNUNET_SECRETSHARING_destroy_session (struct GNUNET_SECRETSHARING_Session *sessi | |||
214 | * This is a helper function, encryption can be done soley with a session's public key | 186 | * This is a helper function, encryption can be done soley with a session's public key |
215 | * and the crypto system parameters. | 187 | * and the crypto system parameters. |
216 | * | 188 | * |
217 | * @param session session to take the key for encryption from, | 189 | * @param public_key public key to use for decryption |
218 | * the session's ready callback must have been already called | ||
219 | * @param message message to encrypt | 190 | * @param message message to encrypt |
220 | * @param message_size number of bytes in @a message | 191 | * @param message_size number of bytes in @a message |
221 | * @param result_ciphertext pointer to store the resulting ciphertext | 192 | * @param result_ciphertext pointer to store the resulting ciphertext |
222 | * @return #GNUNET_YES on succes, #GNUNET_SYSERR if the message is invalid (invalid range) | 193 | * @return #GNUNET_YES on succes, #GNUNET_SYSERR if the message is invalid (invalid range) |
223 | */ | 194 | */ |
224 | int | 195 | int |
225 | GNUNET_SECRETSHARING_encrypt (const struct GNUNET_SECRETSHARING_PublicKey *session, | 196 | GNUNET_SECRETSHARING_encrypt (struct GNUNET_SECRETSHARING_PublicKey *public_key, |
226 | const void *message, | 197 | const void *message, |
227 | size_t message_size, | 198 | size_t message_size, |
228 | struct GNUNET_SECRETSHARING_Ciphertext *result_ciphertext); | 199 | struct GNUNET_SECRETSHARING_Ciphertext *result_ciphertext); |
@@ -235,14 +206,14 @@ GNUNET_SECRETSHARING_encrypt (const struct GNUNET_SECRETSHARING_PublicKey *sessi | |||
235 | * When the operation is canceled, the decrypt_cb is not called anymore, but the calling | 206 | * When the operation is canceled, the decrypt_cb is not called anymore, but the calling |
236 | * peer may already have irrevocably contributed his share for the decryption of the value. | 207 | * peer may already have irrevocably contributed his share for the decryption of the value. |
237 | * | 208 | * |
238 | * @param session session to use for the decryption | 209 | * @param share our secret share to use for decryption |
239 | * @param ciphertext ciphertext to publish in order to decrypt it (if enough peers agree) | 210 | * @param ciphertext ciphertext to publish in order to decrypt it (if enough peers agree) |
240 | * @param decrypt_cb callback called once the decryption succeeded | 211 | * @param decrypt_cb callback called once the decryption succeeded |
241 | * @param decrypt_cb_cls closure for @a decrypt_cb | 212 | * @param decrypt_cb_cls closure for @a decrypt_cb |
242 | * @return handle to cancel the operation | 213 | * @return handle to cancel the operation |
243 | */ | 214 | */ |
244 | struct GNUNET_SECRETSHARING_DecryptionHandle * | 215 | struct GNUNET_SECRETSHARING_DecryptionHandle * |
245 | GNUNET_SECRETSHARING_decrypt (struct GNUNET_SECRETSHARING_Session *session, | 216 | GNUNET_SECRETSHARING_decrypt (struct GNUNET_SECRETSHARING_Share *share, |
246 | struct GNUNET_SECRETSHARING_Ciphertext *ciphertext, | 217 | struct GNUNET_SECRETSHARING_Ciphertext *ciphertext, |
247 | GNUNET_SECRETSHARING_DecryptCallback decrypt_cb, | 218 | GNUNET_SECRETSHARING_DecryptCallback decrypt_cb, |
248 | void *decrypt_cb_cls); | 219 | void *decrypt_cb_cls); |
@@ -260,6 +231,43 @@ void | |||
260 | GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandle *decryption_handle); | 231 | GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandle *decryption_handle); |
261 | 232 | ||
262 | 233 | ||
234 | /** | ||
235 | * Read a share from its binary representation. | ||
236 | * | ||
237 | * @param data binary representation of the share | ||
238 | * @param len length of @a data | ||
239 | * @return the share, or NULL on error | ||
240 | */ | ||
241 | struct GNUNET_SECRETSHARING_Share * | ||
242 | GNUNET_SECRETSHARING_share_read (void *data, size_t len); | ||
243 | |||
244 | |||
245 | /** | ||
246 | * Convert a share to its binary representation. Use | ||
247 | * #GNUNET_SECRETSHARING_share_size to get the necessary size for the binary | ||
248 | * representation. | ||
249 | * | ||
250 | * @param share share to write | ||
251 | * @param buf buffer to write to | ||
252 | * @param buflen number of writable bytes in @a buffer | ||
253 | * @param[out] writelen pointer to store number of bytes written, | ||
254 | * ignored if NULL | ||
255 | * @return GNUNET_YES on success, GNUNET_NO on failure | ||
256 | */ | ||
257 | int | ||
258 | GNUNET_SECRETSHARING_share_write (struct GNUNET_SECRETSHARING_Share *share, | ||
259 | void *buf, size_t buflen, size_t *writelen); | ||
260 | |||
261 | |||
262 | /** | ||
263 | * Get the number of bytes necessary to represent the given share. | ||
264 | * | ||
265 | * @param share share | ||
266 | * @return number of bytes necessary to represent @a share | ||
267 | */ | ||
268 | size_t | ||
269 | GNUNET_SECRETSHARING_share_size (struct GNUNET_SECRETSHARING_Share *share); | ||
270 | |||
263 | 271 | ||
264 | 272 | ||
265 | #if 0 /* keep Emacsens' auto-indent happy */ | 273 | #if 0 /* keep Emacsens' auto-indent happy */ |