Percy++
A C++ implementation of Private Information Retrieval (PIR) protocols
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
itclient.h
1 // Percy++ Copyright 2007,2012,2013,2014
2 // Ian Goldberg <iang@cs.uwaterloo.ca>,
3 // Casey Devet <cjdevet@uwaterloo.ca>,
4 // Ann Yang <y242yang@uwaterloo.ca>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of version 2 of the GNU General Public License as
8 // published by the Free Software Foundation.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // There is a copy of the GNU General Public License in the COPYING file
16 // packaged with this plugin; if you cannot find it, write to the Free
17 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 
20 #ifndef __ITCLIENT_H__
21 #define __ITCLIENT_H__
22 
23 #include <vec_vec_ZZ_p.h>
24 #include <vec_GF2E.h>
25 #include "percyclient.h"
26 #include "gf2e.h"
27 #include "percyparams.h"
28 #include "itparams.h"
29 #include "rsdecoder.h"
30 
31 #ifdef SPIR_SUPPORT
32 #include "spirclient.h"
33 #endif
34 
35 NTL_CLIENT
36 
49 
50 class PercyClient_ZZ_p : public PercyClient {
51 public:
61  PercyClient_ZZ_p (const PercyClientParams * params, nservers_t num_servers,
62  nservers_t t, sid_t * sids, PercyStats * stats = NULL);
63 
65  virtual ~PercyClient_ZZ_p ();
66 
67 private:
68  // Virtual members as described in PercyClient class
69  virtual void encode_request_impl (nqueries_t request_identifier);
70  virtual dbsize_t send_request_impl (nqueries_t request_identifier,
71  vector<ostream*> &osvec, bool send_num_queries = true);
72  virtual dbsize_t receive_replies_impl (nqueries_t request_identifier,
73  vector<istream*> &isvec);
74  virtual nqueries_t process_replies_impl (nservers_t h,
75  vector<vector<PercyResult> >& results);
76 
77  // Based on the sids of the servers, choose the index that will
78  // correspond with each server. This function is called by the
79  // constructor.
80  virtual void choose_indices(sid_t *sids);
81  virtual void choose_interp_indices(nqueries_t qbs);
82 
83  // Private ZZ_p members
84  const ZZ_pParams * params;
85  vec_ZZ_p indices;
86  vec_ZZ_p interp_indices;
87  vector<vec_ZZ_p> vecs_interp_indices;
88  map<nqueries_t, vec_vec_ZZ_p *> queries;
89 #ifdef SPIR_SUPPORT
90  map<nqueries_t, SPIRClientQuery *> spir_query_info;
91 #endif
92  map<nqueries_t, vec_ZZ_p> randmults;
93  vector<vector<vec_ZZ_p> > answers;
94  vector<vector<DecoderResult<ZZ_p> > > unfinished_results;
95  vector<std::set<dbsize_t> > decoded;
96 };
97 
98 
102 
104 public:
110  PercyClient_Chor (const PercyClientParams * params, nservers_t num_servers,
111  PercyStats * stats = NULL);
112 
114  virtual ~PercyClient_Chor ();
115 
116 private:
117  // Virtual members as described in PercyClient class
118  virtual void encode_request_impl (nqueries_t request_identifier);
119  virtual dbsize_t send_request_impl (nqueries_t request_identifier,
120  vector<ostream*> &osvec, bool send_num_queries = true);
121  virtual dbsize_t receive_replies_impl (nqueries_t request_identifier,
122  vector<istream*> &isvec);
123  virtual nqueries_t process_replies_impl (nservers_t h,
124  vector<vector<PercyResult> >& results);
125 
126  // Private Chor members
127  const ChorParams * params;
128  map<nqueries_t, unsigned char *> queries;
129  vector<unsigned char *> answers;
130 };
131 
132 
145 
146 template<typename GF2E_Element>
148 public:
158  PercyClient_GF2E (const PercyClientParams * params, nservers_t num_servers,
159  nservers_t t, sid_t * sids, PercyStats * stats = NULL);
160 
162  virtual ~PercyClient_GF2E ();
163 
164 private:
165  // Virtual members as described in PercyClient class
166  virtual void encode_request_impl (nqueries_t request_identifier);
167  virtual dbsize_t send_request_impl (nqueries_t request_identifier,
168  vector<ostream*> &osvec, bool send_num_queries = true);
169  virtual dbsize_t receive_replies_impl (nqueries_t request_identifier,
170  vector<istream*> &isvec);
171  virtual nqueries_t process_replies_impl (nservers_t h,
172  vector<vector<PercyResult> >& results);
173 
174  virtual void choose_indices(sid_t *sids);
175  virtual void choose_interp_indices(nqueries_t qbs);
176 
177  // A NTL-less method to attempt a fast recovery
178  bool try_fast_recover (nservers_t h, vector<vector<PercyResult> > &results);
179  // Some helpers for it
180  void construct_lagrange_coeffs(GF2E_Element *coeffs, GF2E_Element alpha,
181  nservers_t firstpoint, nservers_t numpoints);
182  inline GF2E_Element interpolate(const GF2E_Element *word_answers,
183  const GF2E_Element *coeffs, nservers_t firstpoint,
184  nservers_t numpoints);
185 
186  // Private GF2E members
187  const GF2EParams * params;
188  GF2E_Element * indices;
189  GF2E_Element * interp_indices;
190  vec_GF2E vec_interp_indices;
191  vector<vec_GF2E> vecs_interp_indices;
192  vec_GF2E indices_ntl;
193  map<nqueries_t, vector<GF2E_Element> > randmults;
194  map<nqueries_t, GF2E_Element *> stored_shares;
195  vector<GF2E_Element *> answers;
196  vector<vector<vec_GF2E> > answers_ntl;
197  map<nqueries_t, vector<dbsize_t> > undecoded_indices;
198  vector<vector<DecoderResult<GF2E> > > unfinished_results;
199  vector<std::set<dbsize_t> > decoded;
200 };
201 
202 #include "itclient_impl.h"
203 
204 #endif
PercyClient_ZZ_p(const PercyClientParams *params, nservers_t num_servers, nservers_t t, sid_t *sids, PercyStats *stats=NULL)
Constructor.
Client parameters.
Definition: percyparams.h:189
Definition: percystats.h:66
nservers_t t
The privacy level.
Definition: percyclient.h:186
A PIR client for the IT-PIR protocol by Goldberg (2007) over GF(2^E).
Definition: itclient.h:147
virtual ~PercyClient_GF2E()
Destructor.
Definition: itclient_impl.h:84
virtual ~PercyClient_ZZ_p()
Destructor.
nservers_t num_servers
The number of servers.
Definition: percyclient.h:183
Definition: itparams.h:162
Definition: itparams.h:33
A PIR client for the IT-PIR protocol by Chor et al. (1995).
Definition: itclient.h:103
A PIR client for the IT-PIR protocol by Goldberg (2007) over the integers modulo p.
Definition: itclient.h:50
PercyClient_Chor(const PercyClientParams *params, nservers_t num_servers, PercyStats *stats=NULL)
Constructor.
An abstract base class for a PIR client.
Definition: percyclient.h:35
PercyClient_GF2E(const PercyClientParams *params, nservers_t num_servers, nservers_t t, sid_t *sids, PercyStats *stats=NULL)
Constructor.
Definition: itclient_impl.h:58
Defines the basic structure of protocol parameters (PercyParams), client parameters (PercyClientParam...
virtual ~PercyClient_Chor()
Destructor.
Definition: itparams.h:144