-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFGbHelper.h
143 lines (119 loc) · 3.73 KB
/
FGbHelper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* File: FGbHelper.h
* Author: ph4r05
*
* Created on May 28, 2014, 11:51 AM
*/
#ifndef FGBHELPER_H
#define FGBHELPER_H
#include "base.h"
#include <string>
#include "faugere/fgb.h"
class FGbHelper {
private:
// Variable names for FGb.
char ** varNames;
// Log file for FGb library.
FILE * fgbFile;
// Limit on the term order for storage.
// Only terms of order/degree less than or equals to this limit will
// be stored and evaluated.
uint orderLimit;
// Byte width of the input cipher.
// Key block size + message block size.
ULONG byteWidth;
// Size of the output block of the cipher in ulong types.
ULONG outputWidthUlong;
public:
FGbHelper();
virtual ~FGbHelper();
/**
* Initialize helper object.
*
* @param byteWidth Function input byte width.
* @param orderLimit Order limit on terms.
* @param outputBits Number of bits on output function.
*/
void init(ULONG byteWidth, uint orderLimit, uint outputBits);
/**
* Deinitialize internal state.
*/
void deinit();
/**
* Returns number of terms in given polynomial.
* @param poly
* @return
*/
I32 getNumberOfTerms(Dpol poly) const;
/**
* Determines if polynomial is 0.
* @param poly
* @return
*/
bool isPolyNull(Dpol poly) const;
/**
* Determines if polynomial is 1*1.
* @param poly
* @return
*/
bool isPoly1(Dpol poly, I32 numVariables) const;
/**
* Calls underlying FGb routine to export polynomial to the
*
* @param numVariables Number of variables the polynomial may contain.
* @param numTerms Number of terms in the polynomial, use getNumberOfTerms().
* @param exps Exponents for each term and each variable in the term.
* Size is numVariables*numTerms. Terms, then variables.
* @param coefs Array of size numTerms, stores coefficients for terms.
* @param polynomial
* @return
*/
I32 exportPolynomial(I32 numVariables, I32 numTerms, I32* exps, I32 * coefs, Dpol polynomial) const;
/**
* Generated FGb polynomial representation.
* Allocates a new memory.
* @param coefs Coefficient storage for the polynomials.
* @param maxOrder Maximal order of the terms stored in coefs.
* @param polyIdx Which polynomial to represent.
* @param numTerms [OPTIONAL] If non-null, it will contain number of terms in the polynomial.
* @param hash [OPTIONAL] If non-null, hash of the polynomial will be computed and set here.
*/
Dpol_INT polynomial2FGb(uint numVariables, std::vector<ULONG> * coefs, uint maxOrder, uint polyIdx, ULONG * numTerms = NULL, ULONG * hash = NULL) const;
/**
* Dumps FGb polynomial to the standard output.
* @param numVariables
* @param poly
*/
void dumpFGbPoly(uint numVariables, Dpol poly) const;
/**
* Dumps polynomial basis.
*/
void dumpBasis(uint numVariables, Dpol * basis, uint numPoly) const;
/**
* Initializes FGb library.
* @param numVariables
*/
void initFGb(uint numVariables) const;
/**
* Deinitializes FGb library.
*/
void deinitFGb() const;
/**
* Reset FGb internal memory.
* @param output
* @param size
* @param iBuff
*/
void resetFGb() const;
/**
* Computes Gb with standard settings.
* @param n_input
* @param inputBasis
* @param outputBasis
* @param t0
* @return
*/
int computeFGb(int n_input, Dpol * inputBasis, Dpol * outputBasis, double * t0) const;
private:
};
#endif /* FGBHELPER_H */