aboutsummaryrefslogtreecommitdiff
path: root/epid/common/math/printutils.h
blob: 9c2efd434553acf7d22dba9a2c592c1de991e51a (plain)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*############################################################################
  # Copyright 2016-2017 Intel Corporation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  ############################################################################*/

/*!
 * \file
 * \brief Print helper interface.
 */
#ifndef EPID_COMMON_MATH_PRINTUTILS_H_
#define EPID_COMMON_MATH_PRINTUTILS_H_

#include "epid/common/math/bignum.h"
#include "epid/common/math/ecgroup.h"
#include "epid/common/math/finitefield.h"
#include "epid/common/types.h"

/// Debug print routines
/*!
  \defgroup EpidPrint print_utils
  Defines an API to print formatted versions of the types used for
  mathematical operations.

  If the symbol EPID_ENABLE_DEBUG_PRINT is not defined, all calls to the
  functions in this module are ignored.

  \ingroup EpidCommon
  @{
*/

/// Print format
typedef enum {
  kPrintUtilUnannotated = 0,  //!< Unannotated output format
  kPrintUtilAnnotated = 1,    //!< Annotated output format
  kPrintUtilFormatCount = 2,  //!< Count of print formats.
} PrintUtilFormat;

#if !defined(EPID_ENABLE_DEBUG_PRINT)

/// Do not print bignum if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintBigNum(...)

/// Do not print ff element if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintFfElement(...)

/// Do not print ec point if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintEcPoint(...)

/// Do not print serialized bignum if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintBigNumStr(...)

/// Do not print Fp element if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintFpElemStr(...)

/// Do not print Fq element if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintFqElemStr(...)

/// Do not print Fq2 element if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintFq2ElemStr(...)

/// Do not print Fq6 element if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintFq6ElemStr(...)

/// Do not print Fq12 element if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintFq12ElemStr(...)

/// Do not print G1 element if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintG1ElemStr(...)

/// Do not print G2 element if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintG2ElemStr(...)

/// Do not print Gt element if EPID_ENABLE_DEBUG_PRINT is undefined
#define PrintGtElemStr(...)

#else

/// Prints BigNum
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] big_num
  BigNum to be printed
  \param[in] var_name
  Result variable name

*/
void PrintBigNum(BigNum const* big_num, char const* var_name);

/// Prints finite field element
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] ff
  Finite field that element to be printed belongs to
  \param[in] ff_element
  Finite field element to be printed
  \param[in] var_name
  Result variable name
  \param[in] format
  Output format

*/
void PrintFfElement(FiniteField const* ff, FfElement const* ff_element,
                    char const* var_name, PrintUtilFormat format);

/// Prints elliptic curve group element
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] g
  Elliptic curve group that element to be printed belongs to
  \param[in] ec_point
  Elliptic curve group element to be printed
  \param[in] var_name
  Result variable name
  \param[in] format
  Output format

*/
void PrintEcPoint(EcGroup const* g, EcPoint const* ec_point,
                  char const* var_name, PrintUtilFormat format);

/// Prints serialized BigNum
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] big_num_str
  Serialized BigNum to be printed
  \param[in] var_name
  Result variable name

*/
void PrintBigNumStr(BigNumStr const* big_num_str, char const* var_name);

/// Prints serialized Fp element
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] fp_elem_str
  Serialized Fp element to be printed
  \param[in] var_name
  Result variable name

*/
void PrintFpElemStr(FpElemStr const* fp_elem_str, char const* var_name);

/// Prints serialized Fq element
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] fq_elem_str
  Serialized Fq element to be printed
  \param[in] var_name
  Result variable name

*/
void PrintFqElemStr(FqElemStr const* fq_elem_str, char const* var_name);

/// Prints serialized Fq2 element
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] fq2_elem_str
  Serialized Fq2 element to be printed
  \param[in] var_name
  Result variable name
  \param[in] format
  Output format

*/
void PrintFq2ElemStr(Fq2ElemStr const* fq2_elem_str, char const* var_name,
                     PrintUtilFormat format);

/// Prints serialized Fq6 element
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] fq6_elem_str
  Serialized Fq6 element to be printed
  \param[in] var_name
  Result variable name
  \param[in] format
  Output format

*/
void PrintFq6ElemStr(Fq6ElemStr const* fq6_elem_str, char const* var_name,
                     PrintUtilFormat format);

/// Prints serialized Fq12 element
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] fq12_elem_str
  Serialized Intel(R) EPID Fq12 element to be printed
  \param[in] var_name
  Result variable name
  \param[in] format
  Output format

*/
void PrintFq12ElemStr(Fq12ElemStr const* fq12_elem_str, char const* var_name,
                      PrintUtilFormat format);

/// Prints serialized G1 element
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] g1_elem_str
  Serialized G1 element to be printed
  \param[in] var_name
  Result variable name
  \param[in] format
  Output format

*/
void PrintG1ElemStr(G1ElemStr const* g1_elem_str, char const* var_name,
                    PrintUtilFormat format);

/// Prints serialized G2 element
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] g2_elem_str
  Serialized G2 element to be printed
  \param[in] var_name
  Result variable name
  \param[in] format
  Output format

*/
void PrintG2ElemStr(G2ElemStr const* g2_elem_str, char const* var_name,
                    PrintUtilFormat format);

/// Prints serialized Gt element
/*!
  Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  in order to activate this routine; otherwise,
  it prints nothing.

  \param[in] gt_elem_str
  Serialized G2 element to be printed
  \param[in] var_name
  Result variable name
  \param[in] format
  Output format

*/
void PrintGtElemStr(GtElemStr const* gt_elem_str, char const* var_name,
                    PrintUtilFormat format);

#endif  // !defined( EPID_ENABLE_DEBUG_PRINT )
/*! @} */

#endif  // EPID_COMMON_MATH_PRINTUTILS_H_