Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : :
5 : : #ifndef _CNXK_AE_H_
6 : : #define _CNXK_AE_H_
7 : :
8 : : #include <rte_common.h>
9 : : #include <rte_crypto_asym.h>
10 : : #include <rte_malloc.h>
11 : :
12 : : #include "roc_ae.h"
13 : :
14 : : #include "cnxk_cryptodev_ops.h"
15 : :
16 : : #define ASYM_SESS_SIZE sizeof(struct rte_cryptodev_asym_session)
17 : :
18 : : #define CNXK_AE_EDDSA_MAX_PARAM_LEN 1024
19 : :
20 : : struct cnxk_ae_sess {
21 : : uint8_t rte_sess[ASYM_SESS_SIZE];
22 : : enum rte_crypto_asym_xform_type xfrm_type;
23 : : union {
24 : : struct rte_crypto_rsa_xform rsa_ctx;
25 : : struct rte_crypto_modex_xform mod_ctx;
26 : : struct roc_ae_ec_ctx ec_ctx;
27 : : };
28 : : uint64_t *cnxk_fpm_iova;
29 : : struct roc_ae_ec_group **ec_grp;
30 : : uint64_t cpt_inst_w4;
31 : : uint64_t cpt_inst_w7;
32 : : uint64_t cpt_inst_w2;
33 : : struct cnxk_cpt_qp *qp;
34 : : struct roc_cpt_lf *lf;
35 : : uint64_t msg_max_sz;
36 : : struct hw_ctx_s {
37 : : union {
38 : : struct {
39 : : uint64_t rsvd : 48;
40 : :
41 : : uint64_t ctx_push_size : 7;
42 : : uint64_t rsvd1 : 1;
43 : :
44 : : uint64_t ctx_hdr_size : 2;
45 : : uint64_t aop_valid : 1;
46 : : uint64_t rsvd2 : 1;
47 : : uint64_t ctx_size : 4;
48 : : } s;
49 : : uint64_t u64;
50 : : } w0;
51 : : uint8_t rsvd[256];
52 : : } hw_ctx __plt_aligned(ROC_ALIGN);
53 : : };
54 : :
55 : : static __rte_always_inline void
56 : : cnxk_ae_modex_param_normalize(uint8_t **data, size_t *len, size_t max)
57 : : {
58 : 0 : uint8_t msw_len = *len % 8;
59 : 0 : uint64_t msw_val = 0;
60 : : size_t i;
61 : :
62 [ # # ]: 0 : if (*len <= 8)
63 : 0 : return;
64 : :
65 [ # # # # ]: 0 : memcpy(&msw_val, *data, msw_len);
66 [ # # # # ]: 0 : if (msw_val != 0)
67 : : return;
68 : :
69 [ # # # # : 0 : for (i = msw_len; i < *len && (*len - i) < max; i += 8) {
# # # # ]
70 : 0 : memcpy(&msw_val, &(*data)[i], 8);
71 [ # # # # ]: 0 : if (msw_val != 0)
72 : : break;
73 : : }
74 : 0 : *data += i;
75 : 0 : *len -= i;
76 : : }
77 : :
78 : : static __rte_always_inline int
79 : : cnxk_ae_fill_modex_params(struct cnxk_ae_sess *sess,
80 : : struct rte_crypto_asym_xform *xform)
81 : : {
82 : : struct rte_crypto_modex_xform *ctx = &sess->mod_ctx;
83 : 0 : size_t exp_len = xform->modex.exponent.length;
84 : 0 : size_t mod_len = xform->modex.modulus.length;
85 : 0 : uint8_t *exp = xform->modex.exponent.data;
86 [ # # ]: 0 : uint8_t *mod = xform->modex.modulus.data;
87 : :
88 : : cnxk_ae_modex_param_normalize(&mod, &mod_len, SIZE_MAX);
89 : : cnxk_ae_modex_param_normalize(&exp, &exp_len, mod_len);
90 : :
91 [ # # # # ]: 0 : if (unlikely(exp_len == 0 || mod_len == 0))
92 : : return -EINVAL;
93 : :
94 [ # # ]: 0 : if (unlikely(exp_len > mod_len))
95 : : return -ENOTSUP;
96 : :
97 : : /* Allocate buffer to hold modexp params */
98 : 0 : ctx->modulus.data = rte_malloc(NULL, mod_len + exp_len, 0);
99 [ # # ]: 0 : if (ctx->modulus.data == NULL)
100 : : return -ENOMEM;
101 : :
102 : : /* Set up modexp prime modulus and private exponent */
103 : : memcpy(ctx->modulus.data, mod, mod_len);
104 : 0 : ctx->exponent.data = ctx->modulus.data + mod_len;
105 : : memcpy(ctx->exponent.data, exp, exp_len);
106 : :
107 : 0 : ctx->modulus.length = mod_len;
108 : 0 : ctx->exponent.length = exp_len;
109 : :
110 : : return 0;
111 : : }
112 : :
113 : : static __rte_always_inline int
114 : : cnxk_ae_fill_rsa_params(struct cnxk_ae_sess *sess,
115 : : struct rte_crypto_asym_xform *xform)
116 : : {
117 : 0 : struct rte_crypto_rsa_priv_key_qt qt = xform->rsa.qt;
118 : : struct rte_crypto_rsa_xform *xfrm_rsa = &xform->rsa;
119 : : struct rte_crypto_rsa_xform *rsa = &sess->rsa_ctx;
120 : 0 : struct rte_crypto_param_t d = xform->rsa.d;
121 : 0 : size_t mod_len = xfrm_rsa->n.length;
122 : 0 : size_t exp_len = xfrm_rsa->e.length;
123 : : uint64_t total_size;
124 : : size_t len = 0;
125 : :
126 : : /* Set private key type */
127 : 0 : rsa->key_type = xfrm_rsa->key_type;
128 : :
129 [ # # ]: 0 : if (rsa->key_type == RTE_RSA_KEY_TYPE_QT) {
130 [ # # # # ]: 0 : if (qt.p.length != 0 && qt.p.data == NULL)
131 : : return -EINVAL;
132 : :
133 : : /* Make sure key length used is not more than mod_len/2 */
134 [ # # ]: 0 : if (qt.p.data != NULL)
135 [ # # ]: 0 : len = (((mod_len / 2) < qt.p.length) ? 0 : qt.p.length * 5);
136 [ # # ]: 0 : } else if (rsa->key_type == RTE_RSA_KEY_TYPE_EXP) {
137 [ # # # # ]: 0 : if (d.length != 0 && d.data == NULL)
138 : : return -EINVAL;
139 : :
140 : : len = d.length;
141 : : }
142 : :
143 : : /* Total size required for RSA key params(n,e,(q,dQ,p,dP,qInv)) */
144 : 0 : total_size = mod_len + exp_len + len;
145 : :
146 : : /* Allocate buffer to hold all RSA keys */
147 : 0 : rsa->n.data = rte_malloc(NULL, total_size, 0);
148 [ # # ]: 0 : if (rsa->n.data == NULL)
149 : : return -ENOMEM;
150 : :
151 : : /* Set up RSA prime modulus and public key exponent */
152 [ # # ]: 0 : memcpy(rsa->n.data, xfrm_rsa->n.data, mod_len);
153 : 0 : rsa->e.data = rsa->n.data + mod_len;
154 : 0 : memcpy(rsa->e.data, xfrm_rsa->e.data, exp_len);
155 : :
156 [ # # ]: 0 : if (rsa->key_type == RTE_RSA_KEY_TYPE_QT) {
157 : : /* Private key in quintuple format */
158 [ # # ]: 0 : rsa->qt.q.data = rsa->e.data + exp_len;
159 : : memcpy(rsa->qt.q.data, qt.q.data, qt.q.length);
160 : 0 : rsa->qt.dQ.data = rsa->qt.q.data + qt.q.length;
161 : : memcpy(rsa->qt.dQ.data, qt.dQ.data, qt.dQ.length);
162 : 0 : rsa->qt.p.data = rsa->qt.dQ.data + qt.dQ.length;
163 [ # # ]: 0 : if (qt.p.data != NULL)
164 : : memcpy(rsa->qt.p.data, qt.p.data, qt.p.length);
165 : 0 : rsa->qt.dP.data = rsa->qt.p.data + qt.p.length;
166 : : memcpy(rsa->qt.dP.data, qt.dP.data, qt.dP.length);
167 : 0 : rsa->qt.qInv.data = rsa->qt.dP.data + qt.dP.length;
168 : : memcpy(rsa->qt.qInv.data, qt.qInv.data, qt.qInv.length);
169 : :
170 : 0 : rsa->qt.q.length = qt.q.length;
171 : 0 : rsa->qt.dQ.length = qt.dQ.length;
172 : 0 : rsa->qt.p.length = qt.p.length;
173 : 0 : rsa->qt.dP.length = qt.dP.length;
174 : 0 : rsa->qt.qInv.length = qt.qInv.length;
175 [ # # ]: 0 : } else if (rsa->key_type == RTE_RSA_KEY_TYPE_EXP) {
176 : : /* Private key in exponent format */
177 : 0 : rsa->d.data = rsa->e.data + exp_len;
178 : : memcpy(rsa->d.data, d.data, d.length);
179 : 0 : rsa->d.length = d.length;
180 : : }
181 : 0 : rsa->n.length = mod_len;
182 : 0 : rsa->e.length = exp_len;
183 : :
184 : : /* Set padding info */
185 : 0 : rsa->padding.type = xform->rsa.padding.type;
186 : :
187 : : return 0;
188 : : }
189 : :
190 : : static __rte_always_inline int
191 : : cnxk_ae_fill_ec_params(struct cnxk_ae_sess *sess, struct rte_crypto_asym_xform *xform)
192 : : {
193 : : struct roc_ae_ec_ctx *ec = &sess->ec_ctx;
194 : 0 : union cpt_inst_w4 w4 = {0};
195 : :
196 [ # # # # : 0 : switch (xform->ec.curve_id) {
# # # #
# ]
197 : 0 : case RTE_CRYPTO_EC_GROUP_SECP192R1:
198 : 0 : ec->curveid = ROC_AE_EC_ID_P192;
199 : 0 : break;
200 : 0 : case RTE_CRYPTO_EC_GROUP_SECP224R1:
201 : 0 : ec->curveid = ROC_AE_EC_ID_P224;
202 : 0 : break;
203 : 0 : case RTE_CRYPTO_EC_GROUP_SECP256R1:
204 : 0 : ec->curveid = ROC_AE_EC_ID_P256;
205 : 0 : break;
206 : 0 : case RTE_CRYPTO_EC_GROUP_SECP384R1:
207 : 0 : ec->curveid = ROC_AE_EC_ID_P384;
208 : 0 : break;
209 : 0 : case RTE_CRYPTO_EC_GROUP_SECP521R1:
210 : 0 : ec->curveid = ROC_AE_EC_ID_P521;
211 : 0 : break;
212 : 0 : case RTE_CRYPTO_EC_GROUP_SM2:
213 : 0 : ec->curveid = ROC_AE_EC_ID_SM2;
214 : 0 : break;
215 : 0 : case RTE_CRYPTO_EC_GROUP_ED25519:
216 : 0 : ec->curveid = ROC_AE_EC_ID_ED25519;
217 : 0 : w4.s.param1 = ROC_AE_ED_PARAM1_25519;
218 : 0 : break;
219 : 0 : case RTE_CRYPTO_EC_GROUP_ED448:
220 : 0 : ec->curveid = ROC_AE_EC_ID_ED448;
221 : 0 : w4.s.param1 = ROC_AE_ED_PARAM1_448;
222 : 0 : break;
223 : : default:
224 : : /* Only NIST curves (FIPS 186-4) and SM2 are supported */
225 : : return -EINVAL;
226 : : }
227 : :
228 [ # # ]: 0 : if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_ECPM)
229 : : return 0;
230 : :
231 : 0 : ec->pkey.length = xform->ec.pkey.length;
232 [ # # ]: 0 : if (ec->pkey.length > ROC_AE_EC_DATA_MAX)
233 : 0 : ec->pkey.length = ROC_AE_EC_DATA_MAX;
234 [ # # ]: 0 : if (ec->pkey.length)
235 [ # # ]: 0 : rte_memcpy(ec->pkey.data, xform->ec.pkey.data, ec->pkey.length);
236 : :
237 : 0 : ec->q.x.length = xform->ec.q.x.length;
238 [ # # ]: 0 : if (ec->q.x.length > ROC_AE_EC_DATA_MAX)
239 : 0 : ec->q.x.length = ROC_AE_EC_DATA_MAX;
240 [ # # ]: 0 : if (ec->q.x.length)
241 [ # # ]: 0 : rte_memcpy(ec->q.x.data, xform->ec.q.x.data, ec->q.x.length);
242 : :
243 [ # # ]: 0 : if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_EDDSA) {
244 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EDDSA;
245 : :
246 : : /* Use q.x to store compressed public key. q.y is set to 0 */
247 : 0 : ec->q.y.length = 0;
248 : 0 : goto _exit;
249 : : }
250 : :
251 : 0 : ec->q.y.length = xform->ec.q.y.length;
252 [ # # ]: 0 : if (ec->q.y.length > ROC_AE_EC_DATA_MAX)
253 : 0 : ec->q.y.length = ROC_AE_EC_DATA_MAX;
254 [ # # ]: 0 : if (xform->ec.q.y.length)
255 [ # # ]: 0 : rte_memcpy(ec->q.y.data, xform->ec.q.y.data, ec->q.y.length);
256 : :
257 : 0 : _exit:
258 : 0 : sess->cpt_inst_w4 = w4.u64;
259 : : return 0;
260 : : }
261 : :
262 : : static __rte_always_inline int
263 : : cnxk_ae_fill_session_parameters(struct cnxk_ae_sess *sess,
264 : : struct rte_crypto_asym_xform *xform)
265 : : {
266 : : int ret;
267 : :
268 : 0 : sess->xfrm_type = xform->xform_type;
269 : 0 : sess->msg_max_sz = cnxk_cpt_asym_get_mlen();
270 : :
271 [ # # # # ]: 0 : switch (xform->xform_type) {
272 : : case RTE_CRYPTO_ASYM_XFORM_RSA:
273 : : ret = cnxk_ae_fill_rsa_params(sess, xform);
274 : : break;
275 : : case RTE_CRYPTO_ASYM_XFORM_MODEX:
276 : : ret = cnxk_ae_fill_modex_params(sess, xform);
277 : : break;
278 : : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
279 : : /* Fall through */
280 : : case RTE_CRYPTO_ASYM_XFORM_ECDH:
281 : : case RTE_CRYPTO_ASYM_XFORM_ECPM:
282 : : case RTE_CRYPTO_ASYM_XFORM_ECFPM:
283 : : case RTE_CRYPTO_ASYM_XFORM_SM2:
284 : : case RTE_CRYPTO_ASYM_XFORM_EDDSA:
285 : : ret = cnxk_ae_fill_ec_params(sess, xform);
286 : : break;
287 : : default:
288 : : return -ENOTSUP;
289 : : }
290 : : return ret;
291 : : }
292 : :
293 : : static inline void
294 : 0 : cnxk_ae_free_session_parameters(struct cnxk_ae_sess *sess)
295 : : {
296 : : struct rte_crypto_modex_xform *mod;
297 : : struct rte_crypto_rsa_xform *rsa;
298 : :
299 [ # # # ]: 0 : switch (sess->xfrm_type) {
300 : 0 : case RTE_CRYPTO_ASYM_XFORM_RSA:
301 : : rsa = &sess->rsa_ctx;
302 : 0 : rte_free(rsa->n.data);
303 : 0 : break;
304 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
305 : : mod = &sess->mod_ctx;
306 : 0 : rte_free(mod->modulus.data);
307 : 0 : break;
308 : : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
309 : : /* Fall through */
310 : : case RTE_CRYPTO_ASYM_XFORM_ECPM:
311 : : case RTE_CRYPTO_ASYM_XFORM_ECFPM:
312 : : break;
313 : : default:
314 : : break;
315 : : }
316 : 0 : }
317 : :
318 : : static __rte_always_inline int
319 : : cnxk_ae_modex_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
320 : : struct rte_crypto_modex_xform *mod, struct cpt_inst_s *inst)
321 : : {
322 : 0 : uint32_t exp_len = mod->exponent.length;
323 : 0 : uint32_t mod_len = mod->modulus.length;
324 : : struct rte_crypto_mod_op_param mod_op;
325 : : uint64_t total_key_len;
326 : : union cpt_inst_w4 w4;
327 : : size_t base_len;
328 : : uint32_t dlen;
329 : : uint8_t *dptr;
330 : :
331 : 0 : mod_op = op->asym->modex;
332 : :
333 : : base_len = mod_op.base.length;
334 : 0 : if (unlikely(base_len > mod_len)) {
335 : : cnxk_ae_modex_param_normalize(&mod_op.base.data, &base_len, mod_len);
336 [ # # ]: 0 : if (base_len > mod_len) {
337 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
338 : 0 : return -ENOTSUP;
339 : : }
340 : : }
341 : :
342 : 0 : total_key_len = mod_len + exp_len;
343 : :
344 : : /* Input buffer */
345 : : dptr = meta_buf->vaddr;
346 : 0 : inst->dptr = (uintptr_t)dptr;
347 : 0 : memcpy(dptr, mod->modulus.data, total_key_len);
348 : 0 : dptr += total_key_len;
349 : : memcpy(dptr, mod_op.base.data, base_len);
350 : 0 : dptr += base_len;
351 : 0 : dlen = total_key_len + base_len;
352 : :
353 : : /* Setup opcodes */
354 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_MODEX;
355 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
356 : :
357 : 0 : w4.s.param1 = mod_len;
358 : 0 : w4.s.param2 = exp_len;
359 : 0 : w4.s.dlen = dlen;
360 : :
361 : 0 : inst->w4.u64 = w4.u64;
362 : 0 : inst->rptr = (uintptr_t)dptr;
363 : :
364 : 0 : return 0;
365 : : }
366 : :
367 : : static __rte_always_inline void
368 : : cnxk_ae_rsa_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
369 : : struct rte_crypto_rsa_xform *rsa,
370 : : rte_crypto_param *crypto_param, struct cpt_inst_s *inst)
371 : : {
372 : : struct rte_crypto_rsa_op_param rsa_op;
373 : 0 : uint32_t mod_len = rsa->n.length;
374 : 0 : uint32_t exp_len = rsa->e.length;
375 : : uint64_t total_key_len;
376 : : union cpt_inst_w4 w4;
377 : : uint32_t in_size;
378 : : uint32_t dlen;
379 : : uint8_t *dptr;
380 : :
381 : : rsa_op = op->asym->rsa;
382 : 0 : total_key_len = mod_len + exp_len;
383 : :
384 : : /* Input buffer */
385 : : dptr = meta_buf->vaddr;
386 : 0 : inst->dptr = (uintptr_t)dptr;
387 : 0 : memcpy(dptr, rsa->n.data, total_key_len);
388 : 0 : dptr += total_key_len;
389 : :
390 : 0 : in_size = crypto_param->length;
391 : 0 : memcpy(dptr, crypto_param->data, in_size);
392 : :
393 : 0 : dptr += in_size;
394 : 0 : dlen = total_key_len + in_size;
395 : :
396 [ # # # # ]: 0 : if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
397 : : /* Use mod_exp operation for no_padding type */
398 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
399 : 0 : w4.s.param2 = exp_len;
400 : : } else {
401 : : if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
402 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_ENC;
403 : : /* Public key encrypt, use BT2*/
404 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE2 |
405 : 0 : ((uint16_t)(exp_len) << 1);
406 : : } else if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
407 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_DEC;
408 : : /* Public key decrypt, use BT1 */
409 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE1;
410 : : }
411 : : }
412 : :
413 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_MODEX;
414 : :
415 : 0 : w4.s.param1 = mod_len;
416 : 0 : w4.s.dlen = dlen;
417 : :
418 : 0 : inst->w4.u64 = w4.u64;
419 : 0 : inst->rptr = (uintptr_t)dptr;
420 : 0 : }
421 : :
422 : : static __rte_always_inline void
423 : : cnxk_ae_rsa_exp_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
424 : : struct rte_crypto_rsa_xform *rsa, rte_crypto_param *crypto_param,
425 : : struct cpt_inst_s *inst)
426 : : {
427 : : struct rte_crypto_rsa_op_param rsa_op;
428 : 0 : uint32_t privkey_len = rsa->d.length;
429 : 0 : uint32_t mod_len = rsa->n.length;
430 : : union cpt_inst_w4 w4;
431 : : uint32_t in_size;
432 : : uint32_t dlen;
433 : : uint8_t *dptr;
434 : :
435 : : rsa_op = op->asym->rsa;
436 : :
437 : : /* Input buffer */
438 : : dptr = meta_buf->vaddr;
439 : 0 : inst->dptr = (uintptr_t)dptr;
440 [ # # # # ]: 0 : memcpy(dptr, rsa->n.data, mod_len);
441 : 0 : dptr += mod_len;
442 : 0 : memcpy(dptr, rsa->d.data, privkey_len);
443 : 0 : dptr += privkey_len;
444 : :
445 : 0 : in_size = crypto_param->length;
446 : 0 : memcpy(dptr, crypto_param->data, in_size);
447 : :
448 : 0 : dptr += in_size;
449 : 0 : dlen = mod_len + privkey_len + in_size;
450 : :
451 [ # # # # ]: 0 : if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
452 : : /* Use mod_exp operation for no_padding type */
453 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
454 : 0 : w4.s.param2 = privkey_len;
455 : : } else {
456 : : if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
457 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_ENC;
458 : : /* Private key encrypt (exponent), use BT1*/
459 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE1 | ((uint16_t)(privkey_len) << 1);
460 : : } else if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
461 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_DEC;
462 : : /* Private key decrypt (exponent), use BT2 */
463 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE2;
464 : : }
465 : : }
466 : :
467 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_MODEX;
468 : :
469 : 0 : w4.s.param1 = mod_len;
470 : 0 : w4.s.dlen = dlen;
471 : :
472 : 0 : inst->w4.u64 = w4.u64;
473 : 0 : inst->rptr = (uintptr_t)dptr;
474 : 0 : }
475 : :
476 : : static __rte_always_inline void
477 : : cnxk_ae_rsa_crt_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
478 : : struct rte_crypto_rsa_xform *rsa, rte_crypto_param *crypto_param,
479 : : struct cpt_inst_s *inst)
480 : : {
481 : 0 : uint32_t qInv_len = rsa->qt.qInv.length;
482 : : struct rte_crypto_rsa_op_param rsa_op;
483 : 0 : uint32_t dP_len = rsa->qt.dP.length;
484 : 0 : uint32_t dQ_len = rsa->qt.dQ.length;
485 : 0 : uint32_t p_len = rsa->qt.p.length;
486 : 0 : uint32_t q_len = rsa->qt.q.length;
487 : 0 : uint32_t mod_len = rsa->n.length;
488 : : uint64_t total_key_len;
489 : : union cpt_inst_w4 w4;
490 : : uint32_t in_size;
491 : : uint32_t dlen;
492 : : uint8_t *dptr;
493 : :
494 : : rsa_op = op->asym->rsa;
495 : 0 : total_key_len = p_len + q_len + dP_len + dQ_len + qInv_len;
496 : :
497 : : /* Input buffer */
498 : : dptr = meta_buf->vaddr;
499 : 0 : inst->dptr = (uintptr_t)dptr;
500 [ # # # # ]: 0 : memcpy(dptr, rsa->qt.q.data, total_key_len);
501 : 0 : dptr += total_key_len;
502 : :
503 : 0 : in_size = crypto_param->length;
504 : 0 : memcpy(dptr, crypto_param->data, in_size);
505 : :
506 : 0 : dptr += in_size;
507 : 0 : dlen = total_key_len + in_size;
508 : :
509 [ # # # # ]: 0 : if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
510 : : /*Use mod_exp operation for no_padding type */
511 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX_CRT;
512 : : } else {
513 : : if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
514 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_ENC_CRT;
515 : : /* Private encrypt, use BT1 */
516 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE1;
517 : : } else if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
518 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_DEC_CRT;
519 : : /* Private decrypt, use BT2 */
520 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE2;
521 : : }
522 : : }
523 : :
524 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_MODEX;
525 : :
526 : 0 : w4.s.param1 = mod_len;
527 : 0 : w4.s.dlen = dlen;
528 : :
529 : 0 : inst->w4.u64 = w4.u64;
530 : 0 : inst->rptr = (uintptr_t)dptr;
531 : 0 : }
532 : :
533 : : static __rte_always_inline int __rte_hot
534 : : cnxk_ae_enqueue_rsa_op(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
535 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
536 : : {
537 : : struct rte_crypto_rsa_op_param *rsa = &op->asym->rsa;
538 : : struct rte_crypto_rsa_xform *ctx = &sess->rsa_ctx;
539 : :
540 [ # # # # : 0 : switch (rsa->op_type) {
# ]
541 [ # # ]: 0 : case RTE_CRYPTO_ASYM_OP_VERIFY:
542 : : cnxk_ae_rsa_prep(op, meta_buf, ctx, &rsa->sign, inst);
543 : : break;
544 [ # # ]: 0 : case RTE_CRYPTO_ASYM_OP_ENCRYPT:
545 : : cnxk_ae_rsa_prep(op, meta_buf, ctx, &rsa->message, inst);
546 : : break;
547 : 0 : case RTE_CRYPTO_ASYM_OP_SIGN:
548 [ # # ]: 0 : if (ctx->key_type == RTE_RSA_KEY_TYPE_QT)
549 : : cnxk_ae_rsa_crt_prep(op, meta_buf, ctx, &rsa->message, inst);
550 : : else
551 : : cnxk_ae_rsa_exp_prep(op, meta_buf, ctx, &rsa->message, inst);
552 : : break;
553 : 0 : case RTE_CRYPTO_ASYM_OP_DECRYPT:
554 [ # # ]: 0 : if (ctx->key_type == RTE_RSA_KEY_TYPE_QT)
555 : : cnxk_ae_rsa_crt_prep(op, meta_buf, ctx, &rsa->cipher, inst);
556 : : else
557 : : cnxk_ae_rsa_exp_prep(op, meta_buf, ctx, &rsa->cipher, inst);
558 : : break;
559 : 0 : default:
560 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
561 : 0 : return -EINVAL;
562 : : }
563 : : return 0;
564 : : }
565 : :
566 : : static __rte_always_inline void
567 : : cnxk_ae_ecdsa_sign_prep(struct rte_crypto_ecdsa_op_param *ecdsa,
568 : : struct roc_ae_buf_ptr *meta_buf,
569 : : uint64_t fpm_table_iova, struct roc_ae_ec_group *ec_grp,
570 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
571 : : {
572 : 0 : uint16_t message_len = ecdsa->message.length;
573 : 0 : uint16_t pkey_len = sess->ec_ctx.pkey.length;
574 : : uint8_t curveid = sess->ec_ctx.curveid;
575 : : uint16_t p_align, k_align, m_align;
576 : 0 : uint16_t k_len = ecdsa->k.length;
577 : : uint16_t order_len, prime_len;
578 : : uint16_t o_offset, pk_offset;
579 : : union cpt_inst_w4 w4;
580 : : uint16_t dlen;
581 : : uint8_t *dptr;
582 : :
583 : 0 : prime_len = ec_grp->prime.length;
584 : 0 : order_len = ec_grp->order.length;
585 : :
586 : : /* Truncate input length to curve prime length */
587 : : if (message_len > prime_len)
588 : : message_len = prime_len;
589 : 0 : m_align = RTE_ALIGN_CEIL(message_len, 8);
590 : :
591 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
592 : 0 : k_align = RTE_ALIGN_CEIL(k_len, 8);
593 : :
594 : : /* Set write offset for order and private key */
595 : 0 : o_offset = prime_len - order_len;
596 : 0 : pk_offset = p_align - pkey_len;
597 : :
598 : : /* Input buffer */
599 : : dptr = meta_buf->vaddr;
600 : 0 : inst->dptr = (uintptr_t)dptr;
601 : :
602 : : /*
603 : : * Set dlen = sum(sizeof(fpm address), ROUNDUP8(scalar len, input len),
604 : : * ROUNDUP8(priv key len, prime len, order len)).
605 : : * Please note, private key, order cannot exceed prime
606 : : * length i.e 3 * p_align.
607 : : */
608 : 0 : dlen = sizeof(fpm_table_iova) + k_align + m_align + p_align * 5;
609 : :
610 : 0 : memset(dptr, 0, dlen);
611 : :
612 : 0 : *(uint64_t *)dptr = fpm_table_iova;
613 : 0 : dptr += sizeof(fpm_table_iova);
614 : :
615 : 0 : memcpy(dptr, ecdsa->k.data, k_len);
616 : 0 : dptr += k_align;
617 : :
618 : 0 : memcpy(dptr, ec_grp->prime.data, prime_len);
619 : 0 : dptr += p_align;
620 : :
621 : 0 : memcpy(dptr + o_offset, ec_grp->order.data, order_len);
622 : 0 : dptr += p_align;
623 : :
624 : 0 : memcpy(dptr + pk_offset, sess->ec_ctx.pkey.data, pkey_len);
625 : 0 : dptr += p_align;
626 : :
627 : 0 : memcpy(dptr, ecdsa->message.data, message_len);
628 : 0 : dptr += m_align;
629 : :
630 : 0 : memcpy(dptr, ec_grp->consta.data, prime_len);
631 : 0 : dptr += p_align;
632 : :
633 : 0 : memcpy(dptr, ec_grp->constb.data, prime_len);
634 : 0 : dptr += p_align;
635 : :
636 : : /* Setup opcodes */
637 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EC;
638 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_SIGN;
639 : :
640 : 0 : w4.s.param1 = curveid | (message_len << 8);
641 : 0 : w4.s.param2 = (p_align << 8) | k_len;
642 : 0 : w4.s.dlen = dlen;
643 : :
644 : 0 : inst->w4.u64 = w4.u64;
645 : 0 : inst->rptr = (uintptr_t)dptr;
646 : 0 : }
647 : :
648 : : static __rte_always_inline void
649 : : cnxk_ae_ecdsa_verify_prep(struct rte_crypto_ecdsa_op_param *ecdsa,
650 : : struct roc_ae_buf_ptr *meta_buf,
651 : : uint64_t fpm_table_iova,
652 : : struct roc_ae_ec_group *ec_grp, struct cnxk_ae_sess *sess,
653 : : struct cpt_inst_s *inst)
654 : : {
655 : 0 : uint32_t message_len = ecdsa->message.length;
656 : 0 : uint16_t qx_len = sess->ec_ctx.q.x.length;
657 : 0 : uint16_t qy_len = sess->ec_ctx.q.y.length;
658 : : uint8_t curveid = sess->ec_ctx.curveid;
659 : : uint16_t o_offset, r_offset, s_offset;
660 : 0 : uint16_t r_len = ecdsa->r.length;
661 : 0 : uint16_t s_len = ecdsa->s.length;
662 : : uint16_t order_len, prime_len;
663 : : uint16_t qx_offset, qy_offset;
664 : : uint16_t p_align, m_align;
665 : : union cpt_inst_w4 w4;
666 : : uint16_t dlen;
667 : : uint8_t *dptr;
668 : :
669 : 0 : prime_len = ec_grp->prime.length;
670 : 0 : order_len = ec_grp->order.length;
671 : :
672 : : /* Truncate input length to curve prime length */
673 : : if (message_len > prime_len)
674 : : message_len = prime_len;
675 : :
676 : 0 : m_align = RTE_ALIGN_CEIL(message_len, 8);
677 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
678 : :
679 : : /* Set write offset for sign, order and public key coordinates */
680 : 0 : o_offset = prime_len - order_len;
681 : 0 : qx_offset = prime_len - qx_len;
682 : 0 : qy_offset = prime_len - qy_len;
683 : 0 : r_offset = prime_len - r_len;
684 : 0 : s_offset = prime_len - s_len;
685 : :
686 : : /* Input buffer */
687 : : dptr = meta_buf->vaddr;
688 : 0 : inst->dptr = (uintptr_t)dptr;
689 : :
690 : : /*
691 : : * Set dlen = sum(sizeof(fpm address), ROUNDUP8(message len),
692 : : * ROUNDUP8(sign len(r and s), public key len(x and y coordinates),
693 : : * prime len, order len)).
694 : : * Please note sign, public key and order can not exceed prime length
695 : : * i.e. 6 * p_align
696 : : */
697 : 0 : dlen = sizeof(fpm_table_iova) + m_align + (8 * p_align);
698 : :
699 : 0 : memset(dptr, 0, dlen);
700 : :
701 : 0 : *(uint64_t *)dptr = fpm_table_iova;
702 : 0 : dptr += sizeof(fpm_table_iova);
703 : :
704 : 0 : memcpy(dptr + r_offset, ecdsa->r.data, r_len);
705 : 0 : dptr += p_align;
706 : :
707 : 0 : memcpy(dptr + s_offset, ecdsa->s.data, s_len);
708 : 0 : dptr += p_align;
709 : :
710 : 0 : memcpy(dptr, ecdsa->message.data, message_len);
711 : 0 : dptr += m_align;
712 : :
713 : 0 : memcpy(dptr + o_offset, ec_grp->order.data, order_len);
714 : 0 : dptr += p_align;
715 : :
716 : 0 : memcpy(dptr, ec_grp->prime.data, prime_len);
717 : 0 : dptr += p_align;
718 : :
719 : 0 : memcpy(dptr + qx_offset, sess->ec_ctx.q.x.data, qx_len);
720 : 0 : dptr += p_align;
721 : :
722 : 0 : memcpy(dptr + qy_offset, sess->ec_ctx.q.y.data, qy_len);
723 : 0 : dptr += p_align;
724 : :
725 : 0 : memcpy(dptr, ec_grp->consta.data, prime_len);
726 : 0 : dptr += p_align;
727 : :
728 : 0 : memcpy(dptr, ec_grp->constb.data, prime_len);
729 : 0 : dptr += p_align;
730 : :
731 : : /* Setup opcodes */
732 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EC;
733 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_VERIFY;
734 : :
735 : 0 : w4.s.param1 = curveid | (message_len << 8);
736 : 0 : w4.s.param2 = 0;
737 : 0 : w4.s.dlen = dlen;
738 : :
739 : 0 : inst->w4.u64 = w4.u64;
740 : 0 : inst->rptr = (uintptr_t)dptr;
741 : 0 : }
742 : :
743 : : static __rte_always_inline int __rte_hot
744 : : cnxk_ae_enqueue_ecdsa_op(struct rte_crypto_op *op,
745 : : struct roc_ae_buf_ptr *meta_buf,
746 : : struct cnxk_ae_sess *sess, uint64_t *fpm_iova,
747 : : struct roc_ae_ec_group **ec_grp,
748 : : struct cpt_inst_s *inst)
749 : : {
750 : : struct rte_crypto_ecdsa_op_param *ecdsa = &op->asym->ecdsa;
751 : 0 : uint8_t curveid = sess->ec_ctx.curveid;
752 : :
753 : 0 : if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_SIGN)
754 : 0 : cnxk_ae_ecdsa_sign_prep(ecdsa, meta_buf, fpm_iova[curveid],
755 : 0 : ec_grp[curveid], sess, inst);
756 [ # # ]: 0 : else if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
757 : 0 : cnxk_ae_ecdsa_verify_prep(ecdsa, meta_buf, fpm_iova[curveid],
758 : 0 : ec_grp[curveid], sess, inst);
759 : : else {
760 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
761 : 0 : return -EINVAL;
762 : : }
763 : : return 0;
764 : : }
765 : :
766 : : static __rte_always_inline void
767 : : cnxk_ae_eddsa_sign_prep(struct rte_crypto_eddsa_op_param *eddsa, struct roc_ae_buf_ptr *meta_buf,
768 : : uint64_t fpm_table_iova, struct roc_ae_ec_group *ec_grp,
769 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
770 : : {
771 : 0 : const uint8_t iv_sha512[] = {
772 : : 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08,
773 : : 0xbb, 0x67, 0xae, 0x85, 0x84, 0xca, 0xa7, 0x3b,
774 : : 0x3c, 0x6e, 0xf3, 0x72, 0xfe, 0x94, 0xf8, 0x2b,
775 : : 0xa5, 0x4f, 0xf5, 0x3a, 0x5f, 0x1d, 0x36, 0xf1,
776 : : 0x51, 0x0e, 0x52, 0x7f, 0xad, 0xe6, 0x82, 0xd1,
777 : : 0x9b, 0x05, 0x68, 0x8c, 0x2b, 0x3e, 0x6c, 0x1f,
778 : : 0x1f, 0x83, 0xd9, 0xab, 0xfb, 0x41, 0xbd, 0x6b,
779 : : 0x5b, 0xe0, 0xcd, 0x19, 0x13, 0x7e, 0x21, 0x79};
780 : 0 : const uint8_t domx_ed25519[] = {
781 : : 0x53, 0x69, 0x67, 0x45, 0x64, 0x32, 0x35, 0x35,
782 : : 0x31, 0x39, 0x20, 0x6E, 0x6F, 0x20, 0x45, 0x64,
783 : : 0x32, 0x35, 0x35, 0x31, 0x39, 0x20, 0x63, 0x6F,
784 : : 0x6C, 0x6C, 0x69, 0x73, 0x69, 0x6F, 0x6E, 0x73,
785 : : 0x00, 0x00};
786 : 0 : const uint8_t domx_ed448[] = {
787 : : 0x53, 0x69, 0x67, 0x45, 0x64, 0x34, 0x34, 0x38,
788 : : 0x00, 0x00};
789 : :
790 : 0 : uint16_t pubkey_len = sess->ec_ctx.q.x.length;
791 : 0 : uint16_t message_len = eddsa->message.length;
792 : 0 : uint16_t pkey_len = sess->ec_ctx.pkey.length;
793 : : uint8_t curveid = sess->ec_ctx.curveid;
794 : : const uint8_t *domx_ptr = NULL;
795 : : uint16_t order_len, prime_len;
796 : : uint16_t ctx_align, k_align;
797 : : uint8_t pub = 0, ph = 0;
798 : : uint64_t message_handle;
799 : : union cpt_inst_w4 w4;
800 : : uint8_t domx_len = 0;
801 : : uint8_t ctx_len = 0;
802 : : uint16_t iv_len = 0;
803 : : uint64_t ctrl = 0;
804 : : uint16_t dlen;
805 : : uint8_t *dptr;
806 : :
807 : 0 : if (eddsa->instance == RTE_CRYPTO_EDCURVE_25519PH ||
808 : : eddsa->instance == RTE_CRYPTO_EDCURVE_448PH)
809 : : ph = 1;
810 : :
811 [ # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519)
812 : : iv_len = sizeof(iv_sha512);
813 : :
814 : 0 : prime_len = ec_grp->prime.length;
815 : 0 : order_len = ec_grp->order.length;
816 : 0 : ctx_len = eddsa->context.length;
817 : :
818 [ # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
819 [ # # ]: 0 : if (ph || ctx_len) {
820 : : domx_ptr = domx_ed25519;
821 : : domx_len = sizeof(domx_ed25519);
822 : : }
823 : : } else {
824 : : domx_ptr = domx_ed448;
825 : : domx_len = sizeof(domx_ed448);
826 : : }
827 : :
828 [ # # ]: 0 : if (pubkey_len)
829 : : pub = 1;
830 : :
831 : 0 : ctx_align = RTE_ALIGN_CEIL(ctx_len + domx_len, 8);
832 : 0 : k_align = RTE_ALIGN_CEIL(pkey_len, 8);
833 : :
834 : : /* Set control word */
835 : : ctrl = message_len;
836 : 0 : ctrl |= (ctx_len + domx_len) << 16;
837 : :
838 : : /* Copy message and set message handle in metabuf */
839 : : dptr = meta_buf->vaddr;
840 [ # # ]: 0 : memcpy(dptr, eddsa->message.data, message_len);
841 : : message_handle = (uint64_t)dptr;
842 : 0 : dptr += RTE_ALIGN_CEIL(message_len, 8);
843 : :
844 : : /* Input buffer */
845 : 0 : inst->dptr = (uintptr_t)dptr;
846 : :
847 : : /*
848 : : * Set dlen = sum(sizeof(fpm address), input handle, ctrl,
849 : : * ROUNDUP8(prime len, order len, constant), ROUNDUP8(priv and
850 : : * pubkey len), ROUNDUP8(context len) and iv len (if ED25519)).
851 : : */
852 : 0 : dlen = sizeof(fpm_table_iova) + sizeof(message_handle) + sizeof(ctrl) + prime_len * 3 +
853 : 0 : k_align * 2 + ctx_align + iv_len;
854 : :
855 : 0 : *(uint64_t *)dptr = fpm_table_iova;
856 : : dptr += sizeof(fpm_table_iova);
857 : :
858 [ # # ]: 0 : *(uint64_t *)dptr = rte_cpu_to_be_64(message_handle);
859 : : dptr += sizeof(message_handle);
860 : :
861 [ # # ]: 0 : *(uint64_t *)dptr = rte_cpu_to_be_64(ctrl);
862 : 0 : dptr += sizeof(ctrl);
863 : :
864 [ # # ]: 0 : memcpy(dptr, ec_grp->prime.data, prime_len);
865 : 0 : dptr += prime_len;
866 : :
867 : 0 : memcpy(dptr, ec_grp->order.data, order_len);
868 : 0 : dptr += prime_len;
869 : :
870 : 0 : memcpy(dptr, ec_grp->consta.data, prime_len);
871 : 0 : dptr += prime_len;
872 : :
873 : 0 : memcpy(dptr, sess->ec_ctx.pkey.data, pkey_len);
874 : 0 : dptr += k_align;
875 : :
876 : 0 : memcpy(dptr, sess->ec_ctx.q.x.data, pubkey_len);
877 : 0 : dptr += k_align;
878 : :
879 : 0 : memcpy(dptr, domx_ptr, domx_len);
880 [ # # ]: 0 : if (eddsa->instance != RTE_CRYPTO_EDCURVE_25519) {
881 : 0 : memset(dptr + (domx_len - 1), ctx_len, 1);
882 : 0 : memset(dptr + (domx_len - 2), ph, 1);
883 : : }
884 : :
885 [ # # ]: 0 : memcpy(dptr + domx_len, eddsa->context.data, ctx_len);
886 : 0 : dptr += ctx_align;
887 : :
888 [ # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
889 : 0 : memcpy(dptr, iv_sha512, iv_len);
890 : 0 : dptr += iv_len;
891 : : }
892 : :
893 : : /* Setup opcodes */
894 : 0 : w4.u64 = sess->cpt_inst_w4;
895 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_ED_SIGN;
896 : 0 : w4.s.param1 |= ((pub << ROC_AE_ED_PARAM1_KEYGEN_BIT) | (ph << ROC_AE_EC_PARAM1_PH_BIT));
897 : 0 : w4.s.param2 = 0;
898 : 0 : w4.s.dlen = dlen;
899 : :
900 : 0 : inst->w4.u64 = w4.u64;
901 : 0 : inst->rptr = (uintptr_t)dptr;
902 : 0 : }
903 : :
904 : : static __rte_always_inline void
905 : : cnxk_ae_eddsa_verify_prep(struct rte_crypto_eddsa_op_param *eddsa, struct roc_ae_buf_ptr *meta_buf,
906 : : uint64_t fpm_table_iova, struct roc_ae_ec_group *ec_grp,
907 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
908 : : {
909 : 0 : const uint8_t iv_sha512[] = {
910 : : 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08,
911 : : 0xbb, 0x67, 0xae, 0x85, 0x84, 0xca, 0xa7, 0x3b,
912 : : 0x3c, 0x6e, 0xf3, 0x72, 0xfe, 0x94, 0xf8, 0x2b,
913 : : 0xa5, 0x4f, 0xf5, 0x3a, 0x5f, 0x1d, 0x36, 0xf1,
914 : : 0x51, 0x0e, 0x52, 0x7f, 0xad, 0xe6, 0x82, 0xd1,
915 : : 0x9b, 0x05, 0x68, 0x8c, 0x2b, 0x3e, 0x6c, 0x1f,
916 : : 0x1f, 0x83, 0xd9, 0xab, 0xfb, 0x41, 0xbd, 0x6b,
917 : : 0x5b, 0xe0, 0xcd, 0x19, 0x13, 0x7e, 0x21, 0x79};
918 : 0 : const uint8_t domx_ed25519[] = {
919 : : 0x53, 0x69, 0x67, 0x45, 0x64, 0x32, 0x35, 0x35,
920 : : 0x31, 0x39, 0x20, 0x6E, 0x6F, 0x20, 0x45, 0x64,
921 : : 0x32, 0x35, 0x35, 0x31, 0x39, 0x20, 0x63, 0x6F,
922 : : 0x6C, 0x6C, 0x69, 0x73, 0x69, 0x6F, 0x6E, 0x73,
923 : : 0x00, 0x00};
924 : 0 : const uint8_t domx_ed448[] = {
925 : : 0x53, 0x69, 0x67, 0x45, 0x64, 0x34, 0x34, 0x38,
926 : : 0x00, 0x00};
927 : :
928 : 0 : uint16_t pubkey_len = sess->ec_ctx.q.x.length;
929 : 0 : uint16_t message_len = eddsa->message.length;
930 : 0 : uint16_t s_len = eddsa->sign.length / 2;
931 : : uint8_t curveid = sess->ec_ctx.curveid;
932 : : uint16_t ctx_align, k_align, s_align;
933 : : const uint8_t *domx_ptr = NULL;
934 : : uint16_t order_len, prime_len;
935 : : uint64_t message_handle;
936 : : union cpt_inst_w4 w4;
937 : : uint8_t domx_len = 0;
938 : : uint16_t iv_len = 0;
939 : : uint8_t ctx_len = 0;
940 : : uint64_t ctrl = 0;
941 : : uint8_t ph = 0;
942 : : uint16_t dlen;
943 : : uint8_t *dptr;
944 : :
945 : 0 : if (eddsa->instance == RTE_CRYPTO_EDCURVE_25519PH ||
946 : : eddsa->instance == RTE_CRYPTO_EDCURVE_448PH)
947 : : ph = 1;
948 : :
949 [ # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519)
950 : : iv_len = sizeof(iv_sha512);
951 : :
952 : 0 : prime_len = ec_grp->prime.length;
953 : 0 : order_len = ec_grp->order.length;
954 : 0 : ctx_len = eddsa->context.length;
955 : :
956 [ # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
957 [ # # ]: 0 : if (ph || ctx_len) {
958 : : domx_ptr = domx_ed25519;
959 : : domx_len = sizeof(domx_ed25519);
960 : : }
961 : : } else {
962 : : domx_ptr = domx_ed448;
963 : : domx_len = sizeof(domx_ed448);
964 : : }
965 : :
966 : 0 : ctx_align = RTE_ALIGN_CEIL(ctx_len + domx_len, 8);
967 : 0 : k_align = RTE_ALIGN_CEIL(pubkey_len, 8);
968 : 0 : s_align = RTE_ALIGN_CEIL(s_len, 8);
969 : :
970 : : /* Set control word */
971 : : ctrl = message_len;
972 : 0 : ctrl |= (ctx_len + domx_len) << 16;
973 : :
974 : : /* Copy message and set message handle in metabuf */
975 : : dptr = meta_buf->vaddr;
976 [ # # ]: 0 : memcpy(dptr, eddsa->message.data, message_len);
977 : : message_handle = (uint64_t)dptr;
978 : 0 : dptr += RTE_ALIGN_CEIL(message_len, 8);
979 : :
980 : : /* Input buffer */
981 : 0 : inst->dptr = (uintptr_t)dptr;
982 : :
983 : : /*
984 : : * Set dlen = sum(sizeof(fpm address), input handle, ctrl,
985 : : * ROUNDUP8(prime len, order len, constant), ROUNDUP8(pub key len),
986 : : * ROUNDUP8(s and r len), context and iv len (if ED25519)).
987 : : */
988 : 0 : dlen = sizeof(fpm_table_iova) + sizeof(message_handle) + sizeof(ctrl) + prime_len * 3 +
989 : 0 : k_align + s_align * 2 + ctx_align + iv_len;
990 : :
991 : 0 : *(uint64_t *)dptr = fpm_table_iova;
992 : : dptr += sizeof(fpm_table_iova);
993 : :
994 [ # # ]: 0 : *(uint64_t *)dptr = rte_cpu_to_be_64(message_handle);
995 : : dptr += sizeof(message_handle);
996 : :
997 [ # # ]: 0 : *(uint64_t *)dptr = rte_cpu_to_be_64(ctrl);
998 : 0 : dptr += sizeof(ctrl);
999 : :
1000 [ # # ]: 0 : memcpy(dptr, ec_grp->prime.data, prime_len);
1001 : 0 : dptr += prime_len;
1002 : :
1003 : 0 : memcpy(dptr, ec_grp->order.data, order_len);
1004 : 0 : dptr += prime_len;
1005 : :
1006 : 0 : memcpy(dptr, ec_grp->consta.data, prime_len);
1007 : 0 : dptr += prime_len;
1008 : :
1009 : 0 : memcpy(dptr, sess->ec_ctx.q.x.data, pubkey_len);
1010 : 0 : dptr += k_align;
1011 : :
1012 : 0 : memcpy(dptr, eddsa->sign.data, s_len);
1013 : 0 : dptr += s_align;
1014 : :
1015 : 0 : memcpy(dptr, eddsa->sign.data + s_len, s_len);
1016 : 0 : dptr += s_align;
1017 : :
1018 : 0 : memcpy(dptr, domx_ptr, domx_len);
1019 [ # # ]: 0 : if (eddsa->instance != RTE_CRYPTO_EDCURVE_25519) {
1020 : 0 : memset(dptr + (domx_len - 1), ctx_len, 1);
1021 : 0 : memset(dptr + (domx_len - 2), ph, 1);
1022 : : }
1023 : :
1024 [ # # ]: 0 : memcpy(dptr + domx_len, eddsa->context.data, ctx_len);
1025 : 0 : dptr += ctx_align;
1026 : :
1027 [ # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
1028 : 0 : memcpy(dptr, iv_sha512, iv_len);
1029 : 0 : dptr += iv_len;
1030 : : }
1031 : :
1032 : : /* Setup opcodes */
1033 : 0 : w4.u64 = sess->cpt_inst_w4;
1034 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_ED_VERIFY;
1035 : :
1036 : 0 : w4.s.param1 |= (ph << ROC_AE_EC_PARAM1_PH_BIT);
1037 : 0 : w4.s.param2 = 0;
1038 : 0 : w4.s.dlen = dlen;
1039 : :
1040 : 0 : inst->w4.u64 = w4.u64;
1041 : 0 : inst->rptr = (uintptr_t)dptr;
1042 : 0 : }
1043 : :
1044 : : static __rte_always_inline int __rte_hot
1045 : : cnxk_ae_enqueue_eddsa_op(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
1046 : : struct cnxk_ae_sess *sess, uint64_t *fpm_iova,
1047 : : struct roc_ae_ec_group **ec_grp, struct cpt_inst_s *inst)
1048 : : {
1049 : : struct rte_crypto_eddsa_op_param *eddsa = &op->asym->eddsa;
1050 : 0 : uint8_t curveid = sess->ec_ctx.curveid;
1051 : :
1052 : 0 : if (eddsa->message.length > (sess->msg_max_sz - CNXK_AE_EDDSA_MAX_PARAM_LEN)) {
1053 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1054 : 0 : return -EINVAL;
1055 : : }
1056 : :
1057 [ # # ]: 0 : if (eddsa->op_type == RTE_CRYPTO_ASYM_OP_SIGN)
1058 [ # # ]: 0 : cnxk_ae_eddsa_sign_prep(eddsa, meta_buf, fpm_iova[curveid], ec_grp[curveid], sess,
1059 : : inst);
1060 [ # # ]: 0 : else if (eddsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
1061 [ # # ]: 0 : cnxk_ae_eddsa_verify_prep(eddsa, meta_buf, fpm_iova[curveid], ec_grp[curveid], sess,
1062 : : inst);
1063 : : else {
1064 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1065 : 0 : return -EINVAL;
1066 : : }
1067 : : return 0;
1068 : : }
1069 : :
1070 : : static __rte_always_inline void
1071 : : cnxk_ae_sm2_sign_prep(struct rte_crypto_sm2_op_param *sm2,
1072 : : struct roc_ae_buf_ptr *meta_buf,
1073 : : uint64_t fpm_table_iova, struct roc_ae_ec_group *ec_grp,
1074 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
1075 : : {
1076 : 0 : uint16_t message_len = sm2->message.length;
1077 : 0 : uint16_t pkey_len = sess->ec_ctx.pkey.length;
1078 : : uint16_t p_align, k_align, m_align;
1079 : 0 : uint16_t k_len = sm2->k.length;
1080 : : uint16_t order_len, prime_len;
1081 : : uint16_t o_offset, pk_offset;
1082 : : union cpt_inst_w4 w4;
1083 : : uint16_t dlen;
1084 : : uint8_t *dptr;
1085 : :
1086 : 0 : prime_len = ec_grp->prime.length;
1087 : : if (prime_len > ROC_AE_EC_DATA_MAX)
1088 : : prime_len = ROC_AE_EC_DATA_MAX;
1089 : 0 : order_len = ec_grp->order.length;
1090 : : if (order_len > ROC_AE_EC_DATA_MAX)
1091 : : order_len = ROC_AE_EC_DATA_MAX;
1092 : :
1093 : : if (pkey_len > ROC_AE_EC_DATA_MAX)
1094 : : pkey_len = ROC_AE_EC_DATA_MAX;
1095 : :
1096 : : /* Truncate input length to curve prime length */
1097 : : if (message_len > prime_len)
1098 : : message_len = prime_len;
1099 : 0 : m_align = RTE_ALIGN_CEIL(message_len, 8);
1100 : :
1101 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
1102 : 0 : k_align = RTE_ALIGN_CEIL(k_len, 8);
1103 : :
1104 : : /* Set write offset for order and private key */
1105 : 0 : o_offset = prime_len - order_len;
1106 : 0 : pk_offset = p_align - pkey_len;
1107 : :
1108 : : /* Input buffer */
1109 : : dptr = meta_buf->vaddr;
1110 : 0 : inst->dptr = (uintptr_t)dptr;
1111 : :
1112 : : /*
1113 : : * Set dlen = sum(sizeof(fpm address), ROUNDUP8(scalar len, input len),
1114 : : * ROUNDUP8(priv key len, prime len, order len)).
1115 : : * Please note, private key, order cannot exceed prime
1116 : : * length i.e 3 * p_align.
1117 : : */
1118 : 0 : dlen = sizeof(fpm_table_iova) + k_align + m_align + p_align * 5;
1119 : :
1120 : 0 : memset(dptr, 0, dlen);
1121 : :
1122 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1123 : 0 : dptr += sizeof(fpm_table_iova);
1124 : :
1125 [ # # ]: 0 : rte_memcpy(dptr, sm2->k.data, k_len);
1126 : 0 : dptr += k_align;
1127 : :
1128 [ # # ]: 0 : rte_memcpy(dptr, ec_grp->prime.data, prime_len);
1129 : 0 : dptr += p_align;
1130 : :
1131 [ # # ]: 0 : rte_memcpy(dptr + o_offset, ec_grp->order.data, order_len);
1132 : 0 : dptr += p_align;
1133 : :
1134 [ # # ]: 0 : rte_memcpy(dptr + pk_offset, sess->ec_ctx.pkey.data, pkey_len);
1135 : 0 : dptr += p_align;
1136 : :
1137 [ # # ]: 0 : rte_memcpy(dptr, sm2->message.data, message_len);
1138 : 0 : dptr += m_align;
1139 : :
1140 [ # # ]: 0 : rte_memcpy(dptr, ec_grp->consta.data, prime_len);
1141 : 0 : dptr += p_align;
1142 : :
1143 [ # # ]: 0 : rte_memcpy(dptr, ec_grp->constb.data, prime_len);
1144 : 0 : dptr += p_align;
1145 : :
1146 : : /* Setup opcodes */
1147 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EC;
1148 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_SIGN;
1149 : :
1150 : : /* prime length of SM2 curve is same as that of P256. */
1151 : 0 : w4.s.param1 = ROC_AE_EC_ID_P256 |
1152 : 0 : ROC_AE_EC_PARAM1_SM2 | ROC_AE_EC_PARAM1_NONNIST | (message_len << 8);
1153 : 0 : w4.s.param2 = (p_align << 8) | k_len;
1154 : 0 : w4.s.dlen = dlen;
1155 : :
1156 : 0 : inst->w4.u64 = w4.u64;
1157 : 0 : inst->rptr = (uintptr_t)dptr;
1158 : 0 : }
1159 : :
1160 : : static __rte_always_inline void
1161 : : cnxk_ae_sm2_verify_prep(struct rte_crypto_sm2_op_param *sm2,
1162 : : struct roc_ae_buf_ptr *meta_buf,
1163 : : uint64_t fpm_table_iova,
1164 : : struct roc_ae_ec_group *ec_grp, struct cnxk_ae_sess *sess,
1165 : : struct cpt_inst_s *inst)
1166 : : {
1167 : 0 : uint32_t message_len = sm2->message.length;
1168 : : uint16_t o_offset, r_offset, s_offset;
1169 : 0 : uint16_t qx_len = sess->ec_ctx.q.x.length;
1170 : 0 : uint16_t qy_len = sess->ec_ctx.q.y.length;
1171 : 0 : uint16_t r_len = sm2->r.length;
1172 : 0 : uint16_t s_len = sm2->s.length;
1173 : : uint16_t order_len, prime_len;
1174 : : uint16_t qx_offset, qy_offset;
1175 : : uint16_t p_align, m_align;
1176 : : union cpt_inst_w4 w4;
1177 : : uint16_t dlen;
1178 : : uint8_t *dptr;
1179 : :
1180 : 0 : prime_len = ec_grp->prime.length;
1181 : : if (prime_len > ROC_AE_EC_DATA_MAX)
1182 : : prime_len = ROC_AE_EC_DATA_MAX;
1183 : 0 : order_len = ec_grp->order.length;
1184 : : if (order_len > ROC_AE_EC_DATA_MAX)
1185 : : order_len = ROC_AE_EC_DATA_MAX;
1186 : :
1187 : : if (qx_len > ROC_AE_EC_DATA_MAX)
1188 : : qx_len = ROC_AE_EC_DATA_MAX;
1189 : :
1190 : : if (qy_len > ROC_AE_EC_DATA_MAX)
1191 : : qy_len = ROC_AE_EC_DATA_MAX;
1192 : :
1193 : : /* Truncate input length to curve prime length */
1194 : 0 : if (message_len > prime_len)
1195 : : message_len = prime_len;
1196 : :
1197 : 0 : m_align = RTE_ALIGN_CEIL(message_len, 8);
1198 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
1199 : :
1200 : : /* Set write offset for sign, order and public key coordinates */
1201 : 0 : o_offset = prime_len - order_len;
1202 : 0 : qx_offset = prime_len - qx_len;
1203 : 0 : qy_offset = prime_len - qy_len;
1204 : 0 : r_offset = prime_len - r_len;
1205 : 0 : s_offset = prime_len - s_len;
1206 : :
1207 : : /* Input buffer */
1208 : : dptr = meta_buf->vaddr;
1209 : 0 : inst->dptr = (uintptr_t)dptr;
1210 : :
1211 : : /*
1212 : : * Set dlen = sum(sizeof(fpm address), ROUNDUP8(message len),
1213 : : * ROUNDUP8(sign len(r and s), public key len(x and y coordinates),
1214 : : * prime len, order len)).
1215 : : * Please note sign, public key and order can not exceed prime length
1216 : : * i.e. 6 * p_align
1217 : : */
1218 : 0 : dlen = sizeof(fpm_table_iova) + m_align + (8 * p_align);
1219 : :
1220 : 0 : memset(dptr, 0, dlen);
1221 : :
1222 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1223 : 0 : dptr += sizeof(fpm_table_iova);
1224 : :
1225 [ # # ]: 0 : rte_memcpy(dptr + r_offset, sm2->r.data, r_len);
1226 : 0 : dptr += p_align;
1227 : :
1228 [ # # ]: 0 : rte_memcpy(dptr + s_offset, sm2->s.data, s_len);
1229 : 0 : dptr += p_align;
1230 : :
1231 [ # # ]: 0 : rte_memcpy(dptr, sm2->message.data, message_len);
1232 : 0 : dptr += m_align;
1233 : :
1234 [ # # ]: 0 : rte_memcpy(dptr + o_offset, ec_grp->order.data, order_len);
1235 : 0 : dptr += p_align;
1236 : :
1237 [ # # ]: 0 : rte_memcpy(dptr, ec_grp->prime.data, prime_len);
1238 : 0 : dptr += p_align;
1239 : :
1240 [ # # ]: 0 : rte_memcpy(dptr + qx_offset, sess->ec_ctx.q.x.data, qx_len);
1241 : 0 : dptr += p_align;
1242 : :
1243 [ # # ]: 0 : rte_memcpy(dptr + qy_offset, sess->ec_ctx.q.y.data, qy_len);
1244 : 0 : dptr += p_align;
1245 : :
1246 [ # # ]: 0 : rte_memcpy(dptr, ec_grp->consta.data, prime_len);
1247 : 0 : dptr += p_align;
1248 : :
1249 [ # # ]: 0 : rte_memcpy(dptr, ec_grp->constb.data, prime_len);
1250 : 0 : dptr += p_align;
1251 : :
1252 : : /* Setup opcodes */
1253 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EC;
1254 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_VERIFY;
1255 : :
1256 : : /* prime length of SM2 curve is same as that of P256. */
1257 : 0 : w4.s.param1 = ROC_AE_EC_ID_P256 |
1258 : 0 : ROC_AE_EC_PARAM1_SM2 | ROC_AE_EC_PARAM1_NONNIST | (message_len << 8);
1259 : 0 : w4.s.param2 = 0;
1260 : 0 : w4.s.dlen = dlen;
1261 : :
1262 : 0 : inst->w4.u64 = w4.u64;
1263 : 0 : inst->rptr = (uintptr_t)dptr;
1264 : 0 : }
1265 : :
1266 : : static __rte_always_inline int __rte_hot
1267 : : cnxk_ae_enqueue_sm2_op(struct rte_crypto_op *op,
1268 : : struct roc_ae_buf_ptr *meta_buf,
1269 : : struct cnxk_ae_sess *sess, uint64_t *fpm_iova,
1270 : : struct roc_ae_ec_group **ec_grp,
1271 : : struct cpt_inst_s *inst)
1272 : : {
1273 : : struct rte_crypto_sm2_op_param *sm2 = &op->asym->sm2;
1274 : 0 : uint8_t curveid = sess->ec_ctx.curveid;
1275 : :
1276 : 0 : if (sm2->op_type == RTE_CRYPTO_ASYM_OP_SIGN)
1277 : 0 : cnxk_ae_sm2_sign_prep(sm2, meta_buf, fpm_iova[curveid],
1278 [ # # ]: 0 : ec_grp[curveid], sess, inst);
1279 [ # # ]: 0 : else if (sm2->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
1280 : 0 : cnxk_ae_sm2_verify_prep(sm2, meta_buf, fpm_iova[curveid],
1281 [ # # ]: 0 : ec_grp[curveid], sess, inst);
1282 : : else {
1283 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1284 : 0 : return -EINVAL;
1285 : : }
1286 : : return 0;
1287 : : }
1288 : :
1289 : : static __rte_always_inline int
1290 : : cnxk_ae_ecfpm_prep(rte_crypto_param *scalar,
1291 : : struct roc_ae_buf_ptr *meta_buf, uint64_t *fpm_iova,
1292 : : struct roc_ae_ec_group *ec_grp, uint8_t curveid,
1293 : : struct cpt_inst_s *inst)
1294 : : {
1295 : : uint16_t scalar_align, p_align;
1296 : : uint16_t dlen, prime_len;
1297 : : uint64_t fpm_table_iova;
1298 : : union cpt_inst_w4 w4;
1299 : : uint8_t *dptr;
1300 : :
1301 : 0 : prime_len = ec_grp->prime.length;
1302 : 0 : fpm_table_iova = (uint64_t)fpm_iova[curveid];
1303 : :
1304 : : /* Input buffer */
1305 : : dptr = meta_buf->vaddr;
1306 : 0 : inst->dptr = (uintptr_t)dptr;
1307 : :
1308 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
1309 : 0 : scalar_align = RTE_ALIGN_CEIL(scalar->length, 8);
1310 : :
1311 : : /*
1312 : : * Set dlen = sum(ROUNDUP8(input point(x and y coordinates), prime,
1313 : : * scalar length),
1314 : : * Please note point length is equivalent to prime of the curve
1315 : : */
1316 : 0 : dlen = sizeof(fpm_table_iova) + 3 * p_align + scalar_align;
1317 : :
1318 : 0 : memset(dptr, 0, dlen);
1319 : :
1320 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1321 : 0 : dptr += sizeof(fpm_table_iova);
1322 : :
1323 : : /* Copy scalar, prime */
1324 : 0 : memcpy(dptr, scalar->data, scalar->length);
1325 : 0 : dptr += scalar_align;
1326 : 0 : memcpy(dptr, ec_grp->prime.data, ec_grp->prime.length);
1327 : 0 : dptr += p_align;
1328 : 0 : memcpy(dptr, ec_grp->consta.data, ec_grp->consta.length);
1329 : 0 : dptr += p_align;
1330 : 0 : memcpy(dptr, ec_grp->constb.data, ec_grp->constb.length);
1331 : 0 : dptr += p_align;
1332 : :
1333 : : /* Setup opcodes */
1334 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_ECC;
1335 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_ECC_FPM;
1336 : :
1337 : 0 : w4.s.param1 = curveid | (1 << 8);
1338 : 0 : w4.s.param2 = scalar->length;
1339 : 0 : w4.s.dlen = dlen;
1340 : :
1341 : 0 : inst->w4.u64 = w4.u64;
1342 : 0 : inst->rptr = (uintptr_t)dptr;
1343 : :
1344 : 0 : return 0;
1345 : : }
1346 : :
1347 : : static __rte_always_inline int
1348 : : cnxk_ae_edfpm_prep(rte_crypto_param *scalar, struct roc_ae_buf_ptr *meta_buf, uint64_t *fpm_iova,
1349 : : struct roc_ae_ec_group *ec_grp, uint8_t curveid, struct cpt_inst_s *inst)
1350 : : {
1351 : 0 : const uint8_t iv_sha512[] = {
1352 : : 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08,
1353 : : 0xbb, 0x67, 0xae, 0x85, 0x84, 0xca, 0xa7, 0x3b,
1354 : : 0x3c, 0x6e, 0xf3, 0x72, 0xfe, 0x94, 0xf8, 0x2b,
1355 : : 0xa5, 0x4f, 0xf5, 0x3a, 0x5f, 0x1d, 0x36, 0xf1,
1356 : : 0x51, 0x0e, 0x52, 0x7f, 0xad, 0xe6, 0x82, 0xd1,
1357 : : 0x9b, 0x05, 0x68, 0x8c, 0x2b, 0x3e, 0x6c, 0x1f,
1358 : : 0x1f, 0x83, 0xd9, 0xab, 0xfb, 0x41, 0xbd, 0x6b,
1359 : : 0x5b, 0xe0, 0xcd, 0x19, 0x13, 0x7e, 0x21, 0x79};
1360 : : uint16_t dlen, prime_len, order_len, iv_len;
1361 : : uint64_t fpm_table_iova;
1362 : : uint16_t scalar_align;
1363 : : union cpt_inst_w4 w4;
1364 : : uint16_t prime_bit;
1365 : : uint8_t *dptr;
1366 : :
1367 : 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
1368 : : prime_bit = ROC_AE_ED_PARAM1_25519;
1369 : : iv_len = sizeof(iv_sha512);
1370 : : } else {
1371 : : prime_bit = ROC_AE_ED_PARAM1_448;
1372 : : iv_len = 0;
1373 : : }
1374 : :
1375 : 0 : prime_len = ec_grp->prime.length;
1376 : 0 : order_len = ec_grp->order.length;
1377 : 0 : fpm_table_iova = (uint64_t)fpm_iova[curveid];
1378 : :
1379 : : /* Input buffer */
1380 : : dptr = meta_buf->vaddr;
1381 : 0 : inst->dptr = (uintptr_t)dptr;
1382 : :
1383 : 0 : scalar_align = RTE_ALIGN_CEIL(scalar->length, 8);
1384 : :
1385 : : /*
1386 : : * Set dlen = sum(sizeof(fpm address), ROUNDUP8(prime len, order len, constant,
1387 : : * private key len and iv len (if ED25519))).
1388 : : */
1389 : 0 : dlen = sizeof(fpm_table_iova) + 3 * prime_len + scalar_align + iv_len;
1390 : :
1391 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1392 : 0 : dptr += sizeof(fpm_table_iova);
1393 : :
1394 [ # # ]: 0 : memcpy(dptr, ec_grp->prime.data, prime_len);
1395 : 0 : dptr += prime_len;
1396 : 0 : memcpy(dptr, ec_grp->order.data, order_len);
1397 : 0 : dptr += prime_len;
1398 : 0 : memcpy(dptr, ec_grp->consta.data, prime_len);
1399 : 0 : dptr += prime_len;
1400 : :
1401 : : memcpy(dptr, scalar->data, scalar->length);
1402 : 0 : dptr += scalar_align;
1403 [ # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
1404 : : memcpy(dptr, iv_sha512, sizeof(iv_sha512));
1405 : 0 : dptr += iv_len;
1406 : : }
1407 : :
1408 : : /* Setup opcodes */
1409 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EDDSA;
1410 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_ED_KEYGEN;
1411 : :
1412 : 0 : w4.s.param1 = prime_bit;
1413 : 0 : w4.s.param2 = 0;
1414 : 0 : w4.s.dlen = dlen;
1415 : :
1416 : 0 : inst->w4.u64 = w4.u64;
1417 : 0 : inst->rptr = (uintptr_t)dptr;
1418 : :
1419 : 0 : return 0;
1420 : : }
1421 : :
1422 : : static __rte_always_inline int
1423 : : cnxk_ae_ecpm_prep(rte_crypto_param *scalar, struct rte_crypto_ec_point *p,
1424 : : struct roc_ae_buf_ptr *meta_buf,
1425 : : struct roc_ae_ec_group *ec_grp, uint8_t curveid,
1426 : : struct cpt_inst_s *inst)
1427 : : {
1428 : 0 : uint16_t x1_len = p->x.length;
1429 : 0 : uint16_t y1_len = p->y.length;
1430 : : uint16_t scalar_align, p_align;
1431 : : uint16_t x1_offset, y1_offset;
1432 : : uint16_t dlen, prime_len;
1433 : : union cpt_inst_w4 w4;
1434 : : uint8_t *dptr;
1435 : :
1436 : 0 : prime_len = ec_grp->prime.length;
1437 : :
1438 : : /* Input buffer */
1439 : : dptr = meta_buf->vaddr;
1440 : 0 : inst->dptr = (uintptr_t)dptr;
1441 : :
1442 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
1443 : 0 : scalar_align = RTE_ALIGN_CEIL(scalar->length, 8);
1444 : :
1445 : : /*
1446 : : * Set dlen = sum(ROUNDUP8(input point(x and y coordinates), prime,
1447 : : * scalar length),
1448 : : * Please note point length is equivalent to prime of the curve
1449 : : */
1450 : 0 : dlen = 5 * p_align + scalar_align;
1451 : :
1452 : 0 : x1_offset = prime_len - x1_len;
1453 : 0 : y1_offset = prime_len - y1_len;
1454 : :
1455 : 0 : memset(dptr, 0, dlen);
1456 : :
1457 : : /* Copy input point, scalar, prime */
1458 : 0 : memcpy(dptr + x1_offset, p->x.data, x1_len);
1459 : 0 : dptr += p_align;
1460 : 0 : memcpy(dptr + y1_offset, p->y.data, y1_len);
1461 : 0 : dptr += p_align;
1462 : 0 : memcpy(dptr, scalar->data, scalar->length);
1463 : 0 : dptr += scalar_align;
1464 : 0 : memcpy(dptr, ec_grp->prime.data, ec_grp->prime.length);
1465 : 0 : dptr += p_align;
1466 : 0 : memcpy(dptr, ec_grp->consta.data, ec_grp->consta.length);
1467 : 0 : dptr += p_align;
1468 : 0 : memcpy(dptr, ec_grp->constb.data, ec_grp->constb.length);
1469 : 0 : dptr += p_align;
1470 : :
1471 : : /* Setup opcodes */
1472 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_ECC;
1473 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_ECC_UMP;
1474 : :
1475 : 0 : w4.s.param1 = curveid;
1476 : 0 : w4.s.param2 = scalar->length;
1477 : 0 : w4.s.dlen = dlen;
1478 : :
1479 : 0 : inst->w4.u64 = w4.u64;
1480 : 0 : inst->rptr = (uintptr_t)dptr;
1481 : :
1482 : 0 : return 0;
1483 : : }
1484 : :
1485 : : static __rte_always_inline int
1486 : : cnxk_ae_random_prep(uint16_t len, struct roc_ae_buf_ptr *meta_buf,
1487 : : struct cpt_inst_s *inst)
1488 : : {
1489 : : union cpt_inst_w4 w4;
1490 : : uint8_t *dptr;
1491 : :
1492 : : /* Input buffer */
1493 : : dptr = meta_buf->vaddr;
1494 : 0 : inst->dptr = (uintptr_t)dptr;
1495 : :
1496 : : /* Setup opcodes */
1497 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_RANDOM;
1498 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_RANDOM;
1499 : :
1500 : 0 : w4.s.param1 = len;
1501 : 0 : w4.s.param2 = 0;
1502 : 0 : w4.s.dlen = 0;
1503 : :
1504 : 0 : inst->w4.u64 = w4.u64;
1505 : 0 : inst->rptr = (uintptr_t)dptr;
1506 : :
1507 : 0 : return 0;
1508 : : }
1509 : :
1510 : : static __rte_always_inline int __rte_hot
1511 : : cnxk_ae_enqueue_ecdh_op(struct rte_crypto_op *op,
1512 : : struct roc_ae_buf_ptr *meta_buf,
1513 : : struct cnxk_ae_sess *sess, uint64_t *fpm_iova,
1514 : : struct roc_ae_ec_group **ec_grp,
1515 : : struct cpt_inst_s *inst)
1516 : : {
1517 : : struct rte_crypto_ecdh_op_param *ecdh = &op->asym->ecdh;
1518 : 0 : uint8_t curveid = sess->ec_ctx.curveid;
1519 : : struct rte_crypto_ec_point point;
1520 : : rte_crypto_uint scalar;
1521 : : int ret = 0;
1522 : :
1523 : 0 : switch (ecdh->ke_type) {
1524 : 0 : case RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE:
1525 : 0 : cnxk_ae_random_prep(ecdh->priv_key.length, meta_buf, inst);
1526 : : break;
1527 : 0 : case RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE:
1528 : 0 : scalar.data = sess->ec_ctx.pkey.data;
1529 : 0 : scalar.length = sess->ec_ctx.pkey.length;
1530 [ # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519 || curveid == ROC_AE_EC_ID_ED448)
1531 [ # # ]: 0 : cnxk_ae_edfpm_prep(&scalar, meta_buf, fpm_iova, ec_grp[curveid],
1532 : : curveid, inst);
1533 : : else
1534 : 0 : cnxk_ae_ecfpm_prep(&scalar, meta_buf, fpm_iova, ec_grp[curveid],
1535 : : curveid, inst);
1536 : : break;
1537 : 0 : case RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY:
1538 : 0 : scalar.data = ec_grp[curveid]->order.data;
1539 : 0 : scalar.length = ec_grp[curveid]->order.length;
1540 : : cnxk_ae_ecpm_prep(&scalar, &ecdh->pub_key, meta_buf,
1541 : : ec_grp[curveid], curveid, inst);
1542 : : break;
1543 : 0 : case RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE:
1544 : 0 : scalar.data = sess->ec_ctx.pkey.data;
1545 : 0 : scalar.length = sess->ec_ctx.pkey.length;
1546 : 0 : point.x.data = sess->ec_ctx.q.x.data;
1547 : 0 : point.x.length = sess->ec_ctx.q.x.length;
1548 : 0 : point.y.data = sess->ec_ctx.q.y.data;
1549 : 0 : point.y.length = sess->ec_ctx.q.y.length;
1550 : 0 : cnxk_ae_ecpm_prep(&scalar, &point, meta_buf,
1551 : 0 : ec_grp[curveid], curveid, inst);
1552 : : break;
1553 : 0 : default:
1554 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1555 : : ret = -EINVAL;
1556 : : }
1557 : :
1558 : : return ret;
1559 : : }
1560 : :
1561 : : static __rte_always_inline void
1562 : : cnxk_ae_dequeue_rsa_op(struct rte_crypto_op *cop, uint8_t *rptr,
1563 : : struct rte_crypto_rsa_xform *rsa_ctx)
1564 : : {
1565 : : struct rte_crypto_rsa_op_param *rsa = &cop->asym->rsa;
1566 : :
1567 : 0 : switch (rsa->op_type) {
1568 : 0 : case RTE_CRYPTO_ASYM_OP_ENCRYPT:
1569 : 0 : rsa->cipher.length = rsa_ctx->n.length;
1570 : 0 : memcpy(rsa->cipher.data, rptr, rsa->cipher.length);
1571 : : break;
1572 : 0 : case RTE_CRYPTO_ASYM_OP_DECRYPT:
1573 [ # # ]: 0 : if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
1574 : 0 : rsa->message.length = rsa_ctx->n.length;
1575 : 0 : memcpy(rsa->message.data, rptr, rsa->message.length);
1576 : : } else {
1577 : : /* Get length of decrypted output */
1578 : 0 : rsa->message.length =
1579 [ # # ]: 0 : rte_cpu_to_be_16(*((uint16_t *)rptr));
1580 : : /*
1581 : : * Offset output data pointer by length field
1582 : : * (2 bytes) and copy decrypted data.
1583 : : */
1584 : 0 : memcpy(rsa->message.data, rptr + 2,
1585 : : rsa->message.length);
1586 : : }
1587 : : break;
1588 : 0 : case RTE_CRYPTO_ASYM_OP_SIGN:
1589 : 0 : rsa->sign.length = rsa_ctx->n.length;
1590 : 0 : memcpy(rsa->sign.data, rptr, rsa->sign.length);
1591 : : break;
1592 : 0 : case RTE_CRYPTO_ASYM_OP_VERIFY:
1593 [ # # ]: 0 : if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
1594 : 0 : rsa->sign.length = rsa_ctx->n.length;
1595 : 0 : memcpy(rsa->sign.data, rptr, rsa->sign.length);
1596 : : } else {
1597 : : /* Get length of signed output */
1598 : 0 : rsa->sign.length =
1599 [ # # ]: 0 : rte_cpu_to_be_16(*((uint16_t *)rptr));
1600 : : /*
1601 : : * Offset output data pointer by length field
1602 : : * (2 bytes) and copy signed data.
1603 : : */
1604 : 0 : memcpy(rsa->sign.data, rptr + 2, rsa->sign.length);
1605 : : }
1606 [ # # ]: 0 : if (memcmp(rsa->sign.data, rsa->message.data,
1607 : : rsa->message.length)) {
1608 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1609 : : }
1610 : : break;
1611 : 0 : default:
1612 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1613 : 0 : break;
1614 : : }
1615 : : }
1616 : :
1617 : : static __rte_always_inline void
1618 : : cnxk_ae_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa, uint8_t *rptr,
1619 : : struct roc_ae_ec_ctx *ec,
1620 : : struct roc_ae_ec_group **ec_grp)
1621 : : {
1622 : 0 : int prime_len = ec_grp[ec->curveid]->prime.length;
1623 : :
1624 : 0 : if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
1625 : : return;
1626 : :
1627 : : /* Separate out sign r and s components */
1628 : 0 : memcpy(ecdsa->r.data, rptr, prime_len);
1629 : 0 : memcpy(ecdsa->s.data, rptr + RTE_ALIGN_CEIL(prime_len, 8), prime_len);
1630 : 0 : ecdsa->r.length = prime_len;
1631 : 0 : ecdsa->s.length = prime_len;
1632 : : }
1633 : :
1634 : : static __rte_always_inline void
1635 : : cnxk_ae_dequeue_eddsa_op(struct rte_crypto_eddsa_op_param *eddsa, uint8_t *rptr)
1636 : : {
1637 : 0 : if (eddsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
1638 : : return;
1639 : :
1640 : : /* Separate out sign r and s components */
1641 [ # # ]: 0 : if (eddsa->instance == RTE_CRYPTO_EDCURVE_25519 ||
1642 : : eddsa->instance == RTE_CRYPTO_EDCURVE_25519CTX ||
1643 : : eddsa->instance == RTE_CRYPTO_EDCURVE_25519PH) {
1644 : 0 : eddsa->sign.length = 64;
1645 : 0 : memcpy(eddsa->sign.data, rptr, eddsa->sign.length);
1646 : : } else {
1647 : 0 : eddsa->sign.length = 114;
1648 : 0 : memcpy(eddsa->sign.data, rptr, 57);
1649 : 0 : memcpy(eddsa->sign.data + 57, rptr + 64, 57);
1650 : : }
1651 : : }
1652 : :
1653 : : static __rte_always_inline void
1654 : : cnxk_ae_dequeue_sm2_op(struct rte_crypto_sm2_op_param *sm2, uint8_t *rptr,
1655 : : struct roc_ae_ec_ctx *ec,
1656 : : struct roc_ae_ec_group **ec_grp)
1657 : : {
1658 : 0 : int prime_len = ec_grp[ec->curveid]->prime.length;
1659 : :
1660 : 0 : if (sm2->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
1661 : : return;
1662 : :
1663 : : /* Separate out sign r and s components */
1664 [ # # ]: 0 : rte_memcpy(sm2->r.data, rptr, prime_len);
1665 [ # # ]: 0 : rte_memcpy(sm2->s.data, rptr + RTE_ALIGN_CEIL(prime_len, 8), prime_len);
1666 : 0 : sm2->r.length = prime_len;
1667 : 0 : sm2->s.length = prime_len;
1668 : : }
1669 : :
1670 : : static __rte_always_inline void
1671 : : cnxk_ae_dequeue_ecpm_op(struct rte_crypto_ecpm_op_param *ecpm, uint8_t *rptr,
1672 : : struct roc_ae_ec_ctx *ec,
1673 : : struct roc_ae_ec_group **ec_grp)
1674 : : {
1675 : 0 : int prime_len = ec_grp[ec->curveid]->prime.length;
1676 : :
1677 : 0 : memcpy(ecpm->r.x.data, rptr, prime_len);
1678 : 0 : memcpy(ecpm->r.y.data, rptr + RTE_ALIGN_CEIL(prime_len, 8), prime_len);
1679 : 0 : ecpm->r.x.length = prime_len;
1680 : 0 : ecpm->r.y.length = prime_len;
1681 : 0 : }
1682 : :
1683 : : static __rte_always_inline void
1684 : : cnxk_ae_dequeue_ecdh_op(struct rte_crypto_ecdh_op_param *ecdh, uint8_t *rptr,
1685 : : struct roc_ae_ec_ctx *ec,
1686 : : struct roc_ae_ec_group **ec_grp, uint16_t flags)
1687 : : {
1688 : 0 : int prime_len = ec_grp[ec->curveid]->prime.length;
1689 : :
1690 : 0 : switch (ecdh->ke_type) {
1691 : 0 : case RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE:
1692 : 0 : memcpy(ecdh->priv_key.data, rptr, prime_len);
1693 : 0 : ecdh->priv_key.length = prime_len;
1694 : 0 : break;
1695 : 0 : case RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE:
1696 [ # # ]: 0 : memcpy(ecdh->pub_key.x.data, rptr, prime_len);
1697 : 0 : ecdh->pub_key.x.length = prime_len;
1698 [ # # ]: 0 : if (!(flags & RTE_CRYPTO_ASYM_FLAG_PUB_KEY_COMPRESSED)) {
1699 : 0 : memcpy(ecdh->pub_key.y.data, rptr + RTE_ALIGN_CEIL(prime_len, 8),
1700 : : prime_len);
1701 : 0 : ecdh->pub_key.y.length = prime_len;
1702 : : }
1703 : : break;
1704 : : case RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY:
1705 : : break;
1706 : 0 : case RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE:
1707 : 0 : memcpy(ecdh->shared_secret.x.data, rptr, prime_len);
1708 : 0 : memcpy(ecdh->shared_secret.y.data, rptr + RTE_ALIGN_CEIL(prime_len, 8), prime_len);
1709 : 0 : ecdh->shared_secret.x.length = prime_len;
1710 : 0 : ecdh->shared_secret.y.length = prime_len;
1711 : 0 : break;
1712 : : default:
1713 : : break;
1714 : : }
1715 : : }
1716 : :
1717 : : static __rte_always_inline void *
1718 : : cnxk_ae_alloc_meta(struct roc_ae_buf_ptr *buf,
1719 : : struct rte_mempool *cpt_meta_pool,
1720 : : struct cpt_inflight_req *infl_req)
1721 : : {
1722 : : uint8_t *mdata;
1723 : :
1724 [ # # ]: 0 : if (unlikely(rte_mempool_get(cpt_meta_pool, (void **)&mdata) < 0))
1725 : : return NULL;
1726 : :
1727 : 0 : buf->vaddr = mdata;
1728 : :
1729 : 0 : infl_req->mdata = mdata;
1730 : 0 : infl_req->op_flags |= CPT_OP_FLAGS_METABUF;
1731 : :
1732 : : return mdata;
1733 : : }
1734 : :
1735 : : static __rte_always_inline int32_t __rte_hot
1736 : : cnxk_ae_enqueue(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
1737 : : struct cpt_inflight_req *infl_req, struct cpt_inst_s *inst,
1738 : : struct cnxk_ae_sess *sess)
1739 : : {
1740 : : struct cpt_qp_meta_info *minfo = &qp->meta_info;
1741 : : struct rte_crypto_asym_op *asym_op = op->asym;
1742 : : struct roc_ae_buf_ptr meta_buf;
1743 : : uint64_t *mop;
1744 : : void *mdata;
1745 : : int ret;
1746 : :
1747 [ # # ]: 0 : mdata = cnxk_ae_alloc_meta(&meta_buf, minfo->pool, infl_req);
1748 [ # # ]: 0 : if (mdata == NULL)
1749 : : return -ENOMEM;
1750 : :
1751 : : /* Reserve 8B for RPTR */
1752 : 0 : meta_buf.vaddr = PLT_PTR_ADD(mdata, sizeof(uint64_t));
1753 : :
1754 [ # # # # : 0 : switch (sess->xfrm_type) {
# # # #
# ]
1755 [ # # ]: 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
1756 : : ret = cnxk_ae_modex_prep(op, &meta_buf, &sess->mod_ctx, inst);
1757 [ # # ]: 0 : if (unlikely(ret))
1758 : 0 : goto req_fail;
1759 : : break;
1760 : : case RTE_CRYPTO_ASYM_XFORM_RSA:
1761 : : ret = cnxk_ae_enqueue_rsa_op(op, &meta_buf, sess, inst);
1762 [ # # ]: 0 : if (unlikely(ret))
1763 : 0 : goto req_fail;
1764 : : break;
1765 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
1766 [ # # ]: 0 : ret = cnxk_ae_enqueue_ecdsa_op(op, &meta_buf, sess,
1767 : : sess->cnxk_fpm_iova,
1768 : : sess->ec_grp, inst);
1769 [ # # ]: 0 : if (unlikely(ret))
1770 : 0 : goto req_fail;
1771 : : break;
1772 : 0 : case RTE_CRYPTO_ASYM_XFORM_EDDSA:
1773 [ # # ]: 0 : ret = cnxk_ae_enqueue_eddsa_op(op, &meta_buf, sess,
1774 : : sess->cnxk_fpm_iova,
1775 : : sess->ec_grp, inst);
1776 [ # # ]: 0 : if (unlikely(ret))
1777 : 0 : goto req_fail;
1778 : : break;
1779 : 0 : case RTE_CRYPTO_ASYM_XFORM_SM2:
1780 [ # # ]: 0 : ret = cnxk_ae_enqueue_sm2_op(op, &meta_buf, sess,
1781 : : sess->cnxk_fpm_iova,
1782 : : sess->ec_grp, inst);
1783 [ # # ]: 0 : if (unlikely(ret))
1784 : 0 : goto req_fail;
1785 : : break;
1786 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECPM:
1787 : 0 : ret = cnxk_ae_ecpm_prep(&asym_op->ecpm.scalar, &asym_op->ecpm.p, &meta_buf,
1788 : 0 : sess->ec_grp[sess->ec_ctx.curveid],
1789 : 0 : sess->ec_ctx.curveid, inst);
1790 : : if (unlikely(ret))
1791 : : goto req_fail;
1792 : : break;
1793 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECFPM:
1794 : 0 : ret = cnxk_ae_ecfpm_prep(&asym_op->ecpm.scalar, &meta_buf,
1795 : : sess->cnxk_fpm_iova,
1796 : 0 : sess->ec_grp[sess->ec_ctx.curveid],
1797 : 0 : sess->ec_ctx.curveid, inst);
1798 : : if (unlikely(ret))
1799 : : goto req_fail;
1800 : : break;
1801 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDH:
1802 [ # # # # : 0 : ret = cnxk_ae_enqueue_ecdh_op(op, &meta_buf, sess,
# ]
1803 : : sess->cnxk_fpm_iova,
1804 : : sess->ec_grp, inst);
1805 [ # # ]: 0 : if (unlikely(ret))
1806 : 0 : goto req_fail;
1807 : : break;
1808 : 0 : default:
1809 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1810 : : ret = -EINVAL;
1811 : 0 : goto req_fail;
1812 : : }
1813 : :
1814 : : mop = mdata;
1815 : 0 : mop[0] = inst->rptr;
1816 : 0 : return 0;
1817 : :
1818 : 0 : req_fail:
1819 [ # # ]: 0 : rte_mempool_put(minfo->pool, infl_req->mdata);
1820 : 0 : return ret;
1821 : : }
1822 : :
1823 : : static __rte_always_inline void
1824 : : cnxk_ae_post_process(struct rte_crypto_op *cop, struct cnxk_ae_sess *sess,
1825 : : uint8_t *rptr)
1826 : : {
1827 : : struct rte_crypto_asym_op *op = cop->asym;
1828 : :
1829 [ # # # # : 0 : switch (sess->xfrm_type) {
# # # # ]
1830 [ # # # # : 0 : case RTE_CRYPTO_ASYM_XFORM_RSA:
# ]
1831 : : cnxk_ae_dequeue_rsa_op(cop, rptr, &sess->rsa_ctx);
1832 : : break;
1833 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
1834 : 0 : op->modex.result.length = sess->mod_ctx.modulus.length;
1835 : 0 : memcpy(op->modex.result.data, rptr, op->modex.result.length);
1836 : : break;
1837 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
1838 [ # # ]: 0 : cnxk_ae_dequeue_ecdsa_op(&op->ecdsa, rptr, &sess->ec_ctx,
1839 : : sess->ec_grp);
1840 : : break;
1841 [ # # ]: 0 : case RTE_CRYPTO_ASYM_XFORM_EDDSA:
1842 : : cnxk_ae_dequeue_eddsa_op(&op->eddsa, rptr);
1843 : : break;
1844 : 0 : case RTE_CRYPTO_ASYM_XFORM_SM2:
1845 [ # # ]: 0 : cnxk_ae_dequeue_sm2_op(&op->sm2, rptr, &sess->ec_ctx,
1846 : : sess->ec_grp);
1847 : : break;
1848 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECPM:
1849 : : case RTE_CRYPTO_ASYM_XFORM_ECFPM:
1850 : 0 : cnxk_ae_dequeue_ecpm_op(&op->ecpm, rptr, &sess->ec_ctx,
1851 : : sess->ec_grp);
1852 : : break;
1853 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDH:
1854 : 0 : cnxk_ae_dequeue_ecdh_op(&op->ecdh, rptr, &sess->ec_ctx,
1855 [ # # # # ]: 0 : sess->ec_grp, op->flags);
1856 : : break;
1857 : 0 : default:
1858 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1859 : 0 : break;
1860 : : }
1861 : : }
1862 : : #endif /* _CNXK_AE_H_ */
|