Debian Codegraph @

sources/ippcp/gfpec/ecnist/ifma_arith_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
17 #ifndef IFMA_ARITH_P521_H
18 #define IFMA_ARITH_P521_H
19
20 #if (_IPP32E >= _IPP32E_K1)
21
22 #include "gfpec/ecnist/ifma_defs_p521.h"
23
24 #define ifma_norm52_p521 OWNAPI(ifma_norm52_p521)
25 #define ifma_norm52_dual_p521 OWNAPI(ifma_norm52_dual_p521)
26 #define ifma_lnorm52_p521 OWNAPI(ifma_lnorm52_p521)
27 #define ifma_lnorm52_dual_p521 OWNAPI(ifma_lnorm52_dual_p521)
28 #define ifma_amm52_p521 OWNAPI(ifma_amm52_p521)
29 #define ifma_amm52_dual_p521 OWNAPI(ifma_amm52_dual_p521)
30 #define ifma_half52_p521 OWNAPI(ifma_half52_p521)
31 #define ifma_neg52_p521 OWNAPI(ifma_neg52_p521)
32 #define ifma_tomont52_p521 OWNAPI(ifma_tomont52_p521)
33 #define ifma_frommont52_p521 OWNAPI(ifma_frommont52_p521)
34 #define ifma_aminv52_p521 OWNAPI(ifma_aminv52_p521)
35 #define convert_radix_to_52_p521 OWNAPI(convert_radix_to_52_p521)
36 #define convert_radix_to_64_p521 OWNAPI(convert_radix_to_64_p521)
37 #define ifma_ams52_p521 OWNAPI(ifma_ams52_p521)
38 #define ifma_ams52_dual_p521 OWNAPI(ifma_ams52_dual_p521)
39
40 /*
41 * p521 = 2^521 - 1
42 * in 2^52 radix
43 */
44 static const __ALIGN64 Ipp64u p521_x1[P521R1_NUM_CHUNK][P521R1_LENFE521_52] = {
45 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF},
46 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF},
47 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x0000000000000001, 0x0000000000000000}
48 };
49 /* 2*p */
50 static const __ALIGN64 Ipp64u p521_x2[P521R1_NUM_CHUNK][P521R1_LENFE521_52] = {
51 {0x000FFFFFFFFFFFFE, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF},
52 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF},
53 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x0000000000000003, 0x0000000000000000}
54 };
55 /* 4*p */
56 static const __ALIGN64 Ipp64u p521_x4[P521R1_NUM_CHUNK][P521R1_LENFE521_52] = {
57 {0x000FFFFFFFFFFFFC, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF},
58 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF},
59 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x0000000000000007, 0x0000000000000000}
60 };
61 /* 6*p */
62 static const __ALIGN64 Ipp64u p521_x6[P521R1_NUM_CHUNK][P521R1_LENFE521_52] = {
63 {0x000FFFFFFFFFFFFA, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF},
64 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF},
65 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000000000000000B, 0x0000000000000000}
66 };
67 /* 8*p */
68 static const __ALIGN64 Ipp64u p521_x8[P521R1_NUM_CHUNK][P521R1_LENFE521_52] = {
69 {0x000FFFFFFFFFFFF8, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF},
70 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF},
71 {0x000FFFFFFFFFFFFF, 0x000FFFFFFFFFFFFF, 0x000000000000000F, 0x0000000000000000}
72 };
73 /* Montgomery(1)
74 * r = 2^(P521_LEN52*DIGIT_SIZE) mod p521
75 */
76 static const __ALIGN64 Ipp64u P521R1_R52[P521R1_NUM_CHUNK][P521R1_LENFE521_52] = {
77 {0x0008000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000},
78 {0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000},
79 {0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000}
80 };
81
82 /**
83 * \brief
84 * normalization input fe521 to (in radix 2^52)
85 * \param[out] pr ptr value (in radix 2^52)
86 * \param[in] a value (52 radix or more)
87 */
88 IPP_OWN_DECL(void, ifma_norm52_p521, (fe521 pr[], const fe521 a))
89
90 /**
91 * \brief
92 * duplicate normalization input double fe521 to (in radix 2^52)
93 * \param[out] pr1 ptr first value (in radix 2^52)
94 * \param[in] a1 value first (52 radix or more)
95 * \param[out] pr2 ptr second value (in radix 2^52)
96 * \param[in] a2 value second (52 radix or more)
97 */
98
99 /* clang-format off */
100 IPP_OWN_DECL(void, ifma_norm52_dual_p521, (fe521 pr1[],
101 const fe521 a1,
102 fe521 pr2[],
103 const fe521 a2))
104 /* clang-format on */
105
106 /**
107 * \brief
108 * light (mul|add only) normalization input fe521 to (in radix 2^52)
109 * \param[out] pr ptr value (in radix 2^52)
110 * \param[in] a value (52 radix or more)
111 */
112 IPP_OWN_DECL(void, ifma_lnorm52_p521, (fe521 pr[], const fe521 a))
113
114 /**
115 * \brief
116 * light (mul|add only) duplicate normalization input double fe521 to (in radix 2^52)
117 * \param[out] pr1 ptr first value (in radix 2^52)
118 * \param[in] a1 value first (52 radix or more)
119 * \param[out] pr2 ptr second value (in radix 2^52)
120 * \param[in] a2 value second (52 radix or more)
121 */
122 /* clang-format off */
123 IPP_OWN_DECL(void, ifma_lnorm52_dual_p521, (fe521 pr1[],
124 const fe521 a1,
125 fe521 pr2[],
126 const fe521 a2))
127 /* clang-format on */
128
129 /**
130 * \brief
131 * R = (A * B) - no normalization
132 * \param[out] pr ptr value
133 * \param[in] a first value (in radix 2^52)
134 * \param[in] b second value (in radix 2^52)
135 */
136 IPP_OWN_DECL(void, ifma_amm52_p521, (fe521 pr[], const fe521 a, const fe521 b))
137
138 /**
139 * \brief
140 * duplicate mul (R = A * B - no normalization) input double complect
141 * \param[out] pr1 ptr first value no normalization
142 * \param[in] a1 value first (in radix 2^52)
143 * \param[in] b1 value second (in radix 2^52)
144 * \param[out] pr2 ptr second value no normalization
145 * \param[in] a2 value first (in radix 2^52)
146 * \param[in] b2 value second (in radix 2^52)
147 */
148 /* clang-format off */
149 IPP_OWN_DECL(void, ifma_amm52_dual_p521, (fe521 pr1[],
150 const fe521 a1,
151 const fe521 b1,
152 fe521 pr2[],
153 const fe521 a2,
154 const fe521 b2))
155 /* clang-format on */
156
157 /**
158 * \brief
159 * R = A/2 - with normalization
160 * \param[out] pr ptr value (in radix 2^52)
161 * \param[in] a value (52 radix or more)
162 */
163 IPP_OWN_DECL(void, ifma_half52_p521, (fe521 pr[], const fe521 a))
164
165 /**
166 * \brief
167 * compute R = (-A) enhanced Montgomery (Gueron modification group operation)
168 * \param[out] pr ptr value (in radix 2^52)
169 * \param[in] a value (in radix 2^52)
170 */
171 IPP_OWN_DECL(void, ifma_neg52_p521, (fe521 pr[], const fe521 a))
172
173 /**
174 * \brief
175 * to Montgomery domain (in radix 2^52)
176 * \param[out] pr ptr value (in radix 2^52) in Montgomery domain
177 * \param[in] a value (in radix 2^52)
178 */
179 IPP_OWN_DECL(void, ifma_tomont52_p521, (fe521 pr[], const fe521 a))
180
181 /**
182 * \brief
183 * from Montgomery domain (in radix 2^52)
184 * \param[out] pr ptr value (in radix 2^52) from Montgomery domain
185 * \param[in] a value (in radix 2^52)
186 */
187 IPP_OWN_DECL(void, ifma_frommont52_p521, (fe521 pr[], const fe521 a))
188
189 /**
190 * \brief
191 * R = 1/Z
192 * \param[out] pr ptr value (in radix 2^52)
193 * \param[in] z value (in radix 2^52)
194 */
195 IPP_OWN_DECL(void, ifma_aminv52_p521, (fe521 pr[], const fe521 z))
196
197 /**
198 * \brief
199 * convert radix 64 to (in radix 2^52)
200 * \param[out] pr ptr value (in radix 2^52)
201 * \param[in] arad64 ptr array size (9) - 521 bit
202 */
203 IPP_OWN_DECL(void, convert_radix_to_52_p521, (fe521 pr[], const Ipp64u arad64[P521R1_LEN64]))
204
205 /**
206 * \brief
207 * convert (in radix 2^52) to radix 64
208 * \param[out] rrad64 ptr array size (9) - 521 bit
209 * \param[in] a value (in radix 2^52)
210 */
211 IPP_OWN_DECL(void, convert_radix_to_64_p521, (Ipp64u rrad64[P521R1_LEN64], const fe521 a))
212
213 /**
214 * \brief
215 * R = (A * A) - no normalization
216 * \param[out] pr ptr value
217 * \param[in] a first value (in radix 2^52)
218 */
219 IPP_OWN_DECL(void, ifma_ams52_p521, (fe521 pr[], const fe521 a))
220
221 /**
222 * \brief
223 * duplicate sqr (R = A * A - no normalization) input double complect
224 * \param[out] pr1 ptr first value no normalization
225 * \param[in] a1 value first (in radix 2^52)
226 * \param[out] pr2 ptr second value no normalization
227 * \param[in] a2 value first (in radix 2^52)
228 */
229 IPP_OWN_DECL(void, ifma_ams52_dual_p521, (fe521 pr1[], const fe521 a1, fe521 pr2[], const fe521 a2))
230
231 /* R = (A + B) */
232 #define fe521_add_no_red(R, A, B) \
233 FE521_LO(R) = m256_add_i64(FE521_LO(A), FE521_LO(B)); \
234 FE521_MID(R) = m256_add_i64(FE521_MID(A), FE521_MID(B)); \
235 FE521_HI(R) = m256_add_i64(FE521_HI(A), FE521_HI(B))
236
237 /* R = (A - B) */
238 #define fe521_sub_no_red(R, A, B) \
239 FE521_LO(R) = m256_sub_i64(FE521_LO(A), FE521_LO(B)); \
240 FE521_MID(R) = m256_sub_i64(FE521_MID(A), FE521_MID(B)); \
241 FE521_HI(R) = m256_sub_i64(FE521_HI(A), FE521_HI(B))
242
243 #endif // (_IPP32E >= _IPP32E_K1)
244
245 #endif