more rework of the logics
[oweals/gnunet.git] / src / scalarproduct / 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  * thus we can receive a slightly longer element (+1 byte)
48  */
49 #define PAILLIER_ELEMENT_LENGTH (2*KEYBITS/8 +1)
50
51 /**
52  * Log an error message at log-level 'level' that indicates
53  * a failure of the command 'cmd' with the message given
54  * by gcry_strerror(rc).
55  */
56 #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)
57
58 ///////////////////////////////////////////////////////////////////////////////
59 //                     Scalar Product Message Types
60 ///////////////////////////////////////////////////////////////////////////////
61
62 /**
63  * Message type passed from client to service 
64  * to initiate a request or responder role
65  */
66 struct GNUNET_SCALARPRODUCT_client_request
67 {
68   /**
69    * GNUNET message header
70    */
71   struct GNUNET_MessageHeader header;
72
73   /**
74    * how many elements the vector in payload contains
75    */
76   uint16_t element_count GNUNET_PACKED;
77
78   /**
79    * how many bytes the mask has
80    */
81   uint16_t mask_length GNUNET_PACKED;
82
83   /**
84    * the transaction/session key used to identify a session
85    */
86   struct GNUNET_HashCode key;
87
88   /**
89    * the identity of a remote peer we want to communicate with
90    */
91   struct GNUNET_PeerIdentity peer;
92
93   /**
94    * followed by long vector[element_count] | [unsigned char mask[mask_bytes]]
95    */
96 };
97   
98 /**
99  * Message type passed from requesting service Alice to responding service Bob
100  * to initiate a request and make bob participate in our protocol
101  */
102 struct GNUNET_SCALARPRODUCT_service_request {
103   /**
104    * GNUNET message header
105    */
106   struct GNUNET_MessageHeader header;
107
108   /**
109    * how many bytes the mask has
110    */
111   uint16_t mask_length GNUNET_PACKED;
112
113   /**
114    * the length of the publickey contained within this message
115    */
116   uint16_t pk_length GNUNET_PACKED;
117
118   /**
119    * the transaction/session key used to identify a session
120    */
121   struct GNUNET_HashCode key;
122
123   /**
124    * how many elements the vector in payload contains
125    */
126   uint16_t element_count GNUNET_PACKED;
127
128   /**
129    * how many elements are actually included after the mask was applied.
130    */
131   uint16_t used_element_count GNUNET_PACKED;
132
133   /**
134    * followed by mask | public_key | vector[used_element_count]
135    */
136 };
137
138 /**
139  * Message type passed from responding service Bob to responding service Alice
140  * to complete a request and allow Alice to compute the result
141  */
142 struct GNUNET_SCALARPRODUCT_service_response {
143   /**
144    * GNUNET message header
145    */
146   struct GNUNET_MessageHeader header;
147
148   /**
149    * how many elements the vector in payload contains
150    */
151   uint16_t element_count GNUNET_PACKED;
152
153   /**
154    * how many elements are actually included after the mask was applied.
155    */
156   uint16_t used_element_count GNUNET_PACKED;
157
158   /**
159    * the transaction/session key used to identify a session
160    */
161   struct GNUNET_HashCode key;
162
163   /**
164    * followed by s | s' | kp[] | kq[]
165    */
166 };
167
168 /**
169  * Message type passed from service client
170  * to finalize a session as requester or responder
171  */
172 struct GNUNET_SCALARPRODUCT_client_response
173 {
174   /**
175    * GNUNET message header
176    */
177   struct GNUNET_MessageHeader header;
178
179   /**
180    * 0 if no product attached
181    */
182   uint32_t product_length GNUNET_PACKED;
183
184   /**
185    * the transaction/session key used to identify a session
186    */
187   struct GNUNET_HashCode key;
188
189   /**
190    * the identity of a remote peer we want to communicate with
191    */
192   struct GNUNET_PeerIdentity peer;
193
194   /**
195    * Workaround for libgcrypt: -1 if negative, 0 if zero, else 1
196    */
197   int8_t range;
198
199   /**
200    * followed by product of length product_length (or nothing)
201    */
202 };
203   
204 #ifdef  __cplusplus
205 }
206 #endif
207
208 #endif  /* SCALARPRODUCT_H */
209