fq2.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*############################################################################
  2. # Copyright 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. /// Definition of Fq2 math
  17. /*! \file */
  18. #ifndef EPID_MEMBER_TINY_MATH_FQ2_H_
  19. #define EPID_MEMBER_TINY_MATH_FQ2_H_
  20. #include <stdint.h>
  21. /// \cond
  22. typedef struct Fq2Elem Fq2Elem;
  23. typedef struct FqElem FqElem;
  24. typedef struct VeryLargeInt VeryLargeInt;
  25. /// \endcond
  26. /// Copy an element's value
  27. /*!
  28. \param[out] result copy target.
  29. \param[in] in copy source.
  30. */
  31. void Fq2Cp(Fq2Elem* result, Fq2Elem const* in);
  32. /// Set an element's value.
  33. /*!
  34. \param[out] result target.
  35. \param[in] in value to set.
  36. */
  37. void Fq2Set(Fq2Elem* result, uint32_t in);
  38. /// Clear an element's value.
  39. /*!
  40. \param[out] result element to clear.
  41. */
  42. void Fq2Clear(Fq2Elem* result);
  43. /// Add two elements of Fq2.
  44. /*!
  45. \param[out] result of adding left and right.
  46. \param[in] left The first operand to be added.
  47. \param[in] right The second operand to be added.
  48. */
  49. void Fq2Add(Fq2Elem* result, Fq2Elem const* left, Fq2Elem const* right);
  50. /// Exponentiate an element of Fq2 by a large integer.
  51. /*!
  52. \param[out] result target.
  53. \param[in] base the base.
  54. \param[in] exp the exponent.
  55. */
  56. void Fq2Exp(Fq2Elem* result, Fq2Elem const* base, VeryLargeInt const* exp);
  57. /// Subtract two elements of Fq2.
  58. /*!
  59. \param[out] result of subtracting left from right.
  60. \param[in] left The operand to be subtracted from.
  61. \param[in] right The operand to subtract.
  62. */
  63. void Fq2Sub(Fq2Elem* result, Fq2Elem const* left, Fq2Elem const* right);
  64. /// Multiply two elements of Fq2.
  65. /*!
  66. \param[out] result of multiplying left and right.
  67. \param[in] left The first operand to be multiplied.
  68. \param[in] right The second operand to be multiplied.
  69. */
  70. void Fq2Mul(Fq2Elem* result, Fq2Elem const* left, Fq2Elem const* right);
  71. /// Invert an element of Fq2.
  72. /*!
  73. \param[out] result the inverse of the element.
  74. \param[in] in the element to invert.
  75. */
  76. void Fq2Inv(Fq2Elem* result, Fq2Elem const* in);
  77. /// Negate an element of Fq2.
  78. /*!
  79. \param[out] result the negative of the element.
  80. \param[in] in the element to negate.
  81. */
  82. void Fq2Neg(Fq2Elem* result, Fq2Elem const* in);
  83. /// Calculate the conjugate of an element of Fq2.
  84. /*!
  85. \param[out] result the conjugate of the element.
  86. \param[in] in the element.
  87. */
  88. void Fq2Conj(Fq2Elem* result, Fq2Elem const* in);
  89. /// Square an element of Fq2.
  90. /*!
  91. \param[out] result the square of the element.
  92. \param[in] in the element to square.
  93. */
  94. void Fq2Square(Fq2Elem* result, Fq2Elem const* in);
  95. /// Multiply an element of Fq2 by and element of Fq.
  96. /*!
  97. \param[out] result of multiplying left and right.
  98. \param[in] left The first operand to be multiplied.
  99. \param[in] right The second operand to be multiplied.
  100. */
  101. void Fq2MulScalar(Fq2Elem* result, Fq2Elem const* left, FqElem const* right);
  102. /// Conditionally Set an element's value to one of two values.
  103. /*!
  104. \param[out] result target.
  105. \param[in] true_val value to set if condition is true.
  106. \param[in] false_val value to set if condition is false.
  107. \param[in] truth_val value of condition.
  108. */
  109. void Fq2CondSet(Fq2Elem* result, Fq2Elem const* true_val,
  110. Fq2Elem const* false_val, int truth_val);
  111. /// Test if two elements in Fq2 are equal
  112. /*!
  113. \param[in] left The first operand to be tested.
  114. \param[in] right The second operand to be tested.
  115. \returns A value different from zero (i.e., true) if indeed
  116. the values are equal. Zero (i.e., false) otherwise.
  117. */
  118. int Fq2Eq(Fq2Elem const* left, Fq2Elem const* right);
  119. /// Multiply an element of Fq2 by xi.
  120. /*!
  121. This function was formerly called as Fq2Const.
  122. \param[out] result of multiplying in by xi.
  123. \param[in] in The first operand to be multiplied.
  124. */
  125. void Fq2MulXi(Fq2Elem* result, Fq2Elem const* in);
  126. /// Test if an element is zero.
  127. /*!
  128. \param[in] value the element to test.
  129. \returns A value different from zero (i.e., true) if indeed
  130. the value is zero. Zero (i.e., false) otherwise.
  131. */
  132. int Fq2IsZero(Fq2Elem const* value);
  133. #endif // EPID_MEMBER_TINY_MATH_FQ2_H_