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