Percy++
A C++ implementation of Private Information Retrieval (PIR) protocols
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
itserver.h
1 // Percy++ Copyright 2007,2012,2013,2014
2 // Ian Goldberg <iang@cs.uwaterloo.ca>,
3 // Casey Devet <cjdevet@uwaterloo.ca>,
4 // Wouter Lueks <wouter@telox.net>
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 __ITSERVER_H__
21 #define __ITSERVER_H__
22 
23 #include <vec_ZZ_p.h>
24 #include "percyserver.h"
25 #include "gf2e.h"
26 #include "itparams.h"
27 
28 NTL_CLIENT
29 
42 
43 class PercyServer_ZZ_p : public PercyServer {
44 public:
51  PercyStats * stats = NULL);
52 
54  virtual ~PercyServer_ZZ_p ();
55 
56 private:
57  virtual bool handle_request_impl (
58  const std::vector<unsigned char*> &requests,
59  const std::vector<unsigned char*> &responses);
60 
61  virtual void combine_results (unsigned char * result,
62  const std::vector<unsigned char*> &worker_results);
63 
64  const ZZ_pParams * params;
65 
66 #ifdef STRASSEN_COUNT_OPERATIONS
67  long nr_multiplications;
68  long nr_additions;
69 #endif
70 
71  void compute_one(const unsigned char * data, ZZ_p * value,
72  bool hybrid_protection, dbsize_t num_blocks,
73  dbsize_t words_per_block, dbsize_t bytes_per_word,
74  nqueries_t num_queries, const vec_ZZ_p *inputvector, dbsize_t c);
75  void compute_all(const unsigned char * data, vec_ZZ_p * responses,
76  bool hybrid_protection, dbsize_t num_blocks,
77  dbsize_t words_per_block, dbsize_t bytes_per_word,
78  dbsize_t last_block_words, nqueries_t num_queries,
79  const vec_ZZ_p * inputvector);
80  void compute_mult_strassen(const unsigned char * data,
81  vec_ZZ_p * responses, dbsize_t num_blocks,
82  dbsize_t words_per_block, dbsize_t bytes_per_word,
83  dbsize_t last_block_words, nqueries_t num_queries,
84  const vec_ZZ_p * inputvector);
85  void matrix_mult_naive(const vec_ZZ_p * matrix_a,
86  dbsize_t num_rows_a, const vec_ZZ_p * matrix_b,
87  dbsize_t num_cols_b, vec_ZZ_p * matrix_res,
88  dbsize_t row_offset = 0, dbsize_t col_offset = 0,
89  dbsize_t inner_offset = 0, dbsize_t inner_dim = 0);
90  nqueries_t optimal_strassen_depth( nqueries_t num_queries,
91  dbsize_t num_blocks, dbsize_t words_per_block,
92  dbsize_t bytes_per_word);
93  void strassen_split(const vec_ZZ_p * matrix_a, dbsize_t num_rows_a,
94  const vec_ZZ_p * matrix_b, dbsize_t num_cols_b,
95  vec_ZZ_p * matrix_res, nqueries_t depth);
96  void strassen_mult(const vec_ZZ_p * matrix_a, dbsize_t num_rows_a,
97  const vec_ZZ_p * matrix_b, dbsize_t num_cols_b,
98  vec_ZZ_p * matrix_res, nqueries_t depth);
99 };
100 
104 
106 public:
113  PercyStats * stats = NULL);
114 
116  virtual ~PercyServer_Chor ();
117 
118 private:
119  virtual bool handle_request_impl (
120  const std::vector<unsigned char*> &requests,
121  const std::vector<unsigned char*> &responses);
122 
123  virtual void combine_results (unsigned char * result,
124  const std::vector<unsigned char*> &worker_results);
125 
126  const ChorParams * params;
127 };
128 
141 
142 template <typename GF2E_Element>
144 public:
151  PercyStats * stats = NULL);
152 
154  virtual ~PercyServer_GF2E ();
155 
156 private:
157  inline void strassen_mult(Matrix<const GF2E_Element> &mat_a,
159  Matrix<GF2E_Element> &mat_c,
160  dbsize_t depth, GF2E_Element * memory);
161 
162  inline void strassen_split(Matrix<const GF2E_Element> &mat_a,
164  Matrix<GF2E_Element> &mat_c,
165  dbsize_t depth, GF2E_Element * memory);
166 
167  GF2E_Element * alloc_strassen_memory(nqueries_t res_rows,
168  dbsize_t inner_dim, dbsize_t res_cols);
169  void free_strassen_memory(GF2E_Element * memory);
170 
171  nqueries_t optimal_strassen_num_queries(nqueries_t num_queries);
172  inline nqueries_t optimal_strassen_depth(nqueries_t res_rows,
173  dbsize_t inner_dim, dbsize_t res_cols);
174 
175  nqueries_t strassen_real_max_depth;
176 
177  virtual bool handle_request_impl (
178  const std::vector<unsigned char*> &requests,
179  const std::vector<unsigned char*> &responses);
180 
181  virtual void combine_results (unsigned char * result,
182  const std::vector<unsigned char*> &worker_results);
183 
184  const GF2EParams * params;
185 };
186 
187 #include "itserver_impl.h"
188 
189 #endif
virtual ~PercyServer_ZZ_p()
Destructor.
Definition: percystats.h:66
A simple database object.
Definition: datastore.h:34
virtual ~PercyServer_Chor()
Destructor.
A PIR server for the IT-PIR protocol by Goldberg (2007) over GF(2^E).
Definition: itserver.h:143
PercyStats * stats
Statistics collection object.
Definition: percyserver.h:141
An abstract base class for a PIR server.
Definition: percyserver.h:34
PercyServer_Chor(DataStore *datastore, const PercyServerParams *params, PercyStats *stats=NULL)
Constructor.
A PIR server for the IT-PIR protocol by Chor et al. (1995).
Definition: itserver.h:105
A PIR server for the IT-PIR protocol by Goldberg (2007) over the integers modulo p.
Definition: itserver.h:43
Definition: itparams.h:162
PercyServer_ZZ_p(DataStore *datastore, const PercyServerParams *params, PercyStats *stats=NULL)
Constructor.
Definition: itparams.h:33
Definition: gf2e_matrix.h:31
virtual ~PercyServer_GF2E()
Destructor.
Definition: itserver_impl.h:41
Server parameters.
Definition: percyparams.h:251
DataStore * datastore
The database used by the server.
Definition: percyserver.h:137
PercyServer_GF2E(DataStore *datastore, const PercyServerParams *params, PercyStats *stats=NULL)
Constructor.
Definition: itserver_impl.h:33
Definition: itparams.h:144