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