aboutsummaryrefslogtreecommitdiff
path: root/src/vectorproduct/gnunet_vectorproduct.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/vectorproduct/gnunet_vectorproduct.h')
-rw-r--r--src/vectorproduct/gnunet_vectorproduct.h274
1 files changed, 274 insertions, 0 deletions
diff --git a/src/vectorproduct/gnunet_vectorproduct.h b/src/vectorproduct/gnunet_vectorproduct.h
new file mode 100644
index 000000000..4b116646b
--- /dev/null
+++ b/src/vectorproduct/gnunet_vectorproduct.h
@@ -0,0 +1,274 @@
1/*
2 This file is part of GNUnet.
3 (C) 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 2, 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 include/gnunet_vectorproduct.h
23 * @brief API to the vectorproduct service
24 * @author Christian M. Fuchs
25 */
26
27#ifndef GNUNET_VECTORPRODUCT_H
28#define GNUNET_VECTORPRODUCT_H
29
30///////////////////////////////////////////////////////////////////////////////
31// Defines
32///////////////////////////////////////////////////////////////////////////////
33#define DISABLE_CRYPTO
34
35/**
36 * Length of the key used for encryption
37 */
38#define KEYBITS 2048
39
40/**
41 * When performing our crypto, we may add two encrypted values with each
42 * a maximal length of GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH.
43 * thus we can receive a slightly longer element (+1 byte)
44 */
45#define PAILLIER_ELEMENT_LENGTH (2*KEYBITS/8 +1)
46
47#ifdef __cplusplus
48extern "C"
49{
50#endif
51
52///////////////////////////////////////////////////////////////////////////////
53// Service Structure Definitions
54///////////////////////////////////////////////////////////////////////////////
55
56/**
57 * Message type passed from requesting service Alice to responding service Bob
58 * to initiate a request and make bob participate in our protocol
59 */
60struct GNUNET_VECTORPRODUCT_service_request {
61 /**
62 * GNUNET message header
63 */
64 struct GNUNET_MessageHeader header;
65
66 /**
67 * how many bytes the mask has
68 */
69 uint16_t mask_length GNUNET_PACKED;
70
71 /**
72 * the length of the publickey contained within this message
73 */
74 uint16_t pk_length GNUNET_PACKED;
75
76 /**
77 * the transaction/session key used to identify a session
78 */
79 struct GNUNET_HashCode key;
80
81 /**
82 * how many elements the vector in payload contains
83 */
84 uint16_t element_count GNUNET_PACKED;
85
86 /**
87 * how many elements are actually included after the mask was applied.
88 */
89 uint16_t used_element_count GNUNET_PACKED;
90
91 /**
92 * followed by mask | public_key | vector[used_element_count]
93 */
94};
95
96/**
97 * Message type passed from responding service Bob to responding service Alice
98 * to complete a request and allow Alice to compute the result
99 */
100struct GNUNET_VECTORPRODUCT_service_response {
101 /**
102 * GNUNET message header
103 */
104 struct GNUNET_MessageHeader header;
105
106 /**
107 * how many elements the vector in payload contains
108 */
109 uint16_t element_count GNUNET_PACKED;
110
111 /**
112 * how many elements are actually included after the mask was applied.
113 */
114 uint16_t used_element_count GNUNET_PACKED;
115
116 /**
117 * the transaction/session key used to identify a session
118 */
119 struct GNUNET_HashCode key;
120
121 /**
122 * followed by s | s' | kp[] | kq[]
123 */
124};
125
126///////////////////////////////////////////////////////////////////////////////
127// Service Structure Definitions
128///////////////////////////////////////////////////////////////////////////////
129
130/**
131 * state a session can be in
132 */
133enum SessionState
134{
135 WAITING_FOR_BOBS_CONNECT,
136 MESSAGE_FROM_RESPONDING_CLIENT_RECEIVED,
137 WAITING_FOR_RESPONSE_FROM_SERVICE,
138 REQUEST_FROM_SERVICE_RECEIVED,
139 FINALIZED
140};
141
142/**
143 * role a peer in a session can assume
144 */
145enum PeerRole
146{
147 ALICE,
148 BOB
149};
150/**
151 * A vectorproduct session which tracks:
152 *
153 * a request form the client to our final response.
154 * or
155 * a request from a service to us(service).
156 */
157struct ServiceSession
158{
159 /**
160 * the role this peer has
161 */
162 enum PeerRole role;
163
164 /**
165 * session information is kept in a DLL
166 */
167 struct ServiceSession *next;
168
169 /**
170 * session information is kept in a DLL
171 */
172 struct ServiceSession *prev;
173
174 /**
175 * (hopefully) unique transaction ID
176 */
177 struct GNUNET_HashCode key;
178
179 /**
180 * state of the session
181 */
182 enum SessionState state;
183
184 /**
185 * Alice or Bob's peerID
186 */
187 struct GNUNET_PeerIdentity peer;
188
189 /**
190 * the client this request is related to
191 */
192 struct GNUNET_SERVER_Client * client;
193
194 /**
195 * how many elements we were supplied with from the client
196 */
197 uint16_t element_count;
198
199 /**
200 * how many elements actually are used after applying the mask
201 */
202 uint16_t used_element_count;
203
204 /**
205 * how many bytes the mask is long.
206 * just for convenience so we don't have to re-re-re calculate it each time
207 */
208 uint16_t mask_length;
209
210 /**
211 * all the vector elements we received
212 */
213 int32_t * vector;
214
215 /**
216 * mask of which elements to check
217 */
218 unsigned char * mask;
219
220 /**
221 * Public key of the remote service, only used by bob
222 */
223 gcry_sexp_t remote_pubkey;
224
225 /**
226 * E(ai)(Bob) or ai(Alice) after applying the mask
227 */
228 gcry_mpi_t * a;
229
230 /**
231 * The computed scalar
232 */
233 gcry_mpi_t product;
234
235 /**
236 * My transmit handle for the current message to a alice/bob
237 */
238 struct GNUNET_MESH_TransmitHandle * service_transmit_handle;
239
240 /**
241 * My transmit handle for the current message to the client
242 */
243 struct GNUNET_SERVER_TransmitHandle * client_transmit_handle;
244
245 /**
246 * tunnel-handle associated with our mesh handle
247 */
248 struct GNUNET_MESH_Tunnel * tunnel;
249
250};
251
252/**
253 * We need to do a minimum of bookkeeping to maintain track of our transmit handles.
254 * each msg is associated with a session and handle. using this information we can determine which msg was sent.
255 */
256struct MessageObject
257{
258 /**
259 * The handle used to transmit with this request
260 */
261 void ** transmit_handle;
262
263 /**
264 * The message to send
265 */
266 struct GNUNET_MessageHeader * msg;
267};
268
269#ifdef __cplusplus
270}
271#endif
272
273#endif /* GNUNET_VECTORPRODUCT_H */
274