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