fq12.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 Fq12 math
  17. /*! \file */
  18. #ifndef EPID_MEMBER_TINY_MATH_FQ12_H_
  19. #define EPID_MEMBER_TINY_MATH_FQ12_H_
  20. #include <stdint.h>
  21. /// \cond
  22. typedef struct Fq12Elem Fq12Elem;
  23. typedef struct VeryLargeInt VeryLargeInt;
  24. /// \endcond
  25. /// Add two elements of Fq12.
  26. /*!
  27. \param[out] result of adding left and right.
  28. \param[in] left The first operand to be added.
  29. \param[in] right The second operand to be added.
  30. */
  31. void Fq12Add(Fq12Elem* result, Fq12Elem const* left, Fq12Elem const* right);
  32. /// Subtract two elements of Fq12.
  33. /*!
  34. \param[out] result of subtracting left from right.
  35. \param[in] left The operand to be subtracted from.
  36. \param[in] right The operand to subtract.
  37. */
  38. void Fq12Sub(Fq12Elem* result, Fq12Elem const* left, Fq12Elem const* right);
  39. /// Square an element of Fq12.
  40. /*!
  41. \param[out] result the square of the element.
  42. \param[in] in the element to square.
  43. */
  44. void Fq12Square(Fq12Elem* result, Fq12Elem const* in);
  45. /// Multiply two elements of Fq12.
  46. /*!
  47. \param[out] result of multiplying left and right.
  48. \param[in] left The first operand to be multiplied.
  49. \param[in] right The second operand to be multiplied.
  50. */
  51. void Fq12Mul(Fq12Elem* result, Fq12Elem const* left, Fq12Elem const* right);
  52. /// Invert an element of Fq12.
  53. /*!
  54. \param[out] result the inverse of the element.
  55. \param[in] in the element to invert.
  56. */
  57. void Fq12Inv(Fq12Elem* result, Fq12Elem const* in);
  58. /// Negate an element of Fq12.
  59. /*!
  60. \param[out] result the negative of the element.
  61. \param[in] in the element to negate.
  62. */
  63. void Fq12Neg(Fq12Elem* result, Fq12Elem const* in);
  64. /// Set an element's value.
  65. /*!
  66. \param[out] result target.
  67. \param[in] val value to set.
  68. */
  69. void Fq12Set(Fq12Elem* result, uint32_t val);
  70. /// Exponentiate an element of Fq12 by a large integer.
  71. /*!
  72. \param[out] result target.
  73. \param[in] base the base.
  74. \param[in] exp the exponent.
  75. */
  76. void Fq12Exp(Fq12Elem* result, Fq12Elem const* base, VeryLargeInt const* exp);
  77. /// Multiply of exponentiation of elements of Fq12 by a large integers.
  78. /*!
  79. \param[out] result target.
  80. \param[in] base0 the base.
  81. \param[in] exp0 the exponent.
  82. \param[in] base1 the base.
  83. \param[in] exp1 the exponent.
  84. \param[in] base2 the base.
  85. \param[in] exp2 the exponent.
  86. \param[in] base3 the base.
  87. \param[in] exp3 the exponent.
  88. */
  89. void Fq12MultiExp(Fq12Elem* result, Fq12Elem const* base0,
  90. VeryLargeInt const* exp0, Fq12Elem const* base1,
  91. VeryLargeInt const* exp1, Fq12Elem const* base2,
  92. VeryLargeInt const* exp2, Fq12Elem const* base3,
  93. VeryLargeInt const* exp3);
  94. /// Test if two elements in Fq12 are equal
  95. /*!
  96. \param[in] left The first operand to be tested.
  97. \param[in] right The second operand to be tested.
  98. \returns A value different from zero (i.e., true) if indeed
  99. the values are equal. Zero (i.e., false) otherwise.
  100. */
  101. int Fq12Eq(Fq12Elem const* left, Fq12Elem const* right);
  102. /// Calculate the conjugate of an element of Fq2.
  103. /*!
  104. \param[out] result the conjugate of the element.
  105. \param[in] in the element.
  106. */
  107. void Fq12Conj(Fq12Elem* result, Fq12Elem const* in);
  108. /// Calculate the cyclotomic exponentiation of an element of Fq12
  109. /// by another element of Fq12.
  110. /*!
  111. \param[in,out] result the base of the exponentiation. This will
  112. receive the result.
  113. \param[in] in the exponent.
  114. \param[in] t pairing parameter t
  115. */
  116. void Fq12ExpCyc(Fq12Elem* result, Fq12Elem const* in, VeryLargeInt const* t);
  117. /// Calculate the cyclotomic square of an element of fq12.
  118. /*!
  119. \param[in,out] result result of the cyclotomic square.
  120. \param[in] in the base.
  121. */
  122. void Fq12SqCyc(Fq12Elem* result, Fq12Elem const* in);
  123. /// Multiply two elements of Fq12.
  124. /*!
  125. Requires that b[2] = b[4] = b[5] = 0.
  126. where right = ((b[0], b[2], b[4]), (b[1], b[3], b[5]))
  127. \param[out] result of multiplying left and right.
  128. \param[in] left The first operand to be multiplied.
  129. \param[in] right The second operand to be multiplied.
  130. */
  131. void Fq12MulSpecial(Fq12Elem* result, Fq12Elem const* left,
  132. Fq12Elem const* right);
  133. /// Copy an element's value
  134. /*!
  135. \param[out] result copy target.
  136. \param[in] in copy source.
  137. */
  138. void Fq12Cp(Fq12Elem* result, Fq12Elem const* in);
  139. /// Clear an element's value.
  140. /*!
  141. \param[out] result element to clear.
  142. */
  143. void Fq12Clear(Fq12Elem* result);
  144. #endif // EPID_MEMBER_TINY_MATH_FQ12_H_