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