global reindent, now with uncrustify hook enabled
[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      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
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 &lt;elgamal_g&gt;.
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 struct GNUNET_SECRETSHARING_DecryptRequestMessage
131 {
132   /**
133    * Type: GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT_REQUEST
134    */
135   struct GNUNET_MessageHeader header;
136
137   /**
138    * Until when should the decryption start?
139    */
140   struct GNUNET_TIME_AbsoluteNBO start;
141
142   /**
143    * Until when should the decryption be finished?
144    */
145   struct GNUNET_TIME_AbsoluteNBO deadline;
146
147   /**
148    * Ciphertext we want to decrypt.
149    */
150   struct GNUNET_SECRETSHARING_Ciphertext ciphertext;
151
152   /* the share with payload */
153 };
154
155
156 struct GNUNET_SECRETSHARING_DecryptResponseMessage
157 {
158   /**
159    * Type: #GNUNET_MESSAGE_TYPE_SECRETSHARING_CLIENT_DECRYPT_DONE
160    */
161   struct GNUNET_MessageHeader header;
162
163   /**
164    * Zero if decryption failed, non-zero if decryption succeeded.
165    * If the decryption failed, plaintext is also zero.
166    */
167   uint32_t success GNUNET_PACKED;
168
169   /**
170    * Decrypted plaintext.
171    */
172   struct GNUNET_SECRETSHARING_FieldElement plaintext;
173 };
174
175
176 GNUNET_NETWORK_STRUCT_END
177
178
179 /**
180  * A share, with all values in in host byte order.
181  */
182 struct GNUNET_SECRETSHARING_Share
183 {
184   /**
185    * Threshold for the key this share belongs to.
186    */
187   uint16_t threshold;
188
189   /**
190    * Peers that have the share.
191    */
192   uint16_t num_peers;
193
194   /**
195    * Index of our peer in the list.
196    */
197   uint16_t my_peer;
198
199   /**
200    * Public key.  Computed from the
201    * exponentiated coefficients.
202    */
203   struct GNUNET_SECRETSHARING_PublicKey public_key;
204
205   /**
206    * Share of 'my_peer'
207    */
208   struct GNUNET_SECRETSHARING_FieldElement my_share;
209
210   /**
211    * Peer identities (includes 'my_peer')
212    */
213   struct GNUNET_PeerIdentity *peers;
214
215   /*
216    * For each peer, store elgamal_g to the peer's
217    * share.
218    */
219   struct GNUNET_SECRETSHARING_FieldElement *sigmas;
220
221   /*
222    * Original indices of peers from the DKG round.
223    */
224   uint16_t *original_indices;
225 };
226
227
228 #endif