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