• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*############################################################################
2   # Copyright 2016-2017 Intel Corporation
3   #
4   # Licensed under the Apache License, Version 2.0 (the "License");
5   # you may not use this file except in compliance with the License.
6   # You may obtain a copy of the License at
7   #
8   #     http://www.apache.org/licenses/LICENSE-2.0
9   #
10   # Unless required by applicable law or agreed to in writing, software
11   # distributed under the License is distributed on an "AS IS" BASIS,
12   # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   # See the License for the specific language governing permissions and
14   # limitations under the License.
15   ############################################################################*/
16 
17 /*!
18  * \file
19  * \brief Print helper interface.
20  */
21 #ifndef EPID_COMMON_MATH_PRINTUTILS_H_
22 #define EPID_COMMON_MATH_PRINTUTILS_H_
23 
24 #include "epid/common/math/bignum.h"
25 #include "epid/common/math/ecgroup.h"
26 #include "epid/common/math/finitefield.h"
27 #include "epid/common/types.h"
28 
29 /// Debug print routines
30 /*!
31   \defgroup EpidPrint print_utils
32   Defines an API to print formatted versions of the types used for
33   mathematical operations.
34 
35   If the symbol EPID_ENABLE_DEBUG_PRINT is not defined, all calls to the
36   functions in this module are ignored.
37 
38   \ingroup EpidCommon
39   @{
40 */
41 
42 /// Print format
43 typedef enum {
44   kPrintUtilUnannotated = 0,  //!< Unannotated output format
45   kPrintUtilAnnotated = 1,    //!< Annotated output format
46   kPrintUtilFormatCount = 2,  //!< Count of print formats.
47 } PrintUtilFormat;
48 
49 #if !defined(EPID_ENABLE_DEBUG_PRINT)
50 
51 /// Do not print bignum if EPID_ENABLE_DEBUG_PRINT is undefined
52 #define PrintBigNum(...)
53 
54 /// Do not print ff element if EPID_ENABLE_DEBUG_PRINT is undefined
55 #define PrintFfElement(...)
56 
57 /// Do not print ec point if EPID_ENABLE_DEBUG_PRINT is undefined
58 #define PrintEcPoint(...)
59 
60 /// Do not print serialized bignum if EPID_ENABLE_DEBUG_PRINT is undefined
61 #define PrintBigNumStr(...)
62 
63 /// Do not print Fp element if EPID_ENABLE_DEBUG_PRINT is undefined
64 #define PrintFpElemStr(...)
65 
66 /// Do not print Fq element if EPID_ENABLE_DEBUG_PRINT is undefined
67 #define PrintFqElemStr(...)
68 
69 /// Do not print Fq2 element if EPID_ENABLE_DEBUG_PRINT is undefined
70 #define PrintFq2ElemStr(...)
71 
72 /// Do not print Fq6 element if EPID_ENABLE_DEBUG_PRINT is undefined
73 #define PrintFq6ElemStr(...)
74 
75 /// Do not print Fq12 element if EPID_ENABLE_DEBUG_PRINT is undefined
76 #define PrintFq12ElemStr(...)
77 
78 /// Do not print G1 element if EPID_ENABLE_DEBUG_PRINT is undefined
79 #define PrintG1ElemStr(...)
80 
81 /// Do not print G2 element if EPID_ENABLE_DEBUG_PRINT is undefined
82 #define PrintG2ElemStr(...)
83 
84 /// Do not print Gt element if EPID_ENABLE_DEBUG_PRINT is undefined
85 #define PrintGtElemStr(...)
86 
87 #else
88 
89 /// Prints BigNum
90 /*!
91   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
92   in order to activate this routine; otherwise,
93   it prints nothing.
94 
95   \param[in] big_num
96   BigNum to be printed
97   \param[in] var_name
98   Result variable name
99 
100 */
101 void PrintBigNum(BigNum const* big_num, char const* var_name);
102 
103 /// Prints finite field element
104 /*!
105   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
106   in order to activate this routine; otherwise,
107   it prints nothing.
108 
109   \param[in] ff
110   Finite field that element to be printed belongs to
111   \param[in] ff_element
112   Finite field element to be printed
113   \param[in] var_name
114   Result variable name
115   \param[in] format
116   Output format
117 
118 */
119 void PrintFfElement(FiniteField const* ff, FfElement const* ff_element,
120                     char const* var_name, PrintUtilFormat format);
121 
122 /// Prints elliptic curve group element
123 /*!
124   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
125   in order to activate this routine; otherwise,
126   it prints nothing.
127 
128   \param[in] g
129   Elliptic curve group that element to be printed belongs to
130   \param[in] ec_point
131   Elliptic curve group element to be printed
132   \param[in] var_name
133   Result variable name
134   \param[in] format
135   Output format
136 
137 */
138 void PrintEcPoint(EcGroup const* g, EcPoint const* ec_point,
139                   char const* var_name, PrintUtilFormat format);
140 
141 /// Prints serialized BigNum
142 /*!
143   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
144   in order to activate this routine; otherwise,
145   it prints nothing.
146 
147   \param[in] big_num_str
148   Serialized BigNum to be printed
149   \param[in] var_name
150   Result variable name
151 
152 */
153 void PrintBigNumStr(BigNumStr const* big_num_str, char const* var_name);
154 
155 /// Prints serialized Fp element
156 /*!
157   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
158   in order to activate this routine; otherwise,
159   it prints nothing.
160 
161   \param[in] fp_elem_str
162   Serialized Fp element to be printed
163   \param[in] var_name
164   Result variable name
165 
166 */
167 void PrintFpElemStr(FpElemStr const* fp_elem_str, char const* var_name);
168 
169 /// Prints serialized Fq element
170 /*!
171   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
172   in order to activate this routine; otherwise,
173   it prints nothing.
174 
175   \param[in] fq_elem_str
176   Serialized Fq element to be printed
177   \param[in] var_name
178   Result variable name
179 
180 */
181 void PrintFqElemStr(FqElemStr const* fq_elem_str, char const* var_name);
182 
183 /// Prints serialized Fq2 element
184 /*!
185   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
186   in order to activate this routine; otherwise,
187   it prints nothing.
188 
189   \param[in] fq2_elem_str
190   Serialized Fq2 element to be printed
191   \param[in] var_name
192   Result variable name
193   \param[in] format
194   Output format
195 
196 */
197 void PrintFq2ElemStr(Fq2ElemStr const* fq2_elem_str, char const* var_name,
198                      PrintUtilFormat format);
199 
200 /// Prints serialized Fq6 element
201 /*!
202   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
203   in order to activate this routine; otherwise,
204   it prints nothing.
205 
206   \param[in] fq6_elem_str
207   Serialized Fq6 element to be printed
208   \param[in] var_name
209   Result variable name
210   \param[in] format
211   Output format
212 
213 */
214 void PrintFq6ElemStr(Fq6ElemStr const* fq6_elem_str, char const* var_name,
215                      PrintUtilFormat format);
216 
217 /// Prints serialized Fq12 element
218 /*!
219   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
220   in order to activate this routine; otherwise,
221   it prints nothing.
222 
223   \param[in] fq12_elem_str
224   Serialized Intel(R) EPID Fq12 element to be printed
225   \param[in] var_name
226   Result variable name
227   \param[in] format
228   Output format
229 
230 */
231 void PrintFq12ElemStr(Fq12ElemStr const* fq12_elem_str, char const* var_name,
232                       PrintUtilFormat format);
233 
234 /// Prints serialized G1 element
235 /*!
236   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
237   in order to activate this routine; otherwise,
238   it prints nothing.
239 
240   \param[in] g1_elem_str
241   Serialized G1 element to be printed
242   \param[in] var_name
243   Result variable name
244   \param[in] format
245   Output format
246 
247 */
248 void PrintG1ElemStr(G1ElemStr const* g1_elem_str, char const* var_name,
249                     PrintUtilFormat format);
250 
251 /// Prints serialized G2 element
252 /*!
253   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
254   in order to activate this routine; otherwise,
255   it prints nothing.
256 
257   \param[in] g2_elem_str
258   Serialized G2 element to be printed
259   \param[in] var_name
260   Result variable name
261   \param[in] format
262   Output format
263 
264 */
265 void PrintG2ElemStr(G2ElemStr const* g2_elem_str, char const* var_name,
266                     PrintUtilFormat format);
267 
268 /// Prints serialized Gt element
269 /*!
270   Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
271   in order to activate this routine; otherwise,
272   it prints nothing.
273 
274   \param[in] gt_elem_str
275   Serialized G2 element to be printed
276   \param[in] var_name
277   Result variable name
278   \param[in] format
279   Output format
280 
281 */
282 void PrintGtElemStr(GtElemStr const* gt_elem_str, char const* var_name,
283                     PrintUtilFormat format);
284 
285 #endif  // !defined( EPID_ENABLE_DEBUG_PRINT )
286 /*! @} */
287 
288 #endif  // EPID_COMMON_MATH_PRINTUTILS_H_
289