Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2019 - 2022 Intel Corporation
3 : : */
4 : :
5 : : #include <stdarg.h>
6 : :
7 : : #include <cryptodev_pmd.h>
8 : :
9 : : #include "qat_device.h"
10 : : #include "qat_logs.h"
11 : :
12 : : #include "qat_asym.h"
13 : : #include "icp_qat_fw_pke.h"
14 : : #include "icp_qat_fw.h"
15 : : #include "qat_pke.h"
16 : : #include "qat_ec.h"
17 : :
18 : : #define ASYM_ENQ_THRESHOLD_NAME "qat_asym_enq_threshold"
19 : : #define RSA_MODULUS_2048_BITS 2048
20 : :
21 : : uint8_t qat_asym_driver_id;
22 : :
23 : : struct qat_crypto_gen_dev_ops qat_asym_gen_dev_ops[QAT_N_GENS];
24 : :
25 : :
26 : : static const char *const arguments[] = {
27 : : ASYM_ENQ_THRESHOLD_NAME,
28 : : NULL
29 : : };
30 : :
31 : : /* An rte_driver is needed in the registration of both the device and the driver
32 : : * with cryptodev.
33 : : * The actual qat pci's rte_driver can't be used as its name represents
34 : : * the whole pci device with all services. Think of this as a holder for a name
35 : : * for the crypto part of the pci device.
36 : : */
37 : : static const char qat_asym_drv_name[] = RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD);
38 : : static const struct rte_driver cryptodev_qat_asym_driver = {
39 : : .name = qat_asym_drv_name,
40 : : .alias = qat_asym_drv_name
41 : : };
42 : :
43 : : /*
44 : : * Macros with suffix _F are used with some of predefinded identifiers:
45 : : * - cookie->input_buffer
46 : : * - qat_func_alignsize
47 : : */
48 : : #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
49 : : #define HEXDUMP(name, where, size) QAT_DP_HEXDUMP_LOG(DEBUG, name, \
50 : : where, size)
51 : : #define HEXDUMP_OFF(name, where, size, idx) QAT_DP_HEXDUMP_LOG(DEBUG, name, \
52 : : &where[idx * size], size)
53 : :
54 : : #define HEXDUMP_OFF_F(name, idx) QAT_DP_HEXDUMP_LOG(DEBUG, name, \
55 : : &cookie->input_buffer[idx * qat_func_alignsize], \
56 : : qat_func_alignsize)
57 : : #else
58 : : #define HEXDUMP(name, where, size)
59 : : #define HEXDUMP_OFF(name, where, size, idx)
60 : : #define HEXDUMP_OFF_F(name, idx)
61 : : #endif
62 : :
63 : : #define CHECK_IF_NOT_EMPTY(param, name, pname, status) \
64 : : do { \
65 : : if (param.length == 0) { \
66 : : QAT_LOG(ERR, \
67 : : "Invalid " name \
68 : : " input parameter, zero length " pname \
69 : : ); \
70 : : status = -EINVAL; \
71 : : } else if (check_zero(param)) { \
72 : : QAT_LOG(ERR, \
73 : : "Invalid " name " input parameter, empty " \
74 : : pname ", length = %d", \
75 : : (int)param.length \
76 : : ); \
77 : : status = -EINVAL; \
78 : : } \
79 : : } while (0)
80 : :
81 : : #define SET_PKE_LN(what, how, idx) \
82 : : rte_memcpy(cookie->input_array[idx] + how - \
83 : : what.length, \
84 : : what.data, \
85 : : what.length)
86 : :
87 : : #define SET_PKE_LN_EC(curve, p, idx) \
88 : : rte_memcpy(cookie->input_array[idx] + \
89 : : qat_func_alignsize - curve.bytesize, \
90 : : curve.p.data, curve.bytesize)
91 : :
92 : : #define SET_PKE_9A_IN(what, idx) \
93 : : rte_memcpy(&cookie->input_buffer[idx * \
94 : : qat_func_alignsize] + \
95 : : qat_func_alignsize - what.length, \
96 : : what.data, what.length)
97 : :
98 : : #define SET_PKE_9A_EC(curve, p, idx) \
99 : : rte_memcpy(&cookie->input_buffer[idx * \
100 : : qat_func_alignsize] + \
101 : : qat_func_alignsize - curve.bytesize, \
102 : : curve.p.data, curve.bytesize)
103 : :
104 : : #define PARAM_CLR(what) \
105 : : rte_free_sensitive(what.data)
106 : :
107 : : static void
108 : : request_init(struct icp_qat_fw_pke_request *qat_req)
109 : : {
110 : : memset(qat_req, 0, sizeof(*qat_req));
111 : 0 : qat_req->pke_hdr.service_type = ICP_QAT_FW_COMN_REQ_CPM_FW_PKE;
112 : 0 : qat_req->pke_hdr.hdr_flags =
113 : : ICP_QAT_FW_COMN_HDR_FLAGS_BUILD
114 : : (ICP_QAT_FW_COMN_REQ_FLAG_SET);
115 : : }
116 : :
117 : : static void
118 : 0 : cleanup_arrays(struct qat_asym_op_cookie *cookie,
119 : : int in_count, int out_count, int alg_size)
120 : : {
121 : : int i;
122 : :
123 [ # # ]: 0 : for (i = 0; i < in_count; i++)
124 : 0 : memset(cookie->input_array[i], 0x0, alg_size);
125 [ # # ]: 0 : for (i = 0; i < out_count; i++)
126 : 0 : memset(cookie->output_array[i], 0x0, alg_size);
127 : 0 : }
128 : :
129 : : static void
130 : 0 : cleanup_crt(struct qat_asym_op_cookie *cookie,
131 : : int alg_size)
132 : : {
133 : : int i;
134 : :
135 : 0 : memset(cookie->input_array[0], 0x0, alg_size);
136 [ # # ]: 0 : for (i = 1; i < QAT_ASYM_RSA_QT_NUM_IN_PARAMS; i++)
137 : 0 : memset(cookie->input_array[i], 0x0, alg_size / 2);
138 [ # # ]: 0 : for (i = 0; i < QAT_ASYM_RSA_NUM_OUT_PARAMS; i++)
139 : 0 : memset(cookie->output_array[i], 0x0, alg_size);
140 : 0 : }
141 : :
142 : : static void
143 : 0 : cleanup(struct qat_asym_op_cookie *cookie,
144 : : const struct rte_crypto_asym_xform *xform)
145 : : {
146 [ # # ]: 0 : if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX)
147 : 0 : cleanup_arrays(cookie, QAT_ASYM_MODEXP_NUM_IN_PARAMS,
148 : : QAT_ASYM_MODEXP_NUM_OUT_PARAMS,
149 : 0 : cookie->alg_bytesize);
150 [ # # ]: 0 : else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV)
151 : 0 : cleanup_arrays(cookie, QAT_ASYM_MODINV_NUM_IN_PARAMS,
152 : : QAT_ASYM_MODINV_NUM_OUT_PARAMS,
153 : 0 : cookie->alg_bytesize);
154 [ # # ]: 0 : else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
155 [ # # ]: 0 : if (xform->rsa.key_type == RTE_RSA_KEY_TYPE_QT)
156 : 0 : cleanup_crt(cookie, cookie->alg_bytesize);
157 : : else {
158 : 0 : cleanup_arrays(cookie, QAT_ASYM_RSA_NUM_IN_PARAMS,
159 : : QAT_ASYM_RSA_NUM_OUT_PARAMS,
160 : 0 : cookie->alg_bytesize);
161 : : }
162 : : } else {
163 : 0 : cleanup_arrays(cookie, QAT_ASYM_MAX_PARAMS,
164 : : QAT_ASYM_MAX_PARAMS,
165 : : QAT_PKE_MAX_LN_SIZE);
166 : : }
167 : 0 : }
168 : :
169 : : static int
170 : 0 : check_zero(rte_crypto_param n)
171 : : {
172 : 0 : int i, len = n.length;
173 : :
174 [ # # ]: 0 : if (len < 8) {
175 [ # # ]: 0 : for (i = len - 1; i >= 0; i--) {
176 [ # # ]: 0 : if (n.data[i] != 0x0)
177 : : return 0;
178 : : }
179 [ # # # # ]: 0 : } else if (len == 8 && *(uint64_t *)&n.data[len - 8] == 0) {
180 : : return 1;
181 [ # # ]: 0 : } else if (*(uint64_t *)&n.data[len - 8] == 0) {
182 [ # # ]: 0 : for (i = len - 9; i >= 0; i--) {
183 [ # # ]: 0 : if (n.data[i] != 0x0)
184 : : return 0;
185 : : }
186 : : } else
187 : : return 0;
188 : :
189 : : return 1;
190 : : }
191 : :
192 : : static struct qat_asym_function
193 : 0 : get_asym_function(const struct rte_crypto_asym_xform *xform)
194 : : {
195 : : struct qat_asym_function qat_function;
196 : :
197 [ # # # ]: 0 : switch (xform->xform_type) {
198 : : case RTE_CRYPTO_ASYM_XFORM_MODEX:
199 : : qat_function = get_modexp_function(xform);
200 : : break;
201 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODINV:
202 : 0 : qat_function = get_modinv_function(xform);
203 : 0 : break;
204 : : default:
205 : : qat_function.func_id = 0;
206 : : break;
207 : : }
208 : :
209 : 0 : return qat_function;
210 : : }
211 : :
212 : : static int
213 : 0 : modexp_set_input(struct icp_qat_fw_pke_request *qat_req,
214 : : struct qat_asym_op_cookie *cookie,
215 : : const struct rte_crypto_asym_op *asym_op,
216 : : const struct rte_crypto_asym_xform *xform)
217 : : {
218 : : struct qat_asym_function qat_function;
219 : : uint32_t alg_bytesize, func_id, in_bytesize;
220 : : int status = 0;
221 : :
222 [ # # # # ]: 0 : CHECK_IF_NOT_EMPTY(xform->modex.modulus, "mod exp",
223 : : "modulus", status);
224 [ # # # # ]: 0 : CHECK_IF_NOT_EMPTY(xform->modex.exponent, "mod exp",
225 : : "exponent", status);
226 [ # # ]: 0 : if (status)
227 : 0 : return status;
228 : :
229 [ # # ]: 0 : if (asym_op->modex.base.length > xform->modex.exponent.length &&
230 [ # # ]: 0 : asym_op->modex.base.length > xform->modex.modulus.length) {
231 : 0 : in_bytesize = asym_op->modex.base.length;
232 [ # # ]: 0 : } else if (xform->modex.exponent.length > xform->modex.modulus.length)
233 : 0 : in_bytesize = xform->modex.exponent.length;
234 : : else
235 : 0 : in_bytesize = xform->modex.modulus.length;
236 : :
237 : 0 : qat_function = get_modexp_function2(in_bytesize);
238 : : func_id = qat_function.func_id;
239 [ # # ]: 0 : if (qat_function.func_id == 0) {
240 : 0 : QAT_LOG(ERR, "Cannot obtain functionality id");
241 : 0 : return -EINVAL;
242 : : }
243 : 0 : alg_bytesize = qat_function.bytesize;
244 : :
245 [ # # ]: 0 : SET_PKE_LN(asym_op->modex.base, alg_bytesize, 0);
246 [ # # ]: 0 : SET_PKE_LN(xform->modex.exponent, alg_bytesize, 1);
247 [ # # ]: 0 : SET_PKE_LN(xform->modex.modulus, alg_bytesize, 2);
248 : :
249 : 0 : cookie->alg_bytesize = alg_bytesize;
250 : 0 : qat_req->pke_hdr.cd_pars.func_id = func_id;
251 : 0 : qat_req->input_param_count = QAT_ASYM_MODEXP_NUM_IN_PARAMS;
252 : 0 : qat_req->output_param_count = QAT_ASYM_MODEXP_NUM_OUT_PARAMS;
253 : :
254 : : HEXDUMP("ModExp base", cookie->input_array[0], alg_bytesize);
255 : : HEXDUMP("ModExp exponent", cookie->input_array[1], alg_bytesize);
256 : : HEXDUMP("ModExp modulus", cookie->input_array[2], alg_bytesize);
257 : :
258 : 0 : return status;
259 : : }
260 : :
261 : : static uint8_t
262 : 0 : modexp_collect(struct rte_crypto_asym_op *asym_op,
263 : : const struct qat_asym_op_cookie *cookie,
264 : : const struct rte_crypto_asym_xform *xform)
265 : : {
266 : 0 : rte_crypto_param n = xform->modex.modulus;
267 : 0 : uint32_t alg_bytesize = cookie->alg_bytesize;
268 : 0 : uint8_t *modexp_result = asym_op->modex.result.data;
269 : :
270 [ # # ]: 0 : if (n.length > alg_bytesize) {
271 : 0 : QAT_LOG(ERR, "Incorrect length of modexp modulus");
272 : 0 : return RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
273 : : }
274 : 0 : rte_memcpy(modexp_result,
275 : 0 : cookie->output_array[0] + alg_bytesize
276 [ # # ]: 0 : - n.length, n.length);
277 : 0 : asym_op->modex.result.length = n.length;
278 : : HEXDUMP("ModExp result", cookie->output_array[0],
279 : : alg_bytesize);
280 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
281 : : }
282 : :
283 : : static int
284 : 0 : modinv_set_input(struct icp_qat_fw_pke_request *qat_req,
285 : : struct qat_asym_op_cookie *cookie,
286 : : const struct rte_crypto_asym_op *asym_op,
287 : : const struct rte_crypto_asym_xform *xform)
288 : : {
289 : : struct qat_asym_function qat_function;
290 : : uint32_t alg_bytesize, func_id;
291 : : int status = 0;
292 : :
293 [ # # # # ]: 0 : CHECK_IF_NOT_EMPTY(xform->modex.modulus, "mod inv",
294 : : "modulus", status);
295 : : if (status)
296 : 0 : return status;
297 : :
298 : 0 : qat_function = get_asym_function(xform);
299 : 0 : func_id = qat_function.func_id;
300 [ # # ]: 0 : if (func_id == 0) {
301 : 0 : QAT_LOG(ERR, "Cannot obtain functionality id");
302 : 0 : return -EINVAL;
303 : : }
304 : 0 : alg_bytesize = qat_function.bytesize;
305 : :
306 [ # # ]: 0 : SET_PKE_LN(asym_op->modinv.base, alg_bytesize, 0);
307 [ # # ]: 0 : SET_PKE_LN(xform->modinv.modulus, alg_bytesize, 1);
308 : :
309 : 0 : cookie->alg_bytesize = alg_bytesize;
310 : 0 : qat_req->pke_hdr.cd_pars.func_id = func_id;
311 : 0 : qat_req->input_param_count =
312 : : QAT_ASYM_MODINV_NUM_IN_PARAMS;
313 : 0 : qat_req->output_param_count =
314 : : QAT_ASYM_MODINV_NUM_OUT_PARAMS;
315 : :
316 : : HEXDUMP("ModInv base", cookie->input_array[0], alg_bytesize);
317 : : HEXDUMP("ModInv modulus", cookie->input_array[1], alg_bytesize);
318 : :
319 : 0 : return 0;
320 : : }
321 : :
322 : : static uint8_t
323 : 0 : modinv_collect(struct rte_crypto_asym_op *asym_op,
324 : : const struct qat_asym_op_cookie *cookie,
325 : : const struct rte_crypto_asym_xform *xform)
326 : : {
327 : 0 : rte_crypto_param n = xform->modinv.modulus;
328 : 0 : uint8_t *modinv_result = asym_op->modinv.result.data;
329 : 0 : uint32_t alg_bytesize = cookie->alg_bytesize;
330 : :
331 [ # # ]: 0 : if (n.length > alg_bytesize) {
332 : 0 : QAT_LOG(ERR, "Incorrect length of modinv modulus");
333 : 0 : return RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
334 : : }
335 : 0 : rte_memcpy(modinv_result,
336 : 0 : cookie->output_array[0] + alg_bytesize
337 [ # # ]: 0 : - n.length, n.length);
338 : 0 : asym_op->modinv.result.length = n.length;
339 : : HEXDUMP("ModInv result", cookie->output_array[0],
340 : : alg_bytesize);
341 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
342 : : }
343 : :
344 : : static int
345 [ # # ]: 0 : rsa_set_pub_input(struct icp_qat_fw_pke_request *qat_req,
346 : : struct qat_asym_op_cookie *cookie,
347 : : const struct rte_crypto_asym_op *asym_op,
348 : : const struct rte_crypto_asym_xform *xform)
349 : : {
350 : : struct qat_asym_function qat_function;
351 : : uint32_t alg_bytesize, func_id;
352 : : int status = 0;
353 : :
354 : : qat_function = get_rsa_enc_function(xform);
355 : : func_id = qat_function.func_id;
356 [ # # ]: 0 : if (func_id == 0) {
357 : 0 : QAT_LOG(ERR, "Cannot obtain functionality id");
358 : 0 : return -EINVAL;
359 : : }
360 : : alg_bytesize = qat_function.bytesize;
361 : :
362 [ # # ]: 0 : if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
363 [ # # ]: 0 : switch (xform->rsa.padding.type) {
364 : 0 : case RTE_CRYPTO_RSA_PADDING_NONE:
365 [ # # ]: 0 : SET_PKE_LN(asym_op->rsa.message, alg_bytesize, 0);
366 : : break;
367 : 0 : default:
368 : 0 : QAT_LOG(ERR,
369 : : "Invalid RSA padding (Encryption)"
370 : : );
371 : 0 : return -EINVAL;
372 : : }
373 : : HEXDUMP("RSA Message", cookie->input_array[0], alg_bytesize);
374 : : } else {
375 [ # # ]: 0 : switch (xform->rsa.padding.type) {
376 : 0 : case RTE_CRYPTO_RSA_PADDING_NONE:
377 [ # # ]: 0 : SET_PKE_LN(asym_op->rsa.sign, alg_bytesize, 0);
378 : : break;
379 : 0 : default:
380 : 0 : QAT_LOG(ERR,
381 : : "Invalid RSA padding (Verify)");
382 : 0 : return -EINVAL;
383 : : }
384 : : HEXDUMP("RSA Signature", cookie->input_array[0],
385 : : alg_bytesize);
386 : : }
387 : :
388 [ # # ]: 0 : SET_PKE_LN(xform->rsa.e, alg_bytesize, 1);
389 [ # # ]: 0 : SET_PKE_LN(xform->rsa.n, alg_bytesize, 2);
390 : :
391 : 0 : cookie->alg_bytesize = alg_bytesize;
392 : 0 : qat_req->pke_hdr.cd_pars.func_id = func_id;
393 : :
394 : : HEXDUMP("RSA Public Key", cookie->input_array[1], alg_bytesize);
395 : : HEXDUMP("RSA Modulus", cookie->input_array[2], alg_bytesize);
396 : :
397 : 0 : return status;
398 : : }
399 : :
400 : : static int
401 : 0 : rsa_set_priv_input(struct icp_qat_fw_pke_request *qat_req,
402 : : struct qat_asym_op_cookie *cookie,
403 : : const struct rte_crypto_asym_op *asym_op,
404 : : const struct rte_crypto_asym_xform *xform)
405 : : {
406 : : struct qat_asym_function qat_function;
407 : : uint32_t alg_bytesize, func_id;
408 : : int status = 0;
409 : :
410 [ # # ]: 0 : if (xform->rsa.key_type == RTE_RSA_KEY_TYPE_QT) {
411 : : qat_function = get_rsa_crt_function(xform);
412 : : func_id = qat_function.func_id;
413 [ # # ]: 0 : if (func_id == 0) {
414 : 0 : QAT_LOG(ERR, "Cannot obtain functionality id");
415 : 0 : return -EINVAL;
416 : : }
417 : : alg_bytesize = qat_function.bytesize;
418 : 0 : qat_req->input_param_count =
419 : : QAT_ASYM_RSA_QT_NUM_IN_PARAMS;
420 : :
421 [ # # ]: 0 : SET_PKE_LN(xform->rsa.qt.p, (alg_bytesize >> 1), 1);
422 [ # # ]: 0 : SET_PKE_LN(xform->rsa.qt.q, (alg_bytesize >> 1), 2);
423 [ # # ]: 0 : SET_PKE_LN(xform->rsa.qt.dP, (alg_bytesize >> 1), 3);
424 [ # # ]: 0 : SET_PKE_LN(xform->rsa.qt.dQ, (alg_bytesize >> 1), 4);
425 [ # # ]: 0 : SET_PKE_LN(xform->rsa.qt.qInv, (alg_bytesize >> 1), 5);
426 : :
427 : : HEXDUMP("RSA p", cookie->input_array[1],
428 : : alg_bytesize);
429 : : HEXDUMP("RSA q", cookie->input_array[2],
430 : : alg_bytesize);
431 : : HEXDUMP("RSA dP", cookie->input_array[3],
432 : : alg_bytesize);
433 : : HEXDUMP("RSA dQ", cookie->input_array[4],
434 : : alg_bytesize);
435 : : HEXDUMP("RSA qInv", cookie->input_array[5],
436 : : alg_bytesize);
437 [ # # ]: 0 : } else if (xform->rsa.key_type ==
438 : : RTE_RSA_KEY_TYPE_EXP) {
439 : : qat_function = get_rsa_dec_function(xform);
440 : : func_id = qat_function.func_id;
441 [ # # ]: 0 : if (func_id == 0) {
442 : 0 : QAT_LOG(ERR, "Cannot obtain functionality id");
443 : 0 : return -EINVAL;
444 : : }
445 : : alg_bytesize = qat_function.bytesize;
446 : :
447 [ # # ]: 0 : SET_PKE_LN(xform->rsa.d, alg_bytesize, 1);
448 [ # # ]: 0 : SET_PKE_LN(xform->rsa.n, alg_bytesize, 2);
449 : :
450 : : HEXDUMP("RSA d", cookie->input_array[1],
451 : : alg_bytesize);
452 : : HEXDUMP("RSA n", cookie->input_array[2],
453 : : alg_bytesize);
454 : : } else {
455 : 0 : QAT_LOG(ERR, "Invalid RSA key type");
456 : 0 : return -EINVAL;
457 : : }
458 : :
459 [ # # ]: 0 : if (asym_op->rsa.op_type ==
460 : : RTE_CRYPTO_ASYM_OP_DECRYPT) {
461 [ # # ]: 0 : switch (xform->rsa.padding.type) {
462 : 0 : case RTE_CRYPTO_RSA_PADDING_NONE:
463 [ # # ]: 0 : SET_PKE_LN(asym_op->rsa.cipher, alg_bytesize, 0);
464 : : HEXDUMP("RSA ciphertext", cookie->input_array[0],
465 : : alg_bytesize);
466 : : break;
467 : 0 : default:
468 : 0 : QAT_LOG(ERR,
469 : : "Invalid padding of RSA (Decrypt)");
470 : 0 : return -(EINVAL);
471 : : }
472 : :
473 [ # # ]: 0 : } else if (asym_op->rsa.op_type ==
474 : : RTE_CRYPTO_ASYM_OP_SIGN) {
475 [ # # ]: 0 : switch (xform->rsa.padding.type) {
476 : 0 : case RTE_CRYPTO_RSA_PADDING_NONE:
477 [ # # ]: 0 : SET_PKE_LN(asym_op->rsa.message, alg_bytesize, 0);
478 : : HEXDUMP("RSA text to be signed", cookie->input_array[0],
479 : : alg_bytesize);
480 : : break;
481 : 0 : default:
482 : 0 : QAT_LOG(ERR,
483 : : "Invalid padding of RSA (Signature)");
484 : 0 : return -(EINVAL);
485 : : }
486 : : }
487 : :
488 : 0 : cookie->alg_bytesize = alg_bytesize;
489 : 0 : qat_req->pke_hdr.cd_pars.func_id = func_id;
490 : 0 : return status;
491 : : }
492 : :
493 : : static int
494 : 0 : rsa_set_input(struct icp_qat_fw_pke_request *qat_req,
495 : : struct qat_asym_op_cookie *cookie,
496 : : const struct rte_crypto_asym_op *asym_op,
497 : : const struct rte_crypto_asym_xform *xform)
498 : : {
499 : 0 : qat_req->input_param_count =
500 : : QAT_ASYM_RSA_NUM_IN_PARAMS;
501 : 0 : qat_req->output_param_count =
502 : : QAT_ASYM_RSA_NUM_OUT_PARAMS;
503 : :
504 [ # # ]: 0 : if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT ||
505 : : asym_op->rsa.op_type ==
506 : : RTE_CRYPTO_ASYM_OP_VERIFY) {
507 : 0 : return rsa_set_pub_input(qat_req, cookie, asym_op, xform);
508 : : } else {
509 : 0 : return rsa_set_priv_input(qat_req, cookie, asym_op, xform);
510 : : }
511 : : }
512 : :
513 : : static uint8_t
514 : 0 : rsa_collect(struct rte_crypto_asym_op *asym_op,
515 : : const struct qat_asym_op_cookie *cookie,
516 : : const struct rte_crypto_asym_xform *xform)
517 : : {
518 : 0 : uint32_t alg_bytesize = cookie->alg_bytesize;
519 : :
520 [ # # ]: 0 : if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT ||
521 : : asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
522 : :
523 [ # # ]: 0 : if (asym_op->rsa.op_type ==
524 : : RTE_CRYPTO_ASYM_OP_ENCRYPT) {
525 : 0 : rte_memcpy(asym_op->rsa.cipher.data,
526 [ # # ]: 0 : cookie->output_array[0],
527 : : alg_bytesize);
528 : 0 : asym_op->rsa.cipher.length = alg_bytesize;
529 : : HEXDUMP("RSA Encrypted data", cookie->output_array[0],
530 : : alg_bytesize);
531 : : } else {
532 [ # # ]: 0 : switch (xform->rsa.padding.type) {
533 : 0 : case RTE_CRYPTO_RSA_PADDING_NONE:
534 : 0 : rte_memcpy(asym_op->rsa.cipher.data,
535 [ # # ]: 0 : cookie->output_array[0],
536 : : alg_bytesize);
537 : 0 : asym_op->rsa.cipher.length = alg_bytesize;
538 : : HEXDUMP("RSA signature",
539 : : cookie->output_array[0],
540 : : alg_bytesize);
541 : 0 : break;
542 : 0 : default:
543 : 0 : QAT_LOG(ERR, "Padding not supported");
544 : 0 : return RTE_CRYPTO_OP_STATUS_ERROR;
545 : : }
546 : : }
547 : : } else {
548 [ # # ]: 0 : if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
549 [ # # ]: 0 : switch (xform->rsa.padding.type) {
550 : 0 : case RTE_CRYPTO_RSA_PADDING_NONE:
551 : 0 : rte_memcpy(asym_op->rsa.message.data,
552 [ # # ]: 0 : cookie->output_array[0],
553 : : alg_bytesize);
554 : 0 : asym_op->rsa.message.length = alg_bytesize;
555 : : HEXDUMP("RSA Decrypted Message",
556 : : cookie->output_array[0],
557 : : alg_bytesize);
558 : : break;
559 : 0 : default:
560 : 0 : QAT_LOG(ERR, "Padding not supported");
561 : 0 : return RTE_CRYPTO_OP_STATUS_ERROR;
562 : : }
563 : : } else {
564 : 0 : rte_memcpy(asym_op->rsa.sign.data,
565 [ # # ]: 0 : cookie->output_array[0],
566 : : alg_bytesize);
567 : 0 : asym_op->rsa.sign.length = alg_bytesize;
568 : : HEXDUMP("RSA Signature", cookie->output_array[0],
569 : : alg_bytesize);
570 : : }
571 : : }
572 : : return RTE_CRYPTO_OP_STATUS_SUCCESS;
573 : : }
574 : :
575 : : static int
576 : 0 : ecdsa_set_input(struct icp_qat_fw_pke_request *qat_req,
577 : : struct qat_asym_op_cookie *cookie,
578 : : const struct rte_crypto_asym_op *asym_op,
579 : : const struct rte_crypto_asym_xform *xform)
580 : : {
581 : : struct qat_asym_function qat_function;
582 : : uint32_t qat_func_alignsize, func_id;
583 : : int curve_id;
584 : :
585 : 0 : curve_id = pick_curve(xform);
586 [ # # ]: 0 : if (curve_id < 0) {
587 : 0 : QAT_LOG(DEBUG, "Incorrect elliptic curve");
588 : 0 : return -EINVAL;
589 : : }
590 : :
591 [ # # # ]: 0 : switch (asym_op->ecdsa.op_type) {
592 : 0 : case RTE_CRYPTO_ASYM_OP_SIGN:
593 : 0 : qat_function = get_ecdsa_function(xform);
594 : : func_id = qat_function.func_id;
595 [ # # ]: 0 : if (func_id == 0) {
596 : 0 : QAT_LOG(ERR, "Cannot obtain functionality id");
597 : 0 : return -EINVAL;
598 : : }
599 : 0 : qat_func_alignsize =
600 : 0 : RTE_ALIGN_CEIL(qat_function.bytesize, 8);
601 : :
602 [ # # ]: 0 : SET_PKE_9A_IN(xform->ec.pkey, 0);
603 [ # # ]: 0 : SET_PKE_9A_IN(asym_op->ecdsa.message, 1);
604 [ # # ]: 0 : SET_PKE_9A_IN(asym_op->ecdsa.k, 2);
605 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], b, 3);
606 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], a, 4);
607 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], p, 5);
608 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], n, 6);
609 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], y, 7);
610 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], x, 8);
611 : :
612 : 0 : cookie->alg_bytesize = curve[curve_id].bytesize;
613 : 0 : cookie->qat_func_alignsize = qat_func_alignsize;
614 : 0 : qat_req->pke_hdr.cd_pars.func_id = func_id;
615 : 0 : qat_req->input_param_count =
616 : : QAT_ASYM_ECDSA_RS_SIGN_IN_PARAMS;
617 : 0 : qat_req->output_param_count =
618 : : QAT_ASYM_ECDSA_RS_SIGN_OUT_PARAMS;
619 : :
620 : : HEXDUMP_OFF_F("ECDSA d", 0);
621 : : HEXDUMP_OFF_F("ECDSA e", 1);
622 : : HEXDUMP_OFF_F("ECDSA k", 2);
623 : : HEXDUMP_OFF_F("ECDSA b", 3);
624 : : HEXDUMP_OFF_F("ECDSA a", 4);
625 : : HEXDUMP_OFF_F("ECDSA n", 5);
626 : : HEXDUMP_OFF_F("ECDSA y", 6);
627 : : HEXDUMP_OFF_F("ECDSA x", 7);
628 : 0 : break;
629 : 0 : case RTE_CRYPTO_ASYM_OP_VERIFY:
630 : 0 : qat_function = get_ecdsa_verify_function(xform);
631 : : func_id = qat_function.func_id;
632 [ # # ]: 0 : if (func_id == 0) {
633 : 0 : QAT_LOG(ERR, "Cannot obtain functionality id");
634 : 0 : return -EINVAL;
635 : : }
636 : 0 : qat_func_alignsize = RTE_ALIGN_CEIL(qat_function.bytesize, 8);
637 : :
638 [ # # ]: 0 : SET_PKE_9A_IN(asym_op->ecdsa.message, 10);
639 [ # # ]: 0 : SET_PKE_9A_IN(asym_op->ecdsa.s, 9);
640 [ # # ]: 0 : SET_PKE_9A_IN(asym_op->ecdsa.r, 8);
641 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], n, 7);
642 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], x, 6);
643 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], y, 5);
644 [ # # ]: 0 : SET_PKE_9A_IN(xform->ec.q.x, 4);
645 [ # # ]: 0 : SET_PKE_9A_IN(xform->ec.q.y, 3);
646 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], a, 2);
647 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], b, 1);
648 [ # # ]: 0 : SET_PKE_9A_EC(curve[curve_id], p, 0);
649 : :
650 : 0 : cookie->alg_bytesize = curve[curve_id].bytesize;
651 : 0 : cookie->qat_func_alignsize = qat_func_alignsize;
652 : 0 : qat_req->pke_hdr.cd_pars.func_id = func_id;
653 : 0 : qat_req->input_param_count =
654 : : QAT_ASYM_ECDSA_RS_VERIFY_IN_PARAMS;
655 : 0 : qat_req->output_param_count =
656 : : QAT_ASYM_ECDSA_RS_VERIFY_OUT_PARAMS;
657 : :
658 : : HEXDUMP_OFF_F("p", 0);
659 : : HEXDUMP_OFF_F("b", 1);
660 : : HEXDUMP_OFF_F("a", 2);
661 : : HEXDUMP_OFF_F("y", 3);
662 : : HEXDUMP_OFF_F("x", 4);
663 : : HEXDUMP_OFF_F("yG", 5);
664 : : HEXDUMP_OFF_F("xG", 6);
665 : : HEXDUMP_OFF_F("n", 7);
666 : : HEXDUMP_OFF_F("r", 8);
667 : : HEXDUMP_OFF_F("s", 9);
668 : : HEXDUMP_OFF_F("e", 10);
669 : 0 : break;
670 : : default:
671 : : return -1;
672 : : }
673 : :
674 : : return 0;
675 : : }
676 : :
677 : : static uint8_t
678 : 0 : ecdsa_collect(struct rte_crypto_asym_op *asym_op,
679 : : const struct qat_asym_op_cookie *cookie)
680 : : {
681 : 0 : uint32_t alg_bytesize = cookie->alg_bytesize;
682 : 0 : uint32_t qat_func_alignsize = cookie->qat_func_alignsize;
683 : 0 : uint32_t ltrim = qat_func_alignsize - alg_bytesize;
684 : :
685 [ # # ]: 0 : if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
686 : 0 : uint8_t *r = asym_op->ecdsa.r.data;
687 : 0 : uint8_t *s = asym_op->ecdsa.s.data;
688 : :
689 : 0 : asym_op->ecdsa.r.length = alg_bytesize;
690 : 0 : asym_op->ecdsa.s.length = alg_bytesize;
691 [ # # ]: 0 : rte_memcpy(r, &cookie->output_array[0][ltrim], alg_bytesize);
692 [ # # ]: 0 : rte_memcpy(s, &cookie->output_array[1][ltrim], alg_bytesize);
693 : :
694 : : HEXDUMP("R", cookie->output_array[0],
695 : : qat_func_alignsize);
696 : : HEXDUMP("S", cookie->output_array[1],
697 : : qat_func_alignsize);
698 : : }
699 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
700 : : }
701 : :
702 : : static int
703 : 0 : ecpm_set_input(struct icp_qat_fw_pke_request *qat_req,
704 : : struct qat_asym_op_cookie *cookie,
705 : : const struct rte_crypto_asym_op *asym_op,
706 : : const struct rte_crypto_asym_xform *xform)
707 : : {
708 : : struct qat_asym_function qat_function;
709 : : uint32_t qat_func_alignsize, func_id;
710 : : int curve_id;
711 : :
712 : 0 : curve_id = pick_curve(xform);
713 [ # # ]: 0 : if (curve_id < 0) {
714 : 0 : QAT_LOG(DEBUG, "Incorrect elliptic curve");
715 : 0 : return -EINVAL;
716 : : }
717 : :
718 : : qat_function = get_ecpm_function(xform);
719 : : func_id = qat_function.func_id;
720 [ # # ]: 0 : if (func_id == 0) {
721 : 0 : QAT_LOG(ERR, "Cannot obtain functionality id");
722 : 0 : return -EINVAL;
723 : : }
724 : 0 : qat_func_alignsize = RTE_ALIGN_CEIL(qat_function.bytesize, 8);
725 : :
726 [ # # ]: 0 : SET_PKE_LN(asym_op->ecpm.scalar, qat_func_alignsize, 0);
727 [ # # ]: 0 : SET_PKE_LN(asym_op->ecpm.p.x, qat_func_alignsize, 1);
728 [ # # ]: 0 : SET_PKE_LN(asym_op->ecpm.p.y, qat_func_alignsize, 2);
729 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], a, 3);
730 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], b, 4);
731 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], p, 5);
732 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], h, 6);
733 : :
734 : 0 : cookie->alg_bytesize = curve[curve_id].bytesize;
735 : 0 : cookie->qat_func_alignsize = qat_func_alignsize;
736 : 0 : qat_req->pke_hdr.cd_pars.func_id = func_id;
737 : 0 : qat_req->input_param_count =
738 : : QAT_ASYM_ECPM_IN_PARAMS;
739 : 0 : qat_req->output_param_count =
740 : : QAT_ASYM_ECPM_OUT_PARAMS;
741 : :
742 : : HEXDUMP("k", cookie->input_array[0], qat_func_alignsize);
743 : : HEXDUMP("xG", cookie->input_array[1], qat_func_alignsize);
744 : : HEXDUMP("yG", cookie->input_array[2], qat_func_alignsize);
745 : : HEXDUMP("a", cookie->input_array[3], qat_func_alignsize);
746 : : HEXDUMP("b", cookie->input_array[4], qat_func_alignsize);
747 : : HEXDUMP("q", cookie->input_array[5], qat_func_alignsize);
748 : : HEXDUMP("h", cookie->input_array[6], qat_func_alignsize);
749 : :
750 : 0 : return 0;
751 : : }
752 : :
753 : : static uint8_t
754 : 0 : ecpm_collect(struct rte_crypto_asym_op *asym_op,
755 : : const struct qat_asym_op_cookie *cookie)
756 : : {
757 : 0 : uint8_t *x = asym_op->ecpm.r.x.data;
758 : 0 : uint8_t *y = asym_op->ecpm.r.y.data;
759 : 0 : uint32_t alg_bytesize = cookie->alg_bytesize;
760 : 0 : uint32_t qat_func_alignsize = cookie->qat_func_alignsize;
761 : 0 : uint32_t ltrim = qat_func_alignsize - alg_bytesize;
762 : :
763 : 0 : asym_op->ecpm.r.x.length = alg_bytesize;
764 : 0 : asym_op->ecpm.r.y.length = alg_bytesize;
765 [ # # ]: 0 : rte_memcpy(x, &cookie->output_array[0][ltrim], alg_bytesize);
766 [ # # ]: 0 : rte_memcpy(y, &cookie->output_array[1][ltrim], alg_bytesize);
767 : :
768 : : HEXDUMP("rX", cookie->output_array[0],
769 : : qat_func_alignsize);
770 : : HEXDUMP("rY", cookie->output_array[1],
771 : : qat_func_alignsize);
772 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
773 : : }
774 : :
775 : : static int
776 : 0 : ecdh_set_input(struct icp_qat_fw_pke_request *qat_req,
777 : : struct qat_asym_op_cookie *cookie,
778 : : const struct rte_crypto_asym_op *asym_op,
779 : : const struct rte_crypto_asym_xform *xform)
780 : : {
781 : : struct qat_asym_function qat_function;
782 : : uint32_t qat_func_alignsize, func_id;
783 : : int curve_id;
784 : :
785 : 0 : curve_id = pick_curve(xform);
786 [ # # ]: 0 : if (curve_id < 0) {
787 : 0 : QAT_LOG(DEBUG, "Incorrect elliptic curve");
788 : 0 : return -EINVAL;
789 : : }
790 : :
791 : : qat_function = get_ecpm_function(xform);
792 : : func_id = qat_function.func_id;
793 [ # # ]: 0 : if (func_id == 0) {
794 : 0 : QAT_LOG(ERR, "Cannot obtain functionality id");
795 : 0 : return -EINVAL;
796 : : }
797 : 0 : qat_func_alignsize = RTE_ALIGN_CEIL(qat_function.bytesize, 8);
798 : :
799 [ # # ]: 0 : if (asym_op->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE) {
800 [ # # ]: 0 : SET_PKE_LN(xform->ec.pkey, qat_func_alignsize, 0);
801 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], x, 1);
802 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], y, 2);
803 [ # # ]: 0 : } else if (asym_op->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE) {
804 [ # # ]: 0 : SET_PKE_LN(xform->ec.pkey, qat_func_alignsize, 0);
805 [ # # ]: 0 : SET_PKE_LN(xform->ec.q.x, qat_func_alignsize, 1);
806 [ # # ]: 0 : SET_PKE_LN(xform->ec.q.y, qat_func_alignsize, 2);
807 : : } else {
808 : : return -EINVAL;
809 : : }
810 : :
811 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], a, 3);
812 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], b, 4);
813 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], p, 5);
814 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], h, 6);
815 : :
816 : 0 : cookie->alg_bytesize = curve[curve_id].bytesize;
817 : 0 : cookie->qat_func_alignsize = qat_func_alignsize;
818 : 0 : qat_req->pke_hdr.cd_pars.func_id = func_id;
819 : 0 : qat_req->input_param_count =
820 : : QAT_ASYM_ECPM_IN_PARAMS;
821 : 0 : qat_req->output_param_count =
822 : : QAT_ASYM_ECPM_OUT_PARAMS;
823 : :
824 : : HEXDUMP("k", cookie->input_array[0], qat_func_alignsize);
825 : : HEXDUMP("xG", cookie->input_array[1], qat_func_alignsize);
826 : : HEXDUMP("yG", cookie->input_array[2], qat_func_alignsize);
827 : : HEXDUMP("a", cookie->input_array[3], qat_func_alignsize);
828 : : HEXDUMP("b", cookie->input_array[4], qat_func_alignsize);
829 : : HEXDUMP("q", cookie->input_array[5], qat_func_alignsize);
830 : : HEXDUMP("h", cookie->input_array[6], qat_func_alignsize);
831 : :
832 : 0 : return 0;
833 : : }
834 : :
835 : : static int
836 : 0 : ecdh_verify_set_input(struct icp_qat_fw_pke_request *qat_req,
837 : : struct qat_asym_op_cookie *cookie,
838 : : const struct rte_crypto_asym_op *asym_op,
839 : : const struct rte_crypto_asym_xform *xform)
840 : : {
841 : : struct qat_asym_function qat_function;
842 : : uint32_t qat_func_alignsize, func_id;
843 : : int curve_id;
844 : :
845 : 0 : curve_id = pick_curve(xform);
846 [ # # ]: 0 : if (curve_id < 0) {
847 : 0 : QAT_LOG(DEBUG, "Incorrect elliptic curve");
848 : 0 : return -EINVAL;
849 : : }
850 : :
851 : : qat_function = get_ec_verify_function(xform);
852 : : func_id = qat_function.func_id;
853 [ # # ]: 0 : if (func_id == 0) {
854 : 0 : QAT_LOG(ERR, "Cannot obtain functionality id");
855 : 0 : return -EINVAL;
856 : : }
857 : 0 : qat_func_alignsize = RTE_ALIGN_CEIL(qat_function.bytesize, 8);
858 : :
859 [ # # ]: 0 : SET_PKE_LN(asym_op->ecdh.pub_key.x, qat_func_alignsize, 0);
860 [ # # ]: 0 : SET_PKE_LN(asym_op->ecdh.pub_key.y, qat_func_alignsize, 1);
861 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], p, 2);
862 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], a, 3);
863 [ # # ]: 0 : SET_PKE_LN_EC(curve[curve_id], b, 4);
864 : :
865 : 0 : cookie->alg_bytesize = curve[curve_id].bytesize;
866 : 0 : cookie->qat_func_alignsize = qat_func_alignsize;
867 : 0 : qat_req->pke_hdr.cd_pars.func_id = func_id;
868 : 0 : qat_req->input_param_count =
869 : : 5;
870 : 0 : qat_req->output_param_count =
871 : : 0;
872 : :
873 : : HEXDUMP("x", cookie->input_array[0], qat_func_alignsize);
874 : : HEXDUMP("y", cookie->input_array[1], qat_func_alignsize);
875 : : HEXDUMP("p", cookie->input_array[2], qat_func_alignsize);
876 : : HEXDUMP("a", cookie->input_array[3], qat_func_alignsize);
877 : : HEXDUMP("b", cookie->input_array[4], qat_func_alignsize);
878 : :
879 : 0 : return 0;
880 : : }
881 : :
882 : : static uint8_t
883 : 0 : ecdh_collect(struct rte_crypto_asym_op *asym_op,
884 : : const struct qat_asym_op_cookie *cookie)
885 : : {
886 : : uint8_t *x, *y;
887 : 0 : uint32_t alg_bytesize = cookie->alg_bytesize;
888 : 0 : uint32_t qat_func_alignsize = cookie->qat_func_alignsize;
889 : 0 : uint32_t ltrim = qat_func_alignsize - alg_bytesize;
890 : :
891 [ # # ]: 0 : if (asym_op->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY)
892 : : return RTE_CRYPTO_OP_STATUS_SUCCESS;
893 : :
894 [ # # ]: 0 : if (asym_op->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE) {
895 : 0 : asym_op->ecdh.pub_key.x.length = alg_bytesize;
896 : 0 : asym_op->ecdh.pub_key.y.length = alg_bytesize;
897 : 0 : x = asym_op->ecdh.pub_key.x.data;
898 : 0 : y = asym_op->ecdh.pub_key.y.data;
899 [ # # ]: 0 : } else if (asym_op->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE) {
900 : 0 : asym_op->ecdh.shared_secret.x.length = alg_bytesize;
901 : 0 : asym_op->ecdh.shared_secret.y.length = alg_bytesize;
902 : 0 : x = asym_op->ecdh.shared_secret.x.data;
903 : 0 : y = asym_op->ecdh.shared_secret.y.data;
904 : : } else {
905 : : return -EINVAL;
906 : : }
907 : :
908 [ # # ]: 0 : rte_memcpy(x, &cookie->output_array[0][ltrim], alg_bytesize);
909 [ # # ]: 0 : rte_memcpy(y, &cookie->output_array[1][ltrim], alg_bytesize);
910 : :
911 : : HEXDUMP("X", cookie->output_array[0],
912 : : qat_func_alignsize);
913 : : HEXDUMP("Y", cookie->output_array[1],
914 : : qat_func_alignsize);
915 : : return RTE_CRYPTO_OP_STATUS_SUCCESS;
916 : : }
917 : :
918 : : static int
919 : 0 : sm2_ecdsa_sign_set_input(struct icp_qat_fw_pke_request *qat_req,
920 : : struct qat_asym_op_cookie *cookie,
921 : : const struct rte_crypto_asym_op *asym_op,
922 : : const struct rte_crypto_asym_xform *xform)
923 : : {
924 : : const struct qat_asym_function qat_function =
925 : : get_sm2_ecdsa_sign_function();
926 : : const uint32_t qat_func_alignsize =
927 : : qat_function.bytesize;
928 : :
929 [ # # ]: 0 : SET_PKE_LN(asym_op->sm2.k, qat_func_alignsize, 0);
930 [ # # ]: 0 : SET_PKE_LN(asym_op->sm2.message, qat_func_alignsize, 1);
931 [ # # ]: 0 : SET_PKE_LN(xform->ec.pkey, qat_func_alignsize, 2);
932 : :
933 : 0 : cookie->alg_bytesize = qat_function.bytesize;
934 : 0 : cookie->qat_func_alignsize = qat_function.bytesize;
935 : 0 : qat_req->pke_hdr.cd_pars.func_id = qat_function.func_id;
936 : 0 : qat_req->input_param_count = 3;
937 : 0 : qat_req->output_param_count = 2;
938 : :
939 : : HEXDUMP("SM2 K test", asym_op->sm2.k.data,
940 : : cookie->alg_bytesize);
941 : : HEXDUMP("SM2 K", cookie->input_array[0],
942 : : cookie->alg_bytesize);
943 : : HEXDUMP("SM2 msg", cookie->input_array[1],
944 : : cookie->alg_bytesize);
945 : : HEXDUMP("SM2 pkey", cookie->input_array[2],
946 : : cookie->alg_bytesize);
947 : :
948 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
949 : : }
950 : :
951 : : static int
952 : 0 : sm2_ecdsa_verify_set_input(struct icp_qat_fw_pke_request *qat_req,
953 : : struct qat_asym_op_cookie *cookie,
954 : : const struct rte_crypto_asym_op *asym_op,
955 : : const struct rte_crypto_asym_xform *xform)
956 : : {
957 : : const struct qat_asym_function qat_function =
958 : : get_sm2_ecdsa_verify_function();
959 : : const uint32_t qat_func_alignsize =
960 : : qat_function.bytesize;
961 : :
962 [ # # ]: 0 : SET_PKE_LN(asym_op->sm2.message, qat_func_alignsize, 0);
963 [ # # ]: 0 : SET_PKE_LN(asym_op->sm2.r, qat_func_alignsize, 1);
964 [ # # ]: 0 : SET_PKE_LN(asym_op->sm2.s, qat_func_alignsize, 2);
965 [ # # ]: 0 : SET_PKE_LN(xform->ec.q.x, qat_func_alignsize, 3);
966 [ # # ]: 0 : SET_PKE_LN(xform->ec.q.y, qat_func_alignsize, 4);
967 : :
968 : 0 : cookie->alg_bytesize = qat_function.bytesize;
969 : 0 : cookie->qat_func_alignsize = qat_function.bytesize;
970 : 0 : qat_req->pke_hdr.cd_pars.func_id = qat_function.func_id;
971 : 0 : qat_req->input_param_count = 5;
972 : 0 : qat_req->output_param_count = 0;
973 : :
974 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
975 : : }
976 : :
977 : : static uint8_t
978 : 0 : sm2_ecdsa_sign_collect(struct rte_crypto_asym_op *asym_op,
979 : : const struct qat_asym_op_cookie *cookie)
980 : : {
981 : 0 : uint32_t alg_bytesize = cookie->alg_bytesize;
982 : :
983 [ # # ]: 0 : if (asym_op->sm2.op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
984 : : return RTE_CRYPTO_OP_STATUS_SUCCESS;
985 : :
986 [ # # ]: 0 : rte_memcpy(asym_op->sm2.r.data, cookie->output_array[0], alg_bytesize);
987 [ # # ]: 0 : rte_memcpy(asym_op->sm2.s.data, cookie->output_array[1], alg_bytesize);
988 : 0 : asym_op->sm2.r.length = alg_bytesize;
989 : 0 : asym_op->sm2.s.length = alg_bytesize;
990 : :
991 : : HEXDUMP("SM2 R", cookie->output_array[0],
992 : : alg_bytesize);
993 : : HEXDUMP("SM2 S", cookie->output_array[1],
994 : : alg_bytesize);
995 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
996 : : }
997 : :
998 : : static int
999 : 0 : sm2_encryption_set_input(struct icp_qat_fw_pke_request *qat_req,
1000 : : struct qat_asym_op_cookie *cookie,
1001 : : const struct rte_crypto_asym_op *asym_op,
1002 : : const struct rte_crypto_asym_xform *xform)
1003 : : {
1004 : : const struct qat_asym_function qat_function =
1005 : : get_sm2_encryption_function();
1006 : : const uint32_t qat_func_alignsize =
1007 : : qat_function.bytesize;
1008 : :
1009 [ # # ]: 0 : SET_PKE_LN(asym_op->sm2.k, qat_func_alignsize, 0);
1010 [ # # ]: 0 : SET_PKE_LN(xform->ec.q.x, qat_func_alignsize, 1);
1011 [ # # ]: 0 : SET_PKE_LN(xform->ec.q.y, qat_func_alignsize, 2);
1012 : :
1013 : 0 : cookie->alg_bytesize = qat_function.bytesize;
1014 : 0 : cookie->qat_func_alignsize = qat_function.bytesize;
1015 : 0 : qat_req->pke_hdr.cd_pars.func_id = qat_function.func_id;
1016 : 0 : qat_req->input_param_count = 3;
1017 : 0 : qat_req->output_param_count = 4;
1018 : :
1019 : : HEXDUMP("SM2 K", cookie->input_array[0],
1020 : : qat_func_alignsize);
1021 : : HEXDUMP("SM2 Q.x", cookie->input_array[1],
1022 : : qat_func_alignsize);
1023 : : HEXDUMP("SM2 Q.y", cookie->input_array[2],
1024 : : qat_func_alignsize);
1025 : :
1026 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
1027 : : }
1028 : :
1029 : : static uint8_t
1030 : 0 : sm2_encryption_collect(struct rte_crypto_asym_op *asym_op,
1031 : : const struct qat_asym_op_cookie *cookie)
1032 : : {
1033 : 0 : uint32_t alg_bytesize = cookie->alg_bytesize;
1034 : :
1035 [ # # ]: 0 : rte_memcpy(asym_op->sm2.c1.x.data, cookie->output_array[0], alg_bytesize);
1036 [ # # ]: 0 : rte_memcpy(asym_op->sm2.c1.y.data, cookie->output_array[1], alg_bytesize);
1037 [ # # ]: 0 : rte_memcpy(asym_op->sm2.kp.x.data, cookie->output_array[2], alg_bytesize);
1038 [ # # ]: 0 : rte_memcpy(asym_op->sm2.kp.y.data, cookie->output_array[3], alg_bytesize);
1039 : 0 : asym_op->sm2.c1.x.length = alg_bytesize;
1040 : 0 : asym_op->sm2.c1.y.length = alg_bytesize;
1041 : 0 : asym_op->sm2.kp.x.length = alg_bytesize;
1042 : 0 : asym_op->sm2.kp.y.length = alg_bytesize;
1043 : :
1044 : : HEXDUMP("c1[x1]", cookie->output_array[0],
1045 : : alg_bytesize);
1046 : : HEXDUMP("c1[y]", cookie->output_array[1],
1047 : : alg_bytesize);
1048 : : HEXDUMP("kp[x]", cookie->output_array[2],
1049 : : alg_bytesize);
1050 : : HEXDUMP("kp[y]", cookie->output_array[3],
1051 : : alg_bytesize);
1052 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
1053 : : }
1054 : :
1055 : :
1056 : : static int
1057 : 0 : sm2_decryption_set_input(struct icp_qat_fw_pke_request *qat_req,
1058 : : struct qat_asym_op_cookie *cookie,
1059 : : const struct rte_crypto_asym_op *asym_op,
1060 : : const struct rte_crypto_asym_xform *xform)
1061 : : {
1062 : : const struct qat_asym_function qat_function =
1063 : : get_sm2_decryption_function();
1064 : : const uint32_t qat_func_alignsize =
1065 : : qat_function.bytesize;
1066 : :
1067 [ # # ]: 0 : SET_PKE_LN(xform->ec.pkey, qat_func_alignsize, 0);
1068 [ # # ]: 0 : SET_PKE_LN(asym_op->sm2.c1.x, qat_func_alignsize, 1);
1069 [ # # ]: 0 : SET_PKE_LN(asym_op->sm2.c1.y, qat_func_alignsize, 2);
1070 : :
1071 : 0 : cookie->alg_bytesize = qat_function.bytesize;
1072 : 0 : cookie->qat_func_alignsize = qat_function.bytesize;
1073 : 0 : qat_req->pke_hdr.cd_pars.func_id = qat_function.func_id;
1074 : 0 : qat_req->input_param_count = 3;
1075 : 0 : qat_req->output_param_count = 2;
1076 : :
1077 : : HEXDUMP("d", cookie->input_array[0],
1078 : : qat_func_alignsize);
1079 : : HEXDUMP("c1[x]", cookie->input_array[1],
1080 : : qat_func_alignsize);
1081 : : HEXDUMP("c1[y]", cookie->input_array[2],
1082 : : qat_func_alignsize);
1083 : :
1084 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
1085 : : }
1086 : :
1087 : :
1088 : : static uint8_t
1089 : 0 : sm2_decryption_collect(struct rte_crypto_asym_op *asym_op,
1090 : : const struct qat_asym_op_cookie *cookie)
1091 : : {
1092 : 0 : uint32_t alg_bytesize = cookie->alg_bytesize;
1093 : :
1094 [ # # ]: 0 : rte_memcpy(asym_op->sm2.kp.x.data, cookie->output_array[0], alg_bytesize);
1095 [ # # ]: 0 : rte_memcpy(asym_op->sm2.kp.y.data, cookie->output_array[1], alg_bytesize);
1096 : 0 : asym_op->sm2.kp.x.length = alg_bytesize;
1097 : 0 : asym_op->sm2.kp.y.length = alg_bytesize;
1098 : :
1099 : : HEXDUMP("kp[x]", cookie->output_array[0],
1100 : : alg_bytesize);
1101 : : HEXDUMP("kp[y]", cookie->output_array[1],
1102 : : alg_bytesize);
1103 : 0 : return RTE_CRYPTO_OP_STATUS_SUCCESS;
1104 : : }
1105 : :
1106 : : static int
1107 : 0 : asym_set_input(struct icp_qat_fw_pke_request *qat_req,
1108 : : struct qat_asym_op_cookie *cookie,
1109 : : const struct rte_crypto_asym_op *asym_op,
1110 : : const struct rte_crypto_asym_xform *xform,
1111 : : uint8_t legacy_alg)
1112 : : {
1113 [ # # # # : 0 : switch (xform->xform_type) {
# # # # ]
1114 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
1115 : 0 : return modexp_set_input(qat_req, cookie, asym_op, xform);
1116 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODINV:
1117 : 0 : return modinv_set_input(qat_req, cookie, asym_op, xform);
1118 : 0 : case RTE_CRYPTO_ASYM_XFORM_RSA:{
1119 [ # # # # ]: 0 : if (unlikely((xform->rsa.n.length < RSA_MODULUS_2048_BITS)
1120 : : && (legacy_alg == 0)))
1121 : : return RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1122 : 0 : return rsa_set_input(qat_req, cookie, asym_op, xform);
1123 : : }
1124 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
1125 : 0 : return ecdsa_set_input(qat_req, cookie, asym_op, xform);
1126 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECPM:
1127 : 0 : return ecpm_set_input(qat_req, cookie, asym_op, xform);
1128 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDH:
1129 [ # # ]: 0 : if (asym_op->ecdh.ke_type ==
1130 : : RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY) {
1131 : 0 : return ecdh_verify_set_input(qat_req, cookie,
1132 : : asym_op, xform);
1133 : : } else {
1134 : 0 : return ecdh_set_input(qat_req, cookie,
1135 : : asym_op, xform);
1136 : : }
1137 : 0 : case RTE_CRYPTO_ASYM_XFORM_SM2:
1138 [ # # ]: 0 : if (asym_op->sm2.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
1139 : 0 : return sm2_encryption_set_input(qat_req, cookie,
1140 : : asym_op, xform);
1141 [ # # ]: 0 : } else if (asym_op->sm2.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
1142 : 0 : return sm2_decryption_set_input(qat_req, cookie,
1143 : : asym_op, xform);
1144 [ # # ]: 0 : } else if (asym_op->sm2.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
1145 : 0 : return sm2_ecdsa_verify_set_input(qat_req, cookie,
1146 : : asym_op, xform);
1147 [ # # ]: 0 : } else if (asym_op->sm2.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
1148 : 0 : return sm2_ecdsa_sign_set_input(qat_req, cookie,
1149 : : asym_op, xform);
1150 : : }
1151 : : break;
1152 : 0 : default:
1153 : 0 : QAT_LOG(ERR, "Invalid/unsupported asymmetric crypto xform");
1154 : 0 : return -EINVAL;
1155 : : }
1156 : : return 1;
1157 : : }
1158 : :
1159 : : static int
1160 : 0 : qat_asym_build_request(void *in_op,
1161 : : uint8_t *out_msg,
1162 : : void *op_cookie,
1163 : : struct qat_qp *qp)
1164 : : {
1165 : : struct rte_crypto_op *op = (struct rte_crypto_op *)in_op;
1166 : 0 : struct rte_crypto_asym_op *asym_op = op->asym;
1167 : : struct icp_qat_fw_pke_request *qat_req =
1168 : : (struct icp_qat_fw_pke_request *)out_msg;
1169 : : struct qat_asym_op_cookie *cookie =
1170 : : (struct qat_asym_op_cookie *)op_cookie;
1171 : : struct rte_crypto_asym_xform *xform;
1172 : : struct qat_asym_session *qat_session = (struct qat_asym_session *)
1173 : 0 : op->asym->session->sess_private_data;
1174 : : int err = 0;
1175 : :
1176 : 0 : op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
1177 [ # # # ]: 0 : switch (op->sess_type) {
1178 : : case RTE_CRYPTO_OP_WITH_SESSION:
1179 : : request_init(qat_req);
1180 : : if (unlikely(qat_session == NULL)) {
1181 : : QAT_DP_LOG(ERR,
1182 : : "Session was not created for this device");
1183 : : op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
1184 : : goto error;
1185 : : }
1186 : 0 : xform = &qat_session->xform;
1187 : 0 : break;
1188 : : case RTE_CRYPTO_OP_SESSIONLESS:
1189 : : request_init(qat_req);
1190 : 0 : xform = op->asym->xform;
1191 : 0 : break;
1192 : 0 : default:
1193 : 0 : QAT_DP_LOG(ERR, "Invalid session/xform settings");
1194 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;
1195 : 0 : goto error;
1196 : : }
1197 : 0 : err = asym_set_input(qat_req, cookie, asym_op, xform,
1198 : 0 : qp->qat_dev->options.legacy_alg);
1199 [ # # ]: 0 : if (err) {
1200 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1201 : 0 : goto error;
1202 : : }
1203 : :
1204 : 0 : qat_req->pke_mid.opaque = (uint64_t)(uintptr_t)op;
1205 : 0 : qat_req->pke_mid.src_data_addr = cookie->input_addr;
1206 : 0 : qat_req->pke_mid.dest_data_addr = cookie->output_addr;
1207 : :
1208 : : HEXDUMP("qat_req:", qat_req, sizeof(struct icp_qat_fw_pke_request));
1209 : :
1210 : 0 : return 0;
1211 : 0 : error:
1212 : 0 : qat_req->pke_mid.opaque = (uint64_t)(uintptr_t)op;
1213 : : HEXDUMP("qat_req:", qat_req, sizeof(struct icp_qat_fw_pke_request));
1214 : 0 : qat_req->output_param_count = 0;
1215 : 0 : qat_req->input_param_count = 0;
1216 : 0 : qat_req->pke_hdr.service_type = ICP_QAT_FW_COMN_REQ_NULL;
1217 : 0 : cookie->error |= err;
1218 : :
1219 : 0 : return 0;
1220 : : }
1221 : :
1222 : : static uint8_t
1223 : 0 : qat_asym_collect_response(struct rte_crypto_op *op,
1224 : : struct qat_asym_op_cookie *cookie,
1225 : : struct rte_crypto_asym_xform *xform)
1226 : : {
1227 : 0 : struct rte_crypto_asym_op *asym_op = op->asym;
1228 : :
1229 [ # # # # : 0 : switch (xform->xform_type) {
# # # # ]
1230 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
1231 : 0 : return modexp_collect(asym_op, cookie, xform);
1232 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODINV:
1233 : 0 : return modinv_collect(asym_op, cookie, xform);
1234 : 0 : case RTE_CRYPTO_ASYM_XFORM_RSA:
1235 : 0 : return rsa_collect(asym_op, cookie, xform);
1236 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
1237 : 0 : return ecdsa_collect(asym_op, cookie);
1238 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECPM:
1239 : 0 : return ecpm_collect(asym_op, cookie);
1240 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDH:
1241 : 0 : return ecdh_collect(asym_op, cookie);
1242 : 0 : case RTE_CRYPTO_ASYM_XFORM_SM2:
1243 [ # # ]: 0 : if (asym_op->sm2.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT)
1244 : 0 : return sm2_encryption_collect(asym_op, cookie);
1245 [ # # ]: 0 : else if (asym_op->sm2.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT)
1246 : 0 : return sm2_decryption_collect(asym_op, cookie);
1247 : : else
1248 : 0 : return sm2_ecdsa_sign_collect(asym_op, cookie);
1249 : :
1250 : 0 : default:
1251 : 0 : QAT_LOG(ERR, "Not supported xform type");
1252 : 0 : return RTE_CRYPTO_OP_STATUS_ERROR;
1253 : : }
1254 : : }
1255 : :
1256 : : static int
1257 : 0 : qat_asym_process_response(void **out_op, uint8_t *resp,
1258 : : void *op_cookie, __rte_unused uint64_t *dequeue_err_count)
1259 : : {
1260 : : struct icp_qat_fw_pke_resp *resp_msg =
1261 : : (struct icp_qat_fw_pke_resp *)resp;
1262 : 0 : struct rte_crypto_op *op = (struct rte_crypto_op *)(uintptr_t)
1263 : 0 : (resp_msg->opaque);
1264 : : struct qat_asym_op_cookie *cookie = op_cookie;
1265 : : struct rte_crypto_asym_xform *xform = NULL;
1266 : : struct qat_asym_session *qat_session = (struct qat_asym_session *)
1267 : 0 : op->asym->session->sess_private_data;
1268 : :
1269 : 0 : *out_op = op;
1270 [ # # ]: 0 : if (cookie->error) {
1271 : 0 : cookie->error = 0;
1272 [ # # ]: 0 : if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
1273 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1274 : 0 : QAT_DP_LOG(DEBUG, "Cookie status returned error");
1275 : : } else {
1276 [ # # ]: 0 : if (ICP_QAT_FW_PKE_RESP_PKE_STAT_GET(
1277 : : resp_msg->pke_resp_hdr.resp_status.pke_resp_flags)) {
1278 [ # # ]: 0 : if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
1279 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1280 : 0 : QAT_DP_LOG(DEBUG, "Asymmetric response status"
1281 : : " returned error");
1282 : : }
1283 [ # # ]: 0 : if (resp_msg->pke_resp_hdr.resp_status.comn_err_code) {
1284 [ # # ]: 0 : if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
1285 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1286 : 0 : QAT_DP_LOG(ERR, "Asymmetric common status"
1287 : : " returned error");
1288 : : }
1289 : : }
1290 : :
1291 [ # # # ]: 0 : switch (op->sess_type) {
1292 : 0 : case RTE_CRYPTO_OP_WITH_SESSION:
1293 : 0 : xform = &qat_session->xform;
1294 : 0 : break;
1295 : 0 : case RTE_CRYPTO_OP_SESSIONLESS:
1296 : 0 : xform = op->asym->xform;
1297 : 0 : break;
1298 : 0 : default:
1299 : 0 : QAT_DP_LOG(ERR,
1300 : : "Invalid session/xform settings in response ring!");
1301 : 0 : op->status = RTE_CRYPTO_OP_STATUS_ERROR;
1302 : : }
1303 [ # # ]: 0 : if (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED)
1304 : 0 : op->status = qat_asym_collect_response(op, cookie, xform);
1305 : : HEXDUMP("resp_msg:", resp_msg, sizeof(struct icp_qat_fw_pke_resp));
1306 [ # # ]: 0 : if (likely(xform != NULL))
1307 : 0 : cleanup(cookie, xform);
1308 : :
1309 : 0 : return 1;
1310 : : }
1311 : :
1312 : : static int
1313 : 0 : session_set_modexp(struct qat_asym_session *qat_session,
1314 : : struct rte_crypto_asym_xform *xform)
1315 : : {
1316 : 0 : uint8_t *modulus = xform->modex.modulus.data;
1317 : 0 : uint8_t *exponent = xform->modex.exponent.data;
1318 : :
1319 : 0 : qat_session->xform.modex.modulus.data =
1320 : 0 : rte_malloc(NULL, xform->modex.modulus.length, 0);
1321 [ # # ]: 0 : if (qat_session->xform.modex.modulus.data == NULL)
1322 : : return -ENOMEM;
1323 : 0 : qat_session->xform.modex.modulus.length = xform->modex.modulus.length;
1324 : 0 : qat_session->xform.modex.exponent.data = rte_malloc(NULL,
1325 : : xform->modex.exponent.length, 0);
1326 [ # # ]: 0 : if (qat_session->xform.modex.exponent.data == NULL) {
1327 : 0 : rte_free(qat_session->xform.modex.exponent.data);
1328 : 0 : return -ENOMEM;
1329 : : }
1330 : 0 : qat_session->xform.modex.exponent.length = xform->modex.exponent.length;
1331 : :
1332 [ # # ]: 0 : rte_memcpy(qat_session->xform.modex.modulus.data, modulus,
1333 : : xform->modex.modulus.length);
1334 [ # # ]: 0 : rte_memcpy(qat_session->xform.modex.exponent.data, exponent,
1335 : : xform->modex.exponent.length);
1336 : :
1337 : : return 0;
1338 : : }
1339 : :
1340 : : static int
1341 : 0 : session_set_modinv(struct qat_asym_session *qat_session,
1342 : : struct rte_crypto_asym_xform *xform)
1343 : : {
1344 : 0 : uint8_t *modulus = xform->modinv.modulus.data;
1345 : :
1346 : 0 : qat_session->xform.modinv.modulus.data =
1347 : 0 : rte_malloc(NULL, xform->modinv.modulus.length, 0);
1348 [ # # ]: 0 : if (qat_session->xform.modinv.modulus.data == NULL)
1349 : : return -ENOMEM;
1350 : 0 : qat_session->xform.modinv.modulus.length = xform->modinv.modulus.length;
1351 : :
1352 [ # # ]: 0 : rte_memcpy(qat_session->xform.modinv.modulus.data, modulus,
1353 : : xform->modinv.modulus.length);
1354 : :
1355 : : return 0;
1356 : : }
1357 : :
1358 : : static int
1359 : 0 : session_set_rsa(struct qat_asym_session *qat_session,
1360 : : struct rte_crypto_asym_xform *xform)
1361 : : {
1362 : 0 : uint8_t *n = xform->rsa.n.data;
1363 : 0 : uint8_t *e = xform->rsa.e.data;
1364 : : int ret = 0;
1365 : :
1366 : 0 : qat_session->xform.rsa.key_type = xform->rsa.key_type;
1367 : :
1368 : 0 : qat_session->xform.rsa.n.data =
1369 : 0 : rte_malloc(NULL, xform->rsa.n.length, 0);
1370 [ # # ]: 0 : if (qat_session->xform.rsa.n.data == NULL)
1371 : : return -ENOMEM;
1372 : 0 : qat_session->xform.rsa.n.length =
1373 : 0 : xform->rsa.n.length;
1374 : :
1375 : 0 : qat_session->xform.rsa.e.data =
1376 : 0 : rte_malloc(NULL, xform->rsa.e.length, 0);
1377 [ # # ]: 0 : if (qat_session->xform.rsa.e.data == NULL) {
1378 : : ret = -ENOMEM;
1379 : 0 : goto err;
1380 : : }
1381 : 0 : qat_session->xform.rsa.e.length =
1382 : 0 : xform->rsa.e.length;
1383 : :
1384 [ # # ]: 0 : if (xform->rsa.key_type == RTE_RSA_KEY_TYPE_QT) {
1385 : 0 : uint8_t *p = xform->rsa.qt.p.data;
1386 : 0 : uint8_t *q = xform->rsa.qt.q.data;
1387 : 0 : uint8_t *dP = xform->rsa.qt.dP.data;
1388 : 0 : uint8_t *dQ = xform->rsa.qt.dQ.data;
1389 : 0 : uint8_t *qInv = xform->rsa.qt.qInv.data;
1390 : :
1391 : 0 : qat_session->xform.rsa.qt.p.data =
1392 : 0 : rte_malloc(NULL, xform->rsa.qt.p.length, 0);
1393 [ # # ]: 0 : if (qat_session->xform.rsa.qt.p.data == NULL) {
1394 : : ret = -ENOMEM;
1395 : 0 : goto err;
1396 : : }
1397 : 0 : qat_session->xform.rsa.qt.p.length =
1398 : 0 : xform->rsa.qt.p.length;
1399 : :
1400 : 0 : qat_session->xform.rsa.qt.q.data =
1401 : 0 : rte_malloc(NULL, xform->rsa.qt.q.length, 0);
1402 [ # # ]: 0 : if (qat_session->xform.rsa.qt.q.data == NULL) {
1403 : : ret = -ENOMEM;
1404 : 0 : goto err;
1405 : : }
1406 : 0 : qat_session->xform.rsa.qt.q.length =
1407 : 0 : xform->rsa.qt.q.length;
1408 : :
1409 : 0 : qat_session->xform.rsa.qt.dP.data =
1410 : 0 : rte_malloc(NULL, xform->rsa.qt.dP.length, 0);
1411 [ # # ]: 0 : if (qat_session->xform.rsa.qt.dP.data == NULL) {
1412 : : ret = -ENOMEM;
1413 : 0 : goto err;
1414 : : }
1415 : 0 : qat_session->xform.rsa.qt.dP.length =
1416 : 0 : xform->rsa.qt.dP.length;
1417 : :
1418 : 0 : qat_session->xform.rsa.qt.dQ.data =
1419 : 0 : rte_malloc(NULL, xform->rsa.qt.dQ.length, 0);
1420 [ # # ]: 0 : if (qat_session->xform.rsa.qt.dQ.data == NULL) {
1421 : : ret = -ENOMEM;
1422 : 0 : goto err;
1423 : : }
1424 : 0 : qat_session->xform.rsa.qt.dQ.length =
1425 : 0 : xform->rsa.qt.dQ.length;
1426 : :
1427 : 0 : qat_session->xform.rsa.qt.qInv.data =
1428 : 0 : rte_malloc(NULL, xform->rsa.qt.qInv.length, 0);
1429 [ # # ]: 0 : if (qat_session->xform.rsa.qt.qInv.data == NULL) {
1430 : : ret = -ENOMEM;
1431 : 0 : goto err;
1432 : : }
1433 : 0 : qat_session->xform.rsa.qt.qInv.length =
1434 : 0 : xform->rsa.qt.qInv.length;
1435 : :
1436 [ # # ]: 0 : rte_memcpy(qat_session->xform.rsa.qt.p.data, p,
1437 : : xform->rsa.qt.p.length);
1438 [ # # ]: 0 : rte_memcpy(qat_session->xform.rsa.qt.q.data, q,
1439 : : xform->rsa.qt.q.length);
1440 [ # # ]: 0 : rte_memcpy(qat_session->xform.rsa.qt.dP.data, dP,
1441 : : xform->rsa.qt.dP.length);
1442 [ # # ]: 0 : rte_memcpy(qat_session->xform.rsa.qt.dQ.data, dQ,
1443 : : xform->rsa.qt.dQ.length);
1444 [ # # ]: 0 : rte_memcpy(qat_session->xform.rsa.qt.qInv.data, qInv,
1445 : : xform->rsa.qt.qInv.length);
1446 : :
1447 : : } else {
1448 : 0 : uint8_t *d = xform->rsa.d.data;
1449 : :
1450 : 0 : qat_session->xform.rsa.d.data =
1451 : 0 : rte_malloc(NULL, xform->rsa.d.length, 0);
1452 [ # # ]: 0 : if (qat_session->xform.rsa.d.data == NULL) {
1453 : : ret = -ENOMEM;
1454 : 0 : goto err;
1455 : : }
1456 : 0 : qat_session->xform.rsa.d.length =
1457 : 0 : xform->rsa.d.length;
1458 [ # # ]: 0 : rte_memcpy(qat_session->xform.rsa.d.data, d,
1459 : : xform->rsa.d.length);
1460 : : }
1461 : :
1462 [ # # ]: 0 : rte_memcpy(qat_session->xform.rsa.n.data, n,
1463 : : xform->rsa.n.length);
1464 [ # # ]: 0 : rte_memcpy(qat_session->xform.rsa.e.data, e,
1465 : : xform->rsa.e.length);
1466 : :
1467 : : return 0;
1468 : :
1469 : 0 : err:
1470 : 0 : rte_free(qat_session->xform.rsa.n.data);
1471 : 0 : rte_free(qat_session->xform.rsa.e.data);
1472 : 0 : rte_free(qat_session->xform.rsa.d.data);
1473 : 0 : rte_free(qat_session->xform.rsa.qt.p.data);
1474 : 0 : rte_free(qat_session->xform.rsa.qt.q.data);
1475 : 0 : rte_free(qat_session->xform.rsa.qt.dP.data);
1476 : 0 : rte_free(qat_session->xform.rsa.qt.dQ.data);
1477 : 0 : rte_free(qat_session->xform.rsa.qt.qInv.data);
1478 : 0 : return ret;
1479 : : }
1480 : :
1481 : : static int
1482 : 0 : session_set_ec(struct qat_asym_session *qat_session,
1483 : : struct rte_crypto_asym_xform *xform)
1484 : : {
1485 : : /* Validate curve for EC operations using pick_curve (not SM2) */
1486 [ # # ]: 0 : if (xform->xform_type != RTE_CRYPTO_ASYM_XFORM_SM2) {
1487 [ # # ]: 0 : if (pick_curve(xform) < 0)
1488 : : return -ENOTSUP;
1489 : : }
1490 : :
1491 : 0 : uint8_t *pkey = xform->ec.pkey.data;
1492 : 0 : uint8_t *q_x = xform->ec.q.x.data;
1493 : 0 : uint8_t *q_y = xform->ec.q.y.data;
1494 : :
1495 [ # # ]: 0 : if (xform->ec.pkey.length) {
1496 : 0 : qat_session->xform.ec.pkey.data =
1497 : 0 : rte_malloc(NULL, xform->ec.pkey.length, 0);
1498 [ # # ]: 0 : if (qat_session->xform.ec.pkey.data == NULL)
1499 : : return -ENOMEM;
1500 : 0 : memcpy(qat_session->xform.ec.pkey.data, pkey,
1501 : : xform->ec.pkey.length);
1502 : 0 : qat_session->xform.ec.pkey.length = xform->ec.pkey.length;
1503 : : }
1504 [ # # ]: 0 : if (xform->ec.q.x.length) {
1505 : 0 : qat_session->xform.ec.q.x.data = rte_malloc(NULL,
1506 : : xform->ec.q.x.length, 0);
1507 [ # # ]: 0 : if (qat_session->xform.ec.q.x.data == NULL) {
1508 : 0 : rte_free(qat_session->xform.ec.pkey.data);
1509 : 0 : return -ENOMEM;
1510 : : }
1511 : 0 : memcpy(qat_session->xform.ec.q.x.data, q_x,
1512 : : xform->ec.q.x.length);
1513 : 0 : qat_session->xform.ec.q.x.length = xform->ec.q.x.length;
1514 : : }
1515 [ # # ]: 0 : if (xform->ec.q.y.length) {
1516 : 0 : qat_session->xform.ec.q.y.data = rte_malloc(NULL,
1517 : : xform->ec.q.y.length, 0);
1518 [ # # ]: 0 : if (qat_session->xform.ec.q.y.data == NULL) {
1519 : 0 : rte_free(qat_session->xform.ec.pkey.data);
1520 : 0 : rte_free(qat_session->xform.ec.q.x.data);
1521 : 0 : return -ENOMEM;
1522 : : }
1523 : 0 : memcpy(qat_session->xform.ec.q.y.data, q_y,
1524 : : xform->ec.q.y.length);
1525 : 0 : qat_session->xform.ec.q.y.length = xform->ec.q.y.length;
1526 : : }
1527 : 0 : qat_session->xform.ec.curve_id = xform->ec.curve_id;
1528 : :
1529 : 0 : return 0;
1530 : :
1531 : : }
1532 : :
1533 : : int
1534 : 0 : qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
1535 : : struct rte_crypto_asym_xform *xform,
1536 : : struct rte_cryptodev_asym_session *session)
1537 : : {
1538 : : struct qat_cryptodev_private *crypto_qat;
1539 : : struct qat_asym_session *qat_session;
1540 : : int ret = 0;
1541 : :
1542 : 0 : crypto_qat = dev->data->dev_private;
1543 [ # # # # : 0 : qat_session = (struct qat_asym_session *) session->sess_private_data;
# ]
1544 : : memset(qat_session, 0, sizeof(*qat_session));
1545 : :
1546 : 0 : qat_session->xform.xform_type = xform->xform_type;
1547 [ # # # # : 0 : switch (xform->xform_type) {
# ]
1548 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
1549 : 0 : ret = session_set_modexp(qat_session, xform);
1550 : 0 : break;
1551 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODINV:
1552 : 0 : ret = session_set_modinv(qat_session, xform);
1553 : 0 : break;
1554 : 0 : case RTE_CRYPTO_ASYM_XFORM_RSA: {
1555 [ # # ]: 0 : if (xform->rsa.padding.type != RTE_CRYPTO_RSA_PADDING_NONE) {
1556 : : ret = -ENOTSUP;
1557 : : return ret;
1558 : : }
1559 [ # # # # ]: 0 : if (unlikely((xform->rsa.n.length < RSA_MODULUS_2048_BITS)
1560 : : && (crypto_qat->qat_dev->options.legacy_alg == 0))) {
1561 : : ret = -ENOTSUP;
1562 : : return ret;
1563 : : }
1564 : 0 : ret = session_set_rsa(qat_session, xform);
1565 : : }
1566 : 0 : break;
1567 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
1568 : : case RTE_CRYPTO_ASYM_XFORM_ECPM:
1569 : : case RTE_CRYPTO_ASYM_XFORM_ECDH:
1570 : : case RTE_CRYPTO_ASYM_XFORM_SM2:
1571 : 0 : ret = session_set_ec(qat_session, xform);
1572 : 0 : break;
1573 : : default:
1574 : : ret = -ENOTSUP;
1575 : : }
1576 : :
1577 [ # # ]: 0 : if (ret) {
1578 : 0 : QAT_LOG(ERR, "Unsupported xform type");
1579 : 0 : return ret;
1580 : : }
1581 : :
1582 : : return 0;
1583 : : }
1584 : :
1585 : : unsigned int
1586 : 0 : qat_asym_session_get_private_size(struct rte_cryptodev *dev __rte_unused)
1587 : : {
1588 : 0 : return RTE_ALIGN_CEIL(sizeof(struct qat_asym_session), 8);
1589 : : }
1590 : :
1591 : : static void
1592 : : session_clear_modexp(struct rte_crypto_modex_xform *modex)
1593 : : {
1594 : 0 : PARAM_CLR(modex->modulus);
1595 : 0 : PARAM_CLR(modex->exponent);
1596 : 0 : }
1597 : :
1598 : : static void
1599 : : session_clear_modinv(struct rte_crypto_modinv_xform *modinv)
1600 : : {
1601 : 0 : PARAM_CLR(modinv->modulus);
1602 : 0 : }
1603 : :
1604 : : static void
1605 : 0 : session_clear_rsa(struct rte_crypto_rsa_xform *rsa)
1606 : : {
1607 : 0 : PARAM_CLR(rsa->n);
1608 : 0 : PARAM_CLR(rsa->e);
1609 [ # # ]: 0 : if (rsa->key_type == RTE_RSA_KEY_TYPE_EXP) {
1610 : 0 : PARAM_CLR(rsa->d);
1611 : : } else {
1612 : 0 : PARAM_CLR(rsa->qt.p);
1613 : 0 : PARAM_CLR(rsa->qt.q);
1614 : 0 : PARAM_CLR(rsa->qt.dP);
1615 : 0 : PARAM_CLR(rsa->qt.dQ);
1616 : 0 : PARAM_CLR(rsa->qt.qInv);
1617 : : }
1618 : 0 : }
1619 : :
1620 : : static void
1621 : 0 : session_clear_xform(struct qat_asym_session *qat_session)
1622 : : {
1623 [ # # # # ]: 0 : switch (qat_session->xform.xform_type) {
1624 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
1625 : : session_clear_modexp(&qat_session->xform.modex);
1626 : : break;
1627 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODINV:
1628 : : session_clear_modinv(&qat_session->xform.modinv);
1629 : : break;
1630 : 0 : case RTE_CRYPTO_ASYM_XFORM_RSA:
1631 : 0 : session_clear_rsa(&qat_session->xform.rsa);
1632 : 0 : break;
1633 : : default:
1634 : : break;
1635 : : }
1636 : 0 : }
1637 : :
1638 : : void
1639 : 0 : qat_asym_session_clear(struct rte_cryptodev *dev,
1640 : : struct rte_cryptodev_asym_session *session)
1641 : : {
1642 : 0 : void *sess_priv = session->sess_private_data;
1643 : : struct qat_asym_session *qat_session =
1644 : : (struct qat_asym_session *)sess_priv;
1645 : :
1646 : : if (sess_priv) {
1647 : 0 : session_clear_xform(qat_session);
1648 : 0 : memset(qat_session, 0, qat_asym_session_get_private_size(dev));
1649 : : }
1650 : 0 : }
1651 : :
1652 : : static uint16_t
1653 : 0 : qat_asym_crypto_enqueue_op_burst(void *qp, struct rte_crypto_op **ops,
1654 : : uint16_t nb_ops)
1655 : : {
1656 : 0 : return qat_enqueue_op_burst(qp, qat_asym_build_request, (void **)ops,
1657 : : nb_ops);
1658 : : }
1659 : :
1660 : : static uint16_t
1661 : 0 : qat_asym_crypto_dequeue_op_burst(void *qp, struct rte_crypto_op **ops,
1662 : : uint16_t nb_ops)
1663 : : {
1664 : 0 : return qat_dequeue_op_burst(qp, (void **)ops, qat_asym_process_response,
1665 : : nb_ops);
1666 : : }
1667 : :
1668 : : void
1669 : 0 : qat_asym_init_op_cookie(void *op_cookie)
1670 : : {
1671 : : int j;
1672 : : struct qat_asym_op_cookie *cookie = op_cookie;
1673 : :
1674 : 0 : cookie->input_addr = rte_mempool_virt2iova(cookie) +
1675 : : offsetof(struct qat_asym_op_cookie,
1676 : : input_params_ptrs);
1677 : :
1678 : 0 : cookie->output_addr = rte_mempool_virt2iova(cookie) +
1679 : : offsetof(struct qat_asym_op_cookie,
1680 : : output_params_ptrs);
1681 : :
1682 [ # # ]: 0 : for (j = 0; j < 8; j++) {
1683 : 0 : cookie->input_params_ptrs[j] =
1684 : 0 : rte_mempool_virt2iova(cookie) +
1685 : : offsetof(struct qat_asym_op_cookie,
1686 : : input_array[j]);
1687 : 0 : cookie->output_params_ptrs[j] =
1688 : 0 : rte_mempool_virt2iova(cookie) +
1689 : : offsetof(struct qat_asym_op_cookie,
1690 : : output_array[j]);
1691 : : }
1692 : 0 : }
1693 : :
1694 : : static int
1695 : 0 : qat_asym_dev_create(struct qat_pci_device *qat_pci_dev)
1696 : : {
1697 : : struct qat_cryptodev_private *internals;
1698 : : struct rte_cryptodev *cryptodev;
1699 : : struct qat_device_info *qat_dev_instance =
1700 : 0 : &qat_pci_devs[qat_pci_dev->qat_dev_id];
1701 : 0 : struct rte_cryptodev_pmd_init_params init_params = {
1702 : : .name = "",
1703 : 0 : .socket_id = qat_dev_instance->pci_dev->device.numa_node,
1704 : : .private_data_size = sizeof(struct qat_cryptodev_private)
1705 : : };
1706 : : const struct qat_crypto_gen_dev_ops *gen_dev_ops =
1707 : 0 : &qat_asym_gen_dev_ops[qat_pci_dev->qat_dev_gen];
1708 : : char name[RTE_CRYPTODEV_NAME_MAX_LEN];
1709 : : char capa_memz_name[RTE_CRYPTODEV_NAME_MAX_LEN];
1710 : 0 : uint16_t sub_id = qat_dev_instance->pci_dev->id.subsystem_device_id;
1711 : : const char *cmdline = NULL;
1712 : :
1713 : : snprintf(name, RTE_CRYPTODEV_NAME_MAX_LEN, "%s_%s",
1714 : 0 : qat_pci_dev->name, "asym");
1715 : 0 : QAT_LOG(DEBUG, "Creating QAT ASYM device %s", name);
1716 : :
1717 [ # # # # ]: 0 : if (qat_pci_dev->qat_dev_gen == QAT_VQAT &&
1718 : : sub_id != ADF_VQAT_ASYM_PCI_SUBSYSTEM_ID) {
1719 : 0 : QAT_LOG(ERR, "Device (vqat instance) %s does not support asymmetric crypto",
1720 : : name);
1721 : 0 : return -EFAULT;
1722 : : }
1723 [ # # ]: 0 : if (gen_dev_ops->cryptodev_ops == NULL) {
1724 : 0 : QAT_LOG(ERR, "Device %s does not support asymmetric crypto",
1725 : : name);
1726 : 0 : return -(EFAULT);
1727 : : }
1728 : :
1729 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1730 : 0 : qat_pci_dev->qat_asym_driver_id =
1731 : : qat_asym_driver_id;
1732 [ # # ]: 0 : } else if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
1733 [ # # ]: 0 : if (qat_pci_dev->qat_asym_driver_id !=
1734 : : qat_asym_driver_id) {
1735 : 0 : QAT_LOG(ERR,
1736 : : "Device %s have different driver id than corresponding device in primary process",
1737 : : name);
1738 : 0 : return -(EFAULT);
1739 : : }
1740 : : }
1741 : :
1742 : : /* Populate subset device to use in cryptodev device creation */
1743 : 0 : qat_dev_instance->asym_rte_dev.driver = &cryptodev_qat_asym_driver;
1744 : 0 : qat_dev_instance->asym_rte_dev.numa_node =
1745 : 0 : qat_dev_instance->pci_dev->device.numa_node;
1746 : 0 : qat_dev_instance->asym_rte_dev.devargs = NULL;
1747 : :
1748 : 0 : cryptodev = rte_cryptodev_pmd_create(name,
1749 : : &(qat_dev_instance->asym_rte_dev), &init_params);
1750 : :
1751 [ # # ]: 0 : if (cryptodev == NULL)
1752 : : return -ENODEV;
1753 : :
1754 : 0 : qat_dev_instance->asym_rte_dev.name = cryptodev->data->name;
1755 : 0 : cryptodev->driver_id = qat_asym_driver_id;
1756 : 0 : cryptodev->dev_ops = gen_dev_ops->cryptodev_ops;
1757 : :
1758 : 0 : cryptodev->enqueue_burst = qat_asym_crypto_enqueue_op_burst;
1759 : 0 : cryptodev->dequeue_burst = qat_asym_crypto_dequeue_op_burst;
1760 : :
1761 : 0 : cryptodev->feature_flags = gen_dev_ops->get_feature_flags(qat_pci_dev);
1762 : :
1763 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1764 : : return 0;
1765 : :
1766 : : snprintf(capa_memz_name, RTE_CRYPTODEV_NAME_MAX_LEN,
1767 : : "QAT_ASYM_CAPA_GEN_%d",
1768 : 0 : qat_pci_dev->qat_dev_gen);
1769 : :
1770 : 0 : internals = cryptodev->data->dev_private;
1771 : 0 : internals->qat_dev = qat_pci_dev;
1772 : 0 : internals->dev_id = cryptodev->data->dev_id;
1773 : :
1774 : 0 : cmdline = qat_dev_cmdline_get_val(qat_pci_dev,
1775 : : ASYM_ENQ_THRESHOLD_NAME);
1776 [ # # ]: 0 : if (cmdline) {
1777 [ # # ]: 0 : internals->min_enq_burst_threshold =
1778 : : atoi(cmdline) > MAX_QP_THRESHOLD_SIZE ?
1779 : : MAX_QP_THRESHOLD_SIZE :
1780 : : atoi(cmdline);
1781 : : }
1782 : :
1783 [ # # ]: 0 : if (qat_pci_dev->options.slice_map & ICP_ACCEL_MASK_PKE_SLICE) {
1784 : 0 : QAT_LOG(ERR, "Device %s does not support PKE slice",
1785 : : name);
1786 : 0 : rte_cryptodev_pmd_destroy(cryptodev);
1787 : : memset(&qat_dev_instance->asym_rte_dev, 0,
1788 : : sizeof(qat_dev_instance->asym_rte_dev));
1789 : 0 : return -1;
1790 : : }
1791 : :
1792 [ # # ]: 0 : if (gen_dev_ops->get_capabilities(internals,
1793 : : capa_memz_name, qat_pci_dev->options.slice_map) < 0) {
1794 : 0 : QAT_LOG(ERR,
1795 : : "Device cannot obtain capabilities, destroying PMD for %s",
1796 : : name);
1797 : 0 : rte_cryptodev_pmd_destroy(cryptodev);
1798 : : memset(&qat_dev_instance->asym_rte_dev, 0,
1799 : : sizeof(qat_dev_instance->asym_rte_dev));
1800 : 0 : return -1;
1801 : : }
1802 : :
1803 : 0 : qat_pci_dev->pmd[QAT_SERVICE_ASYMMETRIC] = internals;
1804 : 0 : internals->service_type = QAT_SERVICE_ASYMMETRIC;
1805 : 0 : QAT_LOG(DEBUG, "Created QAT ASYM device %s as cryptodev instance %d",
1806 : : cryptodev->data->name, internals->dev_id);
1807 : 0 : return 0;
1808 : : }
1809 : :
1810 : : static int
1811 : 0 : qat_asym_dev_destroy(struct qat_pci_device *qat_pci_dev)
1812 : : {
1813 : : struct rte_cryptodev *cryptodev;
1814 : : struct qat_cryptodev_private *dev;
1815 : :
1816 [ # # ]: 0 : if (qat_pci_dev == NULL)
1817 : : return -ENODEV;
1818 : 0 : dev = qat_pci_dev->pmd[QAT_SERVICE_ASYMMETRIC];
1819 [ # # ]: 0 : if (dev == NULL)
1820 : : return 0;
1821 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1822 : 0 : rte_memzone_free(dev->capa_mz);
1823 : : /* free crypto device */
1824 : 0 : cryptodev = rte_cryptodev_pmd_get_dev(dev->dev_id);
1825 : 0 : rte_cryptodev_pmd_destroy(cryptodev);
1826 : 0 : qat_pci_devs[qat_pci_dev->qat_dev_id].asym_rte_dev.name = NULL;
1827 : 0 : qat_pci_dev->pmd[QAT_SERVICE_ASYMMETRIC] = NULL;
1828 : :
1829 : 0 : return 0;
1830 : : }
1831 : :
1832 : : static struct cryptodev_driver qat_crypto_drv;
1833 : 276 : RTE_PMD_REGISTER_CRYPTO_DRIVER(qat_crypto_drv,
1834 : : cryptodev_qat_asym_driver,
1835 : : qat_asym_driver_id);
1836 : :
1837 : 276 : RTE_INIT(qat_asym_init)
1838 : : {
1839 : 276 : qat_cmdline_defines[QAT_SERVICE_ASYMMETRIC] = arguments;
1840 : 276 : qat_service[QAT_SERVICE_ASYMMETRIC].name = "asymmetric crypto";
1841 : 276 : qat_service[QAT_SERVICE_ASYMMETRIC].dev_create = qat_asym_dev_create;
1842 : 276 : qat_service[QAT_SERVICE_ASYMMETRIC].dev_destroy = qat_asym_dev_destroy;
1843 : 276 : }
|