66f05e76d5cb2ea6acf6e396231e4ce351e68a44
[oweals/gnunet.git] / scalarproduct.h
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2010, 2011, 2012, 2013 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file   scalarproduct.h
23  * @brief  Scalar Product Message Types
24  * @author Christian M. Fuchs
25  *
26  * Created on September 2, 2013, 3:43 PM
27  */
28
29 #ifndef SCALARPRODUCT_H
30 #define SCALARPRODUCT_H
31
32 #ifdef  __cplusplus
33 extern "C"
34 {
35 #endif
36 ///////////////////////////////////////////////////////////////////////////////
37 //                      Defines
38 ///////////////////////////////////////////////////////////////////////////////
39 /**
40  * Length of the key used for encryption
41  */
42 #define KEYBITS 2048
43
44 /**
45  * When performing our crypto, we may add two encrypted values with each
46  * a maximal length of GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH.
47  */
48 #define PAILLIER_ELEMENT_LENGTH (2*KEYBITS/sizeof(char))
49
50 /**
51  * Maximum count of elements we can put into a multipart message
52  */
53 #define MULTIPART_ELEMENT_CAPACITY ((GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - sizeof (struct GNUNET_SCALARPRODUCT_multipart_message)) / PAILLIER_ELEMENT_LENGTH)
54
55 /**
56  * Log an error message at log-level 'level' that indicates
57  * a failure of the command 'cmd' with the message given
58  * by gcry_strerror(rc).
59  */
60 #define LOG_GCRY(level, cmd, rc) do { LOG(level, _("`%s' failed at %s:%d with error: %s\n"), cmd, __FILE__, __LINE__, gcry_strerror(rc)); } while(0)
61
62 ///////////////////////////////////////////////////////////////////////////////
63 //                     Scalar Product Message Types
64 ///////////////////////////////////////////////////////////////////////////////
65
66 /**
67  * Message type passed from client to service
68  * to initiate a request or responder role
69  */
70 struct GNUNET_SCALARPRODUCT_client_request
71 {
72   /**
73    * GNUNET message header
74    */
75   struct GNUNET_MessageHeader header;
76
77   /**
78    * how many elements the vector in payload contains
79    */
80   uint32_t element_count GNUNET_PACKED;
81
82   /**
83    * how many bytes the mask has
84    */
85   uint32_t mask_length GNUNET_PACKED;
86
87   /**
88    * the transaction/session key used to identify a session
89    */
90   struct GNUNET_HashCode key;
91
92   /**
93    * the identity of a remote peer we want to communicate with
94    */
95   struct GNUNET_PeerIdentity peer;
96
97   /**
98    * followed by long vector[element_count] | [unsigned char mask[mask_bytes]]
99    */
100 };
101
102 /**
103  * Message type passed from requesting service Alice to responding service Bob
104  * to initiate a request and make bob participate in our protocol
105  */
106 struct GNUNET_SCALARPRODUCT_service_request {
107   /**
108    * GNUNET message header
109    */
110   struct GNUNET_MessageHeader header;
111
112   /**
113    * how many elements the total message including all multipart msgs contains
114    */
115   uint32_t total_element_count GNUNET_PACKED;
116
117     /**
118    * how many elements are actually included after the mask was applied.
119    */
120   uint32_t contained_element_count GNUNET_PACKED;
121
122   /**
123    * how many bytes the mask has
124    */
125   uint32_t mask_length GNUNET_PACKED;
126
127   /**
128    * the length of the publickey contained within this message
129    */
130   uint32_t pk_length GNUNET_PACKED;
131
132   /**
133    * the transaction/session key used to identify a session
134    */
135   struct GNUNET_HashCode key;
136
137   /**
138    * how many elements the vector in payload contains
139    */
140   uint32_t element_count GNUNET_PACKED;
141
142   /**
143    * followed by mask | public_key | vector[used_element_count]
144    */
145 };
146
147 /**
148  * Multipart Message type passed between to supply additional elements for the peer
149  */
150 struct GNUNET_SCALARPRODUCT_multipart_message {
151   /**
152    * GNUNET message header
153    */
154   struct GNUNET_MessageHeader header;
155
156   /**
157    * how many elements we supply within this message
158    */
159   uint32_t multipart_element_count GNUNET_PACKED;
160
161   // followed by vector[multipart_element_count] or k[i][perm]
162 };
163
164 /**
165  * Message type passed from responding service Bob to responding service Alice
166  * to complete a request and allow Alice to compute the result
167  */
168 struct GNUNET_SCALARPRODUCT_service_response {
169   /**
170    * GNUNET message header
171    */
172   struct GNUNET_MessageHeader header;
173
174   /**
175    * how many elements the session input had
176    */
177   uint32_t total_element_count GNUNET_PACKED;
178
179   /**
180    * how many elements were included after the mask was applied including all multipart msgs.
181    */
182   uint32_t used_element_count GNUNET_PACKED;
183
184   /**
185    * how many elements this individual message delivers
186    */
187   uint32_t contained_element_count GNUNET_PACKED;
188
189   /**
190    * the transaction/session key used to identify a session
191    */
192   struct GNUNET_HashCode key;
193
194   /**
195    * followed by s | s' | k[i][perm]
196    */
197 };
198
199 /**
200  * Message type passed from service client
201  * to finalize a session as requester or responder
202  */
203 struct GNUNET_SCALARPRODUCT_client_response
204 {
205   /**
206    * GNUNET message header
207    */
208   struct GNUNET_MessageHeader header;
209
210   /**
211    * 0 if no product attached
212    */
213   uint32_t product_length GNUNET_PACKED;
214
215   /**
216    * the transaction/session key used to identify a session
217    */
218   struct GNUNET_HashCode key;
219
220   /**
221    * the identity of a remote peer we want to communicate with
222    */
223   struct GNUNET_PeerIdentity peer;
224
225   /**
226    * Workaround for libgcrypt: -1 if negative, 0 if zero, else 1
227    */
228   int8_t range;
229
230   /**
231    * followed by product of length product_length (or nothing)
232    */
233 };
234
235 #ifdef  __cplusplus
236 }
237 #endif
238
239 #endif  /* SCALARPRODUCT_H */
240