Percy++
A C++ implementation of Private Information Retrieval (PIR) protocols
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
agclient.h
1 // Percy++ Copyright 2007,2012,2013,2014
2 // Ian Goldberg <iang@cs.uwaterloo.ca>,
3 // Casey Devet <cjdevet@uwaterloo.ca>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of version 2 of the GNU General Public License as
7 // published by the Free Software Foundation.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // There is a copy of the GNU General Public License in the COPYING file
15 // packaged with this plugin; if you cannot find it, write to the Free
16 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301 USA
18 
19 #ifndef __AGCLIENT_H__
20 #define __AGCLIENT_H__
21 
22 #include <NTL/mat_ZZ_p.h>
23 #include "percyclient.h"
24 #include "agparams.h"
25 #include "percystats.h"
26 
27 NTL_CLIENT
28 
29 #ifdef NEED_UINT128
30 #define AG_NTL
31 #endif
32 
33 struct AGDecodeInfo {
34 #ifdef AG_NTL
35  mat_ZZ_p A_inv_B;
36  vec_ZZ_p Delta_vec_inv;
37 #else
38  AG_Element * A_inv_B;
39  AG_Element * Delta_vec_inv;
40 #endif
41 
42  std::vector<dbsize_t> perm;
43 };
44 
45 
51 
52 class PercyAGClient : public PercyClient {
53 public:
58  PercyAGClient (const PercyClientParams * params, PercyStats * stats = NULL);
59 
61  virtual ~PercyAGClient ();
62 
63 private:
65  const AGParams * params;
66 
67  // Virtual members as described in PercyClient class
68  virtual void encode_request_impl (nqueries_t request_identifier);
69  virtual dbsize_t send_request_impl (nqueries_t request_identifier,
70  vector<ostream*> &osvec, bool send_num_queries = true);
71  virtual dbsize_t receive_replies_impl (nqueries_t request_identifier,
72  vector<istream*> &isvec);
73  virtual nqueries_t process_replies_impl (nservers_t h,
74  vector<vector<PercyResult> >& results);
75 
76 #ifndef AG_NTL
77  // Generate random elements of ZZ_p for the first n elements of buffer. If
78  // nonzero is set to true, then the random values will be non-zero.
79  // NOTE:
80  // - Assumes that buffer is large enough to hold n elements.
81  void random_ag_elements (AG_Element * buffer, dbsize_t n,
82  bool nonzero = false);
83 
84  void soft_noise_matrix (AG_Element * M, dbsize_t size);
85  void hard_noise_matrix (AG_Element * M, dbsize_t size);
86 
87  // Compute result = A*B where A is rows_A-by-cols_A and B is cols_A-by-cols_B
88  // NOTE:
89  // - Assumes that result is large enough to hold rows_A*cols_B elements.
90  // - Also assumes cols_A*(p-1)^2 fits in an AG_Element (that is, modulo p
91  // operations do not need to be done until the end).
92  void mult_matrices (AG_Element * results, AG_Element * A, AG_Element * B,
93  dbsize_t rows_A, dbsize_t cols_A, dbsize_t cols_B);
94 
95  // Find the inverse of n modulo p and put it in inv. Return true if such and
96  // inverse exists and false otherwise.
97  bool inv (AG_Element& inv, const AG_Element& n);
98 
99  // Do row operations on M to discover if M is invertible. Return true if M is
100  // invertible and false othersize.
101  // If aux and/or aux2 are specified, then the row operations will also be
102  // performed on them. If M is invertible, then aux becomes M^(-1)*aux and aux2
103  // becomes M^(-1)*aux2.
104  // NOTE:
105  // - Assumes that all of M, aux and aux2 are size-by-size matrices.
106  // - All row operations are in-place and change the contents of M, aux and
107  // aux2. Use copies of these matrices if you will need to keep the
108  // original.
109  // - Assumes that size*(p-1)^2 fits in an AG_Element
110  // - If M is discovered to be singular, the algorithm short-circuits and the
111  // values in M, aux and aux2 are not guaranteed.
112  bool is_invertible (AG_Element * M, dbsize_t size, AG_Element * aux = NULL,
113  AG_Element * aux2 = NULL);
114 #endif
115 
116  AG_Element p;
117  AG_Element q;
118  ZZ q_ntl;
119  ZZ p_ntl;
120 
121 
122  map<nqueries_t, vector<unsigned char *> > queries;
123  map<nqueries_t, vector<AGDecodeInfo> > sentinfo;
124 #ifdef AG_NTL
125  map<nqueries_t, map<nservers_t, vec_vec_ZZ_p> > stored_answers;
126 #else
127  map<nqueries_t, map<nservers_t, vector<AG_Element *> > > stored_answers;
128 #endif
129 };
130 
131 #endif
Client parameters.
Definition: percyparams.h:189
virtual ~PercyAGClient()
Destructor.
Definition: percystats.h:66
Definition: agclient.h:33
PercyAGClient(const PercyClientParams *params, PercyStats *stats=NULL)
Constructor.
Definition: agparams.h:73
An abstract base class for a PIR client.
Definition: percyclient.h:35
A PIR client for the CPIR protocol by Aguilar Melchor and Gaborit (2007).
Definition: agclient.h:52