Debian Codegraph @

sources/ippcp/gfpec/ecnist/ifma_arith_p256_asm.h

raw symbols SCIP
1 /*************************************************************************
2 * Copyright (C) 2026 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 /*
18 * Inline assembly implementations for P-256 IFMA arithmetic
19 * to eliminate stack usage for security against memory attacks
20 *
21 * This file contains:
22 * - External assembly function declarations (implemented in ifma_arith_p256.asm)
23 * - These functions operate directly on ZMM registers (m512 type)
24 */
25
26 #ifndef IFMA_ARITH_P256_ASM_H
27 #define IFMA_ARITH_P256_ASM_H
28
29 #include "owndefs.h"
30
31 #if (_IPP32E >= _IPP32E_K1)
32
33 #include "gfpec/ecnist/ifma_defs.h"
34 #include "gfpec/ecnist/ifma_ecpoint_p256.h"
35 #include "gfpec/ecnist/ifma_arith_p256.h"
36
37 /* Dual Montgomery multiplication - operates directly on registers */
38 #define ifma_amm52_dual_p256_asm_zmm OWNAPI(ifma_amm52_dual_p256_asm_zmm)
39 /* clang-format off */
40 IPP_OWN_DECL(void, ifma_amm52_dual_p256_asm_zmm, (m512* out_r1,
41 const m512* in_a1,
42 const m512* in_b1,
43 m512* out_r2,
44 const m512* in_a2,
45 const m512* in_b6))
46
47 #define ifma_lnorm52_dual_p256_asm_zmm OWNAPI(ifma_lnorm52_dual_p256_asm_zmm)
48 IPP_OWN_DECL(void, ifma_lnorm52_dual_p256_asm_zmm, (m512* out_pr1,
49 m512* in_a1,
50 m512* out_pr2,
51 m512* in_a2))
52 /* clang-format on */
53
54 /* Montgomery multiplication - operates directly on registers */
55 #define ifma_amm52_p256_asm_zmm OWNAPI(ifma_amm52_p256_asm_zmm)
56 IPP_OWN_DECL(void, ifma_amm52_p256_asm_zmm, (m512 * out_pr, const m512* in_a, const m512* in_b))
57
58 /* Dual full normalization - operates directly on registers */
59 #define ifma_norm52_dual_p256_asm_zmm OWNAPI(ifma_norm52_dual_p256_asm_zmm)
60 /* clang-format off */
61 IPP_OWN_DECL(void, ifma_norm52_dual_p256_asm_zmm, (m512* out_pr1,
62 m512* in_a1,
63 m512* out_pr2,
64 m512* in_a2))
65 /* clang-format on */
66
67 /* Single light normalization - operates directly on registers */
68 #define ifma_lnorm52_p256_asm_zmm OWNAPI(ifma_lnorm52_p256_asm_zmm)
69 IPP_OWN_DECL(void, ifma_lnorm52_p256_asm_zmm, (m512 * out_pr, m512* in_a))
70
71 /* Single full normalization - operates directly on registers */
72 #define ifma_norm52_p256_asm_zmm OWNAPI(ifma_norm52_p256_asm_zmm)
73 IPP_OWN_DECL(void, ifma_norm52_p256_asm_zmm, (m512 * out_pr, m512* in_a))
74
75 /* Half (divide by 2) - operates directly on registers */
76 #define ifma_half52_p256_asm_zmm OWNAPI(ifma_half52_p256_asm_zmm)
77 IPP_OWN_DECL(void, ifma_half52_p256_asm_zmm, (m512 * out_pr, m512* in_a))
78
79 /* Inversion (R = 1/z) - operates directly on registers */
80 #define ifma_aminv52_p256_asm_zmm OWNAPI(ifma_aminv52_p256_asm_zmm)
81 IPP_OWN_DECL(void, ifma_aminv52_p256_asm_zmm, (m512 * out_pr, m512* in_a))
82
83 /* Point doubling - operates directly on registers */
84 #define ifma_ec_nistp256_dbl_point_asm_zmm OWNAPI(ifma_ec_nistp256_dbl_point_asm_zmm)
85 /* clang-format off */
86 IPP_OWN_DECL(void, ifma_ec_nistp256_dbl_point_asm_zmm, (m512* out_R_X,
87 m512* out_R_Y,
88 m512* out_R_Z,
89 const m512* in_P_X,
90 const m512* in_P_Y,
91 const m512* in_P_Z))
92
93 /* Point addition - operates directly on registers (in-place)
94 * Computes P = P + Q
95 * P is passed by pointer (input/output), Q is passed by value.
96 * Special cases (infinity, point equality) handled in assembly. */
97 #define ifma_ec_nistp256_add_point_asm_zmm OWNAPI(ifma_ec_nistp256_add_point_asm_zmm)
98 IPP_OWN_DECL(void, ifma_ec_nistp256_add_point_asm_zmm, (m512* P_X,
99 m512* P_Y,
100 m512* P_Z,
101 const m512* in_Q_X,
102 const m512* in_Q_Y,
103 const m512* in_Q_Z))
104 /* clang-format on */
105
106 /* Main scalar multiplication loop - combines precomputation, booth extraction, and dbl3_add
107 * Performs the complete scalar multiplication:
108 * 1. Compute table: tbl[0]=P, tbl[1]=2P, tbl[2]=3P, tbl[3]=4P
109 * 2. R = get_booth_point(first_window)
110 * 3. for (bit -= WIN_SIZE; bit >= 0; bit -= WIN_SIZE) {
111 * H = get_booth_point(pScalar, bit);
112 * R = 8*R + H;
113 * }
114 * 4. Normalize result
115 * R: output point, pScalar: extended scalar, scalarBitSize: bit size, P: input point (in ZMM) */
116 #define ifma_ec_nistp256_mul_point_loop_asm_zmm OWNAPI(ifma_ec_nistp256_mul_point_loop_asm_zmm)
117 /* clang-format off */
118 IPP_OWN_DECL(void, ifma_ec_nistp256_mul_point_loop_asm_zmm, (P256_POINT_IFMA* R,
119 const Ipp8u* pScalar,
120 Ipp32s scalarBitSize,
121 const m512* px,
122 const m512* py,
123 const m512* pz))
124
125 /*
126 * Transformation to affine coordinate
127 * Computes affine coordinates from the given point A passed in the projective representation. */
128 #define ifma_ec_nistp256_get_affine_coords_asm_zmm OWNAPI(ifma_ec_nistp256_get_affine_coords_asm_zmm)
129 IPP_OWN_DECL(void, ifma_ec_nistp256_get_affine_coords_asm_zmm, (m512* out_R_X, m512* out_R_Y,
130 const P256_POINT_IFMA* A))
131 /* clang-format on */
132
133 /*
134 * Transformation from Montgomery domain. */
135 #define ifma_frommont52_p256_asm_zmm OWNAPI(ifma_frommont52_p256_asm_zmm)
136 IPP_OWN_DECL(void, ifma_frommont52_p256_asm_zmm, (m512 * out_pr, m512* in_a))
137
138
139 /* Convenience macros - these just call the assembly functions directly */
140
141 /**
142 * \brief Dual Montgomery multiplication
143 * Computes r1 = a1 * b1 mod p256 and r2 = a2 * b2 mod p256 simultaneously
144 */
145 #define ifma_amm52_dual_p256_mul_asm(out_r1, in_a1, in_b1, out_r2, in_a2, in_b6) \
146 ifma_amm52_dual_p256_asm_zmm((out_r1), (in_a1), (in_b1), (out_r2), (in_a2), (in_b6))
147
148 /**
149 * \brief Dual squaring using assembly
150 */
151 #define ifma_amm52_dual_p256_sqr_asm(r1, a1, r2, a2) \
152 ifma_amm52_dual_p256_asm_zmm(r1, a1, a1, r2, a2, a2);
153
154 /**
155 * \brief Squaring using assembly
156 */
157 #define ifma_ams52_p256_asm(out_pr, in_a) ifma_amm52_p256_asm_zmm(out_pr, in_a, in_a);
158
159 /**
160 * \brief Dual light normalization (carry propagation only)
161 */
162 #define ifma_lnorm52_dual_p256_asm(out_pr1, in_a1, out_pr2, in_a2) \
163 ifma_lnorm52_dual_p256_asm_zmm((out_pr1), (in_a1), (out_pr2), (in_a2))
164
165 /**
166 * \brief Dual full normalization
167 */
168 #define ifma_norm52_dual_p256_asm(out_pr1, in_a1, out_pr2, in_a2) \
169 ifma_norm52_dual_p256_asm_zmm((out_pr1), (in_a1), (out_pr2), (in_a2))
170
171 /**
172 * \brief Single Montgomery multiplication
173 * Computes r = a * b mod p256.
174 */
175 #define ifma_amm52_p256_asm(out_pr, in_a, in_b) ifma_amm52_p256_asm_zmm(out_pr, in_a, in_b);
176
177 /**
178 * \brief Single light normalization (carry propagation only)
179 */
180 #define ifma_lnorm52_p256_asm(out_pr, in_a) ifma_lnorm52_p256_asm_zmm((out_pr), (in_a))
181
182 /**
183 * \brief Single full normalization
184 */
185 #define ifma_norm52_p256_asm(out_pr, in_a) ifma_norm52_p256_asm_zmm((out_pr), (in_a))
186
187 /**
188 * \brief Transformation to affine coordinate
189 */
190 #define ifma_ec_nistp256_get_affine_coords_asm(out_R_X, out_R_Y, A) \
191 ifma_ec_nistp256_get_affine_coords_asm_zmm((out_R_X), (out_R_Y), (A))
192
193 /**
194 * \brief Transformation from Montgomery domain
195 */
196 #define ifma_frommont52_p256_asm(out_pr, in_a) ifma_frommont52_p256_asm_zmm((out_pr), (in_a))
197
198 #endif // (_IPP32E >= _IPP32E_K1)
199
200 #endif // IFMA_ARITH_P256_ASM_H