2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file scalarproduct/gnunet_scalarproduct.h
23 * @brief API to the scalarproduct service
24 * @author Christian M. Fuchs
27 #ifndef GNUNET_SCALARPRODUCT_H
28 #define GNUNET_SCALARPRODUCT_H
30 ///////////////////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////////////////
33 #define DISABLE_CRYPTO
36 * Length of the key used for encryption
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)
45 #define PAILLIER_ELEMENT_LENGTH (2*KEYBITS/8 +1)
52 ///////////////////////////////////////////////////////////////////////////////
53 // Service Structure Definitions
54 ///////////////////////////////////////////////////////////////////////////////
57 * Message type passed from requesting service Alice to responding service Bob
58 * to initiate a request and make bob participate in our protocol
60 struct GNUNET_SCALARPRODUCT_service_request {
62 * GNUNET message header
64 struct GNUNET_MessageHeader header;
67 * how many bytes the mask has
69 uint16_t mask_length GNUNET_PACKED;
72 * the length of the publickey contained within this message
74 uint16_t pk_length GNUNET_PACKED;
77 * the transaction/session key used to identify a session
79 struct GNUNET_HashCode key;
82 * how many elements the vector in payload contains
84 uint16_t element_count GNUNET_PACKED;
87 * how many elements are actually included after the mask was applied.
89 uint16_t used_element_count GNUNET_PACKED;
92 * followed by mask | public_key | vector[used_element_count]
97 * Message type passed from responding service Bob to responding service Alice
98 * to complete a request and allow Alice to compute the result
100 struct GNUNET_SCALARPRODUCT_service_response {
102 * GNUNET message header
104 struct GNUNET_MessageHeader header;
107 * how many elements the vector in payload contains
109 uint16_t element_count GNUNET_PACKED;
112 * how many elements are actually included after the mask was applied.
114 uint16_t used_element_count GNUNET_PACKED;
117 * the transaction/session key used to identify a session
119 struct GNUNET_HashCode key;
122 * followed by s | s' | kp[] | kq[]
126 ///////////////////////////////////////////////////////////////////////////////
127 // Service Structure Definitions
128 ///////////////////////////////////////////////////////////////////////////////
131 * state a session can be in
135 WAITING_FOR_BOBS_CONNECT,
136 MESSAGE_FROM_RESPONDING_CLIENT_RECEIVED,
137 WAITING_FOR_RESPONSE_FROM_SERVICE,
138 REQUEST_FROM_SERVICE_RECEIVED,
143 * role a peer in a session can assume
153 * A scalarproduct session which tracks:
155 * a request form the client to our final response.
157 * a request from a service to us(service).
159 struct ServiceSession
162 * the role this peer has
167 * session information is kept in a DLL
169 struct ServiceSession *next;
172 * session information is kept in a DLL
174 struct ServiceSession *prev;
177 * (hopefully) unique transaction ID
179 struct GNUNET_HashCode key;
182 * state of the session
184 enum SessionState state;
187 * Alice or Bob's peerID
189 struct GNUNET_PeerIdentity peer;
192 * the client this request is related to
194 struct GNUNET_SERVER_Client * client;
197 * how many elements we were supplied with from the client
199 uint16_t element_count;
202 * how many elements actually are used after applying the mask
204 uint16_t used_element_count;
207 * how many bytes the mask is long.
208 * just for convenience so we don't have to re-re-re calculate it each time
210 uint16_t mask_length;
213 * all the vector elements we received
218 * mask of which elements to check
220 unsigned char * mask;
223 * Public key of the remote service, only used by bob
225 gcry_sexp_t remote_pubkey;
228 * E(ai)(Bob) or ai(Alice) after applying the mask
233 * The computed scalar
238 * My transmit handle for the current message to a alice/bob
240 struct GNUNET_MESH_TransmitHandle * service_transmit_handle;
243 * My transmit handle for the current message to the client
245 struct GNUNET_SERVER_TransmitHandle * client_transmit_handle;
248 * tunnel-handle associated with our mesh handle
250 struct GNUNET_MESH_Tunnel * tunnel;
255 * We need to do a minimum of bookkeeping to maintain track of our transmit handles.
256 * each msg is associated with a session and handle. using this information we can determine which msg was sent.
261 * The handle used to transmit with this request
263 void ** transmit_handle;
266 * The message to send
268 struct GNUNET_MessageHeader * msg;
275 #endif /* GNUNET_SCALARPRODUCT_H */