Percy++
A C++ implementation of Private Information Retrieval (PIR) protocols
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
gf2e_matrix.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 __GF2E_MATRIX_H__
21 #define __GF2E_MATRIX_H__
22 
23 #include "gf2e.h"
24 #include <iostream>
25 #include <stdint.h>
26 #include <string.h>
27 #include "xor.h"
28 #include "itserver.h"
29 
30 template <typename GF2E_Element>
32 public:
33  GF2E_Element *data;
34  dbsize_t num_rows;
35  dbsize_t num_cols;
36 
37  // Constructors
38  Matrix () {}
39  Matrix(GF2E_Element *data, dbsize_t num_rows, dbsize_t num_cols) :
40  data(data),
41  num_rows(num_rows),
42  num_cols(num_cols) {}
43 
44  void strassen_submatrices(SubMatrix<GF2E_Element> &m11,
48 
49  void clear();
50 
51  void is_sum_of(const SubMatrix<const GF2E_Element> &m1,
53  void copy_from(const SubMatrix<const GF2E_Element> &src);
54 };
55 
56 template <typename GF2E_Element>
57 std::ostream &operator<<(std::ostream &os,
59 
60 template <typename GF2E_Element>
62 public:
63  Matrix<GF2E_Element> matrix;
64  dbsize_t row;
65  dbsize_t col;
66  dbsize_t num_rows;
67  dbsize_t num_cols;
68 
69  // Constructors
70  SubMatrix () {}
71  SubMatrix (Matrix<GF2E_Element> matrix, dbsize_t row, dbsize_t col,
72  dbsize_t num_rows, dbsize_t num_cols) :
73  matrix(matrix),
74  row(row),
75  col(col),
76  num_rows(num_rows),
77  num_cols(num_cols) {}
78 
79  GF2E_Element* get(dbsize_t row, dbsize_t col) const;
80  GF2E_Element* first() const;
81 
82  void add(const Matrix<GF2E_Element> &m);
83 
84  inline void add_mult_of(
85  const Col<const GF2E_Element> &col_a,
86  const Row<const GF2E_Element> &row_b);
87 };
88 
89 template <typename GF2E_Element>
90 std::ostream &operator<<(std::ostream &os,
92 
93 
94 template <typename GF2E_Element>
95 class PercyServer::Row : public virtual SubMatrix<GF2E_Element> {
96 public:
97  // Constructor
98  Row (Matrix<GF2E_Element> matrix,
99  dbsize_t row, dbsize_t col, dbsize_t num_cols) :
100  SubMatrix<GF2E_Element>(matrix, row, col, 1, num_cols) {}
101 
102  GF2E_Element* get(dbsize_t row) const;
103 
104  inline void add_mult_of(
105  const Row<const GF2E_Element> &row_a,
106  const SubMatrix<const GF2E_Element> &mat_b);
107 };
108 
109 template <typename GF2E_Element>
110 class PercyServer::Col : public virtual SubMatrix<GF2E_Element> {
111 public:
112  // Constructor
113  Col (Matrix<GF2E_Element> matrix,
114  dbsize_t row, dbsize_t col, dbsize_t num_rows) :
115  SubMatrix<GF2E_Element>(matrix, row, col, num_rows, 1) {}
116 
117  GF2E_Element* get(dbsize_t col) const;
118 
119  inline void add_mult_of(
120  const SubMatrix<const GF2E_Element> &mat_a,
121  const Col<const GF2E_Element> &col_b);
122 
123  inline void add_mult_of(
124  const Col<const GF2E_Element> &col_a,
125  const Elem<const GF2E_Element> &elem_b);
126 };
127 
128 template <typename GF2E_Element>
129 class PercyServer::Elem : public Row<GF2E_Element>, public Col<GF2E_Element> {
130 public:
131  // Constructor
132  Elem (Matrix<GF2E_Element> matrix,
133  dbsize_t row, dbsize_t col) :
134  SubMatrix<GF2E_Element>(matrix, row, col, 1, 1),
135  Row<GF2E_Element>(matrix, row, col, 1),
136  Col<GF2E_Element>(matrix, row, col, 1) {}
137 
138  GF2E_Element* get() const;
139 
140  inline void add_mult_of(
141  const Row<const GF2E_Element> &row_a,
142  const Col<const GF2E_Element> &col_b);
143 
144  inline void add_mult_of(
145  const Elem<const GF2E_Element> &elem_a,
146  const Elem<const GF2E_Element> &elem_b);
147 };
148 
149 #include "gf2e_matrix_impl.h"
150 
151 #endif
std::ostream & operator<<(std::ostream &os, PercyMode mode)
Prints a PercyMode string to a stream.
Definition: gf2e_matrix.h:110
Definition: gf2e_matrix.h:129
Definition: gf2e_matrix.h:95
Definition: gf2e_matrix.h:31
Definition: gf2e_matrix.h:61