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 : : #include <rte_memory.h>
12 : :
13 : : #include "roc_ae.h"
14 : : #include "roc_re.h"
15 : :
16 : : #include "cnxk_cryptodev_ops.h"
17 : :
18 : : #define ASYM_SESS_SIZE sizeof(struct rte_cryptodev_asym_session)
19 : :
20 : : #define CNXK_AE_EDDSA_MAX_PARAM_LEN 1024
21 : :
22 : : /*
23 : : * Maximum RSA modulus length (in bytes) supported by CNXK hardware. Must
24 : : * match CNXK_CPT_MAX_ASYM_OP_MOD_LEN in cnxk_cryptodev_ops.c and the
25 : : * modlen.max capability advertised in cnxk_cryptodev_capabilities.c. The
26 : : * per-op scratch buffer (CNXK_CPT_MAX_ASYM_OP_NUM_PARAMS *
27 : : * CNXK_CPT_MAX_ASYM_OP_MOD_LEN) that cnxk_ae_rsa_crt_prep()/
28 : : * cnxk_ae_rsa_exp_prep() write into is sized against this limit, so RSA
29 : : * key material must be rejected up front if it exceeds it.
30 : : */
31 : : #define CNXK_AE_RSA_MAX_MODLEN 1024
32 : :
33 : : struct cnxk_ae_sess {
34 : : uint8_t rte_sess[ASYM_SESS_SIZE];
35 : : enum rte_crypto_asym_xform_type xfrm_type;
36 : : union {
37 : : struct rte_crypto_rsa_xform rsa_ctx;
38 : : struct rte_crypto_modex_xform mod_ctx;
39 : : struct roc_ae_ec_ctx ec_ctx;
40 : : struct rte_crypto_ml_kem_xform ml_kem_ctx;
41 : : struct rte_crypto_ml_dsa_xform ml_dsa_ctx;
42 : : };
43 : : uint64_t *cnxk_fpm_iova;
44 : : uint64_t *cnxk_ml_iova;
45 : : struct roc_ae_ec_group **ec_grp;
46 : : uint64_t cpt_inst_w4;
47 : : uint64_t cpt_inst_w7;
48 : : uint64_t cpt_inst_w2;
49 : : struct cnxk_cpt_qp *qp;
50 : : struct roc_cpt_lf *lf;
51 : : uint64_t msg_max_sz;
52 : : struct hw_ctx_s {
53 : : union {
54 : : struct {
55 : : uint64_t rsvd : 48;
56 : :
57 : : uint64_t ctx_push_size : 7;
58 : : uint64_t rsvd1 : 1;
59 : :
60 : : uint64_t ctx_hdr_size : 2;
61 : : uint64_t aop_valid : 1;
62 : : uint64_t rsvd2 : 1;
63 : : uint64_t ctx_size : 4;
64 : : } s;
65 : : uint64_t u64;
66 : : } w0;
67 : : uint8_t rsvd[256];
68 : : } hw_ctx __plt_aligned(ROC_ALIGN);
69 : : };
70 : :
71 : : static const uint8_t mldsa_hash_algo[] = {
72 : : [RTE_CRYPTO_AUTH_SHA3_224] = 0xA,
73 : : [RTE_CRYPTO_AUTH_SHA3_256] = 0xB,
74 : : [RTE_CRYPTO_AUTH_SHA3_384] = 0xC,
75 : : [RTE_CRYPTO_AUTH_SHA3_512] = 0xD,
76 : : [RTE_CRYPTO_AUTH_SHAKE_128] = 0xE,
77 : : [RTE_CRYPTO_AUTH_SHAKE_256] = 0xF,
78 : : };
79 : :
80 : : static __rte_always_inline void
81 : : cnxk_ae_modex_param_normalize(uint8_t **data, size_t *len, size_t max)
82 : : {
83 : 0 : uint8_t msw_len = *len % 8;
84 : 0 : uint64_t msw_val = 0;
85 : : size_t i;
86 : :
87 [ # # # # : 0 : if (*len <= 8)
# # ]
88 : 0 : return;
89 : :
90 [ # # # # : 0 : memcpy(&msw_val, *data, msw_len);
# # # # ]
91 [ # # # # : 0 : if (msw_val != 0)
# # # # ]
92 : : return;
93 : :
94 [ # # # # : 0 : for (i = msw_len; i < *len && (*len - i) < max; i += 8) {
# # # # #
# # # # #
# # ]
95 : 0 : memcpy(&msw_val, &(*data)[i], 8);
96 [ # # # # : 0 : if (msw_val != 0)
# # # # ]
97 : : break;
98 : : }
99 : 0 : *data += i;
100 : 0 : *len -= i;
101 : : }
102 : :
103 : : static __rte_always_inline int
104 : : cnxk_ae_fill_modex_params(struct cnxk_ae_sess *sess,
105 : : struct rte_crypto_asym_xform *xform)
106 : : {
107 : : struct rte_crypto_modex_xform *ctx = &sess->mod_ctx;
108 : 0 : size_t exp_len = xform->modex.exponent.length;
109 : 0 : size_t mod_len = xform->modex.modulus.length;
110 : 0 : uint8_t *exp = xform->modex.exponent.data;
111 [ # # ]: 0 : uint8_t *mod = xform->modex.modulus.data;
112 : :
113 : : cnxk_ae_modex_param_normalize(&mod, &mod_len, SIZE_MAX);
114 : : cnxk_ae_modex_param_normalize(&exp, &exp_len, mod_len);
115 : :
116 [ # # # # ]: 0 : if (unlikely(exp_len == 0 || mod_len == 0))
117 : : return -EINVAL;
118 : :
119 [ # # ]: 0 : if (unlikely(exp_len > mod_len))
120 : : return -ENOTSUP;
121 : :
122 : : /* Allocate buffer to hold modexp params */
123 : 0 : ctx->modulus.data = rte_malloc(NULL, mod_len + exp_len, 0);
124 [ # # ]: 0 : if (ctx->modulus.data == NULL)
125 : : return -ENOMEM;
126 : :
127 : : /* Set up modexp prime modulus and private exponent */
128 : : memcpy(ctx->modulus.data, mod, mod_len);
129 : 0 : ctx->exponent.data = ctx->modulus.data + mod_len;
130 : : memcpy(ctx->exponent.data, exp, exp_len);
131 : :
132 : 0 : ctx->modulus.length = mod_len;
133 : 0 : ctx->exponent.length = exp_len;
134 : :
135 : : return 0;
136 : : }
137 : :
138 : : static __rte_always_inline int
139 : : cnxk_ae_fill_rsa_params(struct cnxk_ae_sess *sess,
140 : : struct rte_crypto_asym_xform *xform)
141 : : {
142 : 0 : struct rte_crypto_rsa_priv_key_qt qt = xform->rsa.qt;
143 : : struct rte_crypto_rsa_xform *xfrm_rsa = &xform->rsa;
144 : : struct rte_crypto_rsa_xform *rsa = &sess->rsa_ctx;
145 : 0 : struct rte_crypto_param_t d = xform->rsa.d;
146 : 0 : size_t mod_len = xfrm_rsa->n.length;
147 : 0 : size_t exp_len = xfrm_rsa->e.length;
148 : : uint64_t total_size;
149 : : size_t max_len;
150 : : size_t len = 0;
151 : :
152 : : /* Bound n/e against CNXK's RSA capability and require valid data,
153 : : * since they're used unconditionally below.
154 : : */
155 [ # # # # ]: 0 : if (mod_len > CNXK_AE_RSA_MAX_MODLEN || exp_len == 0 || exp_len > CNXK_AE_RSA_MAX_MODLEN ||
156 [ # # # # ]: 0 : xfrm_rsa->n.data == NULL || xfrm_rsa->e.data == NULL)
157 : : return -EINVAL;
158 : :
159 : : /* Set private key type */
160 : 0 : rsa->key_type = xfrm_rsa->key_type;
161 : :
162 [ # # ]: 0 : if (rsa->key_type == RTE_RSA_KEY_TYPE_QT) {
163 : : /* Round up so an odd-length modulus doesn't reject a legitimately
164 : : * sized factor (mod_len/2 alone truncates down).
165 : : */
166 : 0 : max_len = (mod_len + 1) / 2;
167 : :
168 : : /*
169 : : * Each quintuple component (q, dQ, p, dP, qInv) is independently
170 : : * caller-controlled and copied with its own length, so every one of
171 : : * them must be bounds-checked individually against mod_len/2 -
172 : : * relying on qt.p.length alone is not sufficient.
173 : : */
174 [ # # # # : 0 : if (qt.p.length == 0 || qt.p.length > max_len || qt.p.data == NULL ||
# # # # ]
175 [ # # # # : 0 : qt.q.length == 0 || qt.q.length > max_len || qt.q.data == NULL ||
# # ]
176 [ # # # # : 0 : qt.dP.length == 0 || qt.dP.length > max_len || qt.dP.data == NULL ||
# # ]
177 [ # # # # : 0 : qt.dQ.length == 0 || qt.dQ.length > max_len || qt.dQ.data == NULL ||
# # ]
178 [ # # # # ]: 0 : qt.qInv.length == 0 || qt.qInv.length > max_len || qt.qInv.data == NULL)
179 : : return -EINVAL;
180 : :
181 : : /* Total size is the actual sum of the quintuple component lengths */
182 : 0 : len = qt.q.length + qt.dQ.length + qt.p.length + qt.dP.length + qt.qInv.length;
183 [ # # ]: 0 : } else if (rsa->key_type == RTE_RSA_KEY_TYPE_EXP) {
184 : : /*
185 : : * d is optional here: RTE_RSA_KEY_TYPE_EXP also covers
186 : : * public-only (encrypt/verify) transforms that supply just
187 : : * n/e, which cnxk_ae_rsa_prep() uses without ever reading d.
188 : : * When a private exponent is supplied, bound it and require
189 : : * its data.
190 : : */
191 [ # # # # : 0 : if (d.length > mod_len || (d.length != 0 && d.data == NULL))
# # ]
192 : : return -EINVAL;
193 : :
194 : : len = d.length;
195 : : } else {
196 : : /* Reject unknown key_type instead of silently treating it as EXP. */
197 : : return -EINVAL;
198 : : }
199 : :
200 : : /* Total size required for RSA key params(n,e,(q,dQ,p,dP,qInv)) */
201 : 0 : total_size = mod_len + exp_len + len;
202 : :
203 : : /* Allocate buffer to hold all RSA keys */
204 : 0 : rsa->n.data = rte_malloc(NULL, total_size, 0);
205 [ # # ]: 0 : if (rsa->n.data == NULL)
206 : : return -ENOMEM;
207 : :
208 : : /* Set up RSA prime modulus and public key exponent */
209 [ # # ]: 0 : memcpy(rsa->n.data, xfrm_rsa->n.data, mod_len);
210 : 0 : rsa->e.data = rsa->n.data + mod_len;
211 : 0 : memcpy(rsa->e.data, xfrm_rsa->e.data, exp_len);
212 : :
213 [ # # ]: 0 : if (rsa->key_type == RTE_RSA_KEY_TYPE_QT) {
214 : : /* Private key in quintuple format */
215 : 0 : rsa->qt.q.data = rsa->e.data + exp_len;
216 : : memcpy(rsa->qt.q.data, qt.q.data, qt.q.length);
217 : 0 : rsa->qt.dQ.data = rsa->qt.q.data + qt.q.length;
218 : : memcpy(rsa->qt.dQ.data, qt.dQ.data, qt.dQ.length);
219 : 0 : rsa->qt.p.data = rsa->qt.dQ.data + qt.dQ.length;
220 : : memcpy(rsa->qt.p.data, qt.p.data, qt.p.length);
221 : 0 : rsa->qt.dP.data = rsa->qt.p.data + qt.p.length;
222 : : memcpy(rsa->qt.dP.data, qt.dP.data, qt.dP.length);
223 : 0 : rsa->qt.qInv.data = rsa->qt.dP.data + qt.dP.length;
224 : : memcpy(rsa->qt.qInv.data, qt.qInv.data, qt.qInv.length);
225 : :
226 : 0 : rsa->qt.q.length = qt.q.length;
227 : 0 : rsa->qt.dQ.length = qt.dQ.length;
228 : 0 : rsa->qt.p.length = qt.p.length;
229 : 0 : rsa->qt.dP.length = qt.dP.length;
230 : 0 : rsa->qt.qInv.length = qt.qInv.length;
231 [ # # ]: 0 : } else if (rsa->key_type == RTE_RSA_KEY_TYPE_EXP) {
232 : : /* Private key in exponent format */
233 : 0 : rsa->d.data = rsa->e.data + exp_len;
234 [ # # ]: 0 : if (d.data != NULL)
235 : : memcpy(rsa->d.data, d.data, d.length);
236 : 0 : rsa->d.length = d.length;
237 : : }
238 : 0 : rsa->n.length = mod_len;
239 : 0 : rsa->e.length = exp_len;
240 : :
241 : : /* Set padding info */
242 : 0 : rsa->padding.type = xform->rsa.padding.type;
243 : :
244 : : return 0;
245 : : }
246 : :
247 : : static __rte_always_inline int
248 : : cnxk_ae_fill_ec_params(struct cnxk_ae_sess *sess, struct rte_crypto_asym_xform *xform)
249 : : {
250 : : struct roc_ae_ec_ctx *ec = &sess->ec_ctx;
251 : 0 : union cpt_inst_w4 w4 = {0};
252 : :
253 [ # # # # : 0 : switch (xform->ec.curve_id) {
# # # #
# ]
254 : 0 : case RTE_CRYPTO_EC_GROUP_SECP192R1:
255 : 0 : ec->curveid = ROC_AE_EC_ID_P192;
256 : 0 : break;
257 : 0 : case RTE_CRYPTO_EC_GROUP_SECP224R1:
258 : 0 : ec->curveid = ROC_AE_EC_ID_P224;
259 : 0 : break;
260 : 0 : case RTE_CRYPTO_EC_GROUP_SECP256R1:
261 : 0 : ec->curveid = ROC_AE_EC_ID_P256;
262 : 0 : break;
263 : 0 : case RTE_CRYPTO_EC_GROUP_SECP384R1:
264 : 0 : ec->curveid = ROC_AE_EC_ID_P384;
265 : 0 : break;
266 : 0 : case RTE_CRYPTO_EC_GROUP_SECP521R1:
267 : 0 : ec->curveid = ROC_AE_EC_ID_P521;
268 : 0 : break;
269 : 0 : case RTE_CRYPTO_EC_GROUP_SM2:
270 : 0 : ec->curveid = ROC_AE_EC_ID_SM2;
271 : 0 : break;
272 : 0 : case RTE_CRYPTO_EC_GROUP_ED25519:
273 : 0 : ec->curveid = ROC_AE_EC_ID_ED25519;
274 : 0 : w4.s.param1 = ROC_AE_ED_PARAM1_25519;
275 : 0 : break;
276 : 0 : case RTE_CRYPTO_EC_GROUP_ED448:
277 : 0 : ec->curveid = ROC_AE_EC_ID_ED448;
278 : 0 : w4.s.param1 = ROC_AE_ED_PARAM1_448;
279 : 0 : break;
280 : : default:
281 : : /* Only NIST curves (FIPS 186-4) and SM2 are supported */
282 : : return -EINVAL;
283 : : }
284 : :
285 [ # # ]: 0 : if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_ECPM)
286 : : return 0;
287 : :
288 : 0 : ec->pkey.length = xform->ec.pkey.length;
289 [ # # ]: 0 : if (ec->pkey.length > ROC_AE_EC_DATA_MAX)
290 : 0 : ec->pkey.length = ROC_AE_EC_DATA_MAX;
291 [ # # ]: 0 : if (ec->pkey.length)
292 [ # # ]: 0 : rte_memcpy(ec->pkey.data, xform->ec.pkey.data, ec->pkey.length);
293 : :
294 : 0 : ec->q.x.length = xform->ec.q.x.length;
295 [ # # ]: 0 : if (ec->q.x.length > ROC_AE_EC_DATA_MAX)
296 : 0 : ec->q.x.length = ROC_AE_EC_DATA_MAX;
297 [ # # ]: 0 : if (ec->q.x.length)
298 [ # # ]: 0 : rte_memcpy(ec->q.x.data, xform->ec.q.x.data, ec->q.x.length);
299 : :
300 [ # # ]: 0 : if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_EDDSA) {
301 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EDDSA;
302 : :
303 : : /* Use q.x to store compressed public key. q.y is set to 0 */
304 : 0 : ec->q.y.length = 0;
305 : 0 : goto _exit;
306 : : }
307 : :
308 : 0 : ec->q.y.length = xform->ec.q.y.length;
309 [ # # ]: 0 : if (ec->q.y.length > ROC_AE_EC_DATA_MAX)
310 : 0 : ec->q.y.length = ROC_AE_EC_DATA_MAX;
311 [ # # ]: 0 : if (xform->ec.q.y.length)
312 [ # # ]: 0 : rte_memcpy(ec->q.y.data, xform->ec.q.y.data, ec->q.y.length);
313 : :
314 : 0 : _exit:
315 : 0 : sess->cpt_inst_w4 = w4.u64;
316 : : return 0;
317 : : }
318 : :
319 : : static __rte_always_inline int
320 : : cnxk_ae_fill_ml_kem_params(struct cnxk_ae_sess *sess,
321 : : struct rte_crypto_asym_xform *xform)
322 : : {
323 : : struct rte_crypto_ml_kem_xform *ml_kem = &sess->ml_kem_ctx;
324 [ # # ]: 0 : if (xform->mlkem.type == RTE_CRYPTO_ML_KEM_NONE)
325 : : return -EINVAL;
326 : :
327 : 0 : ml_kem->type = xform->mlkem.type;
328 : : return 0;
329 : : }
330 : :
331 : : static __rte_always_inline int
332 : : cnxk_ae_fill_ml_dsa_params(struct cnxk_ae_sess *sess,
333 : : struct rte_crypto_asym_xform *xform)
334 : : {
335 : : struct rte_crypto_ml_dsa_xform *ml_dsa = &sess->ml_dsa_ctx;
336 [ # # ]: 0 : if (xform->mldsa.type == RTE_CRYPTO_ML_DSA_NONE)
337 : : return -EINVAL;
338 : :
339 : 0 : ml_dsa->type = xform->mldsa.type;
340 : 0 : ml_dsa->sign_deterministic = xform->mldsa.sign_deterministic;
341 : 0 : ml_dsa->sign_prehash = xform->mldsa.sign_prehash;
342 : : return 0;
343 : : }
344 : :
345 : : static __rte_always_inline int
346 : : cnxk_ae_fill_session_parameters(struct cnxk_ae_sess *sess,
347 : : struct rte_crypto_asym_xform *xform)
348 : : {
349 : : int ret;
350 : :
351 : 0 : sess->xfrm_type = xform->xform_type;
352 : 0 : sess->msg_max_sz = cnxk_cpt_asym_get_mlen();
353 : :
354 [ # # # # : 0 : switch (xform->xform_type) {
# # ]
355 : : case RTE_CRYPTO_ASYM_XFORM_RSA:
356 : : ret = cnxk_ae_fill_rsa_params(sess, xform);
357 : : break;
358 : : case RTE_CRYPTO_ASYM_XFORM_MODEX:
359 : : ret = cnxk_ae_fill_modex_params(sess, xform);
360 : : break;
361 : : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
362 : : /* Fall through */
363 : : case RTE_CRYPTO_ASYM_XFORM_ECDH:
364 : : case RTE_CRYPTO_ASYM_XFORM_ECPM:
365 : : case RTE_CRYPTO_ASYM_XFORM_ECFPM:
366 : : case RTE_CRYPTO_ASYM_XFORM_SM2:
367 : : case RTE_CRYPTO_ASYM_XFORM_EDDSA:
368 : : ret = cnxk_ae_fill_ec_params(sess, xform);
369 : : break;
370 : : case RTE_CRYPTO_ASYM_XFORM_ML_KEM:
371 : : ret = cnxk_ae_fill_ml_kem_params(sess, xform);
372 : : break;
373 : : case RTE_CRYPTO_ASYM_XFORM_ML_DSA:
374 : : ret = cnxk_ae_fill_ml_dsa_params(sess, xform);
375 : : break;
376 : : default:
377 : : return -ENOTSUP;
378 : : }
379 : : return ret;
380 : : }
381 : :
382 : : static inline void
383 : 0 : cnxk_ae_free_session_parameters(struct cnxk_ae_sess *sess)
384 : : {
385 : : struct rte_crypto_modex_xform *mod;
386 : : struct rte_crypto_rsa_xform *rsa;
387 : :
388 [ # # # ]: 0 : switch (sess->xfrm_type) {
389 : 0 : case RTE_CRYPTO_ASYM_XFORM_RSA:
390 : : rsa = &sess->rsa_ctx;
391 : 0 : rte_free(rsa->n.data);
392 : 0 : break;
393 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
394 : : mod = &sess->mod_ctx;
395 : 0 : rte_free(mod->modulus.data);
396 : 0 : break;
397 : : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
398 : : /* Fall through */
399 : : case RTE_CRYPTO_ASYM_XFORM_ECPM:
400 : : case RTE_CRYPTO_ASYM_XFORM_ECFPM:
401 : : break;
402 : : default:
403 : : break;
404 : : }
405 : 0 : }
406 : :
407 : : static __rte_always_inline int
408 : : cnxk_ae_modex_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
409 : : struct rte_crypto_modex_xform *mod, struct cpt_inst_s *inst)
410 : : {
411 : 0 : uint32_t exp_len = mod->exponent.length;
412 : 0 : uint32_t mod_len = mod->modulus.length;
413 : : struct rte_crypto_mod_op_param mod_op;
414 : : uint64_t total_key_len;
415 : : union cpt_inst_w4 w4;
416 : : size_t base_len;
417 : : uint32_t dlen;
418 : : uint8_t *dptr;
419 : :
420 : 0 : mod_op = op->asym->modex;
421 : :
422 : : base_len = mod_op.base.length;
423 : 0 : if (unlikely(base_len > mod_len)) {
424 : : cnxk_ae_modex_param_normalize(&mod_op.base.data, &base_len, mod_len);
425 [ # # # # ]: 0 : if (base_len > mod_len) {
426 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
427 : 0 : return -ENOTSUP;
428 : : }
429 : : }
430 : :
431 : 0 : total_key_len = mod_len + exp_len;
432 : :
433 : : /* Input buffer */
434 : : dptr = meta_buf->vaddr;
435 : 0 : inst->dptr = (uintptr_t)dptr;
436 : 0 : memcpy(dptr, mod->modulus.data, total_key_len);
437 : 0 : dptr += total_key_len;
438 : : memcpy(dptr, mod_op.base.data, base_len);
439 : 0 : dptr += base_len;
440 : 0 : dlen = total_key_len + base_len;
441 : :
442 : : /* Setup opcodes */
443 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_MODEX;
444 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
445 : :
446 : 0 : w4.s.param1 = mod_len;
447 : 0 : w4.s.param2 = exp_len;
448 : 0 : w4.s.dlen = dlen;
449 : :
450 : 0 : inst->w4.u64 = w4.u64;
451 : 0 : inst->rptr = (uintptr_t)dptr;
452 : :
453 : 0 : return 0;
454 : : }
455 : :
456 : : static __rte_always_inline void
457 : : cnxk_ae_rsa_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
458 : : struct rte_crypto_rsa_xform *rsa,
459 : : rte_crypto_param *crypto_param, struct cpt_inst_s *inst)
460 : : {
461 : : struct rte_crypto_rsa_op_param rsa_op;
462 : 0 : uint32_t mod_len = rsa->n.length;
463 : 0 : uint32_t exp_len = rsa->e.length;
464 : : uint64_t total_key_len;
465 : : union cpt_inst_w4 w4;
466 : : uint32_t in_size;
467 : : uint32_t dlen;
468 : : uint8_t *dptr;
469 : :
470 : : rsa_op = op->asym->rsa;
471 : 0 : total_key_len = mod_len + exp_len;
472 : :
473 : : /* Input buffer */
474 : : dptr = meta_buf->vaddr;
475 : 0 : inst->dptr = (uintptr_t)dptr;
476 : 0 : memcpy(dptr, rsa->n.data, total_key_len);
477 : 0 : dptr += total_key_len;
478 : :
479 : 0 : in_size = crypto_param->length;
480 : 0 : memcpy(dptr, crypto_param->data, in_size);
481 : :
482 : 0 : dptr += in_size;
483 : 0 : dlen = total_key_len + in_size;
484 : :
485 [ # # # # : 0 : if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
# # # # ]
486 : : /* Use mod_exp operation for no_padding type */
487 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
488 : 0 : w4.s.param2 = exp_len;
489 : : } else {
490 : : if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
491 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_ENC;
492 : : /* Public key encrypt, use BT2*/
493 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE2 |
494 : 0 : ((uint16_t)(exp_len) << 1);
495 : : } else if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
496 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_DEC;
497 : : /* Public key decrypt, use BT1 */
498 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE1;
499 : : }
500 : : }
501 : :
502 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_MODEX;
503 : :
504 : 0 : w4.s.param1 = mod_len;
505 : 0 : w4.s.dlen = dlen;
506 : :
507 : 0 : inst->w4.u64 = w4.u64;
508 : 0 : inst->rptr = (uintptr_t)dptr;
509 : 0 : }
510 : :
511 : : static __rte_always_inline void
512 : : cnxk_ae_rsa_exp_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
513 : : struct rte_crypto_rsa_xform *rsa, rte_crypto_param *crypto_param,
514 : : struct cpt_inst_s *inst)
515 : : {
516 : : struct rte_crypto_rsa_op_param rsa_op;
517 : 0 : uint32_t privkey_len = rsa->d.length;
518 : 0 : uint32_t mod_len = rsa->n.length;
519 : : union cpt_inst_w4 w4;
520 : : uint32_t in_size;
521 : : uint32_t dlen;
522 : : uint8_t *dptr;
523 : :
524 : : rsa_op = op->asym->rsa;
525 : :
526 : : /* Input buffer */
527 : : dptr = meta_buf->vaddr;
528 : 0 : inst->dptr = (uintptr_t)dptr;
529 [ # # # # : 0 : memcpy(dptr, rsa->n.data, mod_len);
# # # # ]
530 : 0 : dptr += mod_len;
531 : 0 : memcpy(dptr, rsa->d.data, privkey_len);
532 : 0 : dptr += privkey_len;
533 : :
534 : 0 : in_size = crypto_param->length;
535 : 0 : memcpy(dptr, crypto_param->data, in_size);
536 : :
537 : 0 : dptr += in_size;
538 : 0 : dlen = mod_len + privkey_len + in_size;
539 : :
540 [ # # # # : 0 : if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
# # # # ]
541 : : /* Use mod_exp operation for no_padding type */
542 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX;
543 : 0 : w4.s.param2 = privkey_len;
544 : : } else {
545 : : if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
546 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_ENC;
547 : : /* Private key encrypt (exponent), use BT1*/
548 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE1 | ((uint16_t)(privkey_len) << 1);
549 : : } else if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
550 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_DEC;
551 : : /* Private key decrypt (exponent), use BT2 */
552 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE2;
553 : : }
554 : : }
555 : :
556 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_MODEX;
557 : :
558 : 0 : w4.s.param1 = mod_len;
559 : 0 : w4.s.dlen = dlen;
560 : :
561 : 0 : inst->w4.u64 = w4.u64;
562 : 0 : inst->rptr = (uintptr_t)dptr;
563 : 0 : }
564 : :
565 : : static __rte_always_inline void
566 : : cnxk_ae_rsa_crt_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
567 : : struct rte_crypto_rsa_xform *rsa, rte_crypto_param *crypto_param,
568 : : struct cpt_inst_s *inst)
569 : : {
570 : 0 : uint32_t qInv_len = rsa->qt.qInv.length;
571 : : struct rte_crypto_rsa_op_param rsa_op;
572 : 0 : uint32_t dP_len = rsa->qt.dP.length;
573 : 0 : uint32_t dQ_len = rsa->qt.dQ.length;
574 : 0 : uint32_t p_len = rsa->qt.p.length;
575 : 0 : uint32_t q_len = rsa->qt.q.length;
576 : 0 : uint32_t mod_len = rsa->n.length;
577 : : uint64_t total_key_len;
578 : : union cpt_inst_w4 w4;
579 : : uint32_t in_size;
580 : : uint32_t dlen;
581 : : uint8_t *dptr;
582 : :
583 : : rsa_op = op->asym->rsa;
584 : 0 : total_key_len = p_len + q_len + dP_len + dQ_len + qInv_len;
585 : :
586 : : /* Input buffer */
587 : : dptr = meta_buf->vaddr;
588 : 0 : inst->dptr = (uintptr_t)dptr;
589 [ # # # # : 0 : memcpy(dptr, rsa->qt.q.data, total_key_len);
# # # # ]
590 : 0 : dptr += total_key_len;
591 : :
592 : 0 : in_size = crypto_param->length;
593 : 0 : memcpy(dptr, crypto_param->data, in_size);
594 : :
595 : 0 : dptr += in_size;
596 : 0 : dlen = total_key_len + in_size;
597 : :
598 [ # # # # : 0 : if (rsa->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
# # # # ]
599 : : /*Use mod_exp operation for no_padding type */
600 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_MODEX_CRT;
601 : : } else {
602 : : if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
603 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_ENC_CRT;
604 : : /* Private encrypt, use BT1 */
605 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE1;
606 : : } else if (rsa_op.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
607 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_PKCS_DEC_CRT;
608 : : /* Private decrypt, use BT2 */
609 : 0 : w4.s.param2 = ROC_AE_CPT_BLOCK_TYPE2;
610 : : }
611 : : }
612 : :
613 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_MODEX;
614 : :
615 : 0 : w4.s.param1 = mod_len;
616 : 0 : w4.s.dlen = dlen;
617 : :
618 : 0 : inst->w4.u64 = w4.u64;
619 : 0 : inst->rptr = (uintptr_t)dptr;
620 : 0 : }
621 : :
622 : : static __rte_always_inline int __rte_hot
623 : : cnxk_ae_enqueue_rsa_op(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
624 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
625 : : {
626 : : struct rte_crypto_rsa_op_param *rsa = &op->asym->rsa;
627 : : struct rte_crypto_rsa_xform *ctx = &sess->rsa_ctx;
628 : :
629 [ # # # # : 0 : switch (rsa->op_type) {
# # # # #
# ]
630 [ # # # # ]: 0 : case RTE_CRYPTO_ASYM_OP_VERIFY:
631 : : cnxk_ae_rsa_prep(op, meta_buf, ctx, &rsa->sign, inst);
632 : : break;
633 [ # # # # ]: 0 : case RTE_CRYPTO_ASYM_OP_ENCRYPT:
634 : : cnxk_ae_rsa_prep(op, meta_buf, ctx, &rsa->message, inst);
635 : : break;
636 : 0 : case RTE_CRYPTO_ASYM_OP_SIGN:
637 [ # # # # ]: 0 : if (ctx->key_type == RTE_RSA_KEY_TYPE_QT)
638 : : cnxk_ae_rsa_crt_prep(op, meta_buf, ctx, &rsa->message, inst);
639 : : else
640 : : cnxk_ae_rsa_exp_prep(op, meta_buf, ctx, &rsa->message, inst);
641 : : break;
642 : 0 : case RTE_CRYPTO_ASYM_OP_DECRYPT:
643 [ # # # # ]: 0 : if (ctx->key_type == RTE_RSA_KEY_TYPE_QT)
644 : : cnxk_ae_rsa_crt_prep(op, meta_buf, ctx, &rsa->cipher, inst);
645 : : else
646 : : cnxk_ae_rsa_exp_prep(op, meta_buf, ctx, &rsa->cipher, inst);
647 : : break;
648 : 0 : default:
649 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
650 : 0 : return -EINVAL;
651 : : }
652 : : return 0;
653 : : }
654 : :
655 : : static __rte_always_inline int __rte_hot
656 : : cnxk_ae_enqueue_ml_kem_op(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
657 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
658 : : {
659 : 0 : size_t metabuf_len = cnxk_cpt_asym_get_mlen(), reqbuf_len;
660 : : struct rte_crypto_ml_kem_op *mlkem = &op->asym->mlkem;
661 : : union cpt_inst_w4 w4;
662 : : uint32_t dlen = 0;
663 : : uint16_t param2;
664 : : uint8_t *dptr;
665 : :
666 : : /* Input buffer */
667 : : dptr = meta_buf->vaddr;
668 : 0 : inst->dptr = (uintptr_t)dptr;
669 : :
670 [ # # # # : 0 : switch (mlkem->op) {
# # # # ]
671 : 0 : case RTE_CRYPTO_ML_KEM_OP_KEYGEN:
672 : 0 : reqbuf_len = mlkem->keygen.d.length + mlkem->keygen.z.length;
673 [ # # # # ]: 0 : if (reqbuf_len > (metabuf_len - dlen)) {
674 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
675 : 0 : return -ENOMEM;
676 : : }
677 : :
678 [ # # # # ]: 0 : memcpy(dptr, mlkem->keygen.d.data, mlkem->keygen.d.length);
679 : 0 : dptr += mlkem->keygen.d.length;
680 : 0 : memcpy(dptr, mlkem->keygen.z.data, mlkem->keygen.z.length);
681 : 0 : dptr += mlkem->keygen.z.length;
682 : :
683 : 0 : dlen = mlkem->keygen.d.length + mlkem->keygen.z.length;
684 : 0 : w4.s.opcode_major = ROC_RE_MAJOR_OP_MLKEM;
685 : 0 : w4.s.opcode_minor = ROC_RE_MINOR_OP_MLKEM_KEYGEN;
686 : 0 : param2 = sess->ml_kem_ctx.type;
687 [ # # # # ]: 0 : param2 |= (!!dlen << ROC_RE_ML_KEM_PARAM2_INSEED_BIT);
688 : 0 : break;
689 : 0 : case RTE_CRYPTO_ML_KEM_OP_ENCAP:
690 : 0 : reqbuf_len = mlkem->encap.message.length + mlkem->encap.ek.length;
691 [ # # # # ]: 0 : if (reqbuf_len > (metabuf_len - dlen)) {
692 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
693 : 0 : return -ENOMEM;
694 : : }
695 : :
696 [ # # # # ]: 0 : memcpy(dptr, mlkem->encap.message.data, mlkem->encap.message.length);
697 : 0 : dptr += mlkem->encap.message.length;
698 : 0 : memcpy(dptr, mlkem->encap.ek.data, mlkem->encap.ek.length);
699 : 0 : dptr += mlkem->encap.ek.length;
700 : :
701 : 0 : dlen = mlkem->encap.message.length + mlkem->encap.ek.length;
702 : 0 : w4.s.opcode_major = ROC_RE_MAJOR_OP_MLKEM;
703 : 0 : w4.s.opcode_minor = ROC_RE_MINOR_OP_MLKEM_ENCAP;
704 : 0 : param2 = sess->ml_kem_ctx.type;
705 [ # # # # ]: 0 : param2 |= (!!mlkem->encap.message.length << ROC_RE_ML_KEM_PARAM2_INMSG_BIT);
706 : 0 : break;
707 : 0 : case RTE_CRYPTO_ML_KEM_OP_DECAP:
708 : 0 : reqbuf_len = mlkem->decap.dk.length + mlkem->decap.cipher.length;
709 [ # # # # ]: 0 : if (reqbuf_len > (metabuf_len - dlen)) {
710 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
711 : 0 : return -ENOMEM;
712 : : }
713 : :
714 : 0 : memcpy(dptr, mlkem->decap.dk.data, mlkem->decap.dk.length);
715 : 0 : dptr += mlkem->decap.dk.length;
716 : 0 : memcpy(dptr, mlkem->decap.cipher.data, mlkem->decap.cipher.length);
717 : 0 : dptr += mlkem->decap.cipher.length;
718 : :
719 : 0 : dlen = mlkem->decap.cipher.length + mlkem->decap.dk.length;
720 : 0 : w4.s.opcode_major = ROC_RE_MAJOR_OP_MLKEM;
721 : 0 : w4.s.opcode_minor = ROC_RE_MINOR_OP_MLKEM_DECAP;
722 : 0 : param2 = sess->ml_kem_ctx.type;
723 : 0 : break;
724 : 0 : default:
725 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
726 : 0 : return -EINVAL;
727 : : }
728 : :
729 : 0 : w4.s.param1 = 0;
730 : 0 : w4.s.param2 = param2;
731 : 0 : w4.s.dlen = dlen;
732 : :
733 : 0 : inst->w4.u64 = w4.u64;
734 : :
735 : : /* Reuse entire space of meta buffer as output is large in PQC */
736 : 0 : inst->rptr = (uintptr_t)meta_buf->vaddr;
737 : :
738 : 0 : return 0;
739 : : }
740 : :
741 : : static __rte_always_inline int __rte_hot
742 : : cnxk_ae_enqueue_ml_dsa_op(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
743 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
744 : : {
745 : 0 : size_t metabuf_len = cnxk_cpt_asym_get_mlen(), reqbuf_len;
746 : : struct rte_crypto_ml_dsa_op *mldsa = &op->asym->mldsa;
747 : : enum rte_crypto_auth_algorithm hash;
748 : : bool sign_deterministic;
749 : : union cpt_inst_w4 w4;
750 : : uint16_t param1 = 0;
751 : : uint32_t dlen = 0;
752 : : uint16_t param2;
753 : : uint8_t *dptr;
754 : : uint8_t minor;
755 : :
756 : : /* Input buffer */
757 : : dptr = meta_buf->vaddr;
758 : 0 : inst->dptr = (uintptr_t)dptr;
759 : :
760 [ # # # # : 0 : switch (mldsa->op) {
# # # # ]
761 : 0 : case RTE_CRYPTO_ML_DSA_OP_KEYGEN:
762 : 0 : reqbuf_len = mldsa->keygen.seed.length;
763 [ # # # # ]: 0 : if (reqbuf_len > (metabuf_len - dlen)) {
764 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
765 : 0 : return -ENOMEM;
766 : : }
767 : :
768 : 0 : param2 = sess->ml_dsa_ctx.type;
769 : :
770 [ # # # # ]: 0 : memcpy(dptr, mldsa->keygen.seed.data, mldsa->keygen.seed.length);
771 : 0 : dptr += mldsa->keygen.seed.length;
772 [ # # # # ]: 0 : param2 |= (!!mldsa->keygen.seed.length << ROC_RE_ML_DSA_PARAM2_SEED_BIT);
773 : :
774 : 0 : dlen += mldsa->keygen.seed.length;
775 : 0 : w4.s.opcode_major = ROC_RE_MAJOR_OP_MLDSA;
776 : 0 : w4.s.opcode_minor = ROC_RE_MINOR_OP_MLDSA_KEYGEN;
777 : 0 : break;
778 : 0 : case RTE_CRYPTO_ML_DSA_OP_SIGN:
779 : 0 : reqbuf_len = mldsa->siggen.message.length + mldsa->siggen.privkey.length +
780 : 0 : mldsa->siggen.ctx.length + mldsa->siggen.mu.length +
781 : 0 : mldsa->siggen.seed.length;
782 : :
783 [ # # # # ]: 0 : if (reqbuf_len > (metabuf_len - dlen)) {
784 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
785 : 0 : return -ENOMEM;
786 : : }
787 : :
788 : 0 : sign_deterministic = sess->ml_dsa_ctx.sign_deterministic;
789 : 0 : hash = op->asym->mldsa.siggen.hash;
790 : : minor = ROC_RE_MINOR_OP_MLDSA_SIGN;
791 : :
792 : 0 : param1 = mldsa->siggen.message.length;
793 : 0 : param2 = sess->ml_dsa_ctx.type;
794 [ # # # # ]: 0 : if (hash == 0) {
795 : : minor |= (0 << ROC_RE_ML_DSA_MINOR_MSG_TYPE_BIT);
796 [ # # # # ]: 0 : } else if (mldsa->siggen.mu.length != 0) {
797 : : minor |= (3 << ROC_RE_ML_DSA_MINOR_MSG_TYPE_BIT);
798 : : } else {
799 [ # # # # : 0 : if (!sess->ml_dsa_ctx.sign_prehash ||
# # # # ]
800 [ # # # # ]: 0 : hash >= RTE_DIM(mldsa_hash_algo) || mldsa_hash_algo[hash] == 0) {
801 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
802 : 0 : return -EINVAL;
803 : : }
804 : :
805 : : minor |= (1 << ROC_RE_ML_DSA_MINOR_MSG_TYPE_BIT);
806 : 0 : param2 |= (mldsa_hash_algo[hash] << ROC_RE_ML_DSA_PARAM2_SIGN_BIT);
807 : : }
808 : :
809 [ # # # # ]: 0 : minor |= ((sign_deterministic ? 0 : 2) << ROC_RE_ML_DSA_MINOR_SIGN_TYPE_BIT);
810 : :
811 [ # # # # ]: 0 : if (!sign_deterministic) {
812 [ # # # # ]: 0 : if (!mldsa->siggen.seed.length) {
813 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
814 : 0 : return -EINVAL;
815 : : }
816 : :
817 : 0 : memcpy(dptr, mldsa->siggen.seed.data, mldsa->siggen.seed.length);
818 : 0 : dptr += mldsa->siggen.seed.length;
819 : 0 : dlen += mldsa->siggen.seed.length;
820 : : }
821 : :
822 [ # # # # ]: 0 : memcpy(dptr, mldsa->siggen.privkey.data, mldsa->siggen.privkey.length);
823 : 0 : dptr += mldsa->siggen.privkey.length;
824 : 0 : dlen += mldsa->siggen.privkey.length;
825 : :
826 : 0 : memcpy(dptr, mldsa->siggen.ctx.data, mldsa->siggen.ctx.length);
827 : 0 : dptr += mldsa->siggen.ctx.length;
828 : 0 : dlen += mldsa->siggen.ctx.length;
829 [ # # # # ]: 0 : if (mldsa->siggen.ctx.length > (UINT16_MAX >> ROC_RE_ML_DSA_PARAM2_CTXN_BIT)) {
830 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
831 : 0 : return -EINVAL;
832 : : }
833 : 0 : param2 |= ((uint16_t)mldsa->siggen.ctx.length
834 : 0 : << ROC_RE_ML_DSA_PARAM2_CTXN_BIT);
835 : :
836 [ # # # # ]: 0 : if (mldsa->siggen.mu.length != 0) {
837 : 0 : memcpy(dptr, mldsa->siggen.mu.data, mldsa->siggen.mu.length);
838 : 0 : dptr += mldsa->siggen.mu.length;
839 : 0 : dlen += mldsa->siggen.mu.length;
840 : 0 : param1 = mldsa->siggen.mu.length;
841 [ # # # # ]: 0 : } else if (mldsa->siggen.message.length != 0) {
842 : 0 : memcpy(dptr, mldsa->siggen.message.data, mldsa->siggen.message.length);
843 : 0 : dptr += mldsa->siggen.message.length;
844 : 0 : dlen += mldsa->siggen.message.length;
845 : : }
846 : :
847 : 0 : w4.s.opcode_major = ROC_RE_MAJOR_OP_MLDSA;
848 : 0 : w4.s.opcode_minor = minor;
849 : 0 : break;
850 : 0 : case RTE_CRYPTO_ML_DSA_OP_VERIFY:
851 : 0 : reqbuf_len = mldsa->sigver.message.length + mldsa->sigver.pubkey.length +
852 : 0 : mldsa->sigver.ctx.length + mldsa->sigver.mu.length +
853 : 0 : mldsa->sigver.sign.length;
854 : :
855 [ # # # # ]: 0 : if (reqbuf_len > (metabuf_len - dlen)) {
856 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
857 : 0 : return -ENOMEM;
858 : : }
859 : :
860 : 0 : hash = op->asym->mldsa.sigver.hash;
861 : : minor = ROC_RE_MINOR_OP_MLDSA_VERIFY;
862 : :
863 : 0 : param1 = mldsa->sigver.message.length;
864 : 0 : param2 = sess->ml_dsa_ctx.type;
865 [ # # # # ]: 0 : if (hash == 0) {
866 : : minor |= (0 << ROC_RE_ML_DSA_MINOR_MSG_TYPE_BIT);
867 [ # # # # ]: 0 : } else if (mldsa->sigver.mu.length != 0) {
868 : : minor |= (3 << ROC_RE_ML_DSA_MINOR_MSG_TYPE_BIT);
869 : : } else {
870 [ # # # # : 0 : if (!sess->ml_dsa_ctx.sign_prehash ||
# # # # ]
871 [ # # # # ]: 0 : hash >= RTE_DIM(mldsa_hash_algo) || mldsa_hash_algo[hash] == 0) {
872 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
873 : 0 : return -EINVAL;
874 : : }
875 : :
876 : : minor |= (1 << ROC_RE_ML_DSA_MINOR_MSG_TYPE_BIT);
877 : 0 : param2 |= (mldsa_hash_algo[hash] << ROC_RE_ML_DSA_PARAM2_SIGN_BIT);
878 : : }
879 : :
880 [ # # # # ]: 0 : memcpy(dptr, mldsa->sigver.pubkey.data, mldsa->sigver.pubkey.length);
881 : 0 : dptr += mldsa->sigver.pubkey.length;
882 : 0 : dlen += mldsa->sigver.pubkey.length;
883 : :
884 : 0 : memcpy(dptr, mldsa->sigver.ctx.data, mldsa->sigver.ctx.length);
885 : 0 : dptr += mldsa->sigver.ctx.length;
886 : 0 : dlen += mldsa->sigver.ctx.length;
887 [ # # # # ]: 0 : if (mldsa->sigver.ctx.length > (UINT16_MAX >> ROC_RE_ML_DSA_PARAM2_CTXN_BIT)) {
888 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
889 : 0 : return -EINVAL;
890 : : }
891 : 0 : param2 |= ((uint16_t)mldsa->sigver.ctx.length
892 : 0 : << ROC_RE_ML_DSA_PARAM2_CTXN_BIT);
893 : :
894 [ # # # # ]: 0 : if (mldsa->sigver.mu.length != 0) {
895 : 0 : memcpy(dptr, mldsa->sigver.mu.data, mldsa->sigver.mu.length);
896 : 0 : dptr += mldsa->sigver.mu.length;
897 : 0 : dlen += mldsa->sigver.mu.length;
898 : 0 : param1 = mldsa->sigver.mu.length;
899 [ # # # # ]: 0 : } else if (mldsa->sigver.message.length != 0) {
900 : 0 : memcpy(dptr, mldsa->sigver.message.data, mldsa->sigver.message.length);
901 : 0 : dptr += mldsa->sigver.message.length;
902 : 0 : dlen += mldsa->sigver.message.length;
903 : : }
904 : :
905 : 0 : memcpy(dptr, mldsa->sigver.sign.data, mldsa->sigver.sign.length);
906 : 0 : dptr += mldsa->sigver.sign.length;
907 : 0 : dlen += mldsa->sigver.sign.length;
908 : :
909 : 0 : w4.s.opcode_major = ROC_RE_MAJOR_OP_MLDSA;
910 : 0 : w4.s.opcode_minor = minor;
911 : 0 : break;
912 : 0 : default:
913 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
914 : 0 : return -EINVAL;
915 : : }
916 : :
917 : 0 : w4.s.param1 = param1;
918 : 0 : w4.s.param2 = param2;
919 : 0 : w4.s.dlen = dlen;
920 : :
921 : 0 : inst->w4.u64 = w4.u64;
922 : :
923 : : /* Reuse entire space of meta buffer as output is large in PQC */
924 : 0 : inst->rptr = (uintptr_t)meta_buf->vaddr;
925 : :
926 : 0 : return 0;
927 : : }
928 : :
929 : : static __rte_always_inline void
930 : : cnxk_ae_ecdsa_sign_prep(struct rte_crypto_ecdsa_op_param *ecdsa,
931 : : struct roc_ae_buf_ptr *meta_buf,
932 : : uint64_t fpm_table_iova, struct roc_ae_ec_group *ec_grp,
933 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
934 : : {
935 : 0 : uint16_t message_len = ecdsa->message.length;
936 : 0 : uint16_t pkey_len = sess->ec_ctx.pkey.length;
937 : : uint8_t curveid = sess->ec_ctx.curveid;
938 : : uint16_t p_align, k_align, m_align;
939 : 0 : uint16_t k_len = ecdsa->k.length;
940 : : uint16_t order_len, prime_len;
941 : : uint16_t o_offset, pk_offset;
942 : : union cpt_inst_w4 w4;
943 : : uint16_t dlen;
944 : : uint8_t *dptr;
945 : :
946 : 0 : prime_len = ec_grp->prime.length;
947 : 0 : order_len = ec_grp->order.length;
948 : :
949 : : /* Truncate input length to curve prime length */
950 : : if (message_len > prime_len)
951 : : message_len = prime_len;
952 : 0 : m_align = RTE_ALIGN_CEIL(message_len, 8);
953 : :
954 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
955 : 0 : k_align = RTE_ALIGN_CEIL(k_len, 8);
956 : :
957 : : /* Set write offset for order and private key */
958 : 0 : o_offset = prime_len - order_len;
959 : 0 : pk_offset = p_align - pkey_len;
960 : :
961 : : /* Input buffer */
962 : : dptr = meta_buf->vaddr;
963 : 0 : inst->dptr = (uintptr_t)dptr;
964 : :
965 : : /*
966 : : * Set dlen = sum(sizeof(fpm address), ROUNDUP8(scalar len, input len),
967 : : * ROUNDUP8(priv key len, prime len, order len)).
968 : : * Please note, private key, order cannot exceed prime
969 : : * length i.e 3 * p_align.
970 : : */
971 : 0 : dlen = sizeof(fpm_table_iova) + k_align + m_align + p_align * 5;
972 : :
973 : 0 : memset(dptr, 0, dlen);
974 : :
975 : 0 : *(uint64_t *)dptr = fpm_table_iova;
976 : 0 : dptr += sizeof(fpm_table_iova);
977 : :
978 : 0 : memcpy(dptr, ecdsa->k.data, k_len);
979 : 0 : dptr += k_align;
980 : :
981 : 0 : memcpy(dptr, ec_grp->prime.data, prime_len);
982 : 0 : dptr += p_align;
983 : :
984 : 0 : memcpy(dptr + o_offset, ec_grp->order.data, order_len);
985 : 0 : dptr += p_align;
986 : :
987 : 0 : memcpy(dptr + pk_offset, sess->ec_ctx.pkey.data, pkey_len);
988 : 0 : dptr += p_align;
989 : :
990 : 0 : memcpy(dptr, ecdsa->message.data, message_len);
991 : 0 : dptr += m_align;
992 : :
993 : 0 : memcpy(dptr, ec_grp->consta.data, prime_len);
994 : 0 : dptr += p_align;
995 : :
996 : 0 : memcpy(dptr, ec_grp->constb.data, prime_len);
997 : 0 : dptr += p_align;
998 : :
999 : : /* Setup opcodes */
1000 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EC;
1001 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_SIGN;
1002 : :
1003 : 0 : w4.s.param1 = curveid | (message_len << 8);
1004 : 0 : w4.s.param2 = (p_align << 8) | k_len;
1005 : 0 : w4.s.dlen = dlen;
1006 : :
1007 : 0 : inst->w4.u64 = w4.u64;
1008 : 0 : inst->rptr = (uintptr_t)dptr;
1009 : 0 : }
1010 : :
1011 : : static __rte_always_inline void
1012 : : cnxk_ae_ecdsa_verify_prep(struct rte_crypto_ecdsa_op_param *ecdsa,
1013 : : struct roc_ae_buf_ptr *meta_buf,
1014 : : uint64_t fpm_table_iova,
1015 : : struct roc_ae_ec_group *ec_grp, struct cnxk_ae_sess *sess,
1016 : : struct cpt_inst_s *inst)
1017 : : {
1018 : 0 : uint32_t message_len = ecdsa->message.length;
1019 : 0 : uint16_t qx_len = sess->ec_ctx.q.x.length;
1020 : 0 : uint16_t qy_len = sess->ec_ctx.q.y.length;
1021 : : uint8_t curveid = sess->ec_ctx.curveid;
1022 : : uint16_t o_offset, r_offset, s_offset;
1023 : 0 : uint16_t r_len = ecdsa->r.length;
1024 : 0 : uint16_t s_len = ecdsa->s.length;
1025 : : uint16_t order_len, prime_len;
1026 : : uint16_t qx_offset, qy_offset;
1027 : : uint16_t p_align, m_align;
1028 : : union cpt_inst_w4 w4;
1029 : : uint16_t dlen;
1030 : : uint8_t *dptr;
1031 : :
1032 : 0 : prime_len = ec_grp->prime.length;
1033 : 0 : order_len = ec_grp->order.length;
1034 : :
1035 : : /* Truncate input length to curve prime length */
1036 : : if (message_len > prime_len)
1037 : : message_len = prime_len;
1038 : :
1039 : 0 : m_align = RTE_ALIGN_CEIL(message_len, 8);
1040 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
1041 : :
1042 : : /* Set write offset for sign, order and public key coordinates */
1043 : 0 : o_offset = prime_len - order_len;
1044 : 0 : qx_offset = prime_len - qx_len;
1045 : 0 : qy_offset = prime_len - qy_len;
1046 : 0 : r_offset = prime_len - r_len;
1047 : 0 : s_offset = prime_len - s_len;
1048 : :
1049 : : /* Input buffer */
1050 : : dptr = meta_buf->vaddr;
1051 : 0 : inst->dptr = (uintptr_t)dptr;
1052 : :
1053 : : /*
1054 : : * Set dlen = sum(sizeof(fpm address), ROUNDUP8(message len),
1055 : : * ROUNDUP8(sign len(r and s), public key len(x and y coordinates),
1056 : : * prime len, order len)).
1057 : : * Please note sign, public key and order can not exceed prime length
1058 : : * i.e. 6 * p_align
1059 : : */
1060 : 0 : dlen = sizeof(fpm_table_iova) + m_align + (8 * p_align);
1061 : :
1062 : 0 : memset(dptr, 0, dlen);
1063 : :
1064 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1065 : 0 : dptr += sizeof(fpm_table_iova);
1066 : :
1067 : 0 : memcpy(dptr + r_offset, ecdsa->r.data, r_len);
1068 : 0 : dptr += p_align;
1069 : :
1070 : 0 : memcpy(dptr + s_offset, ecdsa->s.data, s_len);
1071 : 0 : dptr += p_align;
1072 : :
1073 : 0 : memcpy(dptr, ecdsa->message.data, message_len);
1074 : 0 : dptr += m_align;
1075 : :
1076 : 0 : memcpy(dptr + o_offset, ec_grp->order.data, order_len);
1077 : 0 : dptr += p_align;
1078 : :
1079 : 0 : memcpy(dptr, ec_grp->prime.data, prime_len);
1080 : 0 : dptr += p_align;
1081 : :
1082 : 0 : memcpy(dptr + qx_offset, sess->ec_ctx.q.x.data, qx_len);
1083 : 0 : dptr += p_align;
1084 : :
1085 : 0 : memcpy(dptr + qy_offset, sess->ec_ctx.q.y.data, qy_len);
1086 : 0 : dptr += p_align;
1087 : :
1088 : 0 : memcpy(dptr, ec_grp->consta.data, prime_len);
1089 : 0 : dptr += p_align;
1090 : :
1091 : 0 : memcpy(dptr, ec_grp->constb.data, prime_len);
1092 : 0 : dptr += p_align;
1093 : :
1094 : : /* Setup opcodes */
1095 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EC;
1096 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_VERIFY;
1097 : :
1098 : 0 : w4.s.param1 = curveid | (message_len << 8);
1099 : 0 : w4.s.param2 = 0;
1100 : 0 : w4.s.dlen = dlen;
1101 : :
1102 : 0 : inst->w4.u64 = w4.u64;
1103 : 0 : inst->rptr = (uintptr_t)dptr;
1104 : 0 : }
1105 : :
1106 : : static __rte_always_inline int __rte_hot
1107 : : cnxk_ae_enqueue_ecdsa_op(struct rte_crypto_op *op,
1108 : : struct roc_ae_buf_ptr *meta_buf,
1109 : : struct cnxk_ae_sess *sess, uint64_t *fpm_iova,
1110 : : struct roc_ae_ec_group **ec_grp,
1111 : : struct cpt_inst_s *inst)
1112 : : {
1113 : : struct rte_crypto_ecdsa_op_param *ecdsa = &op->asym->ecdsa;
1114 : 0 : uint8_t curveid = sess->ec_ctx.curveid;
1115 : :
1116 : 0 : if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_SIGN)
1117 : 0 : cnxk_ae_ecdsa_sign_prep(ecdsa, meta_buf, fpm_iova[curveid],
1118 : 0 : ec_grp[curveid], sess, inst);
1119 [ # # # # ]: 0 : else if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
1120 : 0 : cnxk_ae_ecdsa_verify_prep(ecdsa, meta_buf, fpm_iova[curveid],
1121 : 0 : ec_grp[curveid], sess, inst);
1122 : : else {
1123 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1124 : 0 : return -EINVAL;
1125 : : }
1126 : : return 0;
1127 : : }
1128 : :
1129 : : static __rte_always_inline void
1130 : : cnxk_ae_eddsa_sign_prep(struct rte_crypto_eddsa_op_param *eddsa, struct roc_ae_buf_ptr *meta_buf,
1131 : : uint64_t fpm_table_iova, struct roc_ae_ec_group *ec_grp,
1132 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
1133 : : {
1134 : 0 : const uint8_t iv_sha512[] = {
1135 : : 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08,
1136 : : 0xbb, 0x67, 0xae, 0x85, 0x84, 0xca, 0xa7, 0x3b,
1137 : : 0x3c, 0x6e, 0xf3, 0x72, 0xfe, 0x94, 0xf8, 0x2b,
1138 : : 0xa5, 0x4f, 0xf5, 0x3a, 0x5f, 0x1d, 0x36, 0xf1,
1139 : : 0x51, 0x0e, 0x52, 0x7f, 0xad, 0xe6, 0x82, 0xd1,
1140 : : 0x9b, 0x05, 0x68, 0x8c, 0x2b, 0x3e, 0x6c, 0x1f,
1141 : : 0x1f, 0x83, 0xd9, 0xab, 0xfb, 0x41, 0xbd, 0x6b,
1142 : : 0x5b, 0xe0, 0xcd, 0x19, 0x13, 0x7e, 0x21, 0x79};
1143 : 0 : const uint8_t domx_ed25519[] = {
1144 : : 0x53, 0x69, 0x67, 0x45, 0x64, 0x32, 0x35, 0x35,
1145 : : 0x31, 0x39, 0x20, 0x6E, 0x6F, 0x20, 0x45, 0x64,
1146 : : 0x32, 0x35, 0x35, 0x31, 0x39, 0x20, 0x63, 0x6F,
1147 : : 0x6C, 0x6C, 0x69, 0x73, 0x69, 0x6F, 0x6E, 0x73,
1148 : : 0x00, 0x00};
1149 : 0 : const uint8_t domx_ed448[] = {
1150 : : 0x53, 0x69, 0x67, 0x45, 0x64, 0x34, 0x34, 0x38,
1151 : : 0x00, 0x00};
1152 : :
1153 : 0 : uint16_t pubkey_len = sess->ec_ctx.q.x.length;
1154 : 0 : uint16_t message_len = eddsa->message.length;
1155 : 0 : uint16_t pkey_len = sess->ec_ctx.pkey.length;
1156 : : uint8_t curveid = sess->ec_ctx.curveid;
1157 : : const uint8_t *domx_ptr = NULL;
1158 : : uint16_t order_len, prime_len;
1159 : : uint16_t ctx_align, k_align;
1160 : : uint8_t pub = 0, ph = 0;
1161 : : uint64_t message_handle;
1162 : : union cpt_inst_w4 w4;
1163 : : uint8_t domx_len = 0;
1164 : : uint8_t ctx_len = 0;
1165 : : uint16_t iv_len = 0;
1166 : : uint64_t ctrl = 0;
1167 : : uint16_t dlen;
1168 : : uint8_t *dptr;
1169 : :
1170 : 0 : if (eddsa->instance == RTE_CRYPTO_EDCURVE_25519PH ||
1171 : : eddsa->instance == RTE_CRYPTO_EDCURVE_448PH)
1172 : : ph = 1;
1173 : :
1174 [ # # # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519)
1175 : : iv_len = sizeof(iv_sha512);
1176 : :
1177 : 0 : prime_len = ec_grp->prime.length;
1178 : 0 : order_len = ec_grp->order.length;
1179 : 0 : ctx_len = eddsa->context.length;
1180 : :
1181 [ # # # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
1182 [ # # # # ]: 0 : if (ph || ctx_len) {
1183 : : domx_ptr = domx_ed25519;
1184 : : domx_len = sizeof(domx_ed25519);
1185 : : }
1186 : : } else {
1187 : : domx_ptr = domx_ed448;
1188 : : domx_len = sizeof(domx_ed448);
1189 : : }
1190 : :
1191 [ # # # # ]: 0 : if (pubkey_len)
1192 : : pub = 1;
1193 : :
1194 : 0 : ctx_align = RTE_ALIGN_CEIL(ctx_len + domx_len, 8);
1195 : 0 : k_align = RTE_ALIGN_CEIL(pkey_len, 8);
1196 : :
1197 : : /* Set control word */
1198 : : ctrl = message_len;
1199 : 0 : ctrl |= (ctx_len + domx_len) << 16;
1200 : :
1201 : : /* Copy message and set message handle in metabuf */
1202 : : dptr = meta_buf->vaddr;
1203 [ # # # # ]: 0 : memcpy(dptr, eddsa->message.data, message_len);
1204 : 0 : message_handle = (uint64_t)dptr;
1205 : 0 : dptr += RTE_ALIGN_CEIL(message_len, 8);
1206 : :
1207 : : /* Input buffer */
1208 : 0 : inst->dptr = (uintptr_t)dptr;
1209 : :
1210 : : /*
1211 : : * Set dlen = sum(sizeof(fpm address), input handle, ctrl,
1212 : : * ROUNDUP8(prime len, order len, constant), ROUNDUP8(priv and
1213 : : * pubkey len), ROUNDUP8(context len) and iv len (if ED25519)).
1214 : : */
1215 : 0 : dlen = sizeof(fpm_table_iova) + sizeof(message_handle) + sizeof(ctrl) + prime_len * 3 +
1216 : 0 : k_align * 2 + ctx_align + iv_len;
1217 : :
1218 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1219 : : dptr += sizeof(fpm_table_iova);
1220 : :
1221 [ # # # # ]: 0 : *(uint64_t *)dptr = rte_cpu_to_be_64(message_handle);
1222 : : dptr += sizeof(message_handle);
1223 : :
1224 [ # # # # ]: 0 : *(uint64_t *)dptr = rte_cpu_to_be_64(ctrl);
1225 : 0 : dptr += sizeof(ctrl);
1226 : :
1227 [ # # # # ]: 0 : memcpy(dptr, ec_grp->prime.data, prime_len);
1228 : 0 : dptr += prime_len;
1229 : :
1230 : 0 : memcpy(dptr, ec_grp->order.data, order_len);
1231 : 0 : dptr += prime_len;
1232 : :
1233 : 0 : memcpy(dptr, ec_grp->consta.data, prime_len);
1234 : 0 : dptr += prime_len;
1235 : :
1236 : 0 : memcpy(dptr, sess->ec_ctx.pkey.data, pkey_len);
1237 : 0 : dptr += k_align;
1238 : :
1239 : 0 : memcpy(dptr, sess->ec_ctx.q.x.data, pubkey_len);
1240 : 0 : dptr += k_align;
1241 : :
1242 : 0 : memcpy(dptr, domx_ptr, domx_len);
1243 [ # # # # ]: 0 : if (eddsa->instance != RTE_CRYPTO_EDCURVE_25519) {
1244 : 0 : memset(dptr + (domx_len - 1), ctx_len, 1);
1245 : 0 : memset(dptr + (domx_len - 2), ph, 1);
1246 : : }
1247 : :
1248 [ # # # # ]: 0 : memcpy(dptr + domx_len, eddsa->context.data, ctx_len);
1249 : 0 : dptr += ctx_align;
1250 : :
1251 [ # # # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
1252 : 0 : memcpy(dptr, iv_sha512, iv_len);
1253 : 0 : dptr += iv_len;
1254 : : }
1255 : :
1256 : : /* Setup opcodes */
1257 : 0 : w4.u64 = sess->cpt_inst_w4;
1258 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_ED_SIGN;
1259 : 0 : w4.s.param1 |= ((pub << ROC_AE_ED_PARAM1_KEYGEN_BIT) | (ph << ROC_AE_EC_PARAM1_PH_BIT));
1260 : 0 : w4.s.param2 = 0;
1261 : 0 : w4.s.dlen = dlen;
1262 : :
1263 : 0 : inst->w4.u64 = w4.u64;
1264 : 0 : inst->rptr = (uintptr_t)dptr;
1265 : 0 : }
1266 : :
1267 : : static __rte_always_inline void
1268 : : cnxk_ae_eddsa_verify_prep(struct rte_crypto_eddsa_op_param *eddsa, struct roc_ae_buf_ptr *meta_buf,
1269 : : uint64_t fpm_table_iova, struct roc_ae_ec_group *ec_grp,
1270 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
1271 : : {
1272 : 0 : const uint8_t iv_sha512[] = {
1273 : : 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08,
1274 : : 0xbb, 0x67, 0xae, 0x85, 0x84, 0xca, 0xa7, 0x3b,
1275 : : 0x3c, 0x6e, 0xf3, 0x72, 0xfe, 0x94, 0xf8, 0x2b,
1276 : : 0xa5, 0x4f, 0xf5, 0x3a, 0x5f, 0x1d, 0x36, 0xf1,
1277 : : 0x51, 0x0e, 0x52, 0x7f, 0xad, 0xe6, 0x82, 0xd1,
1278 : : 0x9b, 0x05, 0x68, 0x8c, 0x2b, 0x3e, 0x6c, 0x1f,
1279 : : 0x1f, 0x83, 0xd9, 0xab, 0xfb, 0x41, 0xbd, 0x6b,
1280 : : 0x5b, 0xe0, 0xcd, 0x19, 0x13, 0x7e, 0x21, 0x79};
1281 : 0 : const uint8_t domx_ed25519[] = {
1282 : : 0x53, 0x69, 0x67, 0x45, 0x64, 0x32, 0x35, 0x35,
1283 : : 0x31, 0x39, 0x20, 0x6E, 0x6F, 0x20, 0x45, 0x64,
1284 : : 0x32, 0x35, 0x35, 0x31, 0x39, 0x20, 0x63, 0x6F,
1285 : : 0x6C, 0x6C, 0x69, 0x73, 0x69, 0x6F, 0x6E, 0x73,
1286 : : 0x00, 0x00};
1287 : 0 : const uint8_t domx_ed448[] = {
1288 : : 0x53, 0x69, 0x67, 0x45, 0x64, 0x34, 0x34, 0x38,
1289 : : 0x00, 0x00};
1290 : :
1291 : 0 : uint16_t pubkey_len = sess->ec_ctx.q.x.length;
1292 : 0 : uint16_t message_len = eddsa->message.length;
1293 : 0 : uint16_t s_len = eddsa->sign.length / 2;
1294 : : uint8_t curveid = sess->ec_ctx.curveid;
1295 : : uint16_t ctx_align, k_align, s_align;
1296 : : const uint8_t *domx_ptr = NULL;
1297 : : uint16_t order_len, prime_len;
1298 : : uint64_t message_handle;
1299 : : union cpt_inst_w4 w4;
1300 : : uint8_t domx_len = 0;
1301 : : uint16_t iv_len = 0;
1302 : : uint8_t ctx_len = 0;
1303 : : uint64_t ctrl = 0;
1304 : : uint8_t ph = 0;
1305 : : uint16_t dlen;
1306 : : uint8_t *dptr;
1307 : :
1308 : 0 : if (eddsa->instance == RTE_CRYPTO_EDCURVE_25519PH ||
1309 : : eddsa->instance == RTE_CRYPTO_EDCURVE_448PH)
1310 : : ph = 1;
1311 : :
1312 [ # # # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519)
1313 : : iv_len = sizeof(iv_sha512);
1314 : :
1315 : 0 : prime_len = ec_grp->prime.length;
1316 : 0 : order_len = ec_grp->order.length;
1317 : 0 : ctx_len = eddsa->context.length;
1318 : :
1319 [ # # # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
1320 [ # # # # ]: 0 : if (ph || ctx_len) {
1321 : : domx_ptr = domx_ed25519;
1322 : : domx_len = sizeof(domx_ed25519);
1323 : : }
1324 : : } else {
1325 : : domx_ptr = domx_ed448;
1326 : : domx_len = sizeof(domx_ed448);
1327 : : }
1328 : :
1329 : 0 : ctx_align = RTE_ALIGN_CEIL(ctx_len + domx_len, 8);
1330 : 0 : k_align = RTE_ALIGN_CEIL(pubkey_len, 8);
1331 : 0 : s_align = RTE_ALIGN_CEIL(s_len, 8);
1332 : :
1333 : : /* Set control word */
1334 : : ctrl = message_len;
1335 : 0 : ctrl |= (ctx_len + domx_len) << 16;
1336 : :
1337 : : /* Copy message and set message handle in metabuf */
1338 : : dptr = meta_buf->vaddr;
1339 [ # # # # ]: 0 : memcpy(dptr, eddsa->message.data, message_len);
1340 : 0 : message_handle = (uint64_t)dptr;
1341 : 0 : dptr += RTE_ALIGN_CEIL(message_len, 8);
1342 : :
1343 : : /* Input buffer */
1344 : 0 : inst->dptr = (uintptr_t)dptr;
1345 : :
1346 : : /*
1347 : : * Set dlen = sum(sizeof(fpm address), input handle, ctrl,
1348 : : * ROUNDUP8(prime len, order len, constant), ROUNDUP8(pub key len),
1349 : : * ROUNDUP8(s and r len), context and iv len (if ED25519)).
1350 : : */
1351 : 0 : dlen = sizeof(fpm_table_iova) + sizeof(message_handle) + sizeof(ctrl) + prime_len * 3 +
1352 : 0 : k_align + s_align * 2 + ctx_align + iv_len;
1353 : :
1354 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1355 : : dptr += sizeof(fpm_table_iova);
1356 : :
1357 [ # # # # ]: 0 : *(uint64_t *)dptr = rte_cpu_to_be_64(message_handle);
1358 : : dptr += sizeof(message_handle);
1359 : :
1360 [ # # # # ]: 0 : *(uint64_t *)dptr = rte_cpu_to_be_64(ctrl);
1361 : 0 : dptr += sizeof(ctrl);
1362 : :
1363 [ # # # # ]: 0 : memcpy(dptr, ec_grp->prime.data, prime_len);
1364 : 0 : dptr += prime_len;
1365 : :
1366 : 0 : memcpy(dptr, ec_grp->order.data, order_len);
1367 : 0 : dptr += prime_len;
1368 : :
1369 : 0 : memcpy(dptr, ec_grp->consta.data, prime_len);
1370 : 0 : dptr += prime_len;
1371 : :
1372 : 0 : memcpy(dptr, sess->ec_ctx.q.x.data, pubkey_len);
1373 : 0 : dptr += k_align;
1374 : :
1375 : 0 : memcpy(dptr, eddsa->sign.data, s_len);
1376 : 0 : dptr += s_align;
1377 : :
1378 : 0 : memcpy(dptr, eddsa->sign.data + s_len, s_len);
1379 : 0 : dptr += s_align;
1380 : :
1381 : 0 : memcpy(dptr, domx_ptr, domx_len);
1382 [ # # # # ]: 0 : if (eddsa->instance != RTE_CRYPTO_EDCURVE_25519) {
1383 : 0 : memset(dptr + (domx_len - 1), ctx_len, 1);
1384 : 0 : memset(dptr + (domx_len - 2), ph, 1);
1385 : : }
1386 : :
1387 [ # # # # ]: 0 : memcpy(dptr + domx_len, eddsa->context.data, ctx_len);
1388 : 0 : dptr += ctx_align;
1389 : :
1390 [ # # # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
1391 : 0 : memcpy(dptr, iv_sha512, iv_len);
1392 : 0 : dptr += iv_len;
1393 : : }
1394 : :
1395 : : /* Setup opcodes */
1396 : 0 : w4.u64 = sess->cpt_inst_w4;
1397 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_ED_VERIFY;
1398 : :
1399 : 0 : w4.s.param1 |= (ph << ROC_AE_EC_PARAM1_PH_BIT);
1400 : 0 : w4.s.param2 = 0;
1401 : 0 : w4.s.dlen = dlen;
1402 : :
1403 : 0 : inst->w4.u64 = w4.u64;
1404 : 0 : inst->rptr = (uintptr_t)dptr;
1405 : 0 : }
1406 : :
1407 : : static __rte_always_inline int __rte_hot
1408 : : cnxk_ae_enqueue_eddsa_op(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf,
1409 : : struct cnxk_ae_sess *sess, uint64_t *fpm_iova,
1410 : : struct roc_ae_ec_group **ec_grp, struct cpt_inst_s *inst)
1411 : : {
1412 : : struct rte_crypto_eddsa_op_param *eddsa = &op->asym->eddsa;
1413 : 0 : uint8_t curveid = sess->ec_ctx.curveid;
1414 : :
1415 : 0 : if (eddsa->message.length > (sess->msg_max_sz - CNXK_AE_EDDSA_MAX_PARAM_LEN)) {
1416 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1417 : 0 : return -EINVAL;
1418 : : }
1419 : :
1420 [ # # # # ]: 0 : if (eddsa->op_type == RTE_CRYPTO_ASYM_OP_SIGN)
1421 [ # # # # ]: 0 : cnxk_ae_eddsa_sign_prep(eddsa, meta_buf, fpm_iova[curveid], ec_grp[curveid], sess,
1422 : : inst);
1423 [ # # # # ]: 0 : else if (eddsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
1424 [ # # # # ]: 0 : cnxk_ae_eddsa_verify_prep(eddsa, meta_buf, fpm_iova[curveid], ec_grp[curveid], sess,
1425 : : inst);
1426 : : else {
1427 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1428 : 0 : return -EINVAL;
1429 : : }
1430 : : return 0;
1431 : : }
1432 : :
1433 : : static __rte_always_inline void
1434 : : cnxk_ae_sm2_sign_prep(struct rte_crypto_sm2_op_param *sm2,
1435 : : struct roc_ae_buf_ptr *meta_buf,
1436 : : uint64_t fpm_table_iova, struct roc_ae_ec_group *ec_grp,
1437 : : struct cnxk_ae_sess *sess, struct cpt_inst_s *inst)
1438 : : {
1439 : 0 : uint16_t message_len = sm2->message.length;
1440 : 0 : uint16_t pkey_len = sess->ec_ctx.pkey.length;
1441 : : uint16_t p_align, k_align, m_align;
1442 : 0 : uint16_t k_len = sm2->k.length;
1443 : : uint16_t order_len, prime_len;
1444 : : uint16_t o_offset, pk_offset;
1445 : : union cpt_inst_w4 w4;
1446 : : uint16_t dlen;
1447 : : uint8_t *dptr;
1448 : :
1449 : 0 : prime_len = ec_grp->prime.length;
1450 : : if (prime_len > ROC_AE_EC_DATA_MAX)
1451 : : prime_len = ROC_AE_EC_DATA_MAX;
1452 : 0 : order_len = ec_grp->order.length;
1453 : : if (order_len > ROC_AE_EC_DATA_MAX)
1454 : : order_len = ROC_AE_EC_DATA_MAX;
1455 : :
1456 : : if (pkey_len > ROC_AE_EC_DATA_MAX)
1457 : : pkey_len = ROC_AE_EC_DATA_MAX;
1458 : :
1459 : : /* Truncate input length to curve prime length */
1460 : : if (message_len > prime_len)
1461 : : message_len = prime_len;
1462 : 0 : m_align = RTE_ALIGN_CEIL(message_len, 8);
1463 : :
1464 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
1465 : 0 : k_align = RTE_ALIGN_CEIL(k_len, 8);
1466 : :
1467 : : /* Set write offset for order and private key */
1468 : 0 : o_offset = prime_len - order_len;
1469 : 0 : pk_offset = p_align - pkey_len;
1470 : :
1471 : : /* Input buffer */
1472 : : dptr = meta_buf->vaddr;
1473 : 0 : inst->dptr = (uintptr_t)dptr;
1474 : :
1475 : : /*
1476 : : * Set dlen = sum(sizeof(fpm address), ROUNDUP8(scalar len, input len),
1477 : : * ROUNDUP8(priv key len, prime len, order len)).
1478 : : * Please note, private key, order cannot exceed prime
1479 : : * length i.e 3 * p_align.
1480 : : */
1481 : 0 : dlen = sizeof(fpm_table_iova) + k_align + m_align + p_align * 5;
1482 : :
1483 : 0 : memset(dptr, 0, dlen);
1484 : :
1485 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1486 : 0 : dptr += sizeof(fpm_table_iova);
1487 : :
1488 [ # # # # ]: 0 : rte_memcpy(dptr, sm2->k.data, k_len);
1489 : 0 : dptr += k_align;
1490 : :
1491 [ # # # # ]: 0 : rte_memcpy(dptr, ec_grp->prime.data, prime_len);
1492 : 0 : dptr += p_align;
1493 : :
1494 [ # # # # ]: 0 : rte_memcpy(dptr + o_offset, ec_grp->order.data, order_len);
1495 : 0 : dptr += p_align;
1496 : :
1497 [ # # # # ]: 0 : rte_memcpy(dptr + pk_offset, sess->ec_ctx.pkey.data, pkey_len);
1498 : 0 : dptr += p_align;
1499 : :
1500 [ # # # # ]: 0 : rte_memcpy(dptr, sm2->message.data, message_len);
1501 : 0 : dptr += m_align;
1502 : :
1503 [ # # # # ]: 0 : rte_memcpy(dptr, ec_grp->consta.data, prime_len);
1504 : 0 : dptr += p_align;
1505 : :
1506 [ # # # # ]: 0 : rte_memcpy(dptr, ec_grp->constb.data, prime_len);
1507 : 0 : dptr += p_align;
1508 : :
1509 : : /* Setup opcodes */
1510 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EC;
1511 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_SIGN;
1512 : :
1513 : : /* prime length of SM2 curve is same as that of P256. */
1514 : 0 : w4.s.param1 = ROC_AE_EC_ID_P256 |
1515 : 0 : ROC_AE_EC_PARAM1_SM2 | ROC_AE_EC_PARAM1_NONNIST | (message_len << 8);
1516 : 0 : w4.s.param2 = (p_align << 8) | k_len;
1517 : 0 : w4.s.dlen = dlen;
1518 : :
1519 : 0 : inst->w4.u64 = w4.u64;
1520 : 0 : inst->rptr = (uintptr_t)dptr;
1521 : 0 : }
1522 : :
1523 : : static __rte_always_inline void
1524 : : cnxk_ae_sm2_verify_prep(struct rte_crypto_sm2_op_param *sm2,
1525 : : struct roc_ae_buf_ptr *meta_buf,
1526 : : uint64_t fpm_table_iova,
1527 : : struct roc_ae_ec_group *ec_grp, struct cnxk_ae_sess *sess,
1528 : : struct cpt_inst_s *inst)
1529 : : {
1530 : 0 : uint32_t message_len = sm2->message.length;
1531 : : uint16_t o_offset, r_offset, s_offset;
1532 : 0 : uint16_t qx_len = sess->ec_ctx.q.x.length;
1533 : 0 : uint16_t qy_len = sess->ec_ctx.q.y.length;
1534 : 0 : uint16_t r_len = sm2->r.length;
1535 : 0 : uint16_t s_len = sm2->s.length;
1536 : : uint16_t order_len, prime_len;
1537 : : uint16_t qx_offset, qy_offset;
1538 : : uint16_t p_align, m_align;
1539 : : union cpt_inst_w4 w4;
1540 : : uint16_t dlen;
1541 : : uint8_t *dptr;
1542 : :
1543 : 0 : prime_len = ec_grp->prime.length;
1544 : : if (prime_len > ROC_AE_EC_DATA_MAX)
1545 : : prime_len = ROC_AE_EC_DATA_MAX;
1546 : 0 : order_len = ec_grp->order.length;
1547 : : if (order_len > ROC_AE_EC_DATA_MAX)
1548 : : order_len = ROC_AE_EC_DATA_MAX;
1549 : :
1550 : : if (qx_len > ROC_AE_EC_DATA_MAX)
1551 : : qx_len = ROC_AE_EC_DATA_MAX;
1552 : :
1553 : : if (qy_len > ROC_AE_EC_DATA_MAX)
1554 : : qy_len = ROC_AE_EC_DATA_MAX;
1555 : :
1556 : : /* Truncate input length to curve prime length */
1557 : 0 : if (message_len > prime_len)
1558 : : message_len = prime_len;
1559 : :
1560 : 0 : m_align = RTE_ALIGN_CEIL(message_len, 8);
1561 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
1562 : :
1563 : : /* Set write offset for sign, order and public key coordinates */
1564 : 0 : o_offset = prime_len - order_len;
1565 : 0 : qx_offset = prime_len - qx_len;
1566 : 0 : qy_offset = prime_len - qy_len;
1567 : 0 : r_offset = prime_len - r_len;
1568 : 0 : s_offset = prime_len - s_len;
1569 : :
1570 : : /* Input buffer */
1571 : : dptr = meta_buf->vaddr;
1572 : 0 : inst->dptr = (uintptr_t)dptr;
1573 : :
1574 : : /*
1575 : : * Set dlen = sum(sizeof(fpm address), ROUNDUP8(message len),
1576 : : * ROUNDUP8(sign len(r and s), public key len(x and y coordinates),
1577 : : * prime len, order len)).
1578 : : * Please note sign, public key and order can not exceed prime length
1579 : : * i.e. 6 * p_align
1580 : : */
1581 : 0 : dlen = sizeof(fpm_table_iova) + m_align + (8 * p_align);
1582 : :
1583 : 0 : memset(dptr, 0, dlen);
1584 : :
1585 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1586 : 0 : dptr += sizeof(fpm_table_iova);
1587 : :
1588 [ # # # # ]: 0 : rte_memcpy(dptr + r_offset, sm2->r.data, r_len);
1589 : 0 : dptr += p_align;
1590 : :
1591 [ # # # # ]: 0 : rte_memcpy(dptr + s_offset, sm2->s.data, s_len);
1592 : 0 : dptr += p_align;
1593 : :
1594 [ # # # # ]: 0 : rte_memcpy(dptr, sm2->message.data, message_len);
1595 : 0 : dptr += m_align;
1596 : :
1597 [ # # # # ]: 0 : rte_memcpy(dptr + o_offset, ec_grp->order.data, order_len);
1598 : 0 : dptr += p_align;
1599 : :
1600 [ # # # # ]: 0 : rte_memcpy(dptr, ec_grp->prime.data, prime_len);
1601 : 0 : dptr += p_align;
1602 : :
1603 [ # # # # ]: 0 : rte_memcpy(dptr + qx_offset, sess->ec_ctx.q.x.data, qx_len);
1604 : 0 : dptr += p_align;
1605 : :
1606 [ # # # # ]: 0 : rte_memcpy(dptr + qy_offset, sess->ec_ctx.q.y.data, qy_len);
1607 : 0 : dptr += p_align;
1608 : :
1609 [ # # # # ]: 0 : rte_memcpy(dptr, ec_grp->consta.data, prime_len);
1610 : 0 : dptr += p_align;
1611 : :
1612 [ # # # # ]: 0 : rte_memcpy(dptr, ec_grp->constb.data, prime_len);
1613 : 0 : dptr += p_align;
1614 : :
1615 : : /* Setup opcodes */
1616 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EC;
1617 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_VERIFY;
1618 : :
1619 : : /* prime length of SM2 curve is same as that of P256. */
1620 : 0 : w4.s.param1 = ROC_AE_EC_ID_P256 |
1621 : 0 : ROC_AE_EC_PARAM1_SM2 | ROC_AE_EC_PARAM1_NONNIST | (message_len << 8);
1622 : 0 : w4.s.param2 = 0;
1623 : 0 : w4.s.dlen = dlen;
1624 : :
1625 : 0 : inst->w4.u64 = w4.u64;
1626 : 0 : inst->rptr = (uintptr_t)dptr;
1627 : 0 : }
1628 : :
1629 : : static __rte_always_inline int __rte_hot
1630 : : cnxk_ae_enqueue_sm2_op(struct rte_crypto_op *op,
1631 : : struct roc_ae_buf_ptr *meta_buf,
1632 : : struct cnxk_ae_sess *sess, uint64_t *fpm_iova,
1633 : : struct roc_ae_ec_group **ec_grp,
1634 : : struct cpt_inst_s *inst)
1635 : : {
1636 : : struct rte_crypto_sm2_op_param *sm2 = &op->asym->sm2;
1637 : 0 : uint8_t curveid = sess->ec_ctx.curveid;
1638 : :
1639 : 0 : if (sm2->op_type == RTE_CRYPTO_ASYM_OP_SIGN)
1640 : 0 : cnxk_ae_sm2_sign_prep(sm2, meta_buf, fpm_iova[curveid],
1641 [ # # # # ]: 0 : ec_grp[curveid], sess, inst);
1642 [ # # # # ]: 0 : else if (sm2->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
1643 : 0 : cnxk_ae_sm2_verify_prep(sm2, meta_buf, fpm_iova[curveid],
1644 [ # # # # ]: 0 : ec_grp[curveid], sess, inst);
1645 : : else {
1646 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1647 : 0 : return -EINVAL;
1648 : : }
1649 : : return 0;
1650 : : }
1651 : :
1652 : : static __rte_always_inline int
1653 : : cnxk_ae_ecfpm_prep(rte_crypto_param *scalar,
1654 : : struct roc_ae_buf_ptr *meta_buf, uint64_t *fpm_iova,
1655 : : struct roc_ae_ec_group *ec_grp, uint8_t curveid,
1656 : : struct cpt_inst_s *inst)
1657 : : {
1658 : : uint16_t scalar_align, p_align;
1659 : : uint16_t dlen, prime_len;
1660 : : uint64_t fpm_table_iova;
1661 : : union cpt_inst_w4 w4;
1662 : : uint8_t *dptr;
1663 : :
1664 : 0 : prime_len = ec_grp->prime.length;
1665 : 0 : fpm_table_iova = (uint64_t)fpm_iova[curveid];
1666 : :
1667 : : /* Input buffer */
1668 : : dptr = meta_buf->vaddr;
1669 : 0 : inst->dptr = (uintptr_t)dptr;
1670 : :
1671 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
1672 : 0 : scalar_align = RTE_ALIGN_CEIL(scalar->length, 8);
1673 : :
1674 : : /*
1675 : : * Set dlen = sum(ROUNDUP8(input point(x and y coordinates), prime,
1676 : : * scalar length),
1677 : : * Please note point length is equivalent to prime of the curve
1678 : : */
1679 : 0 : dlen = sizeof(fpm_table_iova) + 3 * p_align + scalar_align;
1680 : :
1681 : 0 : memset(dptr, 0, dlen);
1682 : :
1683 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1684 : 0 : dptr += sizeof(fpm_table_iova);
1685 : :
1686 : : /* Copy scalar, prime */
1687 : 0 : memcpy(dptr, scalar->data, scalar->length);
1688 : 0 : dptr += scalar_align;
1689 : 0 : memcpy(dptr, ec_grp->prime.data, ec_grp->prime.length);
1690 : 0 : dptr += p_align;
1691 : 0 : memcpy(dptr, ec_grp->consta.data, ec_grp->consta.length);
1692 : 0 : dptr += p_align;
1693 : 0 : memcpy(dptr, ec_grp->constb.data, ec_grp->constb.length);
1694 : 0 : dptr += p_align;
1695 : :
1696 : : /* Setup opcodes */
1697 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_ECC;
1698 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_ECC_FPM;
1699 : :
1700 : 0 : w4.s.param1 = curveid | (1 << 8);
1701 : 0 : w4.s.param2 = scalar->length;
1702 : 0 : w4.s.dlen = dlen;
1703 : :
1704 : 0 : inst->w4.u64 = w4.u64;
1705 : 0 : inst->rptr = (uintptr_t)dptr;
1706 : :
1707 : 0 : return 0;
1708 : : }
1709 : :
1710 : : static __rte_always_inline int
1711 : : cnxk_ae_edfpm_prep(rte_crypto_param *scalar, struct roc_ae_buf_ptr *meta_buf, uint64_t *fpm_iova,
1712 : : struct roc_ae_ec_group *ec_grp, uint8_t curveid, struct cpt_inst_s *inst)
1713 : : {
1714 : 0 : const uint8_t iv_sha512[] = {
1715 : : 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08,
1716 : : 0xbb, 0x67, 0xae, 0x85, 0x84, 0xca, 0xa7, 0x3b,
1717 : : 0x3c, 0x6e, 0xf3, 0x72, 0xfe, 0x94, 0xf8, 0x2b,
1718 : : 0xa5, 0x4f, 0xf5, 0x3a, 0x5f, 0x1d, 0x36, 0xf1,
1719 : : 0x51, 0x0e, 0x52, 0x7f, 0xad, 0xe6, 0x82, 0xd1,
1720 : : 0x9b, 0x05, 0x68, 0x8c, 0x2b, 0x3e, 0x6c, 0x1f,
1721 : : 0x1f, 0x83, 0xd9, 0xab, 0xfb, 0x41, 0xbd, 0x6b,
1722 : : 0x5b, 0xe0, 0xcd, 0x19, 0x13, 0x7e, 0x21, 0x79};
1723 : : uint16_t dlen, prime_len, order_len, iv_len;
1724 : : uint64_t fpm_table_iova;
1725 : : uint16_t scalar_align;
1726 : : union cpt_inst_w4 w4;
1727 : : uint16_t prime_bit;
1728 : : uint8_t *dptr;
1729 : :
1730 : 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
1731 : : prime_bit = ROC_AE_ED_PARAM1_25519;
1732 : : iv_len = sizeof(iv_sha512);
1733 : : } else {
1734 : : prime_bit = ROC_AE_ED_PARAM1_448;
1735 : : iv_len = 0;
1736 : : }
1737 : :
1738 : 0 : prime_len = ec_grp->prime.length;
1739 : 0 : order_len = ec_grp->order.length;
1740 : 0 : fpm_table_iova = (uint64_t)fpm_iova[curveid];
1741 : :
1742 : : /* Input buffer */
1743 : : dptr = meta_buf->vaddr;
1744 : 0 : inst->dptr = (uintptr_t)dptr;
1745 : :
1746 : 0 : scalar_align = RTE_ALIGN_CEIL(scalar->length, 8);
1747 : :
1748 : : /*
1749 : : * Set dlen = sum(sizeof(fpm address), ROUNDUP8(prime len, order len, constant,
1750 : : * private key len and iv len (if ED25519))).
1751 : : */
1752 : 0 : dlen = sizeof(fpm_table_iova) + 3 * prime_len + scalar_align + iv_len;
1753 : :
1754 : 0 : *(uint64_t *)dptr = fpm_table_iova;
1755 : 0 : dptr += sizeof(fpm_table_iova);
1756 : :
1757 [ # # # # ]: 0 : memcpy(dptr, ec_grp->prime.data, prime_len);
1758 : 0 : dptr += prime_len;
1759 : 0 : memcpy(dptr, ec_grp->order.data, order_len);
1760 : 0 : dptr += prime_len;
1761 : 0 : memcpy(dptr, ec_grp->consta.data, prime_len);
1762 : 0 : dptr += prime_len;
1763 : :
1764 : : memcpy(dptr, scalar->data, scalar->length);
1765 : 0 : dptr += scalar_align;
1766 [ # # # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519) {
1767 : : memcpy(dptr, iv_sha512, sizeof(iv_sha512));
1768 : 0 : dptr += iv_len;
1769 : : }
1770 : :
1771 : : /* Setup opcodes */
1772 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_EDDSA;
1773 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_ED_KEYGEN;
1774 : :
1775 : 0 : w4.s.param1 = prime_bit;
1776 : 0 : w4.s.param2 = 0;
1777 : 0 : w4.s.dlen = dlen;
1778 : :
1779 : 0 : inst->w4.u64 = w4.u64;
1780 : 0 : inst->rptr = (uintptr_t)dptr;
1781 : :
1782 : 0 : return 0;
1783 : : }
1784 : :
1785 : : static __rte_always_inline int
1786 : : cnxk_ae_ecpm_prep(rte_crypto_param *scalar, struct rte_crypto_ec_point *p,
1787 : : struct roc_ae_buf_ptr *meta_buf,
1788 : : struct roc_ae_ec_group *ec_grp, uint8_t curveid,
1789 : : struct cpt_inst_s *inst)
1790 : : {
1791 : 0 : uint16_t x1_len = p->x.length;
1792 : 0 : uint16_t y1_len = p->y.length;
1793 : : uint16_t scalar_align, p_align;
1794 : : uint16_t x1_offset, y1_offset;
1795 : : uint16_t dlen, prime_len;
1796 : : union cpt_inst_w4 w4;
1797 : : uint8_t *dptr;
1798 : :
1799 : 0 : prime_len = ec_grp->prime.length;
1800 : :
1801 : : /* Input buffer */
1802 : : dptr = meta_buf->vaddr;
1803 : 0 : inst->dptr = (uintptr_t)dptr;
1804 : :
1805 : 0 : p_align = RTE_ALIGN_CEIL(prime_len, 8);
1806 : 0 : scalar_align = RTE_ALIGN_CEIL(scalar->length, 8);
1807 : :
1808 : : /*
1809 : : * Set dlen = sum(ROUNDUP8(input point(x and y coordinates), prime,
1810 : : * scalar length),
1811 : : * Please note point length is equivalent to prime of the curve
1812 : : */
1813 : 0 : dlen = 5 * p_align + scalar_align;
1814 : :
1815 : 0 : x1_offset = prime_len - x1_len;
1816 : 0 : y1_offset = prime_len - y1_len;
1817 : :
1818 : 0 : memset(dptr, 0, dlen);
1819 : :
1820 : : /* Copy input point, scalar, prime */
1821 : 0 : memcpy(dptr + x1_offset, p->x.data, x1_len);
1822 : 0 : dptr += p_align;
1823 : 0 : memcpy(dptr + y1_offset, p->y.data, y1_len);
1824 : 0 : dptr += p_align;
1825 : 0 : memcpy(dptr, scalar->data, scalar->length);
1826 : 0 : dptr += scalar_align;
1827 : 0 : memcpy(dptr, ec_grp->prime.data, ec_grp->prime.length);
1828 : 0 : dptr += p_align;
1829 : 0 : memcpy(dptr, ec_grp->consta.data, ec_grp->consta.length);
1830 : 0 : dptr += p_align;
1831 : 0 : memcpy(dptr, ec_grp->constb.data, ec_grp->constb.length);
1832 : 0 : dptr += p_align;
1833 : :
1834 : : /* Setup opcodes */
1835 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_ECC;
1836 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_ECC_UMP;
1837 : :
1838 : 0 : w4.s.param1 = curveid;
1839 : 0 : w4.s.param2 = scalar->length;
1840 : 0 : w4.s.dlen = dlen;
1841 : :
1842 : 0 : inst->w4.u64 = w4.u64;
1843 : 0 : inst->rptr = (uintptr_t)dptr;
1844 : :
1845 : 0 : return 0;
1846 : : }
1847 : :
1848 : : static __rte_always_inline int
1849 : : cnxk_ae_random_prep(uint16_t len, struct roc_ae_buf_ptr *meta_buf,
1850 : : struct cpt_inst_s *inst)
1851 : : {
1852 : : union cpt_inst_w4 w4;
1853 : : uint8_t *dptr;
1854 : :
1855 : : /* Input buffer */
1856 : : dptr = meta_buf->vaddr;
1857 : 0 : inst->dptr = (uintptr_t)dptr;
1858 : :
1859 : : /* Setup opcodes */
1860 : 0 : w4.s.opcode_major = ROC_AE_MAJOR_OP_RANDOM;
1861 : 0 : w4.s.opcode_minor = ROC_AE_MINOR_OP_RANDOM;
1862 : :
1863 : 0 : w4.s.param1 = len;
1864 : 0 : w4.s.param2 = 0;
1865 : 0 : w4.s.dlen = 0;
1866 : :
1867 : 0 : inst->w4.u64 = w4.u64;
1868 : 0 : inst->rptr = (uintptr_t)dptr;
1869 : :
1870 : 0 : return 0;
1871 : : }
1872 : :
1873 : : static __rte_always_inline int __rte_hot
1874 : : cnxk_ae_enqueue_ecdh_op(struct rte_crypto_op *op,
1875 : : struct roc_ae_buf_ptr *meta_buf,
1876 : : struct cnxk_ae_sess *sess, uint64_t *fpm_iova,
1877 : : struct roc_ae_ec_group **ec_grp,
1878 : : struct cpt_inst_s *inst)
1879 : : {
1880 : : struct rte_crypto_ecdh_op_param *ecdh = &op->asym->ecdh;
1881 : 0 : uint8_t curveid = sess->ec_ctx.curveid;
1882 : : struct rte_crypto_ec_point point;
1883 : : rte_crypto_uint scalar;
1884 : : int ret = 0;
1885 : :
1886 : 0 : switch (ecdh->ke_type) {
1887 : 0 : case RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE:
1888 : 0 : cnxk_ae_random_prep(ecdh->priv_key.length, meta_buf, inst);
1889 : : break;
1890 : 0 : case RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE:
1891 : 0 : scalar.data = sess->ec_ctx.pkey.data;
1892 : 0 : scalar.length = sess->ec_ctx.pkey.length;
1893 [ # # # # ]: 0 : if (curveid == ROC_AE_EC_ID_ED25519 || curveid == ROC_AE_EC_ID_ED448)
1894 [ # # # # ]: 0 : cnxk_ae_edfpm_prep(&scalar, meta_buf, fpm_iova, ec_grp[curveid],
1895 : : curveid, inst);
1896 : : else
1897 : 0 : cnxk_ae_ecfpm_prep(&scalar, meta_buf, fpm_iova, ec_grp[curveid],
1898 : : curveid, inst);
1899 : : break;
1900 : 0 : case RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY:
1901 : 0 : scalar.data = ec_grp[curveid]->order.data;
1902 : 0 : scalar.length = ec_grp[curveid]->order.length;
1903 : : cnxk_ae_ecpm_prep(&scalar, &ecdh->pub_key, meta_buf,
1904 : : ec_grp[curveid], curveid, inst);
1905 : : break;
1906 : 0 : case RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE:
1907 : 0 : scalar.data = sess->ec_ctx.pkey.data;
1908 : 0 : scalar.length = sess->ec_ctx.pkey.length;
1909 : 0 : point.x.data = sess->ec_ctx.q.x.data;
1910 : 0 : point.x.length = sess->ec_ctx.q.x.length;
1911 : 0 : point.y.data = sess->ec_ctx.q.y.data;
1912 : 0 : point.y.length = sess->ec_ctx.q.y.length;
1913 : 0 : cnxk_ae_ecpm_prep(&scalar, &point, meta_buf,
1914 : 0 : ec_grp[curveid], curveid, inst);
1915 : : break;
1916 : 0 : default:
1917 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1918 : : ret = -EINVAL;
1919 : : }
1920 : :
1921 : : return ret;
1922 : : }
1923 : :
1924 : : static __rte_always_inline void
1925 : : cnxk_ae_dequeue_rsa_op(struct rte_crypto_op *cop, uint8_t *rptr,
1926 : : struct rte_crypto_rsa_xform *rsa_ctx)
1927 : : {
1928 : : struct rte_crypto_rsa_op_param *rsa = &cop->asym->rsa;
1929 : :
1930 : 0 : switch (rsa->op_type) {
1931 : 0 : case RTE_CRYPTO_ASYM_OP_ENCRYPT:
1932 : 0 : rsa->cipher.length = rsa_ctx->n.length;
1933 : 0 : memcpy(rsa->cipher.data, rptr, rsa->cipher.length);
1934 : : break;
1935 : 0 : case RTE_CRYPTO_ASYM_OP_DECRYPT:
1936 [ # # ]: 0 : if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
1937 : 0 : rsa->message.length = rsa_ctx->n.length;
1938 : 0 : memcpy(rsa->message.data, rptr, rsa->message.length);
1939 : : } else {
1940 : : /* Get length of decrypted output */
1941 : 0 : rsa->message.length =
1942 [ # # ]: 0 : rte_cpu_to_be_16(*((uint16_t *)rptr));
1943 : : /*
1944 : : * Offset output data pointer by length field
1945 : : * (2 bytes) and copy decrypted data.
1946 : : */
1947 : 0 : memcpy(rsa->message.data, rptr + 2,
1948 : : rsa->message.length);
1949 : : }
1950 : : break;
1951 : 0 : case RTE_CRYPTO_ASYM_OP_SIGN:
1952 : 0 : rsa->sign.length = rsa_ctx->n.length;
1953 : 0 : memcpy(rsa->sign.data, rptr, rsa->sign.length);
1954 : : break;
1955 : 0 : case RTE_CRYPTO_ASYM_OP_VERIFY:
1956 [ # # ]: 0 : if (rsa_ctx->padding.type == RTE_CRYPTO_RSA_PADDING_NONE) {
1957 : : /* Application compares decrypted data with message for SW padding schemes
1958 : : */
1959 : 0 : rsa->cipher.length = rsa_ctx->n.length;
1960 : 0 : memcpy(rsa->cipher.data, rptr, rsa->cipher.length);
1961 : : } else {
1962 : : /* Get length of signed output */
1963 [ # # ]: 0 : rsa->sign.length = rte_cpu_to_be_16(*((uint16_t *)rptr));
1964 : : /*
1965 : : * Offset output data pointer by length field
1966 : : * (2 bytes) and compare signed data.
1967 : : */
1968 [ # # ]: 0 : if (!rte_memeq_timingsafe(rptr + 2,
1969 : 0 : rsa->message.data, rsa->message.length))
1970 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1971 : : }
1972 : : break;
1973 : 0 : default:
1974 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
1975 : 0 : break;
1976 : : }
1977 : : }
1978 : :
1979 : : static __rte_always_inline void
1980 : : cnxk_ae_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa, uint8_t *rptr,
1981 : : struct roc_ae_ec_ctx *ec,
1982 : : struct roc_ae_ec_group **ec_grp)
1983 : : {
1984 : 0 : int prime_len = ec_grp[ec->curveid]->prime.length;
1985 : :
1986 : 0 : if (ecdsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
1987 : : return;
1988 : :
1989 : : /* Separate out sign r and s components */
1990 : 0 : memcpy(ecdsa->r.data, rptr, prime_len);
1991 : 0 : memcpy(ecdsa->s.data, rptr + RTE_ALIGN_CEIL(prime_len, 8), prime_len);
1992 : 0 : ecdsa->r.length = prime_len;
1993 : 0 : ecdsa->s.length = prime_len;
1994 : : }
1995 : :
1996 : : static __rte_always_inline void
1997 : : cnxk_ae_dequeue_eddsa_op(struct rte_crypto_eddsa_op_param *eddsa, uint8_t *rptr)
1998 : : {
1999 : 0 : if (eddsa->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
2000 : : return;
2001 : :
2002 : : /* Separate out sign r and s components */
2003 [ # # ]: 0 : if (eddsa->instance == RTE_CRYPTO_EDCURVE_25519 ||
2004 : : eddsa->instance == RTE_CRYPTO_EDCURVE_25519CTX ||
2005 : : eddsa->instance == RTE_CRYPTO_EDCURVE_25519PH) {
2006 : 0 : eddsa->sign.length = 64;
2007 : 0 : memcpy(eddsa->sign.data, rptr, eddsa->sign.length);
2008 : : } else {
2009 : 0 : eddsa->sign.length = 114;
2010 : 0 : memcpy(eddsa->sign.data, rptr, 57);
2011 : 0 : memcpy(eddsa->sign.data + 57, rptr + 64, 57);
2012 : : }
2013 : : }
2014 : :
2015 : : static __rte_always_inline void
2016 : : cnxk_ae_dequeue_sm2_op(struct rte_crypto_sm2_op_param *sm2, uint8_t *rptr,
2017 : : struct roc_ae_ec_ctx *ec,
2018 : : struct roc_ae_ec_group **ec_grp)
2019 : : {
2020 : 0 : int prime_len = ec_grp[ec->curveid]->prime.length;
2021 : :
2022 : 0 : if (sm2->op_type == RTE_CRYPTO_ASYM_OP_VERIFY)
2023 : : return;
2024 : :
2025 : : /* Separate out sign r and s components */
2026 [ # # ]: 0 : rte_memcpy(sm2->r.data, rptr, prime_len);
2027 [ # # ]: 0 : rte_memcpy(sm2->s.data, rptr + RTE_ALIGN_CEIL(prime_len, 8), prime_len);
2028 : 0 : sm2->r.length = prime_len;
2029 : 0 : sm2->s.length = prime_len;
2030 : : }
2031 : :
2032 : : static __rte_always_inline void
2033 : : cnxk_ae_dequeue_ecpm_op(struct rte_crypto_ecpm_op_param *ecpm, uint8_t *rptr,
2034 : : struct roc_ae_ec_ctx *ec,
2035 : : struct roc_ae_ec_group **ec_grp)
2036 : : {
2037 : 0 : int prime_len = ec_grp[ec->curveid]->prime.length;
2038 : :
2039 : 0 : memcpy(ecpm->r.x.data, rptr, prime_len);
2040 : 0 : memcpy(ecpm->r.y.data, rptr + RTE_ALIGN_CEIL(prime_len, 8), prime_len);
2041 : 0 : ecpm->r.x.length = prime_len;
2042 : 0 : ecpm->r.y.length = prime_len;
2043 : 0 : }
2044 : :
2045 : : static __rte_always_inline void
2046 : : cnxk_ae_dequeue_ecdh_op(struct rte_crypto_ecdh_op_param *ecdh, uint8_t *rptr,
2047 : : struct roc_ae_ec_ctx *ec,
2048 : : struct roc_ae_ec_group **ec_grp, uint16_t flags)
2049 : : {
2050 : 0 : int prime_len = ec_grp[ec->curveid]->prime.length;
2051 : :
2052 : 0 : switch (ecdh->ke_type) {
2053 : 0 : case RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE:
2054 : 0 : memcpy(ecdh->priv_key.data, rptr, prime_len);
2055 : 0 : ecdh->priv_key.length = prime_len;
2056 : 0 : break;
2057 : 0 : case RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE:
2058 [ # # ]: 0 : memcpy(ecdh->pub_key.x.data, rptr, prime_len);
2059 : 0 : ecdh->pub_key.x.length = prime_len;
2060 [ # # ]: 0 : if (!(flags & RTE_CRYPTO_ASYM_FLAG_PUB_KEY_COMPRESSED)) {
2061 : 0 : memcpy(ecdh->pub_key.y.data, rptr + RTE_ALIGN_CEIL(prime_len, 8),
2062 : : prime_len);
2063 : 0 : ecdh->pub_key.y.length = prime_len;
2064 : : }
2065 : : break;
2066 : : case RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY:
2067 : : break;
2068 : 0 : case RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE:
2069 : 0 : memcpy(ecdh->shared_secret.x.data, rptr, prime_len);
2070 : 0 : memcpy(ecdh->shared_secret.y.data, rptr + RTE_ALIGN_CEIL(prime_len, 8), prime_len);
2071 : 0 : ecdh->shared_secret.x.length = prime_len;
2072 : 0 : ecdh->shared_secret.y.length = prime_len;
2073 : 0 : break;
2074 : : default:
2075 : : break;
2076 : : }
2077 : : }
2078 : :
2079 : : static __rte_always_inline void
2080 : : cnxk_ae_dequeue_mlkem_op(struct rte_crypto_ml_kem_op *mlkem, uint8_t *rptr,
2081 : : enum rte_crypto_ml_kem_type type)
2082 : : {
2083 : 0 : switch (mlkem->op) {
2084 : 0 : case RTE_CRYPTO_ML_KEM_OP_KEYGEN:
2085 : 0 : mlkem->keygen.dk.length = rte_crypto_ml_kem_privkey_size[type];
2086 : 0 : memcpy(mlkem->keygen.dk.data, rptr, mlkem->keygen.dk.length);
2087 : 0 : mlkem->keygen.ek.length = rte_crypto_ml_kem_pubkey_size[type];
2088 : 0 : memcpy(mlkem->keygen.ek.data, rptr + 384 * (type + 1), mlkem->keygen.ek.length);
2089 : : break;
2090 : 0 : case RTE_CRYPTO_ML_KEM_OP_ENCAP:
2091 : 0 : mlkem->encap.sk.length = 32;
2092 : 0 : memcpy(mlkem->encap.sk.data, rptr, mlkem->encap.sk.length);
2093 : 0 : mlkem->encap.cipher.length = rte_crypto_ml_kem_cipher_size[type];
2094 : 0 : memcpy(mlkem->encap.cipher.data, rptr + 32, mlkem->encap.cipher.length);
2095 : : break;
2096 : 0 : case RTE_CRYPTO_ML_KEM_OP_DECAP:
2097 : 0 : mlkem->decap.sk.length = 32;
2098 : 0 : memcpy(mlkem->decap.sk.data, rptr, mlkem->decap.sk.length);
2099 : : break;
2100 : : default:
2101 : : break;
2102 : : }
2103 : : }
2104 : :
2105 : : static __rte_always_inline void
2106 : : cnxk_ae_dequeue_mldsa_op(struct rte_crypto_ml_dsa_op *mldsa, uint8_t *rptr,
2107 : : enum rte_crypto_ml_dsa_type type)
2108 : : {
2109 : 0 : switch (mldsa->op) {
2110 : 0 : case RTE_CRYPTO_ML_DSA_OP_KEYGEN:
2111 : 0 : mldsa->keygen.pubkey.length = rte_crypto_ml_dsa_pubkey_size[type];
2112 : 0 : memcpy(mldsa->keygen.pubkey.data, rptr, mldsa->keygen.pubkey.length);
2113 : 0 : mldsa->keygen.privkey.length = rte_crypto_ml_dsa_privkey_size[type];
2114 : 0 : memcpy(mldsa->keygen.privkey.data, rptr + mldsa->keygen.pubkey.length,
2115 : : mldsa->keygen.privkey.length);
2116 : : break;
2117 : 0 : case RTE_CRYPTO_ML_DSA_OP_SIGN:
2118 : 0 : mldsa->siggen.sign.length = rte_crypto_ml_dsa_sign_size[type];
2119 : 0 : memcpy(mldsa->siggen.sign.data, rptr, mldsa->siggen.sign.length);
2120 : : break;
2121 : : case RTE_CRYPTO_ML_DSA_OP_VERIFY:
2122 : : break;
2123 : : default:
2124 : : break;
2125 : : }
2126 : : }
2127 : :
2128 : : static __rte_always_inline void *
2129 : : cnxk_ae_alloc_meta(struct roc_ae_buf_ptr *buf,
2130 : : struct rte_mempool *cpt_meta_pool,
2131 : : struct cpt_inflight_req *infl_req)
2132 : : {
2133 : : uint8_t *mdata;
2134 : :
2135 [ # # # # ]: 0 : if (unlikely(rte_mempool_get(cpt_meta_pool, (void **)&mdata) < 0))
2136 : : return NULL;
2137 : :
2138 : 0 : buf->vaddr = mdata;
2139 : :
2140 : 0 : infl_req->mdata = mdata;
2141 : 0 : infl_req->op_flags |= CPT_OP_FLAGS_METABUF;
2142 : :
2143 : : return mdata;
2144 : : }
2145 : :
2146 : : static __rte_always_inline int32_t __rte_hot
2147 : : cnxk_ae_enqueue(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
2148 : : struct cpt_inflight_req *infl_req, struct cpt_inst_s *inst,
2149 : : struct cnxk_ae_sess *sess)
2150 : : {
2151 : : struct cpt_qp_meta_info *minfo = &qp->meta_info;
2152 : : struct rte_crypto_asym_op *asym_op = op->asym;
2153 : : struct roc_ae_buf_ptr meta_buf;
2154 : : uint64_t *mop;
2155 : : void *mdata;
2156 : : int ret;
2157 : :
2158 [ # # # # ]: 0 : mdata = cnxk_ae_alloc_meta(&meta_buf, minfo->pool, infl_req);
2159 [ # # # # ]: 0 : if (mdata == NULL)
2160 : : return -ENOMEM;
2161 : :
2162 : : /* Reserve 8B for RPTR */
2163 : 0 : meta_buf.vaddr = PLT_PTR_ADD(mdata, sizeof(uint64_t));
2164 : :
2165 [ # # # # : 0 : switch (sess->xfrm_type) {
# # # # #
# # # # #
# # # # #
# # # ]
2166 [ # # # # ]: 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
2167 : : ret = cnxk_ae_modex_prep(op, &meta_buf, &sess->mod_ctx, inst);
2168 : 0 : break;
2169 : : case RTE_CRYPTO_ASYM_XFORM_RSA:
2170 : : ret = cnxk_ae_enqueue_rsa_op(op, &meta_buf, sess, inst);
2171 : : break;
2172 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
2173 [ # # # # ]: 0 : ret = cnxk_ae_enqueue_ecdsa_op(op, &meta_buf, sess,
2174 : : sess->cnxk_fpm_iova,
2175 : : sess->ec_grp, inst);
2176 : : break;
2177 : 0 : case RTE_CRYPTO_ASYM_XFORM_EDDSA:
2178 [ # # # # ]: 0 : ret = cnxk_ae_enqueue_eddsa_op(op, &meta_buf, sess,
2179 : : sess->cnxk_fpm_iova,
2180 : : sess->ec_grp, inst);
2181 : : break;
2182 : 0 : case RTE_CRYPTO_ASYM_XFORM_SM2:
2183 [ # # # # ]: 0 : ret = cnxk_ae_enqueue_sm2_op(op, &meta_buf, sess,
2184 : : sess->cnxk_fpm_iova,
2185 : : sess->ec_grp, inst);
2186 : : break;
2187 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECPM:
2188 : 0 : ret = cnxk_ae_ecpm_prep(&asym_op->ecpm.scalar, &asym_op->ecpm.p, &meta_buf,
2189 : 0 : sess->ec_grp[sess->ec_ctx.curveid],
2190 : 0 : sess->ec_ctx.curveid, inst);
2191 : 0 : break;
2192 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECFPM:
2193 : 0 : ret = cnxk_ae_ecfpm_prep(&asym_op->ecpm.scalar, &meta_buf,
2194 : : sess->cnxk_fpm_iova,
2195 : 0 : sess->ec_grp[sess->ec_ctx.curveid],
2196 : 0 : sess->ec_ctx.curveid, inst);
2197 : 0 : break;
2198 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDH:
2199 [ # # # # : 0 : ret = cnxk_ae_enqueue_ecdh_op(op, &meta_buf, sess,
# # # # #
# ]
2200 : : sess->cnxk_fpm_iova,
2201 : : sess->ec_grp, inst);
2202 : : break;
2203 : : case RTE_CRYPTO_ASYM_XFORM_ML_KEM:
2204 : : ret = cnxk_ae_enqueue_ml_kem_op(op, &meta_buf, sess, inst);
2205 : 0 : break;
2206 : : case RTE_CRYPTO_ASYM_XFORM_ML_DSA:
2207 : : ret = cnxk_ae_enqueue_ml_dsa_op(op, &meta_buf, sess, inst);
2208 : 0 : break;
2209 : 0 : default:
2210 : 0 : op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
2211 : : ret = -EINVAL;
2212 : 0 : goto req_fail;
2213 : : }
2214 : :
2215 [ # # # # ]: 0 : if (unlikely(ret))
2216 : 0 : goto req_fail;
2217 : :
2218 : : mop = mdata;
2219 : 0 : mop[0] = inst->rptr;
2220 : 0 : return 0;
2221 : :
2222 : 0 : req_fail:
2223 [ # # # # ]: 0 : rte_mempool_put(minfo->pool, infl_req->mdata);
2224 : 0 : return ret;
2225 : : }
2226 : :
2227 : : static __rte_always_inline void
2228 : : cnxk_ae_post_process(struct rte_crypto_op *cop, struct cnxk_ae_sess *sess,
2229 : : uint8_t *rptr)
2230 : : {
2231 : : struct rte_crypto_asym_op *op = cop->asym;
2232 : :
2233 [ # # # # : 0 : switch (sess->xfrm_type) {
# # # # #
# ]
2234 [ # # # # : 0 : case RTE_CRYPTO_ASYM_XFORM_RSA:
# ]
2235 : : cnxk_ae_dequeue_rsa_op(cop, rptr, &sess->rsa_ctx);
2236 : : break;
2237 : 0 : case RTE_CRYPTO_ASYM_XFORM_MODEX:
2238 : 0 : op->modex.result.length = sess->mod_ctx.modulus.length;
2239 : 0 : memcpy(op->modex.result.data, rptr, op->modex.result.length);
2240 : : break;
2241 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
2242 [ # # ]: 0 : cnxk_ae_dequeue_ecdsa_op(&op->ecdsa, rptr, &sess->ec_ctx,
2243 : : sess->ec_grp);
2244 : : break;
2245 [ # # ]: 0 : case RTE_CRYPTO_ASYM_XFORM_EDDSA:
2246 : : cnxk_ae_dequeue_eddsa_op(&op->eddsa, rptr);
2247 : : break;
2248 : 0 : case RTE_CRYPTO_ASYM_XFORM_SM2:
2249 [ # # ]: 0 : cnxk_ae_dequeue_sm2_op(&op->sm2, rptr, &sess->ec_ctx,
2250 : : sess->ec_grp);
2251 : : break;
2252 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECPM:
2253 : : case RTE_CRYPTO_ASYM_XFORM_ECFPM:
2254 : 0 : cnxk_ae_dequeue_ecpm_op(&op->ecpm, rptr, &sess->ec_ctx,
2255 : : sess->ec_grp);
2256 : : break;
2257 : 0 : case RTE_CRYPTO_ASYM_XFORM_ECDH:
2258 : 0 : cnxk_ae_dequeue_ecdh_op(&op->ecdh, rptr, &sess->ec_ctx,
2259 [ # # # # ]: 0 : sess->ec_grp, op->flags);
2260 : : break;
2261 : 0 : case RTE_CRYPTO_ASYM_XFORM_ML_KEM:
2262 [ # # # # ]: 0 : cnxk_ae_dequeue_mlkem_op(&op->mlkem, rptr, sess->ml_kem_ctx.type);
2263 : : break;
2264 : 0 : case RTE_CRYPTO_ASYM_XFORM_ML_DSA:
2265 [ # # # ]: 0 : cnxk_ae_dequeue_mldsa_op(&op->mldsa, rptr, sess->ml_dsa_ctx.type);
2266 : : break;
2267 : 0 : default:
2268 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS;
2269 : 0 : break;
2270 : : }
2271 : : }
2272 : : #endif /* _CNXK_AE_H_ */
|