printutils.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. * \file
  18. * \brief Print helper interface.
  19. */
  20. #ifndef EPID_COMMON_MATH_PRINTUTILS_H_
  21. #define EPID_COMMON_MATH_PRINTUTILS_H_
  22. #include "epid/common/math/bignum.h"
  23. #include "epid/common/math/ecgroup.h"
  24. #include "epid/common/math/finitefield.h"
  25. #include "epid/common/types.h"
  26. /// Debug print routines
  27. /*!
  28. \defgroup EpidPrint print_utils
  29. Defines an API to print formatted versions of the types used for
  30. mathematical operations.
  31. If the symbol EPID_ENABLE_DEBUG_PRINT is not defined, all calls to the
  32. functions in this module are ignored.
  33. \ingroup EpidCommon
  34. @{
  35. */
  36. /// Print format
  37. typedef enum {
  38. kPrintUtilUnannotated = 0, //!< Unannotated output format
  39. kPrintUtilAnnotated = 1, //!< Annotated output format
  40. kPrintUtilFormatCount = 2, //!< Count of print formats.
  41. } PrintUtilFormat;
  42. #if !defined(EPID_ENABLE_DEBUG_PRINT)
  43. /// Do not print bignum if EPID_ENABLE_DEBUG_PRINT is undefined
  44. #define PrintBigNum(...)
  45. /// Do not print ff element if EPID_ENABLE_DEBUG_PRINT is undefined
  46. #define PrintFfElement(...)
  47. /// Do not print ec point if EPID_ENABLE_DEBUG_PRINT is undefined
  48. #define PrintEcPoint(...)
  49. /// Do not print serialized bignum if EPID_ENABLE_DEBUG_PRINT is undefined
  50. #define PrintBigNumStr(...)
  51. /// Do not print Fp element if EPID_ENABLE_DEBUG_PRINT is undefined
  52. #define PrintFpElemStr(...)
  53. /// Do not print Fq element if EPID_ENABLE_DEBUG_PRINT is undefined
  54. #define PrintFqElemStr(...)
  55. /// Do not print Fq2 element if EPID_ENABLE_DEBUG_PRINT is undefined
  56. #define PrintFq2ElemStr(...)
  57. /// Do not print Fq6 element if EPID_ENABLE_DEBUG_PRINT is undefined
  58. #define PrintFq6ElemStr(...)
  59. /// Do not print Fq12 element if EPID_ENABLE_DEBUG_PRINT is undefined
  60. #define PrintFq12ElemStr(...)
  61. /// Do not print G1 element if EPID_ENABLE_DEBUG_PRINT is undefined
  62. #define PrintG1ElemStr(...)
  63. /// Do not print G2 element if EPID_ENABLE_DEBUG_PRINT is undefined
  64. #define PrintG2ElemStr(...)
  65. /// Do not print Gt element if EPID_ENABLE_DEBUG_PRINT is undefined
  66. #define PrintGtElemStr(...)
  67. #else
  68. /// Prints BigNum
  69. /*!
  70. Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  71. in order to activate this routine; otherwise,
  72. it prints nothing.
  73. \param[in] big_num
  74. BigNum to be printed
  75. \param[in] var_name
  76. Result variable name
  77. */
  78. void PrintBigNum(BigNum const* big_num, char const* var_name);
  79. /// Prints finite field element
  80. /*!
  81. Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  82. in order to activate this routine; otherwise,
  83. it prints nothing.
  84. \param[in] ff
  85. Finite field that element to be printed belongs to
  86. \param[in] ff_element
  87. Finite field element to be printed
  88. \param[in] var_name
  89. Result variable name
  90. \param[in] format
  91. Output format
  92. */
  93. void PrintFfElement(FiniteField const* ff, FfElement const* ff_element,
  94. char const* var_name, PrintUtilFormat format);
  95. /// Prints elliptic curve group element
  96. /*!
  97. Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  98. in order to activate this routine; otherwise,
  99. it prints nothing.
  100. \param[in] g
  101. Elliptic curve group that element to be printed belongs to
  102. \param[in] ec_point
  103. Elliptic curve group element to be printed
  104. \param[in] var_name
  105. Result variable name
  106. \param[in] format
  107. Output format
  108. */
  109. void PrintEcPoint(EcGroup const* g, EcPoint const* ec_point,
  110. char const* var_name, PrintUtilFormat format);
  111. /// Prints serialized BigNum
  112. /*!
  113. Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  114. in order to activate this routine; otherwise,
  115. it prints nothing.
  116. \param[in] big_num_str
  117. Serialized BigNum to be printed
  118. \param[in] var_name
  119. Result variable name
  120. */
  121. void PrintBigNumStr(BigNumStr const* big_num_str, char const* var_name);
  122. /// Prints serialized Fp 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. \param[in] fp_elem_str
  128. Serialized Fp element to be printed
  129. \param[in] var_name
  130. Result variable name
  131. */
  132. void PrintFpElemStr(FpElemStr const* fp_elem_str, char const* var_name);
  133. /// Prints serialized Fq element
  134. /*!
  135. Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  136. in order to activate this routine; otherwise,
  137. it prints nothing.
  138. \param[in] fq_elem_str
  139. Serialized Fq element to be printed
  140. \param[in] var_name
  141. Result variable name
  142. */
  143. void PrintFqElemStr(FqElemStr const* fq_elem_str, char const* var_name);
  144. /// Prints serialized Fq2 element
  145. /*!
  146. Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  147. in order to activate this routine; otherwise,
  148. it prints nothing.
  149. \param[in] fq2_elem_str
  150. Serialized Fq2 element to be printed
  151. \param[in] var_name
  152. Result variable name
  153. \param[in] format
  154. Output format
  155. */
  156. void PrintFq2ElemStr(Fq2ElemStr const* fq2_elem_str, char const* var_name,
  157. PrintUtilFormat format);
  158. /// Prints serialized Fq6 element
  159. /*!
  160. Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  161. in order to activate this routine; otherwise,
  162. it prints nothing.
  163. \param[in] fq6_elem_str
  164. Serialized Fq6 element to be printed
  165. \param[in] var_name
  166. Result variable name
  167. \param[in] format
  168. Output format
  169. */
  170. void PrintFq6ElemStr(Fq6ElemStr const* fq6_elem_str, char const* var_name,
  171. PrintUtilFormat format);
  172. /// Prints serialized Fq12 element
  173. /*!
  174. Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  175. in order to activate this routine; otherwise,
  176. it prints nothing.
  177. \param[in] fq12_elem_str
  178. Serialized Intel(R) EPID Fq12 element to be printed
  179. \param[in] var_name
  180. Result variable name
  181. \param[in] format
  182. Output format
  183. */
  184. void PrintFq12ElemStr(Fq12ElemStr const* fq12_elem_str, char const* var_name,
  185. PrintUtilFormat format);
  186. /// Prints serialized G1 element
  187. /*!
  188. Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  189. in order to activate this routine; otherwise,
  190. it prints nothing.
  191. \param[in] g1_elem_str
  192. Serialized G1 element to be printed
  193. \param[in] var_name
  194. Result variable name
  195. \param[in] format
  196. Output format
  197. */
  198. void PrintG1ElemStr(G1ElemStr const* g1_elem_str, char const* var_name,
  199. PrintUtilFormat format);
  200. /// Prints serialized G2 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. \param[in] g2_elem_str
  206. Serialized G2 element to be printed
  207. \param[in] var_name
  208. Result variable name
  209. \param[in] format
  210. Output format
  211. */
  212. void PrintG2ElemStr(G2ElemStr const* g2_elem_str, char const* var_name,
  213. PrintUtilFormat format);
  214. /// Prints serialized Gt element
  215. /*!
  216. Macro EPID_ENABLE_DEBUG_PRINT needs to be defined
  217. in order to activate this routine; otherwise,
  218. it prints nothing.
  219. \param[in] gt_elem_str
  220. Serialized G2 element to be printed
  221. \param[in] var_name
  222. Result variable name
  223. \param[in] format
  224. Output format
  225. */
  226. void PrintGtElemStr(GtElemStr const* gt_elem_str, char const* var_name,
  227. PrintUtilFormat format);
  228. #endif // !defined( EPID_ENABLE_DEBUG_PRINT )
  229. /*! @} */
  230. #endif // EPID_COMMON_MATH_PRINTUTILS_H_