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 EFq2 math 17 /*! \file */ 18 19 #ifndef EPID_MEMBER_TINY_MATH_EFQ2_H_ 20 #define EPID_MEMBER_TINY_MATH_EFQ2_H_ 21 22 /// \cond 23 typedef struct EccPointFq2 EccPointFq2; 24 typedef struct EccPointJacobiFq2 EccPointJacobiFq2; 25 typedef struct FpElem FpElem; 26 /// \endcond 27 28 /// Test if a point is infinity. 29 /*! 30 \param[in] in the point to test. 31 \returns A value different from zero (i.e., true) indeed 32 the value is infinity. Zero (i.e., false) otherwise. 33 */ 34 int EFq2IsInf(EccPointJacobiFq2 const* in); 35 36 /// Convert a point from Affine to Jacobi representation. 37 /*! 38 \param[out] result target. 39 \param[in] in value to set. 40 */ 41 void EFq2FromAffine(EccPointJacobiFq2* result, EccPointFq2 const* in); 42 43 /// Convert a point from Jacobi to Affine representation. 44 /*! 45 \param[out] result target. 46 \param[in] in value to set. 47 \returns 1 on success, 0 on failure 48 */ 49 int EFq2ToAffine(EccPointFq2* result, EccPointJacobiFq2 const* in); 50 51 /// Double a point in EFq2. 52 /*! 53 \param[out] result target. 54 \param[in] in the value to double. 55 */ 56 void EFq2Dbl(EccPointJacobiFq2* result, EccPointJacobiFq2 const* in); 57 58 /// Add two points in EFq2. 59 /*! 60 \param[out] result of adding left and right. 61 \param[in] left The first operand to be added. 62 \param[in] right The second operand to be added. 63 */ 64 void EFq2Add(EccPointJacobiFq2* result, EccPointJacobiFq2 const* left, 65 EccPointJacobiFq2 const* right); 66 67 /// Negate a point on EFq2. 68 /*! 69 \param[out] result the negative of the element. 70 \param[in] in the element to negate. 71 */ 72 void EFq2Neg(EccPointJacobiFq2* result, EccPointJacobiFq2 const* in); 73 74 /// Multiply two points in EFq. 75 /*! 76 This function is mitigated against software side-channel 77 attacks. 78 79 \param[out] result of multiplying left and right. 80 \param[in] left The first operand to be multiplied. 81 \param[in] right The second operand to be multiplied. 82 */ 83 void EFq2MulSSCM(EccPointJacobiFq2* result, EccPointJacobiFq2 const* left, 84 FpElem const* right); 85 86 /// Test if two points on EFq2 are equal 87 /*! 88 \param[in] left The first operand to be tested. 89 \param[in] right The second operand to be tested. 90 \returns A value different from zero (i.e., true) if indeed 91 the values are equal. Zero (i.e., false) otherwise. 92 */ 93 int EFq2Eq(EccPointJacobiFq2 const* left, EccPointJacobiFq2 const* right); 94 95 /// Test if a point is in EFq2. 96 /*! 97 \param[in] in the point to test. 98 \returns A value different from zero (i.e., true) indeed 99 the point is on the curve. Zero (i.e., false) otherwise. 100 */ 101 int EFq2OnCurve(EccPointFq2 const* in); 102 103 #endif // EPID_MEMBER_TINY_MATH_EFQ2_H_ 104