Debian Codegraph @

sources/ippcp/gfpec/ecnist/ifma_ecpoint_p521.h

raw symbols SCIP
1 /*************************************************************************
2 * Copyright (C) 2021 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 #ifndef IFMA_ECPOINT_P521_H
17 #define IFMA_ECPOINT_P521_H
18
19 #include "owndefs.h"
20
21 #if (_IPP32E >= _IPP32E_K1)
22
23 #include "gfpec/ecnist/ifma_defs_p521.h"
24
25 typedef struct P521_POINT_IFMA {
26 #define ifma_ec_nistp521_mul_point OWNAPI(ifma_ec_nistp521_mul_point)
27 #define ifma_ec_nistp521_mul_pointbase OWNAPI(ifma_ec_nistp521_mul_pointbase)
28 #define ifma_ec_nistp521_get_affine_coords OWNAPI(ifma_ec_nistp521_get_affine_coords)
29 #define ifma_ec_nistp521_is_on_curve OWNAPI(ifma_ec_nistp521_is_on_curve)
30 #define ifma_ec_nistp521_dbl_point OWNAPI(ifma_ec_nistp521_dbl_point)
31 #define ifma_ec_nistp521_add_point OWNAPI(ifma_ec_nistp521_add_point)
32 #define ifma_ec_nistp521_add_point_affine OWNAPI(ifma_ec_nistp521_add_point_affine)
33 fe521 x;
34 fe521 y;
35 fe521 z;
36 } P521_POINT_IFMA;
37
38 typedef struct P521_POINT_AFFINE_IFMA {
39 fe521 x;
40 fe521 y;
41 } P521_POINT_AFFINE_IFMA;
42
43 /**
44 * \brief
45 * compute R = [pExtendedScalar]*P = (P + P + ... + P)
46 * \param[out] r point (in radix 2^52)
47 * \param[in] p point (in radix 2^52)
48 * \param[in] pExtendedScalar ptr Extended scalar
49 * \param[in] scalarBitSize size bits scalar
50 */
51 /* clang-format off */
52 IPP_OWN_DECL(void, ifma_ec_nistp521_mul_point, (P521_POINT_IFMA* r,
53 const P521_POINT_IFMA* p,
54 const Ipp8u* pExtendedScalar,
55 const int scalarBitSize))
56 /* clang-format on */
57
58 /**
59 * \brief
60 * compute [pExtendedScalar]*BP
61 * \param[out] r point (in radix 2^52)
62 * \param pExtendedScalar ptr scaler (length 384 bits)
63 */
64 /* clang-format off */
65 IPP_OWN_DECL(void, ifma_ec_nistp521_mul_pointbase, (P521_POINT_IFMA* r,
66 const Ipp8u* pExtendedScalar,
67 int scalarBitSize))
68 /* clang-format on */
69
70 /**
71 * \brief
72 * convert point to affine coordinate
73 * \param[out] prx affine X coordinate
74 * \param[out] pry affine Y coordinate
75 * \param[in] a point
76 */
77 IPP_OWN_DECL(void,
78 ifma_ec_nistp521_get_affine_coords,
79 (fe521 prx[], fe521 pry[], const P521_POINT_IFMA* a))
80
81 /**
82 * \brief
83 * check point on curve P521R1
84 * \param[in] p point (in radix 2^52)
85 * \param[in] use_jproj_coords is Jacobian Projection coordinate or Affine Coordinate
86 * \return int 1 - is true | 0 - is false
87 */
88 /* clang-format off */
89 IPP_OWN_DECL(int, ifma_ec_nistp521_is_on_curve, (const P521_POINT_IFMA* p,
90 const int use_jproj_coords))
91 /* clang-format on */
92 /**
93 * \brief
94 * compute double point P521R1 Enhanced Montgomery Algorithm
95 * \param[out] r point
96 * \param[in] p value point (in radix 2^52)
97 */
98 IPP_OWN_DECL(void, ifma_ec_nistp521_dbl_point, (P521_POINT_IFMA * r, const P521_POINT_IFMA* p))
99
100 /**
101 * \brief
102 * compute add point P384R1 Enhanced Montgomery Algorithm
103 * \param[out] r point
104 * \param[in] p first point (in radix 2^52)
105 * \param[in] q second point (in radix 2^52)
106 */
107 /* clang-format off */
108 IPP_OWN_DECL(void, ifma_ec_nistp521_add_point, (P521_POINT_IFMA* r,
109 const P521_POINT_IFMA* p,
110 const P521_POINT_IFMA* q))
111 /* clang-format on */
112
113 /**
114 * \brief
115 * compute add point affine P384R1 Enhanced Montgomery Algorithm
116 * \param[out] r point
117 * \param[in] p first point (in radix 2^52)
118 * \param[in] q second affine point (in radix 2^52)
119 */
120 /* clang-format off */
121 IPP_OWN_DECL(void, ifma_ec_nistp521_add_point_affine, (P521_POINT_IFMA* r,
122 const P521_POINT_IFMA* p,
123 const P521_POINT_AFFINE_IFMA* q))
124 /* clang-format on */
125
126 #include "gfpec/ecnist/ifma_arith_method_p521.h"
127 #include "gsmodstuff.h"
128 #include "gfpec/pcpgfpstuff.h"
129 #include "gfpec/pcpgfpecstuff.h"
130
131 IPPCP_INLINE void recode_point_to_mont52(P521_POINT_IFMA* pR,
132 const BNU_CHUNK_T* pP,
133 BNU_CHUNK_T* pPool,
134 ifmaArithMethod_p521* method,
135 gsModEngine* pME)
136 {
137 ifma_import to_radix52 = method->import_to52;
138 ifma_encode p_to_mont = method->encode;
139
140 const int elemLen = GFP_FELEN(pME);
141
142 BNU_CHUNK_T* pX = pPool;
143 BNU_CHUNK_T* pY = pPool + elemLen;
144 BNU_CHUNK_T* pZ = pPool + 2 * elemLen;
145
146 GFP_METHOD(pME)->decode(pX, pP, pME);
147 GFP_METHOD(pME)->decode(pY, pP + elemLen, pME);
148 GFP_METHOD(pME)->decode(pZ, pP + 2 * elemLen, pME);
149
150 to_radix52(&(pR->x), (Ipp64u*)pX);
151 to_radix52(&(pR->y), (Ipp64u*)pY);
152 to_radix52(&(pR->z), (Ipp64u*)pZ);
153
154 p_to_mont(&(pR->x), pR->x);
155 p_to_mont(&(pR->y), pR->y);
156 p_to_mont(&(pR->z), pR->z);
157 }
158
159 IPPCP_INLINE void recode_point_to_mont64(IppsGFpECPoint* pR,
160 P521_POINT_IFMA* pP,
161 BNU_CHUNK_T* pPool,
162 ifmaArithMethod_p521* method,
163 gsModEngine* pME)
164 {
165 ifma_export to_radix64 = method->export_to64;
166 ifma_decode p_from_mont = method->decode;
167
168 const int elemLen = GFP_PELEN(pME);
169 BNU_CHUNK_T* pX = pPool;
170 BNU_CHUNK_T* pY = pPool + elemLen;
171 BNU_CHUNK_T* pZ = pPool + 2 * elemLen;
172
173 p_from_mont(&(pP->x), pP->x);
174 p_from_mont(&(pP->y), pP->y);
175 p_from_mont(&(pP->z), pP->z);
176
177 to_radix64((Ipp64u*)pX, pP->x);
178 to_radix64((Ipp64u*)pY, pP->y);
179 to_radix64((Ipp64u*)pZ, pP->z);
180
181 GFP_METHOD(pME)->encode(ECP_POINT_X(pR), pX, pME);
182 GFP_METHOD(pME)->encode(ECP_POINT_Y(pR), pY, pME);
183 GFP_METHOD(pME)->encode(ECP_POINT_Z(pR), pZ, pME);
184 }
185
186
187 #endif // (_IPP32E >= _IPP32E_K1)
188
189 #endif