2 This file is part of GNUnet
3 (C) 2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_secretsharing_service.h
23 * @brief verifiable additive secret sharing and cooperative decryption
24 * @author Florian Dold
27 #ifndef GNUNET_SECRETSHARING_SERVICE_H
28 #define GNUNET_SECRETSHARING_SERVICE_H
33 #if 0 /* keep Emacsens' auto-indent happy */
39 #include "gnunet_common.h"
40 #include "gnunet_time_lib.h"
41 #include "gnunet_configuration_lib.h"
46 * Number of bits for secretsharing keys.
47 * Must be smaller than the Pallier key size used internally
48 * by the secretsharing service.
50 #define GNUNET_SECRETSHARING_KEY_BITS 1024
54 * Session that will eventually establish a shared secred between
55 * the involved peers and allow encryption and cooperative decryption.
57 struct GNUNET_SECRETSHARING_Session;
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.
64 struct GNUNET_SECRETSHARING_Share;
68 * Handle to cancel a cooperative decryption operation.
70 struct GNUNET_SECRETSHARING_DecryptionHandle;
74 * Public key of a group sharing a secret.
76 struct GNUNET_SECRETSHARING_PublicKey
78 uint32_t bits[GNUNET_SECRETSHARING_KEY_BITS / 8 / sizeof (uint32_t)];
83 * Encrypted field element.
85 struct GNUNET_SECRETSHARING_Ciphertext
87 uint32_t bits[2 * GNUNET_SECRETSHARING_KEY_BITS / 8 / sizeof (uint32_t)];
92 * Plain, unencrypted message that can be encrypted with
95 struct GNUNET_SECRETSHARING_Message
98 * Value of the message.
105 * Called once the secret has been established with all peers, or the deadline is due.
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
109 * were able to participate in the secret sharing successfully.
111 * If the secret sharing failed, num_ready_peers is 0 and my_share and public_key is NULL.
114 * @param my_share the share of this peer
115 * @param public_key public key of the session
116 * @param num_ready_peers number of peers in @a ready_peers
117 * @param ready_peers peers that successfuly participated in establishing
120 typedef void (*GNUNET_SECRETSHARING_SecretReadyCallback) (void *cls,
121 const struct GNUNET_SECRETSHARING_Share *my_share,
122 const struct GNUNET_SECRETSHARING_PublicKey public_key,
123 unsigned int num_ready_peers,
124 const struct GNUNET_PeerIdentity *ready_peers);
128 * Called when a decryption has succeeded.
131 * @param data decrypted value
132 * @param data_size number of bytes in @a data
134 typedef void (*GNUNET_SECRETSHARING_DecryptCallback) (void *cls,
140 * Create a session that will eventually establish a shared secret
141 * with the other peers.
143 * @param cfg configuration to use
144 * @param num_peers number of peers in 'peers'
145 * @param peers array of peers that we will share secrets with, can optionally contain the local peer
146 * @param session_id unique session id
147 * @param deadline point in time where the session must be established; taken as hint
148 * by underlying consensus sessions
149 * @param threshold minimum number of peers that must cooperate to decrypt a value
150 * @param cb called when the secret has been established
151 * @param cls closure for cb
153 struct GNUNET_SECRETSHARING_Session *
154 GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *cfg,
155 unsigned int num_peers,
156 const struct GNUNET_PeerIdentity *peers,
157 const struct GNUNET_HashCode *session_id,
158 struct GNUNET_TIME_Absolute deadline,
159 unsigned int threshold,
160 GNUNET_SECRETSHARING_SecretReadyCallback *cb,
165 * Destroy a secret share.
167 * @param share secret share to destroy
170 GNUNET_SECRETSHARING_share_destroy (const struct GNUNET_SECRETSHARING_Share *share);
174 * Destroy a secret sharing session.
176 * @param session session to destroy
179 GNUNET_SECRETSHARING_destroy_session (struct GNUNET_SECRETSHARING_Session *session);
183 * Encrypt a value. This operation is executed locally, no communication is
186 * This is a helper function, encryption can be done soley with a session's public key
187 * and the crypto system parameters.
189 * @param public_key public key to use for decryption
190 * @param message message to encrypt
191 * @param message_size number of bytes in @a message
192 * @param result_ciphertext pointer to store the resulting ciphertext
193 * @return #GNUNET_YES on succes, #GNUNET_SYSERR if the message is invalid (invalid range)
196 GNUNET_SECRETSHARING_encrypt (struct GNUNET_SECRETSHARING_PublicKey *public_key,
199 struct GNUNET_SECRETSHARING_Ciphertext *result_ciphertext);
203 * Publish the given ciphertext for decryption. Once a sufficient (>=k) number of peers has
204 * published the same value, it will be decrypted.
206 * When the operation is canceled, the decrypt_cb is not called anymore, but the calling
207 * peer may already have irrevocably contributed his share for the decryption of the value.
209 * @param share our secret share to use for decryption
210 * @param ciphertext ciphertext to publish in order to decrypt it (if enough peers agree)
211 * @param decrypt_cb callback called once the decryption succeeded
212 * @param decrypt_cb_cls closure for @a decrypt_cb
213 * @return handle to cancel the operation
215 struct GNUNET_SECRETSHARING_DecryptionHandle *
216 GNUNET_SECRETSHARING_decrypt (struct GNUNET_SECRETSHARING_Share *share,
217 struct GNUNET_SECRETSHARING_Ciphertext *ciphertext,
218 GNUNET_SECRETSHARING_DecryptCallback decrypt_cb,
219 void *decrypt_cb_cls);
223 * Cancel a decryption.
225 * The decrypt_cb is not called anymore, but the calling
226 * peer may already have irrevocably contributed his share for the decryption of the value.
228 * @param decryption_handle decryption to cancel
231 GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandle *decryption_handle);
235 * Read a share from its binary representation.
237 * @param data binary representation of the share
238 * @param len length of @a data
239 * @return the share, or NULL on error
241 struct GNUNET_SECRETSHARING_Share *
242 GNUNET_SECRETSHARING_share_read (void *data, size_t len);
246 * Convert a share to its binary representation. Use
247 * #GNUNET_SECRETSHARING_share_size to get the necessary size for the binary
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,
255 * @return GNUNET_YES on success, GNUNET_NO on failure
258 GNUNET_SECRETSHARING_share_write (struct GNUNET_SECRETSHARING_Share *share,
259 void *buf, size_t buflen, size_t *writelen);
263 * Get the number of bytes necessary to represent the given share.
266 * @return number of bytes necessary to represent @a share
269 GNUNET_SECRETSHARING_share_size (struct GNUNET_SECRETSHARING_Share *share);
273 #if 0 /* keep Emacsens' auto-indent happy */