1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2021-2022 Intel Corporation
5 #ifndef _QAT_PKE_FUNCTIONALITY_ARRAYS_H_
6 #define _QAT_PKE_FUNCTIONALITY_ARRAYS_H_
8 #include "icp_qat_fw_mmp_ids.h"
11 * Modular exponentiation functionality IDs
14 struct qat_asym_function {
19 static struct qat_asym_function
20 get_modexp_function(struct rte_crypto_asym_xform *xform)
22 struct qat_asym_function qat_function = { };
24 if (xform->modex.modulus.length <= 64) {
25 qat_function.func_id = MATHS_MODEXP_L512;
26 qat_function.bytesize = 64;
27 } else if (xform->modex.modulus.length <= 128) {
28 qat_function.func_id = MATHS_MODEXP_L1024;
29 qat_function.bytesize = 128;
30 } else if (xform->modex.modulus.length <= 192) {
31 qat_function.func_id = MATHS_MODEXP_L1536;
32 qat_function.bytesize = 192;
33 } else if (xform->modex.modulus.length <= 256) {
34 qat_function.func_id = MATHS_MODEXP_L2048;
35 qat_function.bytesize = 256;
36 } else if (xform->modex.modulus.length <= 320) {
37 qat_function.func_id = MATHS_MODEXP_L2560;
38 qat_function.bytesize = 320;
39 } else if (xform->modex.modulus.length <= 384) {
40 qat_function.func_id = MATHS_MODEXP_L3072;
41 qat_function.bytesize = 384;
42 } else if (xform->modex.modulus.length <= 448) {
43 qat_function.func_id = MATHS_MODEXP_L3584;
44 qat_function.bytesize = 448;
45 } else if (xform->modex.modulus.length <= 512) {
46 qat_function.func_id = MATHS_MODEXP_L4096;
47 qat_function.bytesize = 512;
52 static struct qat_asym_function
53 get_modinv_function(struct rte_crypto_asym_xform *xform)
55 struct qat_asym_function qat_function = { };
57 if (xform->modinv.modulus.data[
58 xform->modinv.modulus.length - 1] & 0x01) {
59 if (xform->modex.modulus.length <= 16) {
60 qat_function.func_id = MATHS_MODINV_ODD_L128;
61 qat_function.bytesize = 16;
62 } else if (xform->modex.modulus.length <= 24) {
63 qat_function.func_id = MATHS_MODINV_ODD_L192;
64 qat_function.bytesize = 24;
65 } else if (xform->modex.modulus.length <= 32) {
66 qat_function.func_id = MATHS_MODINV_ODD_L256;
67 qat_function.bytesize = 32;
68 } else if (xform->modex.modulus.length <= 48) {
69 qat_function.func_id = MATHS_MODINV_ODD_L384;
70 qat_function.bytesize = 48;
71 } else if (xform->modex.modulus.length <= 64) {
72 qat_function.func_id = MATHS_MODINV_ODD_L512;
73 qat_function.bytesize = 64;
74 } else if (xform->modex.modulus.length <= 96) {
75 qat_function.func_id = MATHS_MODINV_ODD_L768;
76 qat_function.bytesize = 96;
77 } else if (xform->modex.modulus.length <= 128) {
78 qat_function.func_id = MATHS_MODINV_ODD_L1024;
79 qat_function.bytesize = 128;
80 } else if (xform->modex.modulus.length <= 192) {
81 qat_function.func_id = MATHS_MODINV_ODD_L1536;
82 qat_function.bytesize = 192;
83 } else if (xform->modex.modulus.length <= 256) {
84 qat_function.func_id = MATHS_MODINV_ODD_L2048;
85 qat_function.bytesize = 256;
86 } else if (xform->modex.modulus.length <= 384) {
87 qat_function.func_id = MATHS_MODINV_ODD_L3072;
88 qat_function.bytesize = 384;
89 } else if (xform->modex.modulus.length <= 512) {
90 qat_function.func_id = MATHS_MODINV_ODD_L4096;
91 qat_function.bytesize = 512;
94 if (xform->modex.modulus.length <= 16) {
95 qat_function.func_id = MATHS_MODINV_EVEN_L128;
96 qat_function.bytesize = 16;
97 } else if (xform->modex.modulus.length <= 24) {
98 qat_function.func_id = MATHS_MODINV_EVEN_L192;
99 qat_function.bytesize = 24;
100 } else if (xform->modex.modulus.length <= 32) {
101 qat_function.func_id = MATHS_MODINV_EVEN_L256;
102 qat_function.bytesize = 32;
103 } else if (xform->modex.modulus.length <= 48) {
104 qat_function.func_id = MATHS_MODINV_EVEN_L384;
105 qat_function.bytesize = 48;
106 } else if (xform->modex.modulus.length <= 64) {
107 qat_function.func_id = MATHS_MODINV_EVEN_L512;
108 qat_function.bytesize = 64;
109 } else if (xform->modex.modulus.length <= 96) {
110 qat_function.func_id = MATHS_MODINV_EVEN_L768;
111 qat_function.bytesize = 96;
112 } else if (xform->modex.modulus.length <= 128) {
113 qat_function.func_id = MATHS_MODINV_EVEN_L1024;
114 qat_function.bytesize = 128;
115 } else if (xform->modex.modulus.length <= 192) {
116 qat_function.func_id = MATHS_MODINV_EVEN_L1536;
117 qat_function.bytesize = 192;
118 } else if (xform->modex.modulus.length <= 256) {
119 qat_function.func_id = MATHS_MODINV_EVEN_L2048;
120 qat_function.bytesize = 256;
121 } else if (xform->modex.modulus.length <= 384) {
122 qat_function.func_id = MATHS_MODINV_EVEN_L3072;
123 qat_function.bytesize = 384;
124 } else if (xform->modex.modulus.length <= 512) {
125 qat_function.func_id = MATHS_MODINV_EVEN_L4096;
126 qat_function.bytesize = 512;
133 static struct qat_asym_function
134 get_rsa_enc_function(struct rte_crypto_asym_xform *xform)
136 struct qat_asym_function qat_function = { };
138 if (xform->rsa.n.length <= 64) {
139 qat_function.func_id = PKE_RSA_EP_512;
140 qat_function.bytesize = 64;
141 } else if (xform->rsa.n.length <= 128) {
142 qat_function.func_id = PKE_RSA_EP_1024;
143 qat_function.bytesize = 128;
144 } else if (xform->rsa.n.length <= 192) {
145 qat_function.func_id = PKE_RSA_EP_1536;
146 qat_function.bytesize = 192;
147 } else if (xform->rsa.n.length <= 256) {
148 qat_function.func_id = PKE_RSA_EP_2048;
149 qat_function.bytesize = 256;
150 } else if (xform->rsa.n.length <= 384) {
151 qat_function.func_id = PKE_RSA_EP_3072;
152 qat_function.bytesize = 384;
153 } else if (xform->rsa.n.length <= 512) {
154 qat_function.func_id = PKE_RSA_EP_4096;
155 qat_function.bytesize = 512;
160 static struct qat_asym_function
161 get_rsa_dec_function(struct rte_crypto_asym_xform *xform)
163 struct qat_asym_function qat_function = { };
165 if (xform->rsa.n.length <= 64) {
166 qat_function.func_id = PKE_RSA_DP1_512;
167 qat_function.bytesize = 64;
168 } else if (xform->rsa.n.length <= 128) {
169 qat_function.func_id = PKE_RSA_DP1_1024;
170 qat_function.bytesize = 128;
171 } else if (xform->rsa.n.length <= 192) {
172 qat_function.func_id = PKE_RSA_DP1_1536;
173 qat_function.bytesize = 192;
174 } else if (xform->rsa.n.length <= 256) {
175 qat_function.func_id = PKE_RSA_DP1_2048;
176 qat_function.bytesize = 256;
177 } else if (xform->rsa.n.length <= 384) {
178 qat_function.func_id = PKE_RSA_DP1_3072;
179 qat_function.bytesize = 384;
180 } else if (xform->rsa.n.length <= 512) {
181 qat_function.func_id = PKE_RSA_DP1_4096;
182 qat_function.bytesize = 512;
187 static struct qat_asym_function
188 get_rsa_crt_function(struct rte_crypto_asym_xform *xform)
190 struct qat_asym_function qat_function = { };
191 int nlen = xform->rsa.qt.p.length * 2;
194 qat_function.func_id = PKE_RSA_DP2_512;
195 qat_function.bytesize = 64;
196 } else if (nlen <= 128) {
197 qat_function.func_id = PKE_RSA_DP2_1024;
198 qat_function.bytesize = 128;
199 } else if (nlen <= 192) {
200 qat_function.func_id = PKE_RSA_DP2_1536;
201 qat_function.bytesize = 192;
202 } else if (nlen <= 256) {
203 qat_function.func_id = PKE_RSA_DP2_2048;
204 qat_function.bytesize = 256;
205 } else if (nlen <= 384) {
206 qat_function.func_id = PKE_RSA_DP2_3072;
207 qat_function.bytesize = 384;
208 } else if (nlen <= 512) {
209 qat_function.func_id = PKE_RSA_DP2_4096;
210 qat_function.bytesize = 512;
215 static struct qat_asym_function
216 get_ecdsa_verify_function(struct rte_crypto_asym_xform *xform)
218 struct qat_asym_function qat_function;
220 switch (xform->ec.curve_id) {
221 case RTE_CRYPTO_EC_GROUP_SECP256R1:
222 qat_function.func_id = PKE_ECDSA_VERIFY_GFP_L256;
223 qat_function.bytesize = 32;
225 case RTE_CRYPTO_EC_GROUP_SECP521R1:
226 qat_function.func_id = PKE_ECDSA_VERIFY_GFP_521;
227 qat_function.bytesize = 66;
230 qat_function.func_id = 0;
235 static struct qat_asym_function
236 get_ecdsa_function(struct rte_crypto_asym_xform *xform)
238 struct qat_asym_function qat_function;
240 switch (xform->ec.curve_id) {
241 case RTE_CRYPTO_EC_GROUP_SECP256R1:
242 qat_function.func_id = PKE_ECDSA_SIGN_RS_GFP_L256;
243 qat_function.bytesize = 32;
245 case RTE_CRYPTO_EC_GROUP_SECP521R1:
246 qat_function.func_id = PKE_ECDSA_SIGN_RS_GFP_521;
247 qat_function.bytesize = 66;
250 qat_function.func_id = 0;