Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / secretsharing / secretsharing.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2013 GNUnet e.V.
4
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.
9
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.
14
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., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @author Florian Dold
23  * @file secretsharing/secretsharing.h
24  * @brief messages used for the secretsharing api
25  */
26 #ifndef SECRETSHARING_H
27 #define SECRETSHARING_H
28
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_time_lib.h"
32 #include "gnunet_common.h"
33 #include "gnunet_secretsharing_service.h"
34
35
36 GNUNET_NETWORK_STRUCT_BEGIN
37
38 struct GNUNET_SECRETSHARING_FieldElement
39 {
40   /**
41    * Value of an element in <elgamal_g>.
42    */
43   unsigned char bits[GNUNET_SECRETSHARING_ELGAMAL_BITS / 8];
44 };
45
46
47 struct GNUNET_SECRETSHARING_CreateMessage
48 {
49   /**
50    * Type: GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_GENERATE
51    */
52   struct GNUNET_MessageHeader header;
53
54   /**
55    * Session ID, will be used for consensus.
56    */
57   struct GNUNET_HashCode session_id GNUNET_PACKED;
58
59   /**
60    * Start time for communication with the other peers.
61    */
62   struct GNUNET_TIME_AbsoluteNBO start;
63
64   /**
65    * Deadline for the establishment of the crypto system.
66    */
67   struct GNUNET_TIME_AbsoluteNBO deadline;
68
69   /**
70    * Mininum number of cooperating peers to decrypt a
71    * value.
72    */
73   uint16_t threshold GNUNET_PACKED;
74
75   /**
76    * Number of peers at the end of this message.
77    */
78   uint16_t num_peers GNUNET_PACKED;
79
80   /* struct GNUNET_PeerIdentity[num_peers]; */
81 };
82
83
84
85 struct GNUNET_SECRETSHARING_ShareHeaderNBO
86 {
87   /**
88    * Threshold for the key this share belongs to.
89    */
90   uint16_t threshold;
91
92   /**
93    * Peers that have the share.
94    */
95   uint16_t num_peers;
96
97   /**
98    * Index of our peer in the list.
99    */
100   uint16_t my_peer;
101
102   /**
103    * Public key. Must correspond to the product of
104    * the homomorphic share commitments.
105    */
106   struct GNUNET_SECRETSHARING_PublicKey public_key;
107
108   /**
109    * Share of 'my_peer'
110    */
111   struct GNUNET_SECRETSHARING_FieldElement my_share;
112 };
113
114
115 /**
116  * Notify the client that then threshold secret has been
117  * established.
118  */
119 struct GNUNET_SECRETSHARING_SecretReadyMessage
120 {
121   /**
122    * Type: GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_SECRET_READY
123    */
124   struct GNUNET_MessageHeader header;
125
126   /* rest: the serialized share */
127
128 };
129
130
131 struct GNUNET_SECRETSHARING_DecryptRequestMessage
132 {
133   /**
134    * Type: GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT_REQUEST
135    */
136   struct GNUNET_MessageHeader header;
137
138   /**
139    * Until when should the decryption start?
140    */
141   struct GNUNET_TIME_AbsoluteNBO start;
142
143   /**
144    * Until when should the decryption be finished?
145    */
146   struct GNUNET_TIME_AbsoluteNBO deadline;
147
148   /**
149    * Ciphertext we want to decrypt.
150    */
151   struct GNUNET_SECRETSHARING_Ciphertext ciphertext;
152
153   /* the share with payload */
154 };
155
156
157 struct GNUNET_SECRETSHARING_DecryptResponseMessage
158 {
159   /**
160    * Type: #GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT_DONE
161    */
162   struct GNUNET_MessageHeader header;
163
164   /**
165    * Zero if decryption failed, non-zero if decryption succeeded.
166    * If the decryption failed, plaintext is also zero.
167    */
168   uint32_t success GNUNET_PACKED;
169
170   /**
171    * Decrypted plaintext.
172    */
173   struct GNUNET_SECRETSHARING_FieldElement plaintext;
174 };
175
176
177 GNUNET_NETWORK_STRUCT_END
178
179
180 /**
181  * A share, with all values in in host byte order.
182  */
183 struct GNUNET_SECRETSHARING_Share
184 {
185   /**
186    * Threshold for the key this share belongs to.
187    */
188   uint16_t threshold;
189
190   /**
191    * Peers that have the share.
192    */
193   uint16_t num_peers;
194
195   /**
196    * Index of our peer in the list.
197    */
198   uint16_t my_peer;
199
200   /**
201    * Public key.  Computed from the
202    * exponentiated coefficients.
203    */
204   struct GNUNET_SECRETSHARING_PublicKey public_key;
205
206   /**
207    * Share of 'my_peer'
208    */
209   struct GNUNET_SECRETSHARING_FieldElement my_share;
210
211   /**
212    * Peer identities (includes 'my_peer')
213    */
214   struct GNUNET_PeerIdentity *peers;
215
216   /*
217    * For each peer, store elgamal_g to the peer's
218    * share.
219    */
220   struct GNUNET_SECRETSHARING_FieldElement *sigmas;
221
222   /*
223    * Original indices of peers from the DKG round.
224    */
225   uint16_t *original_indices;
226 };
227
228
229 #endif