Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2018 Cavium Networks
3 : : * Copyright (c) 2019 Intel Corporation
4 : : */
5 : :
6 : : #include <rte_bus_vdev.h>
7 : : #include <rte_common.h>
8 : : #include <rte_hexdump.h>
9 : : #include <rte_mbuf.h>
10 : : #include <rte_malloc.h>
11 : : #include <rte_memcpy.h>
12 : : #include <rte_pause.h>
13 : :
14 : : #include <rte_cryptodev.h>
15 : : #include <rte_crypto.h>
16 : :
17 : : #include "test_cryptodev.h"
18 : : #include "test_cryptodev_dh_test_vectors.h"
19 : : #include "test_cryptodev_dsa_test_vectors.h"
20 : : #include "test_cryptodev_ecdh_test_vectors.h"
21 : : #include "test_cryptodev_ecdsa_test_vectors.h"
22 : : #include "test_cryptodev_ecpm_test_vectors.h"
23 : : #include "test_cryptodev_eddsa_test_vectors.h"
24 : : #include "test_cryptodev_mod_test_vectors.h"
25 : : #include "test_cryptodev_rsa_test_vectors.h"
26 : : #include "test_cryptodev_sm2_test_vectors.h"
27 : : #include "test_cryptodev_ml_kem_test_vectors.h"
28 : : #include "test_cryptodev_ml_dsa_test_vectors.h"
29 : : #include "test_cryptodev_asym_util.h"
30 : : #include "test.h"
31 : :
32 : : #define TEST_NUM_BUFS 10
33 : : #define TEST_NUM_SESSIONS 4
34 : :
35 : : #ifndef TEST_DATA_SIZE
36 : : #define TEST_DATA_SIZE 4096
37 : : #endif
38 : : #define ASYM_TEST_MSG_LEN 256
39 : : #define TEST_VECTOR_SIZE 256
40 : : #define DEQ_TIMEOUT 10000
41 : :
42 : : #define ADD_ASYM_TESTSUITE(index, parent_ts, child_ts, num_child_ts) \
43 : : for (j = 0; j < num_child_ts; index++, j++) \
44 : : parent_ts.unit_test_suites[index] = child_ts[j]
45 : :
46 : : static int gbl_driver_id;
47 : : static struct crypto_testsuite_params_asym {
48 : : struct rte_mempool *op_mpool;
49 : : struct rte_mempool *session_mpool;
50 : : struct rte_cryptodev_config conf;
51 : : struct rte_cryptodev_qp_conf qp_conf;
52 : : uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
53 : : uint8_t valid_dev_count;
54 : : } testsuite_params, *params = &testsuite_params;
55 : :
56 : : static struct ut_args {
57 : : void *sess;
58 : : struct rte_crypto_op *op;
59 : : struct rte_crypto_op *result_op;
60 : : } _args, *self = &_args;
61 : :
62 : : static int
63 : 2 : queue_ops_rsa_sign_verify(void *sess)
64 : : {
65 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
66 : 2 : struct rte_mempool *op_mpool = ts_params->op_mpool;
67 : 2 : uint8_t dev_id = ts_params->valid_devs[0];
68 : : struct rte_crypto_op *op, *result_op;
69 : : struct rte_crypto_asym_op *asym_op;
70 : : uint8_t output_buf[TEST_DATA_SIZE];
71 : : int status;
72 : :
73 : : /* Set up crypto op data structure */
74 : 2 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
75 [ - + ]: 2 : if (!op) {
76 : 0 : RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
77 : : "operation struct\n");
78 : 0 : return TEST_FAILED;
79 : : }
80 : :
81 : : asym_op = op->asym;
82 : :
83 : : /* Compute sign on the test vector */
84 : 2 : asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
85 : :
86 : 2 : asym_op->rsa.message.data = rsaplaintext.data;
87 : 2 : asym_op->rsa.message.length = rsaplaintext.len;
88 : 2 : asym_op->rsa.sign.length = RTE_DIM(rsa_n);
89 : 2 : asym_op->rsa.sign.data = output_buf;
90 : :
91 : 2 : debug_hexdump(stdout, "message", asym_op->rsa.message.data,
92 : : asym_op->rsa.message.length);
93 : :
94 : : /* Attach asymmetric crypto session to crypto operations */
95 [ + - ]: 2 : rte_crypto_op_attach_asym_session(op, sess);
96 : :
97 : 2 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
98 : :
99 : : /* Process crypto operation */
100 [ - + ]: 2 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
101 : 0 : RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
102 : : status = TEST_FAILED;
103 : 0 : goto error_exit;
104 : : }
105 : :
106 [ - + ]: 2 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
107 : : rte_pause();
108 : :
109 [ - + ]: 2 : if (result_op == NULL) {
110 : 0 : RTE_LOG(ERR, USER1, "Failed to process sign op\n");
111 : : status = TEST_FAILED;
112 : 0 : goto error_exit;
113 : : }
114 : :
115 : 2 : debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
116 : : asym_op->rsa.sign.length);
117 : 2 : asym_op = result_op->asym;
118 : :
119 : : /* Verify sign */
120 : 2 : asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
121 : :
122 : : /* Process crypto operation */
123 [ - + ]: 2 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
124 : 0 : RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
125 : : status = TEST_FAILED;
126 : 0 : goto error_exit;
127 : : }
128 : :
129 [ - + ]: 2 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
130 : : rte_pause();
131 : :
132 [ - + ]: 2 : if (result_op == NULL) {
133 : 0 : RTE_LOG(ERR, USER1, "Failed to process verify op\n");
134 : : status = TEST_FAILED;
135 : 0 : goto error_exit;
136 : : }
137 : :
138 [ - + ]: 2 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
139 : 0 : RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
140 : : status = TEST_FAILED;
141 : 0 : goto error_exit;
142 : : }
143 : :
144 : : /* Negative test */
145 : 2 : result_op->asym->rsa.sign.data[0] ^= 0xff;
146 : 2 : result_op->asym->rsa.sign.length = RTE_DIM(rsa_n);
147 [ - + ]: 2 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &result_op, 1) != 1) {
148 : 0 : RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
149 : : status = TEST_FAILED;
150 : 0 : goto error_exit;
151 : : }
152 : :
153 [ - + ]: 2 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
154 : : rte_pause();
155 : :
156 [ - + ]: 2 : if (result_op == NULL) {
157 : 0 : RTE_LOG(ERR, USER1, "Failed to process verify op\n");
158 : : status = TEST_FAILED;
159 : 0 : goto error_exit;
160 : : }
161 : :
162 [ - + ]: 2 : if (result_op->status != RTE_CRYPTO_OP_STATUS_ERROR) {
163 : 0 : RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
164 : : status = TEST_FAILED;
165 : 0 : goto error_exit;
166 : : }
167 : :
168 : : status = TEST_SUCCESS;
169 : 2 : error_exit:
170 : :
171 : 2 : rte_crypto_op_free(op);
172 : :
173 : 2 : return status;
174 : : }
175 : :
176 : : static int
177 : 2 : queue_ops_rsa_enc_dec(void *sess)
178 : : {
179 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
180 : 2 : struct rte_mempool *op_mpool = ts_params->op_mpool;
181 : 2 : uint8_t dev_id = ts_params->valid_devs[0];
182 : : struct rte_crypto_op *op, *result_op;
183 : : struct rte_crypto_asym_op *asym_op;
184 : 2 : uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
185 : 2 : uint8_t msg_buf[TEST_DATA_SIZE] = {0};
186 : : int ret, status;
187 : :
188 : 2 : memcpy(msg_buf, rsaplaintext.data, rsaplaintext.len);
189 : :
190 : : /* Set up crypto op data structure */
191 : 2 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
192 [ - + ]: 2 : if (!op) {
193 : 0 : RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
194 : : "operation struct\n");
195 : 0 : return TEST_FAILED;
196 : : }
197 : :
198 : : asym_op = op->asym;
199 : :
200 : : /* Compute encryption on the test vector */
201 : 2 : asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
202 : :
203 : 2 : asym_op->rsa.message.data = msg_buf;
204 : 2 : asym_op->rsa.cipher.data = cipher_buf;
205 : 2 : asym_op->rsa.cipher.length = RTE_DIM(rsa_n);
206 : 2 : asym_op->rsa.message.length = rsaplaintext.len;
207 : :
208 : 2 : debug_hexdump(stdout, "message", asym_op->rsa.message.data,
209 : : asym_op->rsa.message.length);
210 : :
211 : : /* Attach asymmetric crypto session to crypto operations */
212 [ + - ]: 2 : rte_crypto_op_attach_asym_session(op, sess);
213 : :
214 : 2 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
215 : :
216 : : /* Process crypto operation */
217 [ - + ]: 2 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
218 : 0 : RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
219 : : status = TEST_FAILED;
220 : 0 : goto error_exit;
221 : : }
222 : :
223 [ - + ]: 2 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
224 : : rte_pause();
225 : :
226 [ - + ]: 2 : if (result_op == NULL) {
227 : 0 : RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
228 : : status = TEST_FAILED;
229 : 0 : goto error_exit;
230 : : }
231 : 2 : debug_hexdump(stdout, "encrypted message", asym_op->rsa.cipher.data,
232 : : asym_op->rsa.cipher.length);
233 : :
234 : : /* Use the resulted output as decryption Input vector*/
235 : 2 : asym_op = result_op->asym;
236 : 2 : asym_op->rsa.message.length = RTE_DIM(rsa_n);
237 : 2 : asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
238 : 2 : memset(asym_op->rsa.message.data, 0, asym_op->rsa.message.length);
239 : :
240 : : /* Process crypto operation */
241 [ - + ]: 2 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
242 : 0 : RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
243 : : status = TEST_FAILED;
244 : 0 : goto error_exit;
245 : : }
246 : :
247 [ - + ]: 2 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
248 : : rte_pause();
249 : :
250 [ - + ]: 2 : if (result_op == NULL) {
251 : 0 : RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
252 : : status = TEST_FAILED;
253 : 0 : goto error_exit;
254 : : }
255 : :
256 [ - + ]: 2 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
257 : 0 : RTE_LOG(ERR, USER1, "Expected crypto op to succeed\n");
258 : : status = TEST_FAILED;
259 : 0 : goto error_exit;
260 : : }
261 : :
262 : : ret = rsa_verify(&rsaplaintext, result_op);
263 : : if (ret) {
264 : : status = TEST_FAILED;
265 : 0 : goto error_exit;
266 : : }
267 : :
268 : : status = TEST_SUCCESS;
269 : 2 : error_exit:
270 : :
271 : 2 : rte_crypto_op_free(op);
272 : :
273 : 2 : return status;
274 : : }
275 : :
276 : : static int
277 : 1 : test_rsa_sign_verify(void)
278 : : {
279 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
280 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
281 : : struct rte_cryptodev_asym_capability_idx idx;
282 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
283 : : struct rte_crypto_asym_xform xform;
284 : 1 : void *sess = NULL;
285 : : struct rte_cryptodev_info dev_info;
286 : : int ret, status = TEST_SUCCESS;
287 : :
288 : : /* Check RSA capability */
289 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
290 [ + - ]: 1 : if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
291 : : return -ENOTSUP;
292 : :
293 : : /* Test case supports op with exponent key only,
294 : : * Check in PMD feature flag for RSA exponent key type support.
295 : : */
296 : 1 : rte_cryptodev_info_get(dev_id, &dev_info);
297 [ - + ]: 1 : if (!(dev_info.feature_flags &
298 : : RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
299 : 0 : RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
300 : : "exponent key type. Test Skipped\n");
301 : 0 : return TEST_SKIPPED;
302 : : }
303 : :
304 : : memcpy(&xform, &rsa_xform, sizeof(rsa_xform));
305 : 1 : xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
306 : :
307 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
308 : :
309 [ - + ]: 1 : if (ret < 0) {
310 : 0 : RTE_LOG(ERR, USER1, "Session creation failed for "
311 : : "sign_verify\n");
312 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
313 : 0 : goto error_exit;
314 : : }
315 : :
316 : 1 : status = queue_ops_rsa_sign_verify(sess);
317 : :
318 : 1 : error_exit:
319 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
320 : :
321 [ + - ]: 1 : if (status == TEST_SKIPPED)
322 : : return status;
323 : :
324 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
325 : :
326 : : return status;
327 : : }
328 : :
329 : : static int
330 : 1 : test_rsa_enc_dec(void)
331 : : {
332 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
333 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
334 : : struct rte_cryptodev_asym_capability_idx idx;
335 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
336 : : struct rte_crypto_asym_xform xform;
337 : 1 : void *sess = NULL;
338 : : struct rte_cryptodev_info dev_info;
339 : : int ret, status = TEST_SUCCESS;
340 : :
341 : : /* Check RSA capability */
342 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
343 [ + - ]: 1 : if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
344 : : return -ENOTSUP;
345 : :
346 : : /* Test case supports op with exponent key only,
347 : : * Check in PMD feature flag for RSA exponent key type support.
348 : : */
349 : 1 : rte_cryptodev_info_get(dev_id, &dev_info);
350 [ - + ]: 1 : if (!(dev_info.feature_flags &
351 : : RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
352 : 0 : RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
353 : : "exponent key type. Test skipped\n");
354 : 0 : return TEST_SKIPPED;
355 : : }
356 : :
357 : : memcpy(&xform, &rsa_xform, sizeof(rsa_xform));
358 : 1 : xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
359 : :
360 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
361 : :
362 [ - + ]: 1 : if (ret < 0) {
363 : 0 : RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
364 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
365 : 0 : goto error_exit;
366 : : }
367 : :
368 : 1 : status = queue_ops_rsa_enc_dec(sess);
369 : :
370 : 1 : error_exit:
371 : :
372 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
373 : :
374 [ + - ]: 1 : if (status == TEST_SKIPPED)
375 : : return status;
376 : :
377 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
378 : :
379 : : return status;
380 : : }
381 : :
382 : : static int
383 : 1 : test_rsa_sign_verify_crt(void)
384 : : {
385 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
386 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
387 : : struct rte_cryptodev_asym_capability_idx idx;
388 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
389 : 1 : void *sess = NULL;
390 : : struct rte_cryptodev_info dev_info;
391 : : int ret, status = TEST_SUCCESS;
392 : :
393 : : /* Check RSA capability */
394 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
395 [ + - ]: 1 : if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
396 : : return -ENOTSUP;
397 : :
398 : : /* Test case supports op with quintuple format key only,
399 : : * Check im PMD feature flag for RSA quintuple key type support.
400 : : */
401 : 1 : rte_cryptodev_info_get(dev_id, &dev_info);
402 [ - + ]: 1 : if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
403 : 0 : RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
404 : : "quintuple key type. Test skipped\n");
405 : 0 : return TEST_SKIPPED;
406 : : }
407 : :
408 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
409 : :
410 [ - + ]: 1 : if (ret < 0) {
411 : 0 : RTE_LOG(ERR, USER1, "Session creation failed for "
412 : : "sign_verify_crt\n");
413 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
414 : 0 : goto error_exit;
415 : : }
416 : :
417 : 1 : status = queue_ops_rsa_sign_verify(sess);
418 : :
419 : 1 : error_exit:
420 : :
421 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
422 : :
423 [ + - ]: 1 : if (status == TEST_SKIPPED)
424 : : return status;
425 : :
426 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
427 : :
428 : : return status;
429 : : }
430 : :
431 : : static int
432 : 1 : test_rsa_enc_dec_crt(void)
433 : : {
434 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
435 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
436 : : struct rte_cryptodev_asym_capability_idx idx;
437 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
438 : 1 : void *sess = NULL;
439 : : struct rte_cryptodev_info dev_info;
440 : : int ret, status = TEST_SUCCESS;
441 : :
442 : : /* Check RSA capability */
443 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
444 [ + - ]: 1 : if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
445 : : return -ENOTSUP;
446 : :
447 : : /* Test case supports op with quintuple format key only,
448 : : * Check in PMD feature flag for RSA quintuple key type support.
449 : : */
450 : 1 : rte_cryptodev_info_get(dev_id, &dev_info);
451 [ - + ]: 1 : if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
452 : 0 : RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
453 : : "quintuple key type. Test skipped\n");
454 : 0 : return TEST_SKIPPED;
455 : : }
456 : :
457 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
458 : :
459 [ - + ]: 1 : if (ret < 0) {
460 : 0 : RTE_LOG(ERR, USER1, "Session creation failed for "
461 : : "enc_dec_crt\n");
462 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
463 : 0 : goto error_exit;
464 : : }
465 : :
466 : 1 : status = queue_ops_rsa_enc_dec(sess);
467 : :
468 : 1 : error_exit:
469 : :
470 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
471 : :
472 [ + - ]: 1 : if (status == TEST_SKIPPED)
473 : : return status;
474 : :
475 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
476 : :
477 : : return status;
478 : : }
479 : :
480 : : static int
481 : 1 : testsuite_setup(void)
482 : : {
483 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
484 : : uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
485 : : struct rte_cryptodev_info info;
486 : : int ret, dev_id = -1;
487 : : uint32_t i, nb_devs;
488 : : uint16_t qp_id;
489 : :
490 : : memset(ts_params, 0, sizeof(*ts_params));
491 : :
492 : : /* Device, op pool and session configuration for asymmetric crypto. 8< */
493 : 1 : ts_params->op_mpool = rte_crypto_op_pool_create(
494 : : "CRYPTO_ASYM_OP_POOL",
495 : : RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
496 : : TEST_NUM_BUFS, 0,
497 : : 0,
498 : 1 : rte_socket_id());
499 [ - + ]: 1 : if (ts_params->op_mpool == NULL) {
500 : 0 : RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
501 : 0 : return TEST_FAILED;
502 : : }
503 : :
504 : : /* Create an OPENSSL device if required */
505 [ + - ]: 1 : if (gbl_driver_id == rte_cryptodev_driver_id_get(
506 : : RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
507 : 1 : nb_devs = rte_cryptodev_device_count_by_driver(
508 : 1 : rte_cryptodev_driver_id_get(
509 : : RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
510 [ - + ]: 1 : if (nb_devs < 1) {
511 : 0 : ret = rte_vdev_init(
512 : : RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
513 : : NULL);
514 : :
515 [ # # ]: 0 : TEST_ASSERT(ret == 0, "Failed to create "
516 : : "instance of pmd : %s",
517 : : RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
518 : : }
519 : : }
520 : :
521 : : /* Get list of valid crypto devs */
522 : 1 : nb_devs = rte_cryptodev_devices_get(
523 : : rte_cryptodev_driver_name_get(gbl_driver_id),
524 : : valid_devs, RTE_CRYPTO_MAX_DEVS);
525 [ - + ]: 1 : if (nb_devs < 1) {
526 : 0 : RTE_LOG(ERR, USER1, "No crypto devices found?\n");
527 : 0 : return TEST_SKIPPED;
528 : : }
529 : :
530 : : /*
531 : : * Get first valid asymmetric device found in test suite param and
532 : : * break
533 : : */
534 [ + - ]: 1 : for (i = 0; i < nb_devs ; i++) {
535 : 1 : rte_cryptodev_info_get(valid_devs[i], &info);
536 [ + - ]: 1 : if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
537 : 1 : dev_id = ts_params->valid_devs[0] = valid_devs[i];
538 : 1 : break;
539 : : }
540 : : }
541 : :
542 [ - + ]: 1 : if (dev_id == -1) {
543 : 0 : RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
544 : : "Test skipped.\n");
545 : 0 : return TEST_FAILED;
546 : : }
547 : :
548 : : /* Set valid device count */
549 : 1 : ts_params->valid_dev_count = nb_devs;
550 : :
551 : : /* configure device with num qp */
552 : 1 : ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
553 : 1 : ts_params->conf.socket_id = SOCKET_ID_ANY;
554 : 1 : ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
555 : : RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
556 [ - + ]: 1 : TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
557 : : &ts_params->conf),
558 : : "Failed to configure cryptodev %u with %u qps",
559 : : dev_id, ts_params->conf.nb_queue_pairs);
560 : :
561 : : /* configure qp */
562 : 1 : ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
563 : 1 : ts_params->qp_conf.mp_session = ts_params->session_mpool;
564 [ + + ]: 9 : for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
565 [ - + ]: 8 : TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
566 : : dev_id, qp_id, &ts_params->qp_conf,
567 : : rte_cryptodev_socket_id(dev_id)),
568 : : "Failed to setup queue pair %u on cryptodev %u ASYM",
569 : : qp_id, dev_id);
570 : : }
571 : :
572 : 1 : ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
573 : : "test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
574 : : SOCKET_ID_ANY);
575 : :
576 [ - + ]: 1 : TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
577 : : "session mempool allocation failed");
578 : : /* >8 End of device, op pool and session configuration for asymmetric crypto section. */
579 : : return TEST_SUCCESS;
580 : : }
581 : :
582 : : static void
583 : 1 : testsuite_teardown(void)
584 : : {
585 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
586 : :
587 : : /* Reset device */
588 : 1 : ts_params->qp_conf.mp_session = NULL;
589 : 1 : ts_params->conf.ff_disable = 0;
590 [ - + ]: 1 : if (rte_cryptodev_configure(ts_params->valid_devs[0], &ts_params->conf))
591 : 0 : RTE_LOG(DEBUG, USER1, "Could not reset cryptodev\n");
592 : :
593 [ + - ]: 1 : if (ts_params->op_mpool != NULL) {
594 : 1 : RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
595 : : rte_mempool_avail_count(ts_params->op_mpool));
596 : : }
597 : :
598 : : /* Free session mempools */
599 [ + - ]: 1 : if (ts_params->session_mpool != NULL) {
600 : 1 : rte_mempool_free(ts_params->session_mpool);
601 : 1 : ts_params->session_mpool = NULL;
602 : : }
603 : 1 : }
604 : :
605 : : static int
606 : 32 : ut_setup_asym(void)
607 : : {
608 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
609 : : uint16_t qp_id;
610 : :
611 : 32 : memset(self, 0, sizeof(*self));
612 : 32 : self->op = rte_crypto_op_alloc(params->op_mpool,
613 : : RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
614 [ - + ]: 32 : TEST_ASSERT_NOT_NULL(self->op,
615 : : "Failed to allocate asymmetric crypto operation struct"
616 : : );
617 : :
618 : : /* Reconfigure device to default parameters */
619 : 32 : ts_params->conf.socket_id = SOCKET_ID_ANY;
620 : :
621 [ - + ]: 32 : TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
622 : : &ts_params->conf),
623 : : "Failed to configure cryptodev %u",
624 : : ts_params->valid_devs[0]);
625 : :
626 [ + + ]: 288 : for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
627 [ - + ]: 256 : TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
628 : : ts_params->valid_devs[0], qp_id,
629 : : &ts_params->qp_conf,
630 : : rte_cryptodev_socket_id(ts_params->valid_devs[0])),
631 : : "Failed to setup queue pair %u on cryptodev %u",
632 : : qp_id, ts_params->valid_devs[0]);
633 : : }
634 : :
635 : : /* Start the device */
636 [ - + ]: 32 : TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
637 : : "Failed to start cryptodev %u",
638 : : ts_params->valid_devs[0]);
639 : :
640 : : return TEST_SUCCESS;
641 : : }
642 : :
643 : : static void
644 : 32 : ut_teardown_asym(void)
645 : : {
646 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
647 : 32 : uint8_t dev_id = ts_params->valid_devs[0];
648 : :
649 [ + + ]: 32 : if (self->sess != NULL)
650 : 16 : rte_cryptodev_asym_session_free(dev_id, self->sess);
651 : 32 : rte_crypto_op_free(self->op);
652 : 32 : self->sess = NULL;
653 : 32 : self->op = NULL;
654 : 32 : self->result_op = NULL;
655 : :
656 : : /* Stop the device */
657 : 32 : rte_cryptodev_stop(ts_params->valid_devs[0]);
658 : 32 : }
659 : :
660 : 8 : static inline void print_asym_capa(
661 : : const struct rte_cryptodev_asymmetric_xform_capability *capa)
662 : : {
663 : : int i = 0;
664 : :
665 : 8 : printf("\nxform type: %s\n===================\n",
666 : 8 : rte_cryptodev_asym_get_xform_string(capa->xform_type));
667 : : printf("operation supported -");
668 : :
669 [ + + ]: 40 : for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
670 : : /* check supported operations */
671 [ + + ]: 32 : if (rte_cryptodev_asym_xform_capability_check_optype(capa, i)) {
672 [ + + ]: 15 : if (capa->xform_type == RTE_CRYPTO_ASYM_XFORM_DH)
673 : 3 : printf(" %s", rte_crypto_asym_ke_strings[i]);
674 : : else
675 : 12 : printf(" %s", rte_crypto_asym_op_strings[i]);
676 : : }
677 : : }
678 [ + + ]: 8 : switch (capa->xform_type) {
679 : 5 : case RTE_CRYPTO_ASYM_XFORM_RSA:
680 : : case RTE_CRYPTO_ASYM_XFORM_MODINV:
681 : : case RTE_CRYPTO_ASYM_XFORM_MODEX:
682 : : case RTE_CRYPTO_ASYM_XFORM_DH:
683 : : case RTE_CRYPTO_ASYM_XFORM_DSA:
684 : 5 : printf(" modlen: min %d max %d increment %d",
685 : 5 : capa->modlen.min,
686 : 5 : capa->modlen.max,
687 : 5 : capa->modlen.increment);
688 : : break;
689 : : case RTE_CRYPTO_ASYM_XFORM_ECDSA:
690 : : case RTE_CRYPTO_ASYM_XFORM_ECPM:
691 : : case RTE_CRYPTO_ASYM_XFORM_SM2:
692 : : default:
693 : : break;
694 : : }
695 : : printf("\n");
696 : 8 : }
697 : :
698 : : static int
699 : 1 : test_capability(void)
700 : : {
701 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
702 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
703 : : struct rte_cryptodev_info dev_info;
704 : : const struct rte_cryptodev_capabilities *dev_capa;
705 : : int i = 0;
706 : : struct rte_cryptodev_asym_capability_idx idx;
707 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
708 : :
709 : 1 : rte_cryptodev_info_get(dev_id, &dev_info);
710 [ - + ]: 1 : if (!(dev_info.feature_flags &
711 : : RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
712 : 0 : RTE_LOG(INFO, USER1,
713 : : "Device doesn't support asymmetric. Test Skipped\n");
714 : 0 : return TEST_SKIPPED;
715 : : }
716 : :
717 : : /* print xform capability */
718 : : for (i = 0;
719 [ + + ]: 42 : dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
720 : 41 : i++) {
721 : : dev_capa = &(dev_info.capabilities[i]);
722 [ + + ]: 41 : if (dev_info.capabilities[i].op ==
723 : : RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
724 : 8 : idx.type = dev_capa->asym.xform_capa.xform_type;
725 : :
726 : 8 : capa = rte_cryptodev_asym_capability_get(dev_id,
727 : : (const struct
728 : : rte_cryptodev_asym_capability_idx *) &idx);
729 [ - + ]: 8 : TEST_ASSERT_NOT_NULL(capa, "Failed to get asymmetric capability");
730 : 8 : print_asym_capa(capa);
731 : : }
732 : : }
733 : : return TEST_SUCCESS;
734 : : }
735 : :
736 : : static int
737 : 1 : test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
738 : : {
739 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
740 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
741 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
742 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
743 : : struct rte_crypto_asym_op *asym_op = NULL;
744 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
745 : 1 : void *sess = NULL;
746 : : int ret, status = TEST_SUCCESS;
747 : : uint8_t output[TEST_DH_MOD_LEN];
748 : 1 : struct rte_crypto_asym_xform xform = *xfrm;
749 : 1 : uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
750 : :
751 : : /* set up crypto op data structure */
752 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
753 [ - + ]: 1 : if (!op) {
754 : 0 : RTE_LOG(ERR, USER1,
755 : : "line %u FAILED: %s",
756 : : __LINE__, "Failed to allocate asymmetric crypto "
757 : : "operation struct");
758 : : status = TEST_FAILED;
759 : 0 : goto error_exit;
760 : : }
761 : : asym_op = op->asym;
762 : :
763 : : /* Setup a xform and op to generate private key only */
764 : 1 : xform.next = NULL;
765 : 1 : asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
766 : 1 : asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
767 : 1 : asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
768 : 1 : asym_op->dh.pub_key.data = (uint8_t *)peer;
769 : 1 : asym_op->dh.pub_key.length = sizeof(peer);
770 : 1 : asym_op->dh.shared_secret.data = output;
771 : 1 : asym_op->dh.shared_secret.length = sizeof(output);
772 : :
773 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
774 [ - + ]: 1 : if (ret < 0) {
775 : 0 : RTE_LOG(ERR, USER1,
776 : : "line %u FAILED: %s", __LINE__,
777 : : "Session creation failed");
778 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
779 : 0 : goto error_exit;
780 : : }
781 : :
782 : : /* attach asymmetric crypto session to crypto operations */
783 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
784 : :
785 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
786 : :
787 : : /* Process crypto operation */
788 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
789 : 0 : RTE_LOG(ERR, USER1,
790 : : "line %u FAILED: %s",
791 : : __LINE__, "Error sending packet for operation");
792 : : status = TEST_FAILED;
793 : 0 : goto error_exit;
794 : : }
795 : :
796 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
797 : : rte_pause();
798 : :
799 [ - + ]: 1 : if (result_op == NULL) {
800 : 0 : RTE_LOG(ERR, USER1,
801 : : "line %u FAILED: %s",
802 : : __LINE__, "Failed to process asym crypto op");
803 : : status = TEST_FAILED;
804 : 0 : goto error_exit;
805 : : }
806 : :
807 : 1 : debug_hexdump(stdout, "shared secret:",
808 : 1 : asym_op->dh.shared_secret.data,
809 : : asym_op->dh.shared_secret.length);
810 : :
811 : 1 : error_exit:
812 [ + - ]: 1 : if (sess != NULL)
813 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
814 : 1 : rte_crypto_op_free(op);
815 : 1 : return status;
816 : : }
817 : :
818 : : static int
819 : 1 : test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
820 : : {
821 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
822 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
823 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
824 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
825 : : struct rte_crypto_asym_op *asym_op = NULL;
826 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
827 : 1 : void *sess = NULL;
828 : : int ret, status = TEST_SUCCESS;
829 : : uint8_t output[TEST_DH_MOD_LEN];
830 : 1 : struct rte_crypto_asym_xform xform = *xfrm;
831 : :
832 : : /* set up crypto op data structure */
833 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
834 [ - + ]: 1 : if (!op) {
835 : 0 : RTE_LOG(ERR, USER1,
836 : : "line %u FAILED: %s",
837 : : __LINE__, "Failed to allocate asymmetric crypto "
838 : : "operation struct");
839 : : status = TEST_FAILED;
840 : 0 : goto error_exit;
841 : : }
842 : : asym_op = op->asym;
843 : :
844 : : /* Setup a xform and op to generate private key only */
845 : 1 : xform.next = NULL;
846 : 1 : asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE;
847 : 1 : asym_op->dh.priv_key.data = output;
848 : 1 : asym_op->dh.priv_key.length = sizeof(output);
849 : :
850 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
851 [ - + ]: 1 : if (ret < 0) {
852 : 0 : RTE_LOG(ERR, USER1,
853 : : "line %u FAILED: %s", __LINE__,
854 : : "Session creation failed");
855 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
856 : 0 : goto error_exit;
857 : : }
858 : :
859 : : /* attach asymmetric crypto session to crypto operations */
860 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
861 : :
862 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
863 : :
864 : : /* Process crypto operation */
865 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
866 : 0 : RTE_LOG(ERR, USER1,
867 : : "line %u FAILED: %s",
868 : : __LINE__, "Error sending packet for operation");
869 : : status = TEST_FAILED;
870 : 0 : goto error_exit;
871 : : }
872 : :
873 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
874 : : rte_pause();
875 : :
876 [ - + ]: 1 : if (result_op == NULL) {
877 : 0 : RTE_LOG(ERR, USER1,
878 : : "line %u FAILED: %s",
879 : : __LINE__, "Failed to process asym crypto op");
880 : : status = TEST_FAILED;
881 : 0 : goto error_exit;
882 : : }
883 : :
884 : 1 : debug_hexdump(stdout, "private key:",
885 : 1 : asym_op->dh.priv_key.data,
886 : : asym_op->dh.priv_key.length);
887 : :
888 : :
889 : 1 : error_exit:
890 [ + - ]: 1 : if (sess != NULL)
891 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
892 : 1 : rte_crypto_op_free(op);
893 : :
894 : 1 : return status;
895 : : }
896 : :
897 : :
898 : : static int
899 : 1 : test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
900 : : {
901 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
902 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
903 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
904 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
905 : : struct rte_crypto_asym_op *asym_op = NULL;
906 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
907 : 1 : void *sess = NULL;
908 : : int ret, status = TEST_SUCCESS;
909 : : uint8_t output[TEST_DH_MOD_LEN];
910 : 1 : struct rte_crypto_asym_xform xform = *xfrm;
911 : :
912 : : /* set up crypto op data structure */
913 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
914 [ - + ]: 1 : if (!op) {
915 : 0 : RTE_LOG(ERR, USER1,
916 : : "line %u FAILED: %s",
917 : : __LINE__, "Failed to allocate asymmetric crypto "
918 : : "operation struct");
919 : : status = TEST_FAILED;
920 : 0 : goto error_exit;
921 : : }
922 : : asym_op = op->asym;
923 : : /* Setup a xform chain to generate public key
924 : : * using test private key
925 : : *
926 : : */
927 : 1 : xform.next = NULL;
928 : :
929 : 1 : asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
930 : 1 : asym_op->dh.pub_key.data = output;
931 : 1 : asym_op->dh.pub_key.length = sizeof(output);
932 : : /* load pre-defined private key */
933 : 1 : asym_op->dh.priv_key.data = rte_malloc(NULL,
934 : : dh_test_params.priv_key.length,
935 : : 0);
936 : 1 : asym_op->dh.priv_key = dh_test_params.priv_key;
937 : :
938 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
939 [ - + ]: 1 : if (ret < 0) {
940 : 0 : RTE_LOG(ERR, USER1,
941 : : "line %u FAILED: %s", __LINE__,
942 : : "Session creation failed");
943 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
944 : 0 : goto error_exit;
945 : : }
946 : :
947 : : /* attach asymmetric crypto session to crypto operations */
948 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
949 : :
950 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
951 : :
952 : : /* Process crypto operation */
953 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
954 : 0 : RTE_LOG(ERR, USER1,
955 : : "line %u FAILED: %s",
956 : : __LINE__, "Error sending packet for operation");
957 : : status = TEST_FAILED;
958 : 0 : goto error_exit;
959 : : }
960 : :
961 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
962 : : rte_pause();
963 : :
964 [ - + ]: 1 : if (result_op == NULL) {
965 : 0 : RTE_LOG(ERR, USER1,
966 : : "line %u FAILED: %s",
967 : : __LINE__, "Failed to process asym crypto op");
968 : : status = TEST_FAILED;
969 : 0 : goto error_exit;
970 : : }
971 : :
972 : 1 : debug_hexdump(stdout, "pub key:",
973 : 1 : asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
974 : :
975 : 1 : debug_hexdump(stdout, "priv key:",
976 : 1 : asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
977 : :
978 : 1 : error_exit:
979 [ + - ]: 1 : if (sess != NULL)
980 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
981 : 1 : rte_crypto_op_free(op);
982 : :
983 : 1 : return status;
984 : : }
985 : :
986 : : static int
987 : 1 : test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
988 : : {
989 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
990 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
991 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
992 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
993 : : struct rte_crypto_asym_op *asym_op = NULL;
994 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
995 : 1 : void *sess = NULL;
996 : : int ret, status = TEST_SUCCESS;
997 : : uint8_t out_pub_key[TEST_DH_MOD_LEN];
998 : : uint8_t out_prv_key[TEST_DH_MOD_LEN];
999 : : struct rte_crypto_asym_xform pub_key_xform;
1000 : 1 : struct rte_crypto_asym_xform xform = *xfrm;
1001 : :
1002 : : /* set up crypto op data structure */
1003 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1004 [ - + ]: 1 : if (!op) {
1005 : 0 : RTE_LOG(ERR, USER1,
1006 : : "line %u FAILED: %s",
1007 : : __LINE__, "Failed to allocate asymmetric crypto "
1008 : : "operation struct");
1009 : : status = TEST_FAILED;
1010 : 0 : goto error_exit;
1011 : : }
1012 : : asym_op = op->asym;
1013 : : /* Setup a xform chain to generate
1014 : : * private key first followed by
1015 : : * public key
1016 : : */
1017 : 1 : pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1018 : 1 : xform.next = &pub_key_xform;
1019 : :
1020 : 1 : asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
1021 : 1 : asym_op->dh.pub_key.data = out_pub_key;
1022 : 1 : asym_op->dh.pub_key.length = sizeof(out_pub_key);
1023 : 1 : asym_op->dh.priv_key.data = out_prv_key;
1024 : 1 : asym_op->dh.priv_key.length = 0;
1025 : :
1026 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1027 [ - + ]: 1 : if (ret < 0) {
1028 : 0 : RTE_LOG(ERR, USER1,
1029 : : "line %u FAILED: %s", __LINE__,
1030 : : "Session creation failed");
1031 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1032 : 0 : goto error_exit;
1033 : : }
1034 : :
1035 : : /* attach asymmetric crypto session to crypto operations */
1036 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
1037 : :
1038 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1039 : :
1040 : : /* Process crypto operation */
1041 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1042 : 0 : RTE_LOG(ERR, USER1,
1043 : : "line %u FAILED: %s",
1044 : : __LINE__, "Error sending packet for operation");
1045 : : status = TEST_FAILED;
1046 : 0 : goto error_exit;
1047 : : }
1048 : :
1049 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1050 : : rte_pause();
1051 : :
1052 [ - + ]: 1 : if (result_op == NULL) {
1053 : 0 : RTE_LOG(ERR, USER1,
1054 : : "line %u FAILED: %s",
1055 : : __LINE__, "Failed to process asym crypto op");
1056 : : status = TEST_FAILED;
1057 : 0 : goto error_exit;
1058 : : }
1059 : 1 : debug_hexdump(stdout, "priv key:",
1060 : : out_prv_key, asym_op->dh.priv_key.length);
1061 : 1 : debug_hexdump(stdout, "pub key:",
1062 : : out_pub_key, asym_op->dh.pub_key.length);
1063 : :
1064 : 1 : error_exit:
1065 [ + - ]: 1 : if (sess != NULL)
1066 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
1067 : 1 : rte_crypto_op_free(op);
1068 : :
1069 : 1 : return status;
1070 : : }
1071 : :
1072 : : static int
1073 : 1 : test_mod_inv(void)
1074 : : {
1075 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1076 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1077 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1078 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
1079 : : struct rte_crypto_asym_op *asym_op = NULL;
1080 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
1081 : 1 : void *sess = NULL;
1082 : : int status = TEST_SUCCESS;
1083 : : struct rte_cryptodev_asym_capability_idx cap_idx;
1084 : : const struct rte_cryptodev_asymmetric_xform_capability *capability;
1085 : 1 : uint8_t input[TEST_DATA_SIZE] = {0};
1086 : : int ret = 0;
1087 : 1 : uint8_t result[sizeof(mod_p)] = { 0 };
1088 : :
1089 [ - + ]: 1 : if (rte_cryptodev_asym_get_xform_enum(
1090 : : &modinv_xform.xform_type, "modinv") < 0) {
1091 : 0 : RTE_LOG(ERR, USER1,
1092 : : "Invalid ASYM algorithm specified\n");
1093 : 0 : return -1;
1094 : : }
1095 : :
1096 : 1 : cap_idx.type = modinv_xform.xform_type;
1097 : 1 : capability = rte_cryptodev_asym_capability_get(dev_id,
1098 : : &cap_idx);
1099 : :
1100 [ - + ]: 1 : if (capability == NULL) {
1101 : 0 : RTE_LOG(INFO, USER1,
1102 : : "Device doesn't support MOD INV. Test Skipped\n");
1103 : 0 : return TEST_SKIPPED;
1104 : : }
1105 : :
1106 [ - + ]: 1 : if (rte_cryptodev_asym_xform_capability_check_modlen(
1107 : : capability,
1108 : 1 : modinv_xform.modinv.modulus.length)) {
1109 : 0 : RTE_LOG(ERR, USER1,
1110 : : "Invalid MODULUS length specified\n");
1111 : 0 : return TEST_SKIPPED;
1112 : : }
1113 : :
1114 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
1115 [ - + ]: 1 : if (ret < 0) {
1116 : 0 : RTE_LOG(ERR, USER1, "line %u "
1117 : : "FAILED: %s", __LINE__,
1118 : : "Session creation failed");
1119 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1120 : 0 : goto error_exit;
1121 : : }
1122 : :
1123 : : /* generate crypto op data structure */
1124 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1125 [ - + ]: 1 : if (!op) {
1126 : 0 : RTE_LOG(ERR, USER1,
1127 : : "line %u FAILED: %s",
1128 : : __LINE__, "Failed to allocate asymmetric crypto "
1129 : : "operation struct");
1130 : : status = TEST_FAILED;
1131 : 0 : goto error_exit;
1132 : : }
1133 : :
1134 : : asym_op = op->asym;
1135 : : memcpy(input, base, sizeof(base));
1136 : 1 : asym_op->modinv.base.data = input;
1137 : 1 : asym_op->modinv.base.length = sizeof(base);
1138 : 1 : asym_op->modinv.result.data = result;
1139 : 1 : asym_op->modinv.result.length = sizeof(result);
1140 : :
1141 : : /* attach asymmetric crypto session to crypto operations */
1142 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
1143 : :
1144 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1145 : :
1146 : : /* Process crypto operation */
1147 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1148 : 0 : RTE_LOG(ERR, USER1,
1149 : : "line %u FAILED: %s",
1150 : : __LINE__, "Error sending packet for operation");
1151 : : status = TEST_FAILED;
1152 : 0 : goto error_exit;
1153 : : }
1154 : :
1155 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1156 : : rte_pause();
1157 : :
1158 [ - + ]: 1 : if (result_op == NULL) {
1159 : 0 : RTE_LOG(ERR, USER1,
1160 : : "line %u FAILED: %s",
1161 : : __LINE__, "Failed to process asym crypto op");
1162 : : status = TEST_FAILED;
1163 : 0 : goto error_exit;
1164 : : }
1165 : :
1166 : 1 : ret = verify_modinv(mod_inv, result_op);
1167 [ + - ]: 1 : if (ret) {
1168 : 0 : RTE_LOG(ERR, USER1,
1169 : : "operation verification failed\n");
1170 : : status = TEST_FAILED;
1171 : : }
1172 : :
1173 : 1 : error_exit:
1174 [ + - ]: 1 : if (sess)
1175 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
1176 : :
1177 : 1 : rte_crypto_op_free(op);
1178 : :
1179 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1180 : :
1181 : : return status;
1182 : : }
1183 : :
1184 : : static int
1185 : 1 : test_mod_exp(void)
1186 : : {
1187 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1188 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1189 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1190 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
1191 : : struct rte_crypto_asym_op *asym_op = NULL;
1192 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
1193 : 1 : void *sess = NULL;
1194 : : int status = TEST_SUCCESS;
1195 : : struct rte_cryptodev_asym_capability_idx cap_idx;
1196 : : const struct rte_cryptodev_asymmetric_xform_capability *capability;
1197 : 1 : uint8_t input[TEST_DATA_SIZE] = {0};
1198 : : int ret = 0;
1199 : 1 : uint8_t result[sizeof(mod_p)] = { 0 };
1200 : :
1201 [ - + ]: 1 : if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1202 : : "modexp")
1203 : : < 0) {
1204 : 0 : RTE_LOG(ERR, USER1,
1205 : : "Invalid ASYM algorithm specified\n");
1206 : 0 : return -1;
1207 : : }
1208 : :
1209 : : /* check for modlen capability */
1210 : 1 : cap_idx.type = modex_xform.xform_type;
1211 : 1 : capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1212 : :
1213 [ - + ]: 1 : if (capability == NULL) {
1214 : 0 : RTE_LOG(INFO, USER1,
1215 : : "Device doesn't support MOD EXP. Test Skipped\n");
1216 : 0 : return TEST_SKIPPED;
1217 : : }
1218 : :
1219 [ - + ]: 1 : if (rte_cryptodev_asym_xform_capability_check_modlen(
1220 : 1 : capability, modex_xform.modex.modulus.length)) {
1221 : 0 : RTE_LOG(ERR, USER1,
1222 : : "Invalid MODULUS length specified\n");
1223 : 0 : return TEST_SKIPPED;
1224 : : }
1225 : :
1226 : : /* Create op, create session, and process packets. 8< */
1227 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1228 [ - + ]: 1 : if (!op) {
1229 : 0 : RTE_LOG(ERR, USER1,
1230 : : "line %u FAILED: %s",
1231 : : __LINE__, "Failed to allocate asymmetric crypto "
1232 : : "operation struct");
1233 : : status = TEST_FAILED;
1234 : 0 : goto error_exit;
1235 : : }
1236 : :
1237 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
1238 [ - + ]: 1 : if (ret < 0) {
1239 : 0 : RTE_LOG(ERR, USER1,
1240 : : "line %u "
1241 : : "FAILED: %s", __LINE__,
1242 : : "Session creation failed");
1243 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1244 : 0 : goto error_exit;
1245 : : }
1246 : :
1247 : 1 : asym_op = op->asym;
1248 : : memcpy(input, base, sizeof(base));
1249 : 1 : asym_op->modex.base.data = input;
1250 : 1 : asym_op->modex.base.length = sizeof(base);
1251 : 1 : asym_op->modex.result.data = result;
1252 : 1 : asym_op->modex.result.length = sizeof(result);
1253 : : /* attach asymmetric crypto session to crypto operations */
1254 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
1255 : :
1256 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1257 : : /* Process crypto operation */
1258 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1259 : 0 : RTE_LOG(ERR, USER1,
1260 : : "line %u FAILED: %s",
1261 : : __LINE__, "Error sending packet for operation");
1262 : : status = TEST_FAILED;
1263 : 0 : goto error_exit;
1264 : : }
1265 : :
1266 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1267 : : rte_pause();
1268 : :
1269 [ - + ]: 1 : if (result_op == NULL) {
1270 : 0 : RTE_LOG(ERR, USER1,
1271 : : "line %u FAILED: %s",
1272 : : __LINE__, "Failed to process asym crypto op");
1273 : : status = TEST_FAILED;
1274 : 0 : goto error_exit;
1275 : : }
1276 : : /* >8 End of create op, create session, and process packets section. */
1277 : 1 : ret = verify_modexp(mod_exp, result_op);
1278 [ + - ]: 1 : if (ret) {
1279 : 0 : RTE_LOG(ERR, USER1,
1280 : : "operation verification failed\n");
1281 : : status = TEST_FAILED;
1282 : : }
1283 : :
1284 : 1 : error_exit:
1285 [ + - ]: 1 : if (sess != NULL)
1286 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
1287 : :
1288 : 1 : rte_crypto_op_free(op);
1289 : :
1290 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1291 : :
1292 : : return status;
1293 : : }
1294 : :
1295 : : static int
1296 : 1 : test_dh_key_generation(void)
1297 : : {
1298 : : int status;
1299 : :
1300 : 1 : debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1301 : 1 : debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1302 : 1 : debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1303 : : dh_test_params.priv_key.length);
1304 : :
1305 : 1 : RTE_LOG(INFO, USER1,
1306 : : "Test Public and Private key pair generation\n");
1307 : :
1308 : 1 : status = test_dh_gen_kp(&dh_xform);
1309 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1310 : :
1311 : 1 : RTE_LOG(INFO, USER1,
1312 : : "Test Public Key Generation using pre-defined priv key\n");
1313 : :
1314 : 1 : status = test_dh_gen_pub_key(&dh_xform);
1315 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1316 : :
1317 : 1 : RTE_LOG(INFO, USER1,
1318 : : "Test Private Key Generation only\n");
1319 : :
1320 : 1 : status = test_dh_gen_priv_key(&dh_xform);
1321 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1322 : :
1323 : 1 : RTE_LOG(INFO, USER1,
1324 : : "Test shared secret compute\n");
1325 : :
1326 : 1 : status = test_dh_gen_shared_sec(&dh_xform);
1327 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "Test failed");
1328 : :
1329 : : return status;
1330 : : }
1331 : :
1332 : : static int
1333 : 1 : test_dsa_sign(struct rte_crypto_dsa_op_param *dsa_op)
1334 : : {
1335 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1336 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1337 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1338 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
1339 : : struct rte_crypto_asym_op *asym_op = NULL;
1340 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
1341 : 1 : void *sess = NULL;
1342 : : int status = TEST_SUCCESS;
1343 : : int ret;
1344 : :
1345 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
1346 [ - + ]: 1 : if (ret < 0) {
1347 : 0 : RTE_LOG(ERR, USER1,
1348 : : "line %u FAILED: %s", __LINE__,
1349 : : "Session creation failed");
1350 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1351 : 0 : goto error_exit;
1352 : : }
1353 : : /* set up crypto op data structure */
1354 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1355 [ - + ]: 1 : if (!op) {
1356 : 0 : RTE_LOG(ERR, USER1,
1357 : : "line %u FAILED: %s",
1358 : : __LINE__, "Failed to allocate asymmetric crypto "
1359 : : "operation struct");
1360 : : status = TEST_FAILED;
1361 : 0 : goto error_exit;
1362 : : }
1363 : : asym_op = op->asym;
1364 : 1 : asym_op->dsa = *dsa_op;
1365 : :
1366 : 1 : debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1367 : : dsa_xform.dsa.p.length);
1368 : 1 : debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1369 : : dsa_xform.dsa.q.length);
1370 : 1 : debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1371 : : dsa_xform.dsa.g.length);
1372 : 1 : debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1373 : : dsa_xform.dsa.x.length);
1374 : :
1375 : : /* attach asymmetric crypto session to crypto operations */
1376 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
1377 : 1 : asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1378 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1379 : :
1380 : : /* Process crypto operation */
1381 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1382 : 0 : RTE_LOG(ERR, USER1,
1383 : : "line %u FAILED: %s",
1384 : : __LINE__, "Error sending packet for operation");
1385 : : status = TEST_FAILED;
1386 : 0 : goto error_exit;
1387 : : }
1388 : :
1389 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1390 : : rte_pause();
1391 : :
1392 [ - + ]: 1 : if (result_op == NULL) {
1393 : 0 : RTE_LOG(ERR, USER1,
1394 : : "line %u FAILED: %s",
1395 : : __LINE__, "Failed to process asym crypto op");
1396 : : status = TEST_FAILED;
1397 : 0 : goto error_exit;
1398 : : }
1399 : :
1400 : : asym_op = result_op->asym;
1401 : 1 : dsa_op->r.length = asym_op->dsa.r.length;
1402 : 1 : dsa_op->s.length = asym_op->dsa.s.length;
1403 : :
1404 : 1 : debug_hexdump(stdout, "r:",
1405 : 1 : asym_op->dsa.r.data, asym_op->dsa.r.length);
1406 : 1 : debug_hexdump(stdout, "s:",
1407 : 1 : asym_op->dsa.s.data, asym_op->dsa.s.length);
1408 : 1 : error_exit:
1409 [ + - ]: 1 : if (sess != NULL)
1410 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
1411 : 1 : rte_crypto_op_free(op);
1412 : 1 : return status;
1413 : : }
1414 : :
1415 : : static int
1416 : 1 : test_dsa_verify(struct rte_crypto_dsa_op_param *dsa_op)
1417 : : {
1418 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1419 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1420 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1421 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
1422 : : struct rte_crypto_asym_op *asym_op = NULL;
1423 : 1 : struct rte_crypto_op *op = NULL, *result_op = NULL;
1424 : 1 : void *sess = NULL;
1425 : : int status = TEST_SUCCESS;
1426 : : int ret;
1427 : :
1428 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
1429 [ - + ]: 1 : if (ret < 0) {
1430 : 0 : RTE_LOG(ERR, USER1,
1431 : : "line %u FAILED: %s", __LINE__,
1432 : : "Session creation failed");
1433 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1434 : 0 : goto error_exit;
1435 : : }
1436 : : /* set up crypto op data structure */
1437 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1438 [ - + ]: 1 : if (!op) {
1439 : 0 : RTE_LOG(ERR, USER1,
1440 : : "line %u FAILED: %s",
1441 : : __LINE__, "Failed to allocate asymmetric crypto "
1442 : : "operation struct");
1443 : : status = TEST_FAILED;
1444 : 0 : goto error_exit;
1445 : : }
1446 : : asym_op = op->asym;
1447 : 1 : asym_op->dsa = *dsa_op;
1448 : :
1449 : 1 : debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1450 : : dsa_xform.dsa.p.length);
1451 : 1 : debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1452 : : dsa_xform.dsa.q.length);
1453 : 1 : debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1454 : : dsa_xform.dsa.g.length);
1455 : :
1456 : : /* attach asymmetric crypto session to crypto operations */
1457 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
1458 : :
1459 : 1 : debug_hexdump(stdout, "r:",
1460 : 1 : asym_op->dsa.r.data, asym_op->dsa.r.length);
1461 : 1 : debug_hexdump(stdout, "s:",
1462 : 1 : asym_op->dsa.s.data, asym_op->dsa.s.length);
1463 : :
1464 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM verify operation");
1465 : : /* Test PMD DSA sign verification using signer public key */
1466 : 1 : asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1467 : :
1468 : : /* copy signer public key */
1469 : 1 : asym_op->dsa.y.data = dsa_test_params.y.data;
1470 : 1 : asym_op->dsa.y.length = dsa_test_params.y.length;
1471 : :
1472 : : /* Process crypto operation */
1473 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1474 : 0 : RTE_LOG(ERR, USER1,
1475 : : "line %u FAILED: %s",
1476 : : __LINE__, "Error sending packet for operation");
1477 : : status = TEST_FAILED;
1478 : 0 : goto error_exit;
1479 : : }
1480 : :
1481 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1482 : : rte_pause();
1483 : :
1484 [ - + ]: 1 : if (result_op == NULL) {
1485 : 0 : RTE_LOG(ERR, USER1,
1486 : : "line %u FAILED: %s",
1487 : : __LINE__, "Failed to process asym crypto op");
1488 : : status = TEST_FAILED;
1489 : 0 : goto error_exit;
1490 : : }
1491 : :
1492 [ + - ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1493 : 0 : RTE_LOG(ERR, USER1,
1494 : : "line %u FAILED: %s",
1495 : : __LINE__, "Failed to process asym crypto op");
1496 : : status = TEST_FAILED;
1497 : : }
1498 : 1 : error_exit:
1499 [ + - ]: 1 : if (sess != NULL)
1500 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
1501 : 1 : rte_crypto_op_free(op);
1502 : 1 : return status;
1503 : : }
1504 : :
1505 : : static int
1506 : 1 : test_dsa(void)
1507 : : {
1508 : : int status;
1509 : : uint8_t r[TEST_DH_MOD_LEN];
1510 : : uint8_t s[TEST_DH_MOD_LEN];
1511 : : struct rte_crypto_dsa_op_param dsa_op;
1512 : 1 : uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1513 : :
1514 : 1 : dsa_op.message.data = dgst;
1515 : 1 : dsa_op.message.length = sizeof(dgst);
1516 : 1 : dsa_op.r.data = r;
1517 : 1 : dsa_op.s.data = s;
1518 : 1 : dsa_op.r.length = sizeof(r);
1519 : 1 : dsa_op.s.length = sizeof(s);
1520 : :
1521 : 1 : status = test_dsa_sign(&dsa_op);
1522 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "DSA sign test failed");
1523 : 1 : status = test_dsa_verify(&dsa_op);
1524 [ - + ]: 1 : TEST_ASSERT_EQUAL(status, 0, "DSA verify test failed");
1525 : : return status;
1526 : : }
1527 : :
1528 : : static int
1529 : 0 : test_ecdsa_sign_verify(enum curve curve_id)
1530 : : {
1531 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1532 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1533 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1534 : : struct crypto_testsuite_ecdsa_params input_params;
1535 : 0 : void *sess = NULL;
1536 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
1537 : 0 : struct rte_crypto_op *result_op = NULL;
1538 : : uint8_t output_buf_r[TEST_DATA_SIZE];
1539 : : uint8_t output_buf_s[TEST_DATA_SIZE];
1540 : : struct rte_crypto_asym_xform xform;
1541 : : struct rte_crypto_asym_op *asym_op;
1542 : : struct rte_cryptodev_info dev_info;
1543 : 0 : struct rte_crypto_op *op = NULL;
1544 : : int ret, status = TEST_SUCCESS;
1545 : :
1546 [ # # # # : 0 : switch (curve_id) {
# # # ]
1547 : 0 : case SECP192R1:
1548 : 0 : input_params = ecdsa_param_secp192r1;
1549 : 0 : break;
1550 : 0 : case SECP224R1:
1551 : 0 : input_params = ecdsa_param_secp224r1;
1552 : 0 : break;
1553 : 0 : case SECP256R1:
1554 : 0 : input_params = ecdsa_param_secp256r1;
1555 : 0 : break;
1556 : 0 : case SECP384R1:
1557 : 0 : input_params = ecdsa_param_secp384r1;
1558 : 0 : break;
1559 : 0 : case SECP521R1:
1560 : 0 : input_params = ecdsa_param_secp521r1;
1561 : 0 : break;
1562 : 0 : case SECP521R1_UA:
1563 : 0 : input_params = ecdsa_param_secp521r1_ua;
1564 : 0 : break;
1565 : 0 : default:
1566 : 0 : RTE_LOG(ERR, USER1,
1567 : : "line %u FAILED: %s", __LINE__,
1568 : : "Unsupported curve id\n");
1569 : : status = TEST_FAILED;
1570 : 0 : goto exit;
1571 : : }
1572 : :
1573 : 0 : rte_cryptodev_info_get(dev_id, &dev_info);
1574 : :
1575 : : /* Setup crypto op data structure */
1576 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1577 [ # # ]: 0 : if (op == NULL) {
1578 : 0 : RTE_LOG(ERR, USER1,
1579 : : "line %u FAILED: %s", __LINE__,
1580 : : "Failed to allocate asymmetric crypto "
1581 : : "operation struct\n");
1582 : : status = TEST_FAILED;
1583 : 0 : goto exit;
1584 : : }
1585 : : asym_op = op->asym;
1586 : :
1587 : : /* Setup asym xform */
1588 : 0 : xform.next = NULL;
1589 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
1590 : 0 : xform.ec.curve_id = input_params.curve;
1591 : 0 : xform.ec.pkey.data = input_params.pkey.data;
1592 : 0 : xform.ec.pkey.length = input_params.pkey.length;
1593 : 0 : xform.ec.q.x.data = input_params.pubkey_qx.data;
1594 : 0 : xform.ec.q.x.length = input_params.pubkey_qx.length;
1595 : 0 : xform.ec.q.y.data = input_params.pubkey_qy.data;
1596 : 0 : xform.ec.q.y.length = input_params.pubkey_qy.length;
1597 : :
1598 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1599 [ # # ]: 0 : if (ret < 0) {
1600 : 0 : RTE_LOG(ERR, USER1,
1601 : : "line %u FAILED: %s", __LINE__,
1602 : : "Session creation failed\n");
1603 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1604 : 0 : goto exit;
1605 : : }
1606 : :
1607 : : /* Attach asymmetric crypto session to crypto operations */
1608 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
1609 : :
1610 : : /* Compute sign */
1611 : :
1612 : : /* Populate op with operational details */
1613 : 0 : op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1614 : 0 : op->asym->ecdsa.message.data = input_params.digest.data;
1615 : 0 : op->asym->ecdsa.message.length = input_params.digest.length;
1616 : 0 : op->asym->ecdsa.k.data = input_params.scalar.data;
1617 : 0 : op->asym->ecdsa.k.length = input_params.scalar.length;
1618 : :
1619 : : /* Init out buf */
1620 : 0 : op->asym->ecdsa.r.data = output_buf_r;
1621 : 0 : op->asym->ecdsa.s.data = output_buf_s;
1622 : :
1623 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1624 : :
1625 : : /* Process crypto operation */
1626 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1627 : 0 : RTE_LOG(ERR, USER1,
1628 : : "line %u FAILED: %s", __LINE__,
1629 : : "Error sending packet for operation\n");
1630 : : status = TEST_FAILED;
1631 : 0 : goto exit;
1632 : : }
1633 : :
1634 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1635 : : rte_pause();
1636 : :
1637 [ # # ]: 0 : if (result_op == NULL) {
1638 : 0 : RTE_LOG(ERR, USER1,
1639 : : "line %u FAILED: %s", __LINE__,
1640 : : "Failed to process asym crypto op\n");
1641 : : status = TEST_FAILED;
1642 : 0 : goto exit;
1643 : : }
1644 : :
1645 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1646 : 0 : RTE_LOG(ERR, USER1,
1647 : : "line %u FAILED: %s", __LINE__,
1648 : : "Failed to process asym crypto op\n");
1649 : : status = TEST_FAILED;
1650 : 0 : goto exit;
1651 : : }
1652 : :
1653 : : asym_op = result_op->asym;
1654 : :
1655 : 0 : debug_hexdump(stdout, "r:",
1656 : 0 : asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
1657 : 0 : debug_hexdump(stdout, "s:",
1658 : 0 : asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
1659 : :
1660 : 0 : ret = verify_ecdsa_sign(input_params.sign_r.data,
1661 : : input_params.sign_s.data, result_op);
1662 [ # # ]: 0 : if (ret) {
1663 : : status = TEST_FAILED;
1664 : 0 : RTE_LOG(ERR, USER1,
1665 : : "line %u FAILED: %s", __LINE__,
1666 : : "ECDSA sign failed.\n");
1667 : 0 : goto exit;
1668 : : }
1669 : :
1670 : : /* Verify sign */
1671 : :
1672 : : /* Populate op with operational details */
1673 : 0 : op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1674 : 0 : op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
1675 : 0 : op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
1676 : 0 : op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
1677 : 0 : op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
1678 : :
1679 : : /* Enqueue sign result for verify */
1680 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1681 : : status = TEST_FAILED;
1682 : 0 : RTE_LOG(ERR, USER1,
1683 : : "line %u FAILED: %s", __LINE__,
1684 : : "Error sending packet for operation\n");
1685 : 0 : goto exit;
1686 : : }
1687 : :
1688 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1689 : : rte_pause();
1690 : :
1691 [ # # ]: 0 : if (result_op == NULL) {
1692 : : status = TEST_FAILED;
1693 : 0 : goto exit;
1694 : : }
1695 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1696 : : status = TEST_FAILED;
1697 : 0 : RTE_LOG(ERR, USER1,
1698 : : "line %u FAILED: %s", __LINE__,
1699 : : "ECDSA verify failed.\n");
1700 : 0 : goto exit;
1701 : : }
1702 : :
1703 : 0 : exit:
1704 [ # # ]: 0 : if (sess != NULL)
1705 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
1706 : 0 : rte_crypto_op_free(op);
1707 : 0 : return status;
1708 : : };
1709 : :
1710 : : static int
1711 : 0 : test_ecdsa_sign_verify_all_curve(void)
1712 : : {
1713 : : int status, overall_status = TEST_SUCCESS;
1714 : : enum curve curve_id;
1715 : : int test_index = 0;
1716 : : const char *msg;
1717 : :
1718 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
1719 : 0 : if (curve_id == ED25519 || curve_id == ED448 ||
1720 [ # # # # ]: 0 : curve_id == ECGROUP19 || curve_id == ECGROUP20 ||
1721 : : curve_id == ECGROUP21)
1722 : 0 : continue;
1723 : :
1724 : 0 : status = test_ecdsa_sign_verify(curve_id);
1725 [ # # ]: 0 : if (status == TEST_SUCCESS) {
1726 : : msg = "succeeded";
1727 [ # # ]: 0 : } else if (status == TEST_SKIPPED) {
1728 : : msg = "skipped";
1729 : : } else {
1730 : : msg = "failed";
1731 : : overall_status = status;
1732 : : }
1733 : 0 : printf(" %u) TestCase Sign/Veriy Curve %s %s\n",
1734 : : test_index ++, curve[curve_id], msg);
1735 : : }
1736 : 0 : return overall_status;
1737 : : }
1738 : :
1739 : : static int
1740 : 0 : test_ecdsa_sign_verify_qat_curves(void)
1741 : : {
1742 : : int status, overall_status = TEST_SUCCESS;
1743 : : enum curve curve_id;
1744 : : int test_index = 0;
1745 : : const char *msg;
1746 : :
1747 [ # # ]: 0 : for (curve_id = SECP256R1; curve_id <= SECP521R1; curve_id++) {
1748 : :
1749 : 0 : status = test_ecdsa_sign_verify(curve_id);
1750 [ # # ]: 0 : if (status == TEST_SUCCESS) {
1751 : : msg = "succeeded";
1752 : : } else {
1753 : : msg = "failed";
1754 : : overall_status = status;
1755 : : }
1756 : 0 : printf(" %u) TestCase Sign/Veriy Curve %s %s\n",
1757 : : test_index ++, curve[curve_id], msg);
1758 : : }
1759 : 0 : return overall_status;
1760 : : }
1761 : :
1762 : : static int
1763 : 0 : test_ecpm(enum curve curve_id)
1764 : : {
1765 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1766 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1767 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1768 : : struct crypto_testsuite_ecpm_params input_params;
1769 : 0 : void *sess = NULL;
1770 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
1771 : 0 : struct rte_crypto_op *result_op = NULL;
1772 : : uint8_t output_buf_x[TEST_DATA_SIZE];
1773 : : uint8_t output_buf_y[TEST_DATA_SIZE];
1774 : : struct rte_crypto_asym_xform xform;
1775 : : struct rte_crypto_asym_op *asym_op;
1776 : : struct rte_cryptodev_info dev_info;
1777 : 0 : struct rte_crypto_op *op = NULL;
1778 : : int ret, status = TEST_SUCCESS;
1779 : :
1780 [ # # # # : 0 : switch (curve_id) {
# # ]
1781 : 0 : case SECP192R1:
1782 : 0 : input_params = ecpm_param_secp192r1;
1783 : 0 : break;
1784 : 0 : case SECP224R1:
1785 : 0 : input_params = ecpm_param_secp224r1;
1786 : 0 : break;
1787 : 0 : case SECP256R1:
1788 : 0 : input_params = ecpm_param_secp256r1;
1789 : 0 : break;
1790 : 0 : case SECP384R1:
1791 : 0 : input_params = ecpm_param_secp384r1;
1792 : 0 : break;
1793 : 0 : case SECP521R1:
1794 : 0 : input_params = ecpm_param_secp521r1;
1795 : 0 : break;
1796 : 0 : default:
1797 : 0 : RTE_LOG(ERR, USER1,
1798 : : "line %u FAILED: %s", __LINE__,
1799 : : "Unsupported curve id\n");
1800 : : status = TEST_FAILED;
1801 : 0 : goto exit;
1802 : : }
1803 : :
1804 : 0 : rte_cryptodev_info_get(dev_id, &dev_info);
1805 : :
1806 : : /* Setup crypto op data structure */
1807 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1808 [ # # ]: 0 : if (op == NULL) {
1809 : 0 : RTE_LOG(ERR, USER1,
1810 : : "line %u FAILED: %s", __LINE__,
1811 : : "Failed to allocate asymmetric crypto "
1812 : : "operation struct\n");
1813 : : status = TEST_FAILED;
1814 : 0 : goto exit;
1815 : : }
1816 : : asym_op = op->asym;
1817 : :
1818 : : /* Setup asym xform */
1819 : : memset(&xform, 0, sizeof(xform));
1820 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
1821 : 0 : xform.ec.curve_id = input_params.curve;
1822 : :
1823 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1824 [ # # ]: 0 : if (ret < 0) {
1825 : 0 : RTE_LOG(ERR, USER1,
1826 : : "line %u FAILED: %s", __LINE__,
1827 : : "Session creation failed\n");
1828 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1829 : 0 : goto exit;
1830 : : }
1831 : :
1832 : : /* Attach asymmetric crypto session to crypto operations */
1833 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
1834 : :
1835 : : /* Populate op with operational details */
1836 : 0 : op->asym->ecpm.p.x.data = input_params.gen_x.data;
1837 : 0 : op->asym->ecpm.p.x.length = input_params.gen_x.length;
1838 : 0 : op->asym->ecpm.p.y.data = input_params.gen_y.data;
1839 : 0 : op->asym->ecpm.p.y.length = input_params.gen_y.length;
1840 : 0 : op->asym->ecpm.scalar.data = input_params.privkey.data;
1841 : 0 : op->asym->ecpm.scalar.length = input_params.privkey.length;
1842 : :
1843 : : /* Init out buf */
1844 : 0 : op->asym->ecpm.r.x.data = output_buf_x;
1845 : 0 : op->asym->ecpm.r.y.data = output_buf_y;
1846 : :
1847 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1848 : :
1849 : : /* Process crypto operation */
1850 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1851 : 0 : RTE_LOG(ERR, USER1,
1852 : : "line %u FAILED: %s", __LINE__,
1853 : : "Error sending packet for operation\n");
1854 : : status = TEST_FAILED;
1855 : 0 : goto exit;
1856 : : }
1857 : :
1858 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1859 : : rte_pause();
1860 : :
1861 [ # # ]: 0 : if (result_op == NULL) {
1862 : 0 : RTE_LOG(ERR, USER1,
1863 : : "line %u FAILED: %s", __LINE__,
1864 : : "Failed to process asym crypto op\n");
1865 : : status = TEST_FAILED;
1866 : 0 : goto exit;
1867 : : }
1868 : :
1869 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1870 : 0 : RTE_LOG(ERR, USER1,
1871 : : "line %u FAILED: %s", __LINE__,
1872 : : "Failed to process asym crypto op\n");
1873 : : status = TEST_FAILED;
1874 : 0 : goto exit;
1875 : : }
1876 : :
1877 : : asym_op = result_op->asym;
1878 : :
1879 : 0 : debug_hexdump(stdout, "r x:",
1880 : 0 : asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
1881 : 0 : debug_hexdump(stdout, "r y:",
1882 : 0 : asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
1883 : :
1884 : 0 : ret = verify_ecpm(input_params.pubkey_x.data,
1885 : : input_params.pubkey_y.data, result_op);
1886 [ # # ]: 0 : if (ret) {
1887 : : status = TEST_FAILED;
1888 : 0 : RTE_LOG(ERR, USER1,
1889 : : "line %u FAILED: %s", __LINE__,
1890 : : "EC Point Multiplication failed.\n");
1891 : 0 : goto exit;
1892 : : }
1893 : :
1894 : 0 : exit:
1895 [ # # ]: 0 : if (sess != NULL)
1896 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
1897 : 0 : rte_crypto_op_free(op);
1898 : 0 : return status;
1899 : : }
1900 : :
1901 : : static int
1902 : 0 : test_ecpm_all_curve(void)
1903 : : {
1904 : : int status, overall_status = TEST_SUCCESS;
1905 : : enum curve curve_id;
1906 : : int test_index = 0;
1907 : : const char *msg;
1908 : :
1909 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
1910 : 0 : if (curve_id == SECP521R1_UA || curve_id == ECGROUP19 ||
1911 : : curve_id == ECGROUP20 || curve_id == ECGROUP21 ||
1912 [ # # ]: 0 : curve_id == ED25519 || curve_id == ED448)
1913 : 0 : continue;
1914 : :
1915 : 0 : status = test_ecpm(curve_id);
1916 [ # # ]: 0 : if (status == TEST_SUCCESS) {
1917 : : msg = "succeeded";
1918 [ # # ]: 0 : } else if (status == TEST_SKIPPED) {
1919 : : msg = "skipped";
1920 : : } else {
1921 : : msg = "failed";
1922 : : overall_status = status;
1923 : : }
1924 : 0 : printf(" %u) TestCase EC Point Mul Curve %s %s\n",
1925 : : test_index ++, curve[curve_id], msg);
1926 : : }
1927 : 0 : return overall_status;
1928 : : }
1929 : :
1930 : : static int
1931 : 0 : test_ecpm_qat_curves(void)
1932 : : {
1933 : : int status, overall_status = TEST_SUCCESS;
1934 : : enum curve curve_id;
1935 : : int test_index = 0;
1936 : : const char *msg;
1937 : :
1938 [ # # ]: 0 : for (curve_id = SECP256R1; curve_id <= SECP521R1; curve_id++) {
1939 : 0 : status = test_ecpm(curve_id);
1940 [ # # ]: 0 : if (status == TEST_SUCCESS) {
1941 : : msg = "succeeded";
1942 : : } else {
1943 : : msg = "failed";
1944 : : overall_status = status;
1945 : : }
1946 : 0 : printf(" %u) TestCase EC Point Mul Curve %s %s\n",
1947 : : test_index ++, curve[curve_id], msg);
1948 : : }
1949 : 0 : return overall_status;
1950 : : }
1951 : :
1952 : : static int
1953 : 0 : test_ecdh_priv_key_generate(enum curve curve_id)
1954 : : {
1955 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1956 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
1957 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
1958 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
1959 : : struct rte_cryptodev_asym_capability_idx idx;
1960 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
1961 : 0 : struct rte_crypto_asym_xform xform = {0};
1962 : 0 : struct rte_crypto_op *result_op = NULL;
1963 : : uint8_t output_buf[TEST_DATA_SIZE];
1964 : : struct rte_crypto_asym_op *asym_op;
1965 : 0 : struct rte_crypto_op *op = NULL;
1966 : : int ret, status = TEST_SUCCESS;
1967 : : uint16_t output_buflen = 0;
1968 : 0 : void *sess = NULL;
1969 : : int curve;
1970 : :
1971 : : /* Check ECDH capability */
1972 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
1973 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
1974 [ # # ]: 0 : if (capa == NULL)
1975 : : return TEST_SKIPPED;
1976 : :
1977 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE)))
1978 : : return TEST_SKIPPED;
1979 : :
1980 : : switch (curve_id) {
1981 : : case SECP192R1:
1982 : : curve = RTE_CRYPTO_EC_GROUP_SECP192R1;
1983 : : output_buflen = 24;
1984 : : break;
1985 : : case SECP224R1:
1986 : : curve = RTE_CRYPTO_EC_GROUP_SECP224R1;
1987 : : output_buflen = 28;
1988 : : break;
1989 : : case SECP256R1:
1990 : : curve = RTE_CRYPTO_EC_GROUP_SECP256R1;
1991 : : output_buflen = 32;
1992 : : break;
1993 : : case SECP384R1:
1994 : : curve = RTE_CRYPTO_EC_GROUP_SECP384R1;
1995 : : output_buflen = 48;
1996 : : break;
1997 : : case SECP521R1:
1998 : : curve = RTE_CRYPTO_EC_GROUP_SECP521R1;
1999 : : output_buflen = 66;
2000 : : break;
2001 : 0 : default:
2002 : 0 : RTE_LOG(ERR, USER1,
2003 : : "line %u FAILED: %s", __LINE__,
2004 : : "Unsupported curve id\n");
2005 : : status = TEST_FAILED;
2006 : 0 : goto exit;
2007 : : }
2008 : :
2009 : : /* Setup crypto op data structure */
2010 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2011 [ # # ]: 0 : if (op == NULL) {
2012 : 0 : RTE_LOG(ERR, USER1,
2013 : : "line %u FAILED: %s", __LINE__,
2014 : : "Failed to allocate asymmetric crypto "
2015 : : "operation struct\n");
2016 : : status = TEST_FAILED;
2017 : 0 : goto exit;
2018 : : }
2019 : : asym_op = op->asym;
2020 : :
2021 : : /* Setup asym xform */
2022 : 0 : xform.next = NULL;
2023 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2024 : 0 : xform.ec.curve_id = curve;
2025 : :
2026 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2027 [ # # ]: 0 : if (ret < 0) {
2028 : 0 : RTE_LOG(ERR, USER1,
2029 : : "line %u FAILED: %s", __LINE__,
2030 : : "Session creation failed\n");
2031 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2032 : 0 : goto exit;
2033 : : }
2034 : :
2035 : : /* Attach asymmetric crypto session to crypto operations */
2036 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
2037 : :
2038 : : /* Populate op with operational details */
2039 : 0 : asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE;
2040 : :
2041 : : /* Init out buf */
2042 : 0 : asym_op->ecdh.priv_key.data = output_buf;
2043 : 0 : asym_op->ecdh.priv_key.length = output_buflen;
2044 : :
2045 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2046 : :
2047 : : /* Process crypto operation */
2048 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2049 : 0 : RTE_LOG(ERR, USER1,
2050 : : "line %u FAILED: %s", __LINE__,
2051 : : "Error sending packet for operation\n");
2052 : : status = TEST_FAILED;
2053 : 0 : goto exit;
2054 : : }
2055 : :
2056 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2057 : : rte_pause();
2058 : :
2059 [ # # ]: 0 : if (result_op == NULL) {
2060 : 0 : RTE_LOG(ERR, USER1,
2061 : : "line %u FAILED: %s", __LINE__,
2062 : : "Failed to process asym crypto op\n");
2063 : : status = TEST_FAILED;
2064 : 0 : goto exit;
2065 : : }
2066 : :
2067 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2068 : 0 : RTE_LOG(ERR, USER1,
2069 : : "line %u FAILED: %s", __LINE__,
2070 : : "Failed to process asym crypto op\n");
2071 : : status = TEST_FAILED;
2072 : 0 : goto exit;
2073 : : }
2074 : :
2075 : : asym_op = result_op->asym;
2076 : :
2077 : 0 : debug_hexdump(stdout, "priv_key:",
2078 : 0 : asym_op->ecdh.priv_key.data, asym_op->ecdh.priv_key.length);
2079 : :
2080 : 0 : exit:
2081 [ # # ]: 0 : if (sess != NULL)
2082 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
2083 : 0 : rte_crypto_op_free(op);
2084 : 0 : return status;
2085 : : }
2086 : :
2087 : : static int
2088 : 0 : test_ecdh_pub_key_generate(enum curve curve_id)
2089 : : {
2090 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2091 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
2092 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
2093 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
2094 : : struct crypto_testsuite_ecdh_params input_params;
2095 : : struct rte_cryptodev_asym_capability_idx idx;
2096 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
2097 : 0 : struct rte_crypto_asym_xform xform = {0};
2098 : 0 : struct rte_crypto_op *result_op = NULL;
2099 : : uint8_t output_buf_x[TEST_DATA_SIZE];
2100 : : uint8_t output_buf_y[TEST_DATA_SIZE];
2101 : : struct rte_crypto_asym_op *asym_op;
2102 : 0 : struct rte_crypto_op *op = NULL;
2103 : : int ret, status = TEST_SUCCESS;
2104 : 0 : void *sess = NULL;
2105 : :
2106 : : /* Check ECDH capability */
2107 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2108 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2109 [ # # ]: 0 : if (capa == NULL)
2110 : : return TEST_SKIPPED;
2111 : :
2112 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE)))
2113 : : return TEST_SKIPPED;
2114 : :
2115 [ # # ]: 0 : if (curve_id == ED25519 || curve_id == ED448) {
2116 : : /* Check EdDSA capability */
2117 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
2118 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2119 [ # # ]: 0 : if (capa == NULL)
2120 : : return TEST_SKIPPED;
2121 : : }
2122 : :
2123 [ # # # # : 0 : switch (curve_id) {
# # # # #
# # ]
2124 : 0 : case SECP192R1:
2125 : 0 : input_params = ecdh_param_secp192r1;
2126 : 0 : break;
2127 : 0 : case SECP224R1:
2128 : 0 : input_params = ecdh_param_secp224r1;
2129 : 0 : break;
2130 : 0 : case SECP256R1:
2131 : 0 : input_params = ecdh_param_secp256r1;
2132 : 0 : break;
2133 : 0 : case SECP384R1:
2134 : 0 : input_params = ecdh_param_secp384r1;
2135 : 0 : break;
2136 : 0 : case SECP521R1:
2137 : 0 : input_params = ecdh_param_secp521r1;
2138 : 0 : break;
2139 : 0 : case ECGROUP19:
2140 : 0 : input_params = ecdh_param_group19;
2141 : 0 : break;
2142 : 0 : case ECGROUP20:
2143 : 0 : input_params = ecdh_param_group20;
2144 : 0 : break;
2145 : 0 : case ECGROUP21:
2146 : 0 : input_params = ecdh_param_group21;
2147 : 0 : break;
2148 : 0 : case ED25519:
2149 : 0 : input_params = ecdh_param_ed25519;
2150 : 0 : break;
2151 : 0 : case ED448:
2152 : 0 : input_params = ecdh_param_ed448;
2153 : 0 : break;
2154 : 0 : default:
2155 : 0 : RTE_LOG(ERR, USER1,
2156 : : "line %u FAILED: %s", __LINE__,
2157 : : "Unsupported curve id\n");
2158 : : status = TEST_FAILED;
2159 : 0 : goto exit;
2160 : : }
2161 : :
2162 : 0 : debug_hexdump(stdout, "pkey:",
2163 : : input_params.pkey_A.data, input_params.pkey_A.length);
2164 : :
2165 : : /* Setup crypto op data structure */
2166 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2167 [ # # ]: 0 : if (op == NULL) {
2168 : 0 : RTE_LOG(ERR, USER1,
2169 : : "line %u FAILED: %s", __LINE__,
2170 : : "Failed to allocate asymmetric crypto "
2171 : : "operation struct\n");
2172 : : status = TEST_FAILED;
2173 : 0 : goto exit;
2174 : : }
2175 : : asym_op = op->asym;
2176 : :
2177 : : /* Setup asym xform */
2178 : 0 : xform.next = NULL;
2179 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2180 : 0 : xform.ec.curve_id = input_params.curve;
2181 : 0 : xform.ec.pkey.data = input_params.pkey_A.data;
2182 : 0 : xform.ec.pkey.length = input_params.pkey_A.length;
2183 : :
2184 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2185 [ # # ]: 0 : if (ret < 0) {
2186 : 0 : RTE_LOG(ERR, USER1,
2187 : : "line %u FAILED: %s", __LINE__,
2188 : : "Session creation failed\n");
2189 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2190 : 0 : goto exit;
2191 : : }
2192 : :
2193 : : /* Attach asymmetric crypto session to crypto operations */
2194 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
2195 : :
2196 : : /* Populate op with operational details */
2197 : 0 : asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
2198 [ # # ]: 0 : if (curve_id == ED25519 || curve_id == ED448)
2199 : 0 : asym_op->flags |= RTE_CRYPTO_ASYM_FLAG_PUB_KEY_COMPRESSED;
2200 : :
2201 : : /* Init out buf */
2202 : 0 : asym_op->ecdh.pub_key.x.data = output_buf_x;
2203 [ # # ]: 0 : if (curve_id == ED25519 || curve_id == ED448)
2204 : 0 : asym_op->ecdh.pub_key.y.data = NULL;
2205 : : else
2206 : 0 : asym_op->ecdh.pub_key.y.data = output_buf_y;
2207 : :
2208 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2209 : :
2210 : : /* Process crypto operation */
2211 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2212 : 0 : RTE_LOG(ERR, USER1,
2213 : : "line %u FAILED: %s", __LINE__,
2214 : : "Error sending packet for operation\n");
2215 : : status = TEST_FAILED;
2216 : 0 : goto exit;
2217 : : }
2218 : :
2219 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2220 : : rte_pause();
2221 : :
2222 [ # # ]: 0 : if (result_op == NULL) {
2223 : 0 : RTE_LOG(ERR, USER1,
2224 : : "line %u FAILED: %s", __LINE__,
2225 : : "Failed to process asym crypto op\n");
2226 : : status = TEST_FAILED;
2227 : 0 : goto exit;
2228 : : }
2229 : :
2230 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2231 : 0 : RTE_LOG(ERR, USER1,
2232 : : "line %u FAILED: %s", __LINE__,
2233 : : "Failed to process asym crypto op\n");
2234 : : status = TEST_FAILED;
2235 : 0 : goto exit;
2236 : : }
2237 : :
2238 : : asym_op = result_op->asym;
2239 : :
2240 : 0 : debug_hexdump(stdout, "qx:",
2241 : 0 : asym_op->ecdh.pub_key.x.data, asym_op->ecdh.pub_key.x.length);
2242 : 0 : debug_hexdump(stdout, "qy:",
2243 : 0 : asym_op->ecdh.pub_key.y.data, asym_op->ecdh.pub_key.y.length);
2244 : :
2245 [ # # ]: 0 : if (curve_id == ED25519 || curve_id == ED448)
2246 : 0 : ret = memcmp(input_params.pubkey_qA_x.data, result_op->asym->ecdh.pub_key.x.data,
2247 : 0 : result_op->asym->ecdh.pub_key.x.length);
2248 : : else
2249 : 0 : ret = verify_ecdh_secret(input_params.pubkey_qA_x.data,
2250 : : input_params.pubkey_qA_y.data, result_op);
2251 : :
2252 [ # # ]: 0 : if (ret) {
2253 : : status = TEST_FAILED;
2254 : 0 : RTE_LOG(ERR, USER1,
2255 : : "line %u FAILED: %s", __LINE__,
2256 : : "ECDH public key generation failed.\n");
2257 : 0 : goto exit;
2258 : : }
2259 : :
2260 : 0 : exit:
2261 [ # # ]: 0 : if (sess != NULL)
2262 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
2263 : 0 : rte_crypto_op_free(op);
2264 : 0 : return status;
2265 : : }
2266 : :
2267 : : static int
2268 : 0 : test_ecdh_pub_key_verify(enum curve curve_id)
2269 : : {
2270 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2271 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
2272 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
2273 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
2274 : : struct crypto_testsuite_ecdh_params input_params;
2275 : : struct rte_cryptodev_asym_capability_idx idx;
2276 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
2277 : 0 : struct rte_crypto_asym_xform xform = {0};
2278 : 0 : struct rte_crypto_op *result_op = NULL;
2279 : : struct rte_crypto_asym_op *asym_op;
2280 : 0 : struct rte_crypto_op *op = NULL;
2281 : : int ret, status = TEST_SUCCESS;
2282 : 0 : void *sess = NULL;
2283 : :
2284 : : /* Check ECDH capability */
2285 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2286 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2287 [ # # ]: 0 : if (capa == NULL)
2288 : : return TEST_SKIPPED;
2289 : :
2290 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY)))
2291 : : return TEST_SKIPPED;
2292 : :
2293 [ # # # # : 0 : switch (curve_id) {
# # # #
# ]
2294 : 0 : case SECP192R1:
2295 : 0 : input_params = ecdh_param_secp192r1;
2296 : 0 : break;
2297 : 0 : case SECP224R1:
2298 : 0 : input_params = ecdh_param_secp224r1;
2299 : 0 : break;
2300 : 0 : case SECP256R1:
2301 : 0 : input_params = ecdh_param_secp256r1;
2302 : 0 : break;
2303 : 0 : case SECP384R1:
2304 : 0 : input_params = ecdh_param_secp384r1;
2305 : 0 : break;
2306 : 0 : case SECP521R1:
2307 : 0 : input_params = ecdh_param_secp521r1;
2308 : 0 : break;
2309 : 0 : case ECGROUP19:
2310 : 0 : input_params = ecdh_param_group19;
2311 : 0 : break;
2312 : 0 : case ECGROUP20:
2313 : 0 : input_params = ecdh_param_group20;
2314 : 0 : break;
2315 : 0 : case ECGROUP21:
2316 : 0 : input_params = ecdh_param_group21;
2317 : 0 : break;
2318 : 0 : default:
2319 : 0 : RTE_LOG(ERR, USER1,
2320 : : "line %u FAILED: %s", __LINE__,
2321 : : "Unsupported curve id\n");
2322 : : status = TEST_FAILED;
2323 : 0 : goto exit;
2324 : : }
2325 : :
2326 : 0 : debug_hexdump(stdout, "qx:",
2327 : : input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length);
2328 : 0 : debug_hexdump(stdout, "qy:",
2329 : : input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length);
2330 : :
2331 : : /* Setup crypto op data structure */
2332 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2333 [ # # ]: 0 : if (op == NULL) {
2334 : 0 : RTE_LOG(ERR, USER1,
2335 : : "line %u FAILED: %s", __LINE__,
2336 : : "Failed to allocate asymmetric crypto "
2337 : : "operation struct\n");
2338 : : status = TEST_FAILED;
2339 : 0 : goto exit;
2340 : : }
2341 : : asym_op = op->asym;
2342 : :
2343 : : /* Setup asym xform */
2344 : 0 : xform.next = NULL;
2345 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2346 : 0 : xform.ec.curve_id = input_params.curve;
2347 : :
2348 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2349 [ # # ]: 0 : if (ret < 0) {
2350 : 0 : RTE_LOG(ERR, USER1,
2351 : : "line %u FAILED: %s", __LINE__,
2352 : : "Session creation failed\n");
2353 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2354 : 0 : goto exit;
2355 : : }
2356 : :
2357 : : /* Attach asymmetric crypto session to crypto operations */
2358 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
2359 : :
2360 : : /* Populate op with operational details */
2361 : 0 : asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY;
2362 : 0 : asym_op->ecdh.pub_key.x.data = input_params.pubkey_qA_x.data;
2363 : 0 : asym_op->ecdh.pub_key.x.length = input_params.pubkey_qA_x.length;
2364 : 0 : asym_op->ecdh.pub_key.y.data = input_params.pubkey_qA_y.data;
2365 : 0 : asym_op->ecdh.pub_key.y.length = input_params.pubkey_qA_y.length;
2366 : :
2367 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2368 : :
2369 : : /* Process crypto operation */
2370 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2371 : 0 : RTE_LOG(ERR, USER1,
2372 : : "line %u FAILED: %s", __LINE__,
2373 : : "Error sending packet for operation\n");
2374 : : status = TEST_FAILED;
2375 : 0 : goto exit;
2376 : : }
2377 : :
2378 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2379 : : rte_pause();
2380 : :
2381 [ # # ]: 0 : if (result_op == NULL) {
2382 : 0 : RTE_LOG(ERR, USER1,
2383 : : "line %u FAILED: %s", __LINE__,
2384 : : "Failed to process asym crypto op\n");
2385 : : status = TEST_FAILED;
2386 : 0 : goto exit;
2387 : : }
2388 : :
2389 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2390 : 0 : RTE_LOG(ERR, USER1,
2391 : : "line %u FAILED: %s", __LINE__,
2392 : : "Failed to process asym crypto op\n");
2393 : : status = TEST_FAILED;
2394 : 0 : goto exit;
2395 : : }
2396 : :
2397 : 0 : exit:
2398 [ # # ]: 0 : if (sess != NULL)
2399 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
2400 : 0 : rte_crypto_op_free(op);
2401 : 0 : return status;
2402 : : }
2403 : :
2404 : : static int
2405 : 0 : test_ecdh_shared_secret(enum curve curve_id)
2406 : : {
2407 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2408 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
2409 : 0 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
2410 : 0 : struct rte_mempool *op_mpool = ts_params->op_mpool;
2411 : : struct crypto_testsuite_ecdh_params input_params;
2412 : : struct rte_cryptodev_asym_capability_idx idx;
2413 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
2414 : 0 : struct rte_crypto_asym_xform xform = {0};
2415 : 0 : struct rte_crypto_op *result_op = NULL;
2416 : : uint8_t output_buf_x[TEST_DATA_SIZE];
2417 : : uint8_t output_buf_y[TEST_DATA_SIZE];
2418 : : struct rte_crypto_asym_op *asym_op;
2419 : 0 : struct rte_crypto_op *op = NULL;
2420 : : int ret, status = TEST_SUCCESS;
2421 : 0 : void *sess = NULL;
2422 : :
2423 : : /* Check ECDH capability */
2424 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2425 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2426 [ # # ]: 0 : if (capa == NULL)
2427 : : return TEST_SKIPPED;
2428 : :
2429 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE)))
2430 : : return TEST_SKIPPED;
2431 : :
2432 [ # # # # : 0 : switch (curve_id) {
# # # #
# ]
2433 : 0 : case SECP192R1:
2434 : 0 : input_params = ecdh_param_secp192r1;
2435 : 0 : break;
2436 : 0 : case SECP224R1:
2437 : 0 : input_params = ecdh_param_secp224r1;
2438 : 0 : break;
2439 : 0 : case SECP256R1:
2440 : 0 : input_params = ecdh_param_secp256r1;
2441 : 0 : break;
2442 : 0 : case SECP384R1:
2443 : 0 : input_params = ecdh_param_secp384r1;
2444 : 0 : break;
2445 : 0 : case SECP521R1:
2446 : 0 : input_params = ecdh_param_secp521r1;
2447 : 0 : break;
2448 : 0 : case ECGROUP19:
2449 : 0 : input_params = ecdh_param_group19;
2450 : 0 : break;
2451 : 0 : case ECGROUP20:
2452 : 0 : input_params = ecdh_param_group20;
2453 : 0 : break;
2454 : 0 : case ECGROUP21:
2455 : 0 : input_params = ecdh_param_group21;
2456 : 0 : break;
2457 : 0 : default:
2458 : 0 : RTE_LOG(ERR, USER1,
2459 : : "line %u FAILED: %s", __LINE__,
2460 : : "Unsupported curve id\n");
2461 : : status = TEST_FAILED;
2462 : 0 : goto exit;
2463 : : }
2464 : :
2465 : : /* zA = dA.QB */
2466 : 0 : debug_hexdump(stdout, "pkey:",
2467 : : input_params.pkey_A.data, input_params.pkey_A.length);
2468 : 0 : debug_hexdump(stdout, "qx:",
2469 : : input_params.pubkey_qB_x.data, input_params.pubkey_qB_x.length);
2470 : 0 : debug_hexdump(stdout, "qy:",
2471 : : input_params.pubkey_qB_y.data, input_params.pubkey_qB_y.length);
2472 : :
2473 : : /* Setup crypto op data structure */
2474 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2475 [ # # ]: 0 : if (op == NULL) {
2476 : 0 : RTE_LOG(ERR, USER1,
2477 : : "line %u FAILED: %s", __LINE__,
2478 : : "Failed to allocate asymmetric crypto "
2479 : : "operation struct\n");
2480 : : status = TEST_FAILED;
2481 : 0 : goto exit;
2482 : : }
2483 : : asym_op = op->asym;
2484 : :
2485 : : /* Setup asym xform */
2486 : 0 : xform.next = NULL;
2487 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2488 : 0 : xform.ec.curve_id = input_params.curve;
2489 : 0 : xform.ec.pkey.data = input_params.pkey_A.data;
2490 : 0 : xform.ec.pkey.length = input_params.pkey_A.length;
2491 : 0 : xform.ec.q.x.data = input_params.pubkey_qB_x.data;
2492 : 0 : xform.ec.q.x.length = input_params.pubkey_qB_x.length;
2493 : 0 : xform.ec.q.y.data = input_params.pubkey_qB_y.data;
2494 : 0 : xform.ec.q.y.length = input_params.pubkey_qB_y.length;
2495 : :
2496 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2497 [ # # ]: 0 : if (ret < 0) {
2498 : 0 : RTE_LOG(ERR, USER1,
2499 : : "line %u FAILED: %s", __LINE__,
2500 : : "Session creation failed\n");
2501 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2502 : 0 : goto exit;
2503 : : }
2504 : :
2505 : : /* Attach asymmetric crypto session to crypto operations */
2506 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
2507 : :
2508 : : /* Populate op with operational details */
2509 : 0 : asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
2510 : :
2511 : : /* Init out buf */
2512 : 0 : asym_op->ecdh.shared_secret.x.data = output_buf_x;
2513 : 0 : asym_op->ecdh.shared_secret.y.data = output_buf_y;
2514 : :
2515 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2516 : :
2517 : : /* Process crypto operation */
2518 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2519 : 0 : RTE_LOG(ERR, USER1,
2520 : : "line %u FAILED: %s", __LINE__,
2521 : : "Error sending packet for operation\n");
2522 : : status = TEST_FAILED;
2523 : 0 : goto exit;
2524 : : }
2525 : :
2526 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2527 : : rte_pause();
2528 : :
2529 [ # # ]: 0 : if (result_op == NULL) {
2530 : 0 : RTE_LOG(ERR, USER1,
2531 : : "line %u FAILED: %s", __LINE__,
2532 : : "Failed to process asym crypto op\n");
2533 : : status = TEST_FAILED;
2534 : 0 : goto exit;
2535 : : }
2536 : :
2537 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2538 : 0 : RTE_LOG(ERR, USER1,
2539 : : "line %u FAILED: %s", __LINE__,
2540 : : "Failed to process asym crypto op\n");
2541 : : status = TEST_FAILED;
2542 : 0 : goto exit;
2543 : : }
2544 : :
2545 : : asym_op = result_op->asym;
2546 : :
2547 : 0 : debug_hexdump(stdout, "secret_x:",
2548 : 0 : asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length);
2549 : 0 : debug_hexdump(stdout, "secret_y:",
2550 : 0 : asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length);
2551 : :
2552 : 0 : ret = verify_ecdh_secret(input_params.secret_x.data,
2553 : : input_params.secret_y.data, result_op);
2554 [ # # ]: 0 : if (ret) {
2555 : : status = TEST_FAILED;
2556 : 0 : RTE_LOG(ERR, USER1,
2557 : : "line %u FAILED: %s", __LINE__,
2558 : : "ECDH shared secret compute failed.\n");
2559 : 0 : goto exit;
2560 : : }
2561 : :
2562 [ # # ]: 0 : if (sess != NULL)
2563 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
2564 : 0 : rte_crypto_op_free(op);
2565 : :
2566 : : /* zB = dB.QA */
2567 : 0 : debug_hexdump(stdout, "pkey:",
2568 : : input_params.pkey_B.data, input_params.pkey_B.length);
2569 : 0 : debug_hexdump(stdout, "qx:",
2570 : : input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length);
2571 : 0 : debug_hexdump(stdout, "qy:",
2572 : : input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length);
2573 : :
2574 : : /* Setup crypto op data structure */
2575 : 0 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2576 [ # # ]: 0 : if (op == NULL) {
2577 : 0 : RTE_LOG(ERR, USER1,
2578 : : "line %u FAILED: %s", __LINE__,
2579 : : "Failed to allocate asymmetric crypto "
2580 : : "operation struct\n");
2581 : : status = TEST_FAILED;
2582 : 0 : goto exit;
2583 : : }
2584 : : asym_op = op->asym;
2585 : :
2586 : : /* Setup asym xform */
2587 : 0 : xform.next = NULL;
2588 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2589 : 0 : xform.ec.curve_id = input_params.curve;
2590 : 0 : xform.ec.pkey.data = input_params.pkey_B.data;
2591 : 0 : xform.ec.pkey.length = input_params.pkey_B.length;
2592 : 0 : xform.ec.q.x.data = input_params.pubkey_qA_x.data;
2593 : 0 : xform.ec.q.x.length = input_params.pubkey_qA_x.length;
2594 : 0 : xform.ec.q.y.data = input_params.pubkey_qA_y.data;
2595 : 0 : xform.ec.q.y.length = input_params.pubkey_qA_y.length;
2596 : :
2597 : 0 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2598 [ # # ]: 0 : if (ret < 0) {
2599 : 0 : RTE_LOG(ERR, USER1,
2600 : : "line %u FAILED: %s", __LINE__,
2601 : : "Session creation failed\n");
2602 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2603 : 0 : goto exit;
2604 : : }
2605 : :
2606 : : /* Attach asymmetric crypto session to crypto operations */
2607 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
2608 : :
2609 : : /* Populate op with operational details */
2610 : 0 : asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
2611 : :
2612 : : /* Init out buf */
2613 : 0 : asym_op->ecdh.shared_secret.x.data = output_buf_x;
2614 : 0 : asym_op->ecdh.shared_secret.y.data = output_buf_y;
2615 : :
2616 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2617 : :
2618 : : /* Process crypto operation */
2619 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2620 : 0 : RTE_LOG(ERR, USER1,
2621 : : "line %u FAILED: %s", __LINE__,
2622 : : "Error sending packet for operation\n");
2623 : : status = TEST_FAILED;
2624 : 0 : goto exit;
2625 : : }
2626 : :
2627 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2628 : : rte_pause();
2629 : :
2630 [ # # ]: 0 : if (result_op == NULL) {
2631 : 0 : RTE_LOG(ERR, USER1,
2632 : : "line %u FAILED: %s", __LINE__,
2633 : : "Failed to process asym crypto op\n");
2634 : : status = TEST_FAILED;
2635 : 0 : goto exit;
2636 : : }
2637 : :
2638 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2639 : 0 : RTE_LOG(ERR, USER1,
2640 : : "line %u FAILED: %s", __LINE__,
2641 : : "Failed to process asym crypto op\n");
2642 : : status = TEST_FAILED;
2643 : 0 : goto exit;
2644 : : }
2645 : :
2646 : : asym_op = result_op->asym;
2647 : :
2648 : 0 : debug_hexdump(stdout, "secret_x:",
2649 : 0 : asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length);
2650 : 0 : debug_hexdump(stdout, "secret_y:",
2651 : 0 : asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length);
2652 : :
2653 : 0 : ret = verify_ecdh_secret(input_params.secret_x.data,
2654 : : input_params.secret_y.data, result_op);
2655 [ # # ]: 0 : if (ret) {
2656 : : status = TEST_FAILED;
2657 : 0 : RTE_LOG(ERR, USER1,
2658 : : "line %u FAILED: %s", __LINE__,
2659 : : "ECDH shared secret compute failed.\n");
2660 : 0 : goto exit;
2661 : : }
2662 : :
2663 : 0 : exit:
2664 [ # # ]: 0 : if (sess != NULL)
2665 : 0 : rte_cryptodev_asym_session_free(dev_id, sess);
2666 : 0 : rte_crypto_op_free(op);
2667 : 0 : return status;
2668 : : }
2669 : :
2670 : : static int
2671 : 0 : test_ecdh_all_curve(void)
2672 : : {
2673 : : int status, overall_status = TEST_SUCCESS;
2674 : : enum curve curve_id;
2675 : : int test_index = 0;
2676 : : const char *msg;
2677 : :
2678 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2679 : 0 : if (curve_id == SECP521R1_UA || curve_id == ECGROUP19 ||
2680 : : curve_id == ECGROUP20 || curve_id == ECGROUP21 ||
2681 [ # # ]: 0 : curve_id == ED25519 || curve_id == ED448)
2682 : 0 : continue;
2683 : :
2684 : 0 : status = test_ecdh_priv_key_generate(curve_id);
2685 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2686 : : msg = "succeeded";
2687 [ # # ]: 0 : } else if (status == TEST_SKIPPED) {
2688 : : msg = "skipped";
2689 : : } else {
2690 : : msg = "failed";
2691 : : overall_status = status;
2692 : : }
2693 : 0 : printf(" %u) TestCase ECDH private key generation for Curve %s %s\n",
2694 : : test_index ++, curve[curve_id], msg);
2695 : : }
2696 : :
2697 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2698 [ # # ]: 0 : if (curve_id == SECP521R1_UA)
2699 : 0 : continue;
2700 : :
2701 : 0 : status = test_ecdh_pub_key_generate(curve_id);
2702 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2703 : : msg = "succeeded";
2704 [ # # ]: 0 : } else if (status == TEST_SKIPPED) {
2705 : : msg = "skipped";
2706 : : } else {
2707 : : msg = "failed";
2708 : : overall_status = status;
2709 : : }
2710 : 0 : printf(" %u) TestCase ECDH public key generation for Curve %s %s\n",
2711 : : test_index ++, curve[curve_id], msg);
2712 : : }
2713 : :
2714 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2715 [ # # # # ]: 0 : if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
2716 : 0 : continue;
2717 : :
2718 : 0 : status = test_ecdh_pub_key_verify(curve_id);
2719 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2720 : : msg = "succeeded";
2721 [ # # ]: 0 : } else if (status == TEST_SKIPPED) {
2722 : : msg = "skipped";
2723 : : } else {
2724 : : msg = "failed";
2725 : : overall_status = status;
2726 : : }
2727 : 0 : printf(" %u) TestCase ECDH public key verification for Curve %s %s\n",
2728 : : test_index ++, curve[curve_id], msg);
2729 : : }
2730 : :
2731 [ # # ]: 0 : for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2732 [ # # # # ]: 0 : if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
2733 : 0 : continue;
2734 : :
2735 : 0 : status = test_ecdh_shared_secret(curve_id);
2736 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2737 : : msg = "succeeded";
2738 [ # # ]: 0 : } else if (status == TEST_SKIPPED) {
2739 : : msg = "skipped";
2740 : : } else {
2741 : : msg = "failed";
2742 : : overall_status = status;
2743 : : }
2744 : 0 : printf(" %u) TestCase ECDH shared secret compute for Curve %s %s\n",
2745 : : test_index ++, curve[curve_id], msg);
2746 : : }
2747 : :
2748 : 0 : return overall_status;
2749 : : }
2750 : :
2751 : : static int
2752 : 0 : test_ecdh_qat_curves(void)
2753 : : {
2754 : : int status, overall_status = TEST_SUCCESS;
2755 : : enum curve curve_id;
2756 : : int test_index = 0;
2757 : : const char *msg;
2758 : :
2759 [ # # ]: 0 : for (curve_id = SECP256R1; curve_id <= SECP521R1; curve_id++) {
2760 : 0 : status = test_ecdh_pub_key_generate(curve_id);
2761 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2762 : : msg = "succeeded";
2763 [ # # ]: 0 : } else if (status == TEST_SKIPPED) {
2764 : : msg = "skipped";
2765 : : } else {
2766 : : msg = "failed";
2767 : : overall_status = status;
2768 : : }
2769 : 0 : printf(" %u) TestCase ECDH public key generation for Curve %s %s\n",
2770 : : test_index ++, curve[curve_id], msg);
2771 : : }
2772 : :
2773 [ # # ]: 0 : for (curve_id = SECP256R1; curve_id <= SECP521R1; curve_id++) {
2774 : 0 : status = test_ecdh_pub_key_verify(curve_id);
2775 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2776 : : msg = "succeeded";
2777 [ # # ]: 0 : } else if (status == TEST_SKIPPED) {
2778 : : msg = "skipped";
2779 : : } else {
2780 : : msg = "failed";
2781 : : overall_status = status;
2782 : : }
2783 : 0 : printf(" %u) TestCase ECDH public key verification for Curve %s %s\n",
2784 : : test_index ++, curve[curve_id], msg);
2785 : : }
2786 : :
2787 [ # # ]: 0 : for (curve_id = SECP256R1; curve_id <= SECP521R1; curve_id++) {
2788 : 0 : status = test_ecdh_shared_secret(curve_id);
2789 [ # # ]: 0 : if (status == TEST_SUCCESS) {
2790 : : msg = "succeeded";
2791 [ # # ]: 0 : } else if (status == TEST_SKIPPED) {
2792 : : msg = "skipped";
2793 : : } else {
2794 : : msg = "failed";
2795 : : overall_status = status;
2796 : : }
2797 : 0 : printf(" %u) TestCase ECDH shared secret compute for Curve %s %s\n",
2798 : : test_index ++, curve[curve_id], msg);
2799 : : }
2800 : :
2801 : 0 : return overall_status;
2802 : : }
2803 : :
2804 : :
2805 : : static int
2806 : 1 : test_sm2_sign(void)
2807 : : {
2808 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2809 : 1 : struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
2810 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
2811 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
2812 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
2813 : : struct rte_cryptodev_asym_capability_idx idx;
2814 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
2815 : 1 : struct rte_crypto_op *result_op = NULL;
2816 : : uint8_t output_buf_r[TEST_DATA_SIZE];
2817 : : uint8_t output_buf_s[TEST_DATA_SIZE];
2818 : : struct rte_crypto_asym_xform xform;
2819 : : struct rte_crypto_asym_op *asym_op;
2820 : 1 : struct rte_crypto_op *op = NULL;
2821 : : int ret, status = TEST_SUCCESS;
2822 : 1 : void *sess = NULL;
2823 : :
2824 : : /* Check SM2 capability */
2825 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
2826 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2827 [ + - ]: 1 : if (capa == NULL)
2828 : : return -ENOTSUP;
2829 : :
2830 : : /* Setup crypto op data structure */
2831 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2832 [ - + ]: 1 : if (op == NULL) {
2833 : 0 : RTE_LOG(ERR, USER1,
2834 : : "line %u FAILED: %s", __LINE__,
2835 : : "Failed to allocate asymmetric crypto "
2836 : : "operation struct\n");
2837 : : status = TEST_FAILED;
2838 : 0 : goto exit;
2839 : : }
2840 : :
2841 : : asym_op = op->asym;
2842 : :
2843 : : /* Setup asym xform */
2844 : 1 : xform.next = NULL;
2845 : 1 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
2846 : 1 : xform.ec.curve_id = input_params.curve;
2847 : 1 : xform.ec.pkey.data = input_params.pkey.data;
2848 : 1 : xform.ec.pkey.length = input_params.pkey.length;
2849 : 1 : xform.ec.q.x.data = input_params.pubkey_qx.data;
2850 : 1 : xform.ec.q.x.length = input_params.pubkey_qx.length;
2851 : 1 : xform.ec.q.y.data = input_params.pubkey_qy.data;
2852 : 1 : xform.ec.q.y.length = input_params.pubkey_qy.length;
2853 : :
2854 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2855 [ - + ]: 1 : if (ret < 0) {
2856 : 0 : RTE_LOG(ERR, USER1,
2857 : : "line %u FAILED: %s", __LINE__,
2858 : : "Session creation failed\n");
2859 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2860 : 0 : goto exit;
2861 : : }
2862 : :
2863 : : /* Attach asymmetric crypto session to crypto operations */
2864 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
2865 : :
2866 : : /* Compute sign */
2867 : :
2868 : : /* Populate op with operational details */
2869 : 1 : asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
2870 [ + - ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
2871 : : RTE_CRYPTO_ASYM_OP_SIGN, RTE_CRYPTO_SM2_PH))
2872 : 1 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
2873 : : else
2874 : 0 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
2875 : :
2876 [ + - ]: 1 : if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) {
2877 : 1 : asym_op->sm2.message.data = input_params.message.data;
2878 : 1 : asym_op->sm2.message.length = input_params.message.length;
2879 : 1 : asym_op->sm2.id.data = input_params.id.data;
2880 : 1 : asym_op->sm2.id.length = input_params.id.length;
2881 : : } else {
2882 : 0 : asym_op->sm2.message.data = input_params.digest.data;
2883 : 0 : asym_op->sm2.message.length = input_params.digest.length;
2884 : 0 : asym_op->sm2.id.data = NULL;
2885 : 0 : asym_op->sm2.id.length = 0;
2886 : : }
2887 : :
2888 [ + - ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
2889 : : RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
2890 : 1 : asym_op->sm2.k.data = NULL;
2891 : 1 : asym_op->sm2.k.length = 0;
2892 : : } else {
2893 : 0 : asym_op->sm2.k.data = input_params.k.data;
2894 : 0 : asym_op->sm2.k.length = input_params.k.length;
2895 : : }
2896 : :
2897 : : /* Init out buf */
2898 : 1 : asym_op->sm2.r.data = output_buf_r;
2899 : 1 : asym_op->sm2.s.data = output_buf_s;
2900 : :
2901 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2902 : :
2903 : : /* Process crypto operation */
2904 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2905 : 0 : RTE_LOG(ERR, USER1,
2906 : : "line %u FAILED: %s", __LINE__,
2907 : : "Error sending packet for operation\n");
2908 : : status = TEST_FAILED;
2909 : 0 : goto exit;
2910 : : }
2911 : :
2912 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2913 : : rte_pause();
2914 : :
2915 [ - + ]: 1 : if (result_op == NULL) {
2916 : 0 : RTE_LOG(ERR, USER1,
2917 : : "line %u FAILED: %s", __LINE__,
2918 : : "Failed to process asym crypto op\n");
2919 : : status = TEST_FAILED;
2920 : 0 : goto exit;
2921 : : }
2922 : :
2923 [ - + ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2924 : 0 : RTE_LOG(ERR, USER1,
2925 : : "line %u FAILED: %s", __LINE__,
2926 : : "Failed to process asym crypto op\n");
2927 : : status = TEST_FAILED;
2928 : 0 : goto exit;
2929 : : }
2930 : :
2931 : : asym_op = result_op->asym;
2932 : :
2933 : 1 : debug_hexdump(stdout, "r:",
2934 : 1 : asym_op->sm2.r.data, asym_op->sm2.r.length);
2935 : 1 : debug_hexdump(stdout, "s:",
2936 : 1 : asym_op->sm2.s.data, asym_op->sm2.s.length);
2937 : :
2938 [ - + ]: 1 : if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
2939 : : RTE_CRYPTO_ASYM_OP_SIGN, RTE_CRYPTO_SM2_RNG)) {
2940 : : /* Verify sign (by comparison). */
2941 [ # # ]: 0 : if (memcmp(input_params.sign_r.data, asym_op->sm2.r.data,
2942 : : asym_op->sm2.r.length) != 0) {
2943 : : status = TEST_FAILED;
2944 : 0 : RTE_LOG(ERR, USER1,
2945 : : "line %u FAILED: %s", __LINE__,
2946 : : "SM2 sign failed.\n");
2947 : 0 : goto exit;
2948 : : }
2949 [ # # ]: 0 : if (memcmp(input_params.sign_s.data, asym_op->sm2.s.data,
2950 : : asym_op->sm2.s.length) != 0) {
2951 : : status = TEST_FAILED;
2952 : 0 : RTE_LOG(ERR, USER1,
2953 : : "line %u FAILED: %s", __LINE__,
2954 : : "SM2 sign failed.\n");
2955 : 0 : goto exit;
2956 : : }
2957 : : } else {
2958 : : /* Verify sign (in roundtrip).
2959 : : * Due to random number used per message, sign op
2960 : : * would produce different output for same message
2961 : : * every time. Hence, we can't have expected output
2962 : : * to match, instead reverse op to verify.
2963 : : */
2964 : :
2965 : : /* Populate op with operational details */
2966 : 1 : asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
2967 : :
2968 : : /* Enqueue sign result for verify */
2969 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2970 : : status = TEST_FAILED;
2971 : 0 : RTE_LOG(ERR, USER1,
2972 : : "line %u FAILED: %s", __LINE__,
2973 : : "Error sending packet for operation\n");
2974 : 0 : goto exit;
2975 : : }
2976 : :
2977 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2978 : : rte_pause();
2979 : :
2980 [ - + ]: 1 : if (result_op == NULL) {
2981 : : status = TEST_FAILED;
2982 : 0 : goto exit;
2983 : : }
2984 [ + - ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2985 : : status = TEST_FAILED;
2986 : 0 : RTE_LOG(ERR, USER1,
2987 : : "line %u FAILED: %s", __LINE__,
2988 : : "SM2 verify failed.\n");
2989 : 0 : goto exit;
2990 : : }
2991 : : }
2992 : :
2993 : 1 : exit:
2994 [ + - ]: 1 : if (sess != NULL)
2995 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
2996 : 1 : rte_crypto_op_free(op);
2997 : 1 : return status;
2998 : : };
2999 : :
3000 : : static int
3001 : 1 : test_sm2_verify(void)
3002 : : {
3003 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3004 : 1 : struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
3005 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
3006 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
3007 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
3008 : : struct rte_cryptodev_asym_capability_idx idx;
3009 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
3010 : 1 : struct rte_crypto_op *result_op = NULL;
3011 : : struct rte_crypto_asym_xform xform;
3012 : : struct rte_crypto_asym_op *asym_op;
3013 : 1 : struct rte_crypto_op *op = NULL;
3014 : : int ret, status = TEST_SUCCESS;
3015 : 1 : void *sess = NULL;
3016 : :
3017 : : /* Check SM2 capability */
3018 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
3019 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
3020 [ + - ]: 1 : if (capa == NULL)
3021 : : return -ENOTSUP;
3022 : :
3023 : : /* Setup crypto op data structure */
3024 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3025 [ - + ]: 1 : if (op == NULL) {
3026 : 0 : RTE_LOG(ERR, USER1,
3027 : : "line %u FAILED: %s", __LINE__,
3028 : : "Failed to allocate asymmetric crypto "
3029 : : "operation struct\n");
3030 : : status = TEST_FAILED;
3031 : 0 : goto exit;
3032 : : }
3033 : :
3034 : : asym_op = op->asym;
3035 : :
3036 : : /* Setup asym xform */
3037 : 1 : xform.next = NULL;
3038 : 1 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
3039 : 1 : xform.ec.curve_id = input_params.curve;
3040 : 1 : xform.ec.pkey.data = input_params.pkey.data;
3041 : 1 : xform.ec.pkey.length = input_params.pkey.length;
3042 : 1 : xform.ec.q.x.data = input_params.pubkey_qx.data;
3043 : 1 : xform.ec.q.x.length = input_params.pubkey_qx.length;
3044 : 1 : xform.ec.q.y.data = input_params.pubkey_qy.data;
3045 : 1 : xform.ec.q.y.length = input_params.pubkey_qy.length;
3046 : :
3047 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3048 [ - + ]: 1 : if (ret < 0) {
3049 : 0 : RTE_LOG(ERR, USER1,
3050 : : "line %u FAILED: %s", __LINE__,
3051 : : "Session creation failed\n");
3052 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3053 : 0 : goto exit;
3054 : : }
3055 : :
3056 : : /* Attach asymmetric crypto session to crypto operations */
3057 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
3058 : :
3059 : : /* Verify given sign */
3060 : :
3061 : : /* Populate op with operational details */
3062 : 1 : asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
3063 : :
3064 [ + - ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
3065 : : RTE_CRYPTO_ASYM_OP_VERIFY, RTE_CRYPTO_SM2_PH))
3066 : 1 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
3067 : : else
3068 : 0 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
3069 : :
3070 [ + - ]: 1 : if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) {
3071 : 1 : asym_op->sm2.message.data = input_params.message.data;
3072 : 1 : asym_op->sm2.message.length = input_params.message.length;
3073 : 1 : asym_op->sm2.id.data = input_params.id.data;
3074 : 1 : asym_op->sm2.id.length = input_params.id.length;
3075 : : } else {
3076 : 0 : asym_op->sm2.message.data = input_params.digest.data;
3077 : 0 : asym_op->sm2.message.length = input_params.digest.length;
3078 : 0 : asym_op->sm2.id.data = NULL;
3079 : 0 : asym_op->sm2.id.length = 0;
3080 : : }
3081 : :
3082 : 1 : asym_op->sm2.r.data = input_params.sign_r.data;
3083 : 1 : asym_op->sm2.r.length = input_params.sign_r.length;
3084 : 1 : asym_op->sm2.s.data = input_params.sign_s.data;
3085 : 1 : asym_op->sm2.s.length = input_params.sign_s.length;
3086 : :
3087 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3088 : :
3089 : : /* Process crypto operation */
3090 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3091 : 0 : RTE_LOG(ERR, USER1,
3092 : : "line %u FAILED: %s", __LINE__,
3093 : : "Error sending packet for operation\n");
3094 : : status = TEST_FAILED;
3095 : 0 : goto exit;
3096 : : }
3097 : :
3098 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3099 : : rte_pause();
3100 : :
3101 [ - + ]: 1 : if (result_op == NULL) {
3102 : 0 : RTE_LOG(ERR, USER1,
3103 : : "line %u FAILED: %s", __LINE__,
3104 : : "Failed to process asym crypto op\n");
3105 : : status = TEST_FAILED;
3106 : 0 : goto exit;
3107 : : }
3108 : :
3109 [ + - ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3110 : 0 : RTE_LOG(ERR, USER1,
3111 : : "line %u FAILED: %s", __LINE__,
3112 : : "Failed to process asym crypto op\n");
3113 : : status = TEST_FAILED;
3114 : 0 : goto exit;
3115 : : }
3116 : :
3117 : 1 : exit:
3118 [ + - ]: 1 : if (sess != NULL)
3119 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
3120 : 1 : rte_crypto_op_free(op);
3121 : 1 : return status;
3122 : : };
3123 : :
3124 : : static int
3125 : 1 : test_sm2_enc(void)
3126 : : {
3127 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3128 : 1 : struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
3129 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
3130 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
3131 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
3132 : : uint8_t output_buf[TEST_DATA_SIZE], *pbuf = NULL;
3133 : : struct rte_cryptodev_asym_capability_idx idx;
3134 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
3135 : 1 : struct rte_crypto_op *result_op = NULL;
3136 : : struct rte_crypto_asym_xform xform;
3137 : : struct rte_crypto_asym_op *asym_op;
3138 : 1 : struct rte_crypto_op *op = NULL;
3139 : : int ret, status = TEST_SUCCESS;
3140 : 1 : void *sess = NULL;
3141 : :
3142 : : /* Check SM2 capability */
3143 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
3144 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
3145 [ + - ]: 1 : if (capa == NULL)
3146 : : return -ENOTSUP;
3147 [ + - ]: 1 : if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
3148 : : RTE_CRYPTO_ASYM_OP_ENCRYPT, 0))
3149 : : return TEST_SKIPPED;
3150 : :
3151 : : /* Setup crypto op data structure */
3152 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3153 [ - + ]: 1 : if (op == NULL) {
3154 : 0 : RTE_LOG(ERR, USER1,
3155 : : "line %u FAILED: %s", __LINE__,
3156 : : "Failed to allocate asymmetric crypto "
3157 : : "operation struct\n");
3158 : : status = TEST_FAILED;
3159 : 0 : goto exit;
3160 : : }
3161 : : asym_op = op->asym;
3162 : :
3163 : : /* Setup asym xform */
3164 : 1 : xform.next = NULL;
3165 : 1 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
3166 : 1 : xform.ec.curve_id = input_params.curve;
3167 : 1 : xform.ec.pkey.data = input_params.pkey.data;
3168 : 1 : xform.ec.pkey.length = input_params.pkey.length;
3169 : 1 : xform.ec.q.x.data = input_params.pubkey_qx.data;
3170 : 1 : xform.ec.q.x.length = input_params.pubkey_qx.length;
3171 : 1 : xform.ec.q.y.data = input_params.pubkey_qy.data;
3172 : 1 : xform.ec.q.y.length = input_params.pubkey_qy.length;
3173 : :
3174 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3175 [ - + ]: 1 : if (ret < 0) {
3176 : 0 : RTE_LOG(ERR, USER1,
3177 : : "line %u FAILED: %s", __LINE__,
3178 : : "Session creation failed\n");
3179 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3180 : 0 : goto exit;
3181 : : }
3182 : :
3183 : : /* Attach asymmetric crypto session to crypto operations */
3184 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
3185 : :
3186 : : /* Compute encrypt */
3187 : :
3188 : : /* Populate op with operational details */
3189 : 1 : asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
3190 [ - + ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
3191 : : RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_PH))
3192 : 0 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
3193 : : else
3194 : 1 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
3195 : :
3196 : 1 : asym_op->sm2.message.data = input_params.message.data;
3197 : 1 : asym_op->sm2.message.length = input_params.message.length;
3198 : :
3199 [ + - ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
3200 : : RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
3201 : 1 : asym_op->sm2.k.data = NULL;
3202 : 1 : asym_op->sm2.k.length = 0;
3203 : : } else {
3204 : 0 : asym_op->sm2.k.data = input_params.k.data;
3205 : 0 : asym_op->sm2.k.length = input_params.k.length;
3206 : : }
3207 : :
3208 : : /* Init out buf */
3209 : 1 : asym_op->sm2.cipher.data = output_buf;
3210 : :
3211 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3212 : :
3213 : : /* Process crypto operation */
3214 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3215 : 0 : RTE_LOG(ERR, USER1,
3216 : : "line %u FAILED: %s", __LINE__,
3217 : : "Error sending packet for operation\n");
3218 : : status = TEST_FAILED;
3219 : 0 : goto exit;
3220 : : }
3221 : :
3222 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3223 : : rte_pause();
3224 : :
3225 [ - + ]: 1 : if (result_op == NULL) {
3226 : 0 : RTE_LOG(ERR, USER1,
3227 : : "line %u FAILED: %s", __LINE__,
3228 : : "Failed to process asym crypto op\n");
3229 : : status = TEST_FAILED;
3230 : 0 : goto exit;
3231 : : }
3232 : :
3233 [ - + ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3234 : 0 : RTE_LOG(ERR, USER1,
3235 : : "line %u FAILED: %s", __LINE__,
3236 : : "Failed to process asym crypto op\n");
3237 : : status = TEST_FAILED;
3238 : 0 : goto exit;
3239 : : }
3240 : :
3241 : : asym_op = result_op->asym;
3242 : :
3243 : 1 : debug_hexdump(stdout, "cipher:",
3244 : 1 : asym_op->sm2.cipher.data, asym_op->sm2.cipher.length);
3245 : :
3246 [ - + ]: 1 : if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
3247 : : RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
3248 [ # # ]: 0 : if (memcmp(input_params.cipher.data, asym_op->sm2.cipher.data,
3249 : : asym_op->sm2.cipher.length) != 0) {
3250 : : status = TEST_FAILED;
3251 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
3252 : : "SM2 encrypt failed.\n");
3253 : 0 : goto exit;
3254 : : }
3255 : : } else {
3256 : : /* Verify cipher (in roundtrip).
3257 : : * Due to random number used per message, encrypt op
3258 : : * would produce different output for same message
3259 : : * every time. Hence, we can't have expected output
3260 : : * to match, instead reverse op to decrypt.
3261 : : */
3262 : :
3263 : : /* Populate op with operational details */
3264 : 1 : op->asym->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
3265 : 1 : pbuf = rte_malloc(NULL, TEST_DATA_SIZE, 0);
3266 : 1 : op->asym->sm2.message.data = pbuf;
3267 : 1 : op->asym->sm2.message.length = TEST_DATA_SIZE;
3268 : :
3269 : : /* Enqueue cipher result for decrypt */
3270 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3271 : : status = TEST_FAILED;
3272 : 0 : RTE_LOG(ERR, USER1,
3273 : : "line %u FAILED: %s", __LINE__,
3274 : : "Error sending packet for operation\n");
3275 : 0 : goto exit;
3276 : : }
3277 : :
3278 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3279 : : rte_pause();
3280 : :
3281 [ - + ]: 1 : if (result_op == NULL) {
3282 : : status = TEST_FAILED;
3283 : 0 : goto exit;
3284 : : }
3285 [ - + ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3286 : : status = TEST_FAILED;
3287 : 0 : RTE_LOG(ERR, USER1,
3288 : : "line %u FAILED: %s", __LINE__,
3289 : : "SM2 encrypt failed.\n");
3290 : 0 : goto exit;
3291 : : }
3292 : :
3293 : : asym_op = result_op->asym;
3294 [ + - ]: 1 : if (memcmp(input_params.message.data, asym_op->sm2.message.data,
3295 : : asym_op->sm2.message.length) != 0) {
3296 : : status = TEST_FAILED;
3297 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
3298 : : "SM2 encrypt failed.\n");
3299 : 0 : goto exit;
3300 : : }
3301 : : }
3302 : 1 : exit:
3303 : 1 : rte_free(pbuf);
3304 : :
3305 [ + - ]: 1 : if (sess != NULL)
3306 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
3307 : 1 : rte_crypto_op_free(op);
3308 : 1 : return status;
3309 : : };
3310 : :
3311 : : static int
3312 : 1 : test_sm2_dec(void)
3313 : : {
3314 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3315 : 1 : struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
3316 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
3317 : 1 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
3318 : 1 : struct rte_mempool *op_mpool = ts_params->op_mpool;
3319 : : struct rte_cryptodev_asym_capability_idx idx;
3320 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
3321 : 1 : struct rte_crypto_op *result_op = NULL;
3322 : : uint8_t output_buf_m[TEST_DATA_SIZE];
3323 : : struct rte_crypto_asym_xform xform;
3324 : : struct rte_crypto_asym_op *asym_op;
3325 : 1 : struct rte_crypto_op *op = NULL;
3326 : : int ret, status = TEST_SUCCESS;
3327 : 1 : void *sess = NULL;
3328 : :
3329 : : /* Check SM2 capability */
3330 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
3331 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
3332 [ + - ]: 1 : if (capa == NULL)
3333 : : return -ENOTSUP;
3334 [ + - ]: 1 : if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
3335 : : RTE_CRYPTO_ASYM_OP_DECRYPT, 0))
3336 : : return TEST_SKIPPED;
3337 : :
3338 : : /* Setup crypto op data structure */
3339 : 1 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3340 [ - + ]: 1 : if (op == NULL) {
3341 : 0 : RTE_LOG(ERR, USER1,
3342 : : "line %u FAILED: %s", __LINE__,
3343 : : "Failed to allocate asymmetric crypto "
3344 : : "operation struct\n");
3345 : : status = TEST_FAILED;
3346 : 0 : goto exit;
3347 : : }
3348 : : asym_op = op->asym;
3349 : :
3350 : : /* Setup asym xform */
3351 : 1 : xform.next = NULL;
3352 : 1 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
3353 : 1 : xform.ec.curve_id = input_params.curve;
3354 : 1 : xform.ec.pkey.data = input_params.pkey.data;
3355 : 1 : xform.ec.pkey.length = input_params.pkey.length;
3356 : 1 : xform.ec.q.x.data = input_params.pubkey_qx.data;
3357 : 1 : xform.ec.q.x.length = input_params.pubkey_qx.length;
3358 : 1 : xform.ec.q.y.data = input_params.pubkey_qy.data;
3359 : 1 : xform.ec.q.y.length = input_params.pubkey_qy.length;
3360 : :
3361 : 1 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3362 [ - + ]: 1 : if (ret < 0) {
3363 : 0 : RTE_LOG(ERR, USER1,
3364 : : "line %u FAILED: %s", __LINE__,
3365 : : "Session creation failed\n");
3366 [ # # ]: 0 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3367 : 0 : goto exit;
3368 : : }
3369 : :
3370 : : /* Attach asymmetric crypto session to crypto operations */
3371 [ + - ]: 1 : rte_crypto_op_attach_asym_session(op, sess);
3372 : :
3373 : : /* Compute decrypt */
3374 : :
3375 : : /* Populate op with operational details */
3376 : 1 : asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
3377 [ - + ]: 1 : if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
3378 : : RTE_CRYPTO_ASYM_OP_DECRYPT, RTE_CRYPTO_SM2_PH))
3379 : 0 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
3380 : : else
3381 : 1 : asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
3382 : :
3383 : 1 : asym_op->sm2.cipher.data = input_params.cipher.data;
3384 : 1 : asym_op->sm2.cipher.length = input_params.cipher.length;
3385 : :
3386 : : /* Init out buf */
3387 : 1 : asym_op->sm2.message.data = output_buf_m;
3388 : 1 : asym_op->sm2.message.length = RTE_DIM(output_buf_m);
3389 : :
3390 : 1 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3391 : :
3392 : : /* Process crypto operation */
3393 [ - + ]: 1 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3394 : 0 : RTE_LOG(ERR, USER1,
3395 : : "line %u FAILED: %s", __LINE__,
3396 : : "Error sending packet for operation\n");
3397 : : status = TEST_FAILED;
3398 : 0 : goto exit;
3399 : : }
3400 : :
3401 [ - + ]: 1 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3402 : : rte_pause();
3403 : :
3404 [ - + ]: 1 : if (result_op == NULL) {
3405 : 0 : RTE_LOG(ERR, USER1,
3406 : : "line %u FAILED: %s", __LINE__,
3407 : : "Failed to process asym crypto op\n");
3408 : : status = TEST_FAILED;
3409 : 0 : goto exit;
3410 : : }
3411 : :
3412 [ - + ]: 1 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3413 : 0 : RTE_LOG(ERR, USER1,
3414 : : "line %u FAILED: %s", __LINE__,
3415 : : "Failed to process asym crypto op\n");
3416 : : status = TEST_FAILED;
3417 : 0 : goto exit;
3418 : : }
3419 : :
3420 : : asym_op = result_op->asym;
3421 : :
3422 : 1 : debug_hexdump(stdout, "message:",
3423 : 1 : asym_op->sm2.message.data, asym_op->sm2.message.length);
3424 : :
3425 : 1 : if (memcmp(input_params.message.data, asym_op->sm2.message.data,
3426 [ + - ]: 1 : op->asym->sm2.message.length)) {
3427 : : status = TEST_FAILED;
3428 : 0 : RTE_LOG(ERR, USER1,
3429 : : "line %u FAILED: %s", __LINE__,
3430 : : "SM2 decrypt failed.\n");
3431 : 0 : goto exit;
3432 : : }
3433 : 1 : exit:
3434 [ + - ]: 1 : if (sess != NULL)
3435 : 1 : rte_cryptodev_asym_session_free(dev_id, sess);
3436 : 1 : rte_crypto_op_free(op);
3437 : 1 : return status;
3438 : : };
3439 : :
3440 : : static int
3441 : 9 : test_eddsa_sign(struct crypto_testsuite_eddsa_params *input_params)
3442 : : {
3443 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3444 : 9 : enum rte_crypto_edward_instance instance = input_params->instance;
3445 : 9 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
3446 : 9 : struct rte_mempool *op_mpool = ts_params->op_mpool;
3447 : 9 : uint8_t dev_id = ts_params->valid_devs[0];
3448 : 9 : struct rte_crypto_op *result_op = NULL;
3449 : : uint8_t output_buf_r[TEST_DATA_SIZE];
3450 : : struct rte_crypto_asym_xform xform;
3451 : : struct rte_crypto_asym_op *asym_op;
3452 : 9 : struct rte_crypto_op *op = NULL;
3453 : : int ret, status = TEST_FAILED;
3454 : 9 : void *sess = NULL;
3455 : : bool ctx = false;
3456 : :
3457 [ + + ]: 9 : if (instance == RTE_CRYPTO_EDCURVE_25519CTX)
3458 : : ctx = true;
3459 : :
3460 : : /* Setup crypto op data structure */
3461 : 9 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3462 [ - + ]: 9 : if (op == NULL) {
3463 : 0 : RTE_LOG(ERR, USER1,
3464 : : "line %u FAILED: %s", __LINE__,
3465 : : "Failed to allocate asymmetric crypto "
3466 : : "operation struct\n");
3467 : : status = TEST_FAILED;
3468 : 0 : goto exit;
3469 : : }
3470 : :
3471 : : asym_op = op->asym;
3472 : :
3473 : : /* Setup asym xform */
3474 : 9 : xform.next = NULL;
3475 : 9 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
3476 : 9 : xform.ec.curve_id = input_params->curve;
3477 : 9 : xform.ec.pkey.data = input_params->pkey.data;
3478 : 9 : xform.ec.pkey.length = input_params->pkey.length;
3479 : 9 : xform.ec.q.x.data = input_params->pubkey.data;
3480 : 9 : xform.ec.q.x.length = input_params->pubkey.length;
3481 : :
3482 : 9 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3483 [ + - ]: 9 : if (ret < 0) {
3484 : 9 : RTE_LOG(ERR, USER1,
3485 : : "line %u FAILED: %s", __LINE__,
3486 : : "Session creation failed\n");
3487 [ - + ]: 9 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3488 : 9 : goto exit;
3489 : : }
3490 : :
3491 : : /* Attach asymmetric crypto session to crypto operations */
3492 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
3493 : :
3494 : : /* Compute sign */
3495 : :
3496 : : /* Populate op with operational details */
3497 : 0 : asym_op->eddsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
3498 : 0 : asym_op->eddsa.instance = input_params->instance;
3499 : 0 : asym_op->eddsa.message.data = input_params->message.data;
3500 : 0 : asym_op->eddsa.message.length = input_params->message.length;
3501 : 0 : asym_op->eddsa.context.length = 0;
3502 [ # # ]: 0 : if (ctx) {
3503 : 0 : asym_op->eddsa.context.data = input_params->context.data;
3504 : 0 : asym_op->eddsa.context.length = input_params->context.length;
3505 : : }
3506 : :
3507 : : /* Init out buf */
3508 : 0 : asym_op->eddsa.sign.data = output_buf_r;
3509 : :
3510 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3511 : :
3512 : : /* Process crypto operation */
3513 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3514 : 0 : RTE_LOG(ERR, USER1,
3515 : : "line %u FAILED: %s", __LINE__,
3516 : : "Error sending packet for operation\n");
3517 : 0 : goto exit;
3518 : : }
3519 : :
3520 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3521 : : rte_pause();
3522 : :
3523 [ # # ]: 0 : if (result_op == NULL) {
3524 : 0 : RTE_LOG(ERR, USER1,
3525 : : "line %u FAILED: %s", __LINE__,
3526 : : "Failed to process asym crypto op\n");
3527 : 0 : goto exit;
3528 : : }
3529 : :
3530 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3531 : 0 : RTE_LOG(ERR, USER1,
3532 : : "line %u FAILED: %s", __LINE__,
3533 : : "Failed to process asym crypto op\n");
3534 : 0 : goto exit;
3535 : : }
3536 : :
3537 : : asym_op = result_op->asym;
3538 : :
3539 : 0 : debug_hexdump(stdout, "sign:",
3540 : 0 : asym_op->eddsa.sign.data, asym_op->eddsa.sign.length);
3541 : :
3542 : : /* Verify sign (by comparison). */
3543 [ # # ]: 0 : if (memcmp(input_params->sign.data, asym_op->eddsa.sign.data,
3544 : : asym_op->eddsa.sign.length) != 0) {
3545 : 0 : RTE_LOG(ERR, USER1,
3546 : : "line %u FAILED: %s", __LINE__,
3547 : : "EdDSA sign failed.\n");
3548 : 0 : goto exit;
3549 : : }
3550 : :
3551 : : status = TEST_SUCCESS;
3552 : 9 : exit:
3553 [ + - ]: 9 : if (sess != NULL)
3554 : 9 : rte_cryptodev_asym_session_free(dev_id, sess);
3555 : 9 : rte_crypto_op_free(op);
3556 : 9 : return status;
3557 : : };
3558 : :
3559 : : static int
3560 : 9 : test_eddsa_verify(struct crypto_testsuite_eddsa_params *input_params)
3561 : : {
3562 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3563 : 9 : enum rte_crypto_edward_instance instance = input_params->instance;
3564 : 9 : struct rte_mempool *sess_mpool = ts_params->session_mpool;
3565 : 9 : struct rte_mempool *op_mpool = ts_params->op_mpool;
3566 : 9 : uint8_t dev_id = ts_params->valid_devs[0];
3567 : 9 : struct rte_crypto_op *result_op = NULL;
3568 : : struct rte_crypto_asym_xform xform;
3569 : : struct rte_crypto_asym_op *asym_op;
3570 : 9 : struct rte_crypto_op *op = NULL;
3571 : : int ret, status = TEST_FAILED;
3572 : 9 : void *sess = NULL;
3573 : : bool ctx = false;
3574 : :
3575 [ + + ]: 9 : if (instance == RTE_CRYPTO_EDCURVE_25519CTX)
3576 : : ctx = true;
3577 : :
3578 : : /* Setup crypto op data structure */
3579 : 9 : op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3580 [ - + ]: 9 : if (op == NULL) {
3581 : 0 : RTE_LOG(ERR, USER1,
3582 : : "line %u FAILED: %s", __LINE__,
3583 : : "Failed to allocate asymmetric crypto "
3584 : : "operation struct\n");
3585 : 0 : goto exit;
3586 : : }
3587 : :
3588 : : asym_op = op->asym;
3589 : :
3590 : : /* Setup asym xform */
3591 : 9 : xform.next = NULL;
3592 : 9 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
3593 : 9 : xform.ec.curve_id = input_params->curve;
3594 : 9 : xform.ec.pkey.length = 0;
3595 : 9 : xform.ec.q.x.data = input_params->pubkey.data;
3596 : 9 : xform.ec.q.x.length = input_params->pubkey.length;
3597 : :
3598 : 9 : ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3599 [ + - ]: 9 : if (ret < 0) {
3600 : 9 : RTE_LOG(ERR, USER1,
3601 : : "line %u FAILED: %s", __LINE__,
3602 : : "Session creation failed\n");
3603 [ - + ]: 9 : status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3604 : 9 : goto exit;
3605 : : }
3606 : :
3607 : : /* Attach asymmetric crypto session to crypto operations */
3608 [ # # ]: 0 : rte_crypto_op_attach_asym_session(op, sess);
3609 : :
3610 : : /* Compute sign */
3611 : :
3612 : : /* Populate op with operational details */
3613 : 0 : asym_op->eddsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
3614 : 0 : asym_op->eddsa.instance = input_params->instance;
3615 : 0 : asym_op->eddsa.message.data = input_params->message.data;
3616 : 0 : asym_op->eddsa.message.length = input_params->message.length;
3617 : 0 : asym_op->eddsa.context.length = 0;
3618 [ # # ]: 0 : if (ctx) {
3619 : 0 : asym_op->eddsa.context.data = input_params->context.data;
3620 : 0 : asym_op->eddsa.context.length = input_params->context.length;
3621 : : }
3622 : :
3623 : 0 : asym_op->eddsa.sign.data = input_params->sign.data;
3624 : 0 : asym_op->eddsa.sign.length = input_params->sign.length;
3625 : :
3626 : 0 : RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3627 : :
3628 : : /* Process crypto operation */
3629 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3630 : 0 : RTE_LOG(ERR, USER1,
3631 : : "line %u FAILED: %s", __LINE__,
3632 : : "Error sending packet for operation\n");
3633 : 0 : goto exit;
3634 : : }
3635 : :
3636 [ # # ]: 0 : while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3637 : : rte_pause();
3638 : :
3639 [ # # ]: 0 : if (result_op == NULL) {
3640 : 0 : RTE_LOG(ERR, USER1,
3641 : : "line %u FAILED: %s", __LINE__,
3642 : : "Failed to process asym crypto op\n");
3643 : 0 : goto exit;
3644 : : }
3645 : :
3646 [ # # ]: 0 : if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3647 : 0 : RTE_LOG(ERR, USER1,
3648 : : "line %u FAILED: %s", __LINE__,
3649 : : "Failed to process asym crypto op\n");
3650 : 0 : goto exit;
3651 : : }
3652 : :
3653 : : status = TEST_SUCCESS;
3654 : 9 : exit:
3655 [ + - ]: 9 : if (sess != NULL)
3656 : 9 : rte_cryptodev_asym_session_free(dev_id, sess);
3657 : 9 : rte_crypto_op_free(op);
3658 : 9 : return status;
3659 : : };
3660 : :
3661 : : static int
3662 : 1 : test_eddsa_sign_verify_all_curve(void)
3663 : : {
3664 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3665 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
3666 : : struct crypto_testsuite_eddsa_params input_params;
3667 : : struct rte_cryptodev_asym_capability_idx idx;
3668 : : int status, overall_status = TEST_SUCCESS;
3669 : 1 : uint8_t dev_id = ts_params->valid_devs[0];
3670 : : uint8_t i, tc = 0;
3671 : : const char *msg;
3672 : :
3673 : : /* Check EdDSA capability */
3674 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
3675 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
3676 [ + - ]: 1 : if (capa == NULL)
3677 : : return TEST_SKIPPED;
3678 : :
3679 : : /* Sign tests */
3680 [ + + ]: 9 : for (i = 0; i < RTE_DIM(eddsa_test_params); i++) {
3681 : 8 : memcpy(&input_params, &eddsa_test_params[i],
3682 : : sizeof(input_params));
3683 : 8 : status = test_eddsa_sign(&input_params);
3684 [ + - ]: 8 : if (status == TEST_SUCCESS) {
3685 : : msg = "succeeded";
3686 : : } else {
3687 : : msg = "failed";
3688 : : overall_status = status;
3689 : : }
3690 : 8 : printf(" %u) TestCase Sign %s %s\n",
3691 : 8 : tc++, input_params.description, msg);
3692 : : }
3693 : :
3694 : : /* Verify tests */
3695 [ + + ]: 9 : for (i = 0; i < RTE_DIM(eddsa_test_params); i++) {
3696 : 8 : memcpy(&input_params, &eddsa_test_params[i],
3697 : : sizeof(input_params));
3698 : 8 : status = test_eddsa_verify(&input_params);
3699 [ + - ]: 8 : if (status == TEST_SUCCESS) {
3700 : : msg = "succeeded";
3701 : : } else {
3702 : : msg = "failed";
3703 : : overall_status = status;
3704 : : }
3705 : 8 : printf(" %u) TestCase Verify %s %s\n",
3706 : 8 : tc++, input_params.description, msg);
3707 : : }
3708 : :
3709 : : /* Negative tests */
3710 : : memcpy(&input_params, &eddsa_test_params[1],
3711 : : sizeof(input_params));
3712 : 1 : input_params.pubkey.data[0] ^= 0x01;
3713 : :
3714 : 1 : status = test_eddsa_sign(&input_params);
3715 [ + - ]: 1 : if (status == TEST_FAILED) {
3716 : : msg = "succeeded";
3717 : : } else {
3718 : : msg = "failed";
3719 : : overall_status = status;
3720 : : }
3721 : 1 : printf(" %u) TestCase Negative Sign %s %s\n",
3722 : 1 : tc++, input_params.description, msg);
3723 : :
3724 : 1 : status = test_eddsa_verify(&input_params);
3725 [ + - ]: 1 : if (status == TEST_FAILED) {
3726 : : msg = "succeeded";
3727 : : } else {
3728 : : msg = "failed";
3729 : : overall_status = status;
3730 : : }
3731 : 1 : printf(" %u) TestCase Negative Verify %s %s\n",
3732 : : tc++, input_params.description, msg);
3733 : :
3734 : 1 : return overall_status;
3735 : : }
3736 : :
3737 : 16 : static int send_one(void)
3738 : : {
3739 : : int ticks = 0;
3740 : :
3741 [ - + ]: 16 : if (rte_cryptodev_enqueue_burst(params->valid_devs[0], 0,
3742 : 16 : &self->op, 1) != 1) {
3743 : 0 : RTE_LOG(ERR, USER1,
3744 : : "line %u FAILED: Error sending packet for operation on device %d",
3745 : : __LINE__, params->valid_devs[0]);
3746 : 0 : return TEST_FAILED;
3747 : : }
3748 : 16 : while (rte_cryptodev_dequeue_burst(params->valid_devs[0], 0,
3749 [ - + ]: 16 : &self->result_op, 1) == 0) {
3750 : : rte_delay_ms(1);
3751 : 0 : ticks++;
3752 [ # # ]: 0 : if (ticks >= DEQ_TIMEOUT) {
3753 : 0 : RTE_LOG(ERR, USER1,
3754 : : "line %u FAILED: Cannot dequeue the crypto op on device %d",
3755 : : __LINE__, params->valid_devs[0]);
3756 : 0 : return TEST_FAILED;
3757 : : }
3758 : : }
3759 [ - + ]: 16 : TEST_ASSERT_NOT_NULL(self->result_op,
3760 : : "Failed to process asym crypto op");
3761 [ - + ]: 16 : TEST_ASSERT_SUCCESS(self->result_op->status,
3762 : : "Failed to process asym crypto op, error status received");
3763 : : return TEST_SUCCESS;
3764 : : }
3765 : :
3766 : 0 : static int send_one_no_status_check(void)
3767 : : {
3768 : : int ticks = 0;
3769 : :
3770 [ # # ]: 0 : if (rte_cryptodev_enqueue_burst(params->valid_devs[0], 0,
3771 : 0 : &self->op, 1) != 1) {
3772 : 0 : RTE_LOG(ERR, USER1,
3773 : : "line %u FAILED: Error sending packet for operation on device %d",
3774 : : __LINE__, params->valid_devs[0]);
3775 : 0 : return TEST_FAILED;
3776 : : }
3777 : 0 : while (rte_cryptodev_dequeue_burst(params->valid_devs[0], 0,
3778 [ # # ]: 0 : &self->result_op, 1) == 0) {
3779 : : rte_delay_ms(1);
3780 : 0 : ticks++;
3781 [ # # ]: 0 : if (ticks >= DEQ_TIMEOUT) {
3782 : 0 : RTE_LOG(ERR, USER1,
3783 : : "line %u FAILED: Cannot dequeue the crypto op on device %d",
3784 : : __LINE__, params->valid_devs[0]);
3785 : 0 : return TEST_FAILED;
3786 : : }
3787 : : }
3788 [ # # ]: 0 : TEST_ASSERT_NOT_NULL(self->result_op,
3789 : : "Failed to process asym crypto op");
3790 : : return TEST_SUCCESS;
3791 : : }
3792 : :
3793 : : static int
3794 : 11 : modular_cmpeq(const uint8_t *a, size_t a_len, const uint8_t *b, size_t b_len)
3795 : : {
3796 : : const uint8_t *new_a, *new_b;
3797 : : size_t i, j;
3798 : :
3799 : : /* Strip leading NUL bytes */
3800 [ + - ]: 11 : for (i = 0; i < a_len; i++)
3801 [ + - ]: 11 : if (a[i] != 0)
3802 : : break;
3803 : :
3804 [ + - ]: 11 : for (j = 0; j < b_len; j++)
3805 [ - + ]: 11 : if (b[j] != 0)
3806 : : break;
3807 : :
3808 [ + - ]: 11 : if (a_len - i != b_len - j)
3809 : : return 1;
3810 : :
3811 : 11 : new_a = &a[i];
3812 : 11 : new_b = &b[j];
3813 [ - + ]: 11 : if (memcmp(new_a, new_b, a_len - i))
3814 : 0 : return 1;
3815 : :
3816 : : return 0;
3817 : : }
3818 : :
3819 : : static int
3820 : 11 : modular_exponentiation(const void *test_data)
3821 : : {
3822 : : const struct modex_test_data *vector = test_data;
3823 : 11 : uint8_t input[TEST_DATA_SIZE] = { 0 };
3824 : 11 : uint8_t exponent[TEST_DATA_SIZE] = { 0 };
3825 : 11 : uint8_t modulus[TEST_DATA_SIZE] = { 0 };
3826 : 11 : uint8_t result[TEST_DATA_SIZE] = { 0 };
3827 : 11 : struct rte_crypto_asym_xform xform = { };
3828 : 11 : const uint8_t dev_id = params->valid_devs[0];
3829 : : const struct rte_cryptodev_asymmetric_xform_capability *cap;
3830 : : struct rte_cryptodev_asym_capability_idx cap_idx;
3831 : :
3832 : 11 : cap_idx.type = RTE_CRYPTO_ASYM_XFORM_MODEX;
3833 : 11 : cap = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
3834 [ + - - + ]: 22 : if (cap == NULL || rte_cryptodev_asym_xform_capability_check_modlen(
3835 : 11 : cap, vector->modulus.len))
3836 : 0 : return TEST_SKIPPED;
3837 : :
3838 : 11 : memcpy(input, vector->base.data, vector->base.len);
3839 : 11 : memcpy(exponent, vector->exponent.data, vector->exponent.len);
3840 : 11 : memcpy(modulus, vector->modulus.data, vector->modulus.len);
3841 : :
3842 : 11 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX;
3843 : 11 : xform.modex.exponent.data = exponent;
3844 : 11 : xform.modex.exponent.length = vector->exponent.len;
3845 : 11 : xform.modex.modulus.data = modulus;
3846 : 11 : xform.modex.modulus.length = vector->modulus.len;
3847 : :
3848 [ - + ]: 11 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
3849 : 11 : params->session_mpool, &self->sess) < 0) {
3850 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
3851 : : __LINE__);
3852 : 0 : return TEST_FAILED;
3853 : : }
3854 [ + - ]: 11 : rte_crypto_op_attach_asym_session(self->op, self->sess);
3855 : 11 : self->op->asym->modex.base.data = input;
3856 : 11 : self->op->asym->modex.base.length = vector->base.len;
3857 : 11 : self->op->asym->modex.result.data = result;
3858 : :
3859 [ - + ]: 11 : TEST_ASSERT_SUCCESS(send_one(),
3860 : : "Failed to process crypto op");
3861 [ - + ]: 11 : TEST_ASSERT_SUCCESS(modular_cmpeq(vector->reminder.data, vector->reminder.len,
3862 : : self->result_op->asym->modex.result.data,
3863 : : self->result_op->asym->modex.result.length),
3864 : : "operation verification failed\n");
3865 : :
3866 : : return TEST_SUCCESS;
3867 : : }
3868 : :
3869 : : static int
3870 : 1 : modular_multiplicative_inverse(const void *test_data)
3871 : : {
3872 : : const struct modinv_test_data *vector = test_data;
3873 : 1 : uint8_t input[TEST_DATA_SIZE] = { 0 };
3874 : 1 : uint8_t modulus[TEST_DATA_SIZE] = { 0 };
3875 : 1 : uint8_t result[TEST_DATA_SIZE] = { 0 };
3876 : 1 : struct rte_crypto_asym_xform xform = { };
3877 : 1 : const uint8_t dev_id = params->valid_devs[0];
3878 : :
3879 : 1 : memcpy(input, vector->base.data, vector->base.len);
3880 : 1 : memcpy(modulus, vector->modulus.data, vector->modulus.len);
3881 : 1 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODINV;
3882 : 1 : xform.modex.modulus.data = modulus;
3883 : 1 : xform.modex.modulus.length = vector->modulus.len;
3884 [ - + ]: 1 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
3885 : 1 : params->session_mpool, &self->sess) < 0) {
3886 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
3887 : : __LINE__);
3888 : 0 : return TEST_FAILED;
3889 : : }
3890 [ + - ]: 1 : rte_crypto_op_attach_asym_session(self->op, self->sess);
3891 : :
3892 : 1 : self->op->asym->modinv.base.data = input;
3893 : 1 : self->op->asym->modinv.base.length = vector->base.len;
3894 : 1 : self->op->asym->modinv.result.data = result;
3895 : 1 : self->op->asym->modinv.result.length = vector->modulus.len;
3896 : :
3897 [ - + ]: 1 : TEST_ASSERT_SUCCESS(send_one(),
3898 : : "Failed to process crypto op");
3899 [ - + ]: 1 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->inverse.data,
3900 : : self->result_op->asym->modinv.result.data,
3901 : : self->result_op->asym->modinv.result.length,
3902 : : "Incorrect reminder\n");
3903 : :
3904 : : return TEST_SUCCESS;
3905 : : }
3906 : :
3907 : : static int
3908 : 0 : mlkem_keygen(const void *test_data)
3909 : : {
3910 : : const struct crypto_testsuite_mlkem_params *vector = test_data;
3911 : 0 : const uint8_t dev_id = params->valid_devs[0];
3912 : 0 : struct rte_crypto_asym_xform xform = {0};
3913 : 0 : uint8_t ek[TEST_DATA_SIZE] = {0};
3914 : 0 : uint8_t dk[TEST_DATA_SIZE] = {0};
3915 : :
3916 : 0 : xform.mlkem.type = vector->type;
3917 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ML_KEM;
3918 [ # # ]: 0 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
3919 : 0 : params->session_mpool, &self->sess) < 0) {
3920 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
3921 : : __LINE__);
3922 : 0 : return TEST_FAILED;
3923 : : }
3924 : :
3925 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
3926 : 0 : self->op->asym->mlkem.op = RTE_CRYPTO_ML_KEM_OP_KEYGEN;
3927 : 0 : self->op->asym->mlkem.keygen.d.data = vector->d.data;
3928 : 0 : self->op->asym->mlkem.keygen.d.length = vector->d.length;
3929 : 0 : self->op->asym->mlkem.keygen.z.data = vector->z.data;
3930 : 0 : self->op->asym->mlkem.keygen.z.length = vector->z.length;
3931 : 0 : self->op->asym->mlkem.keygen.dk.data = dk;
3932 : 0 : self->op->asym->mlkem.keygen.dk.length = 0;
3933 : 0 : self->op->asym->mlkem.keygen.ek.data = ek;
3934 : 0 : self->op->asym->mlkem.keygen.ek.length = 0;
3935 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
3936 : : "Failed to process crypto op (ML-KEM KeyGen)");
3937 : 0 : debug_hexdump(stdout, "Decapsulation key",
3938 : 0 : self->result_op->asym->mlkem.keygen.dk.data,
3939 : 0 : self->result_op->asym->mlkem.keygen.dk.length);
3940 : 0 : debug_hexdump(stdout, "Encapsulation key",
3941 : 0 : self->result_op->asym->mlkem.keygen.ek.data,
3942 : 0 : self->result_op->asym->mlkem.keygen.ek.length);
3943 : :
3944 : : /* Verify the result with the test vector */
3945 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mlkem.keygen.dk.length,
3946 : : rte_crypto_ml_kem_privkey_size[vector->type],
3947 : : "Incorrect Decapsulation key length\n");
3948 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mlkem.keygen.ek.length,
3949 : : rte_crypto_ml_kem_pubkey_size[vector->type],
3950 : : "Incorrect Encapsulation key length\n");
3951 : :
3952 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->dk.data,
3953 : : self->result_op->asym->mlkem.keygen.dk.data,
3954 : : self->result_op->asym->mlkem.keygen.dk.length,
3955 : : "Incorrect Decapsulation key\n");
3956 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->ek.data,
3957 : : self->result_op->asym->mlkem.keygen.ek.data,
3958 : : self->result_op->asym->mlkem.keygen.ek.length,
3959 : : "Incorrect Encapsulation key\n");
3960 : 0 : RTE_LOG(DEBUG, USER1, "Deterministic keygen test passed\n");
3961 : :
3962 : 0 : rte_cryptodev_asym_session_free(dev_id, self->sess);
3963 : 0 : return TEST_SUCCESS;
3964 : : }
3965 : :
3966 : : static int
3967 : 0 : mlkem_encap(const void *test_data)
3968 : : {
3969 : : const struct crypto_testsuite_mlkem_params *vector = test_data;
3970 : 0 : const uint8_t dev_id = params->valid_devs[0];
3971 : 0 : struct rte_crypto_asym_xform xform = {0};
3972 : 0 : uint8_t cipher[TEST_DATA_SIZE] = {0};
3973 : 0 : uint8_t skcopy[TEST_DATA_SIZE] = {0};
3974 : 0 : uint8_t sk[TEST_DATA_SIZE] = {0};
3975 : : size_t cipher_len;
3976 : :
3977 : 0 : xform.mlkem.type = vector->type;
3978 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ML_KEM;
3979 [ # # ]: 0 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
3980 : 0 : params->session_mpool, &self->sess) < 0) {
3981 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
3982 : : __LINE__);
3983 : 0 : return TEST_FAILED;
3984 : : }
3985 : :
3986 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
3987 : :
3988 : : /* Encapsulate */
3989 : 0 : self->op->asym->mlkem.op = RTE_CRYPTO_ML_KEM_OP_ENCAP;
3990 : 0 : self->op->asym->mlkem.encap.message.data = vector->message.data;
3991 : 0 : self->op->asym->mlkem.encap.message.length = vector->message.length;
3992 : 0 : self->op->asym->mlkem.encap.ek.data = vector->ek.data;
3993 : 0 : self->op->asym->mlkem.encap.ek.length = vector->ek.length;
3994 : 0 : self->op->asym->mlkem.encap.cipher.data = cipher;
3995 : 0 : self->op->asym->mlkem.encap.cipher.length =
3996 : 0 : rte_crypto_ml_kem_cipher_size[vector->type];
3997 : 0 : self->op->asym->mlkem.encap.sk.data = sk;
3998 : 0 : self->op->asym->mlkem.encap.sk.length = 32;
3999 : :
4000 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
4001 : : "Failed to process crypto op (ML-KEM Encap)");
4002 : 0 : debug_hexdump(stdout, "Cipher",
4003 : 0 : self->result_op->asym->mlkem.encap.cipher.data,
4004 : 0 : self->result_op->asym->mlkem.encap.cipher.length);
4005 : 0 : debug_hexdump(stdout, "Shared secret from encap",
4006 : 0 : self->result_op->asym->mlkem.encap.sk.data,
4007 : 0 : self->result_op->asym->mlkem.encap.sk.length);
4008 : :
4009 : : /* Verify the result with the test vector */
4010 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mlkem.encap.cipher.length,
4011 : : rte_crypto_ml_kem_cipher_size[vector->type],
4012 : : "Incorrect Cipher length\n");
4013 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mlkem.encap.sk.length, 32,
4014 : : "Incorrect Shared key length\n");
4015 : :
4016 : : /* If random message is set, cipher and shared secret are deterministic */
4017 [ # # ]: 0 : if (vector->message.length != 0) {
4018 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data,
4019 : : self->result_op->asym->mlkem.encap.cipher.data,
4020 : : self->result_op->asym->mlkem.encap.cipher.length,
4021 : : "Incorrect Cipher\n");
4022 : :
4023 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->sk.data,
4024 : : self->result_op->asym->mlkem.encap.sk.data,
4025 : : self->result_op->asym->mlkem.encap.sk.length,
4026 : : "Incorrect Shared secret\n");
4027 : 0 : RTE_LOG(DEBUG, USER1, "Deterministic encap test passed\n");
4028 : : }
4029 : :
4030 : : /* Decapsulate and verify */
4031 : 0 : cipher_len = self->result_op->asym->mlkem.encap.cipher.length;
4032 : 0 : memcpy(skcopy, self->result_op->asym->mlkem.encap.sk.data,
4033 : : self->result_op->asym->mlkem.encap.sk.length);
4034 : : memset(sk, 0, sizeof(sk));
4035 : :
4036 : 0 : self->op->asym->mlkem.op = RTE_CRYPTO_ML_KEM_OP_DECAP;
4037 : 0 : self->op->asym->mlkem.decap.dk.data = vector->dk.data;
4038 : 0 : self->op->asym->mlkem.decap.dk.length = vector->dk.length;
4039 : 0 : self->op->asym->mlkem.decap.cipher.data = cipher;
4040 : 0 : self->op->asym->mlkem.decap.cipher.length = cipher_len;
4041 : 0 : self->op->asym->mlkem.decap.sk.data = sk;
4042 : 0 : self->op->asym->mlkem.decap.sk.length = 32;
4043 : :
4044 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
4045 : : "Failed to process crypto op (ML-KEM Decap)");
4046 : :
4047 : 0 : debug_hexdump(stdout, "Shared secret from decap",
4048 : 0 : self->result_op->asym->mlkem.decap.sk.data,
4049 : 0 : self->result_op->asym->mlkem.decap.sk.length);
4050 : :
4051 : : /* Verify the result with the test vector */
4052 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mlkem.decap.sk.length, 32,
4053 : : "Incorrect Shared secret length\n");
4054 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(self->result_op->asym->mlkem.decap.sk.data,
4055 : : skcopy, self->result_op->asym->mlkem.decap.sk.length,
4056 : : "Incorrect Shared secret\n");
4057 : :
4058 : : /* Negative test */
4059 : 0 : cipher[0] ^= 0x01;
4060 : : memset(sk, 0, sizeof(sk));
4061 : :
4062 : 0 : self->op->asym->mlkem.op = RTE_CRYPTO_ML_KEM_OP_DECAP;
4063 : 0 : self->op->asym->mlkem.decap.dk.data = vector->dk.data;
4064 : 0 : self->op->asym->mlkem.decap.dk.length = vector->dk.length;
4065 : 0 : self->op->asym->mlkem.decap.cipher.data = cipher;
4066 : 0 : self->op->asym->mlkem.decap.cipher.length = cipher_len;
4067 : 0 : self->op->asym->mlkem.decap.sk.data = sk;
4068 : 0 : self->op->asym->mlkem.decap.sk.length = 32;
4069 : :
4070 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one_no_status_check(),
4071 : : "Failed to process crypto op (ML-KEM Decap)");
4072 : :
4073 : 0 : debug_hexdump(stdout, "Shared secret from negative test",
4074 : 0 : self->result_op->asym->mlkem.decap.sk.data,
4075 : 0 : self->result_op->asym->mlkem.decap.sk.length);
4076 : :
4077 : : /* Verify the result with the test vector */
4078 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mlkem.decap.sk.length, 32,
4079 : : "Incorrect Shared secret length\n");
4080 : :
4081 [ # # ]: 0 : if (!memcmp(self->result_op->asym->mlkem.decap.sk.data, skcopy, 32)) {
4082 : 0 : rte_cryptodev_asym_session_free(dev_id, self->sess);
4083 : 0 : return TEST_FAILED;
4084 : : }
4085 : :
4086 : 0 : rte_cryptodev_asym_session_free(dev_id, self->sess);
4087 : 0 : return TEST_SUCCESS;
4088 : : }
4089 : :
4090 : : static int
4091 : 0 : mlkem_decap(const void *test_data)
4092 : : {
4093 : : const struct crypto_testsuite_mlkem_params *vector = test_data;
4094 : 0 : const uint8_t dev_id = params->valid_devs[0];
4095 : 0 : struct rte_crypto_asym_xform xform = {0};
4096 : 0 : uint8_t cipher[TEST_DATA_SIZE] = {0};
4097 : 0 : uint8_t sk[TEST_DATA_SIZE] = {0};
4098 : : size_t cipher_len;
4099 : :
4100 : 0 : xform.mlkem.type = vector->type;
4101 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ML_KEM;
4102 [ # # ]: 0 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
4103 : 0 : params->session_mpool, &self->sess) < 0) {
4104 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
4105 : : __LINE__);
4106 : 0 : return TEST_FAILED;
4107 : : }
4108 : :
4109 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
4110 : :
4111 : : /* Decapsulate and verify */
4112 : 0 : self->op->asym->mlkem.op = RTE_CRYPTO_ML_KEM_OP_DECAP;
4113 : 0 : self->op->asym->mlkem.decap.dk.data = vector->dk.data;
4114 : 0 : self->op->asym->mlkem.decap.dk.length = vector->dk.length;
4115 : 0 : self->op->asym->mlkem.decap.cipher.data = vector->cipher.data;
4116 : 0 : self->op->asym->mlkem.decap.cipher.length = vector->cipher.length;
4117 : 0 : self->op->asym->mlkem.decap.sk.data = sk;
4118 : 0 : self->op->asym->mlkem.decap.sk.length = 32;
4119 : :
4120 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
4121 : : "Failed to process crypto op (ML-KEM Decap)");
4122 : :
4123 : 0 : debug_hexdump(stdout, "Shared secret from decap",
4124 : 0 : self->result_op->asym->mlkem.decap.sk.data,
4125 : 0 : self->result_op->asym->mlkem.decap.sk.length);
4126 : :
4127 : : /* Verify the result with the test vector */
4128 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mlkem.decap.sk.length, 32,
4129 : : "Incorrect Shared secret length\n");
4130 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(self->result_op->asym->mlkem.decap.sk.data,
4131 : : vector->sk.data, vector->sk.length,
4132 : : "Incorrect Shared secret\n");
4133 : :
4134 : : /* Negative test */
4135 : 0 : memcpy(cipher, vector->cipher.data, vector->cipher.length);
4136 : : cipher_len = vector->cipher.length;
4137 : 0 : cipher[0] ^= 0x01;
4138 : : memset(sk, 0, sizeof(sk));
4139 : :
4140 : 0 : self->op->asym->mlkem.op = RTE_CRYPTO_ML_KEM_OP_DECAP;
4141 : 0 : self->op->asym->mlkem.decap.dk.data = vector->dk.data;
4142 : 0 : self->op->asym->mlkem.decap.dk.length = vector->dk.length;
4143 : 0 : self->op->asym->mlkem.decap.cipher.data = cipher;
4144 : 0 : self->op->asym->mlkem.decap.cipher.length = cipher_len;
4145 : 0 : self->op->asym->mlkem.decap.sk.data = sk;
4146 : 0 : self->op->asym->mlkem.decap.sk.length = 32;
4147 : :
4148 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one_no_status_check(),
4149 : : "Failed to process crypto op (ML-KEM Decap)");
4150 : :
4151 : 0 : debug_hexdump(stdout, "Shared secret from negative test",
4152 : 0 : self->result_op->asym->mlkem.decap.sk.data,
4153 : 0 : self->result_op->asym->mlkem.decap.sk.length);
4154 : :
4155 : : /* Verify the result with the test vector */
4156 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mlkem.decap.sk.length, 32,
4157 : : "Incorrect Shared secret length\n");
4158 : :
4159 : 0 : if (!memcmp(self->result_op->asym->mlkem.decap.sk.data,
4160 [ # # ]: 0 : vector->sk.data, vector->sk.length)) {
4161 : 0 : rte_cryptodev_asym_session_free(dev_id, self->sess);
4162 : 0 : return TEST_FAILED;
4163 : : }
4164 : :
4165 : 0 : rte_cryptodev_asym_session_free(dev_id, self->sess);
4166 : 0 : return TEST_SUCCESS;
4167 : : }
4168 : :
4169 : : static int
4170 : 0 : mldsa_keygen(const void *test_data)
4171 : : {
4172 : : const struct crypto_testsuite_mldsa_params *vector = test_data;
4173 : 0 : const uint8_t dev_id = params->valid_devs[0];
4174 : 0 : struct rte_crypto_asym_xform xform = {0};
4175 : 0 : uint8_t privkey[TEST_DATA_SIZE] = {0};
4176 : 0 : uint8_t pubkey[TEST_DATA_SIZE] = {0};
4177 : :
4178 : 0 : xform.mldsa.type = vector->type;
4179 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ML_DSA;
4180 [ # # ]: 0 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
4181 : 0 : params->session_mpool, &self->sess) < 0) {
4182 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
4183 : : __LINE__);
4184 : 0 : return TEST_FAILED;
4185 : : }
4186 : :
4187 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
4188 : 0 : self->op->asym->mldsa.op = RTE_CRYPTO_ML_DSA_OP_KEYGEN;
4189 : 0 : self->op->asym->mldsa.keygen.seed.data = vector->seed.data;
4190 : 0 : self->op->asym->mldsa.keygen.seed.length = vector->seed.length;
4191 : 0 : self->op->asym->mldsa.keygen.privkey.data = privkey;
4192 : 0 : self->op->asym->mldsa.keygen.privkey.length = 0;
4193 : 0 : self->op->asym->mldsa.keygen.pubkey.data = pubkey;
4194 : 0 : self->op->asym->mldsa.keygen.pubkey.length = 0;
4195 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
4196 : : "Failed to process crypto op (ML-DSA KeyGen)");
4197 : :
4198 : 0 : debug_hexdump(stdout, "Private key",
4199 : 0 : self->result_op->asym->mldsa.keygen.privkey.data,
4200 : 0 : self->result_op->asym->mldsa.keygen.privkey.length);
4201 : 0 : debug_hexdump(stdout, "Public key",
4202 : 0 : self->result_op->asym->mldsa.keygen.pubkey.data,
4203 : 0 : self->result_op->asym->mldsa.keygen.pubkey.length);
4204 : :
4205 : : /* Verify the result with the test vector */
4206 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mldsa.keygen.privkey.length,
4207 : : rte_crypto_ml_dsa_privkey_size[vector->type],
4208 : : "Incorrect Private key length\n");
4209 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mldsa.keygen.pubkey.length,
4210 : : rte_crypto_ml_dsa_pubkey_size[vector->type],
4211 : : "Incorrect Public key length\n");
4212 : :
4213 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->privkey.data,
4214 : : self->result_op->asym->mldsa.keygen.privkey.data,
4215 : : self->result_op->asym->mldsa.keygen.privkey.length,
4216 : : "Incorrect Private key\n");
4217 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->pubkey.data,
4218 : : self->result_op->asym->mldsa.keygen.pubkey.data,
4219 : : self->result_op->asym->mldsa.keygen.pubkey.length,
4220 : : "Incorrect Public key\n");
4221 : 0 : RTE_LOG(DEBUG, USER1, "Deterministic keygen test passed\n");
4222 : :
4223 : 0 : rte_cryptodev_asym_session_free(dev_id, self->sess);
4224 : 0 : return TEST_SUCCESS;
4225 : : }
4226 : :
4227 : : static int
4228 : 0 : mldsa_sign(const void *test_data)
4229 : : {
4230 : : const struct crypto_testsuite_mldsa_params *vector = test_data;
4231 : 0 : const uint8_t dev_id = params->valid_devs[0];
4232 : 0 : struct rte_crypto_asym_xform xform = {0};
4233 : : struct rte_cryptodev_info dev_info;
4234 : 0 : uint8_t sign[TEST_DATA_SIZE] = {0};
4235 : : size_t sign_len;
4236 : :
4237 : 0 : xform.mldsa.type = vector->type;
4238 : 0 : xform.mldsa.sign_deterministic = vector->sign_deterministic;
4239 : 0 : xform.mldsa.sign_prehash = !!vector->hash;
4240 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ML_DSA;
4241 : :
4242 : 0 : rte_cryptodev_info_get(dev_id, &dev_info);
4243 : :
4244 : : /* Check if prehash is supported */
4245 [ # # ]: 0 : if (vector->hash) {
4246 [ # # ]: 0 : if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MLDSA_SIGN_PREHASH)) {
4247 : 0 : RTE_LOG(DEBUG, USER1,
4248 : : "Device doesn't support prehash in ML-DSA signature generation. Test skipped\n");
4249 : 0 : return TEST_SKIPPED;
4250 : : }
4251 : : }
4252 : :
4253 [ # # ]: 0 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
4254 : 0 : params->session_mpool, &self->sess) < 0) {
4255 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
4256 : : __LINE__);
4257 : 0 : return TEST_FAILED;
4258 : : }
4259 : :
4260 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
4261 : :
4262 : : /* Sign */
4263 : 0 : self->op->asym->mldsa.op = RTE_CRYPTO_ML_DSA_OP_SIGN;
4264 : 0 : self->op->asym->mldsa.siggen.seed.data = vector->seed.data;
4265 : 0 : self->op->asym->mldsa.siggen.seed.length = vector->seed.length;
4266 : 0 : self->op->asym->mldsa.siggen.privkey.data = vector->privkey.data;
4267 : 0 : self->op->asym->mldsa.siggen.privkey.length = vector->privkey.length;
4268 : 0 : self->op->asym->mldsa.siggen.message.data = vector->message.data;
4269 : 0 : self->op->asym->mldsa.siggen.message.length = vector->message.length;
4270 : 0 : self->op->asym->mldsa.siggen.ctx.data = vector->context.data;
4271 : 0 : self->op->asym->mldsa.siggen.ctx.length = vector->context.length;
4272 : 0 : self->op->asym->mldsa.siggen.mu.data = vector->mu.data;
4273 : 0 : self->op->asym->mldsa.siggen.mu.length = vector->mu.length;
4274 : 0 : self->op->asym->mldsa.siggen.sign.data = sign;
4275 : 0 : self->op->asym->mldsa.siggen.sign.length =
4276 : 0 : rte_crypto_ml_dsa_sign_size[vector->type];
4277 : 0 : self->op->asym->mldsa.siggen.hash = vector->hash;
4278 : :
4279 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
4280 : : "Failed to process crypto op (ML-DSA Sign)");
4281 : :
4282 : 0 : debug_hexdump(stdout, "Signature",
4283 : 0 : self->result_op->asym->mldsa.siggen.sign.data,
4284 : 0 : self->result_op->asym->mldsa.siggen.sign.length);
4285 : :
4286 : : /* Verify the result with the test vector */
4287 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->asym->mldsa.siggen.sign.length,
4288 : : rte_crypto_ml_dsa_sign_size[vector->type],
4289 : : "Incorrect Signature length\n");
4290 : :
4291 : : /* Verify signature if it is deterministic */
4292 [ # # ]: 0 : if (vector->sign_deterministic) {
4293 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->sign.data,
4294 : : self->result_op->asym->mldsa.siggen.sign.data,
4295 : : self->result_op->asym->mldsa.siggen.sign.length,
4296 : : "Incorrect Signature\n");
4297 : 0 : RTE_LOG(DEBUG, USER1, "Deterministic signature test passed\n");
4298 : : }
4299 : :
4300 : : /* Verify the signature */
4301 : 0 : sign_len = self->result_op->asym->mldsa.siggen.sign.length;
4302 : :
4303 : 0 : self->op->asym->mldsa.op = RTE_CRYPTO_ML_DSA_OP_VERIFY;
4304 : 0 : self->op->asym->mldsa.sigver.message.data = vector->message.data;
4305 : 0 : self->op->asym->mldsa.sigver.message.length = vector->message.length;
4306 : 0 : self->op->asym->mldsa.sigver.ctx.data = vector->context.data;
4307 : 0 : self->op->asym->mldsa.sigver.ctx.length = vector->context.length;
4308 : 0 : self->op->asym->mldsa.sigver.mu.data = vector->mu.data;
4309 : 0 : self->op->asym->mldsa.sigver.mu.length = vector->mu.length;
4310 : 0 : self->op->asym->mldsa.sigver.pubkey.data = vector->pubkey.data;
4311 : 0 : self->op->asym->mldsa.sigver.pubkey.length = vector->pubkey.length;
4312 : 0 : self->op->asym->mldsa.sigver.sign.data = sign;
4313 : 0 : self->op->asym->mldsa.sigver.sign.length = sign_len;
4314 : 0 : self->op->asym->mldsa.sigver.hash = vector->hash;
4315 : :
4316 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
4317 : : "Failed to process crypto op (ML-DSA Verify)");
4318 : :
4319 : : /* Verify the result */
4320 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4321 : : "Failed to verify the signature");
4322 : :
4323 : : /* Negative test */
4324 : 0 : sign[0] ^= 0x01;
4325 : :
4326 : 0 : self->op->asym->mldsa.op = RTE_CRYPTO_ML_DSA_OP_VERIFY;
4327 : 0 : self->op->asym->mldsa.sigver.message.data = vector->message.data;
4328 : 0 : self->op->asym->mldsa.sigver.message.length = vector->message.length;
4329 : 0 : self->op->asym->mldsa.sigver.ctx.data = vector->context.data;
4330 : 0 : self->op->asym->mldsa.sigver.ctx.length = vector->context.length;
4331 : 0 : self->op->asym->mldsa.sigver.mu.data = vector->mu.data;
4332 : 0 : self->op->asym->mldsa.sigver.mu.length = vector->mu.length;
4333 : 0 : self->op->asym->mldsa.sigver.pubkey.data = vector->pubkey.data;
4334 : 0 : self->op->asym->mldsa.sigver.pubkey.length = vector->pubkey.length;
4335 : 0 : self->op->asym->mldsa.sigver.sign.data = sign;
4336 : 0 : self->op->asym->mldsa.sigver.sign.length = sign_len;
4337 : 0 : self->op->asym->mldsa.sigver.hash = vector->hash;
4338 : :
4339 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one_no_status_check(),
4340 : : "Failed to process crypto op (ML-DSA Verify)");
4341 : :
4342 : : /* Verify the result */
4343 [ # # ]: 0 : if (self->result_op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
4344 : 0 : rte_cryptodev_asym_session_free(dev_id, self->sess);
4345 : 0 : return TEST_FAILED;
4346 : : }
4347 : :
4348 : 0 : rte_cryptodev_asym_session_free(dev_id, self->sess);
4349 : 0 : return TEST_SUCCESS;
4350 : : }
4351 : :
4352 : : static int
4353 : 0 : mldsa_verify(const void *test_data)
4354 : : {
4355 : : const struct crypto_testsuite_mldsa_params *vector = test_data;
4356 : 0 : const uint8_t dev_id = params->valid_devs[0];
4357 : 0 : struct rte_crypto_asym_xform xform = {0};
4358 : : struct rte_cryptodev_info dev_info;
4359 : 0 : uint8_t sign[TEST_DATA_SIZE] = {0};
4360 : : size_t sign_len;
4361 : :
4362 : 0 : xform.mldsa.type = vector->type;
4363 : 0 : xform.mldsa.sign_deterministic = vector->sign_deterministic;
4364 : 0 : xform.mldsa.sign_prehash = !!vector->hash;
4365 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ML_DSA;
4366 : :
4367 : 0 : rte_cryptodev_info_get(dev_id, &dev_info);
4368 : :
4369 : : /* Check if prehash is supported */
4370 [ # # ]: 0 : if (vector->hash) {
4371 [ # # ]: 0 : if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MLDSA_SIGN_PREHASH)) {
4372 : 0 : RTE_LOG(DEBUG, USER1,
4373 : : "Device doesn't support prehash in ML-DSA verify. Test skipped\n");
4374 : 0 : return TEST_SKIPPED;
4375 : : }
4376 : : }
4377 : :
4378 [ # # ]: 0 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
4379 : 0 : params->session_mpool, &self->sess) < 0) {
4380 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
4381 : : __LINE__);
4382 : 0 : return TEST_FAILED;
4383 : : }
4384 : :
4385 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
4386 : :
4387 : : /* Verify the signature */
4388 : 0 : self->op->asym->mldsa.op = RTE_CRYPTO_ML_DSA_OP_VERIFY;
4389 : 0 : self->op->asym->mldsa.sigver.message.data = vector->message.data;
4390 : 0 : self->op->asym->mldsa.sigver.message.length = vector->message.length;
4391 : 0 : self->op->asym->mldsa.sigver.ctx.data = vector->context.data;
4392 : 0 : self->op->asym->mldsa.sigver.ctx.length = vector->context.length;
4393 : 0 : self->op->asym->mldsa.sigver.mu.data = vector->mu.data;
4394 : 0 : self->op->asym->mldsa.sigver.mu.length = vector->mu.length;
4395 : 0 : self->op->asym->mldsa.sigver.pubkey.data = vector->pubkey.data;
4396 : 0 : self->op->asym->mldsa.sigver.pubkey.length = vector->pubkey.length;
4397 : 0 : self->op->asym->mldsa.sigver.sign.data = vector->sign.data;
4398 : 0 : self->op->asym->mldsa.sigver.sign.length = vector->sign.length;
4399 : 0 : self->op->asym->mldsa.sigver.hash = vector->hash;
4400 : :
4401 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
4402 : : "Failed to process crypto op (ML-DSA Verify)");
4403 : :
4404 : : /* Verify the result */
4405 [ # # ]: 0 : TEST_ASSERT_EQUAL(self->result_op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4406 : : "Failed to verify the signature");
4407 : :
4408 : : /* Negative test */
4409 : 0 : memcpy(sign, vector->sign.data, vector->sign.length);
4410 : : sign_len = vector->sign.length;
4411 : 0 : sign[0] ^= 0x01;
4412 : :
4413 : 0 : self->op->asym->mldsa.op = RTE_CRYPTO_ML_DSA_OP_VERIFY;
4414 : 0 : self->op->asym->mldsa.sigver.message.data = vector->message.data;
4415 : 0 : self->op->asym->mldsa.sigver.message.length = vector->message.length;
4416 : 0 : self->op->asym->mldsa.sigver.ctx.data = vector->context.data;
4417 : 0 : self->op->asym->mldsa.sigver.ctx.length = vector->context.length;
4418 : 0 : self->op->asym->mldsa.sigver.mu.data = vector->mu.data;
4419 : 0 : self->op->asym->mldsa.sigver.mu.length = vector->mu.length;
4420 : 0 : self->op->asym->mldsa.sigver.pubkey.data = vector->pubkey.data;
4421 : 0 : self->op->asym->mldsa.sigver.pubkey.length = vector->pubkey.length;
4422 : 0 : self->op->asym->mldsa.sigver.sign.data = sign;
4423 : 0 : self->op->asym->mldsa.sigver.sign.length = sign_len;
4424 : 0 : self->op->asym->mldsa.sigver.hash = vector->hash;
4425 : :
4426 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one_no_status_check(),
4427 : : "Failed to process crypto op (ML-DSA Verify)");
4428 : :
4429 : : /* Verify the result */
4430 [ # # ]: 0 : if (self->result_op->status == RTE_CRYPTO_OP_STATUS_SUCCESS) {
4431 : 0 : rte_cryptodev_asym_session_free(dev_id, self->sess);
4432 : 0 : return TEST_FAILED;
4433 : : }
4434 : :
4435 : 0 : rte_cryptodev_asym_session_free(dev_id, self->sess);
4436 : 0 : return TEST_SUCCESS;
4437 : : }
4438 : :
4439 : : static int
4440 : 0 : test_mlkem_keygen(void)
4441 : : {
4442 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
4443 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
4444 : : struct rte_cryptodev_asym_capability_idx idx;
4445 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
4446 : : int overall_status = TEST_SUCCESS;
4447 : : int ret;
4448 : :
4449 : : /* Check if ML-KEM is supported */
4450 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ML_KEM;
4451 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
4452 [ # # ]: 0 : if (capa == NULL) {
4453 : 0 : RTE_LOG(DEBUG, USER1,
4454 : : "Device doesn't support ML-KEM. Test skipped\n");
4455 : 0 : return TEST_SKIPPED;
4456 : : }
4457 : :
4458 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ML_KEM_OP_KEYGEN))) {
4459 : 0 : RTE_LOG(DEBUG, USER1,
4460 : : "Device doesn't support ML-KEM keygen operation. Test skipped\n");
4461 : 0 : return TEST_SKIPPED;
4462 : : }
4463 : :
4464 [ # # ]: 0 : for (uint8_t i = 0; i < RTE_DIM(mlkem_keygen_test_vectors); i++) {
4465 : 0 : if (!(capa->mlkem_capa[RTE_CRYPTO_ML_KEM_OP_KEYGEN] &
4466 [ # # ]: 0 : (1 << mlkem_keygen_test_vectors[i].type))) {
4467 : 0 : RTE_LOG(DEBUG, USER1,
4468 : : "Device doesn't support ML-KEM param %u. TestCase %s skipped\n",
4469 : : mlkem_keygen_test_vectors[i].type,
4470 : : mlkem_keygen_test_vectors[i].name);
4471 : 0 : printf(" %u) TestCase %s: skipped\n", i,
4472 : : mlkem_keygen_test_vectors[i].name);
4473 : 0 : continue;
4474 : : }
4475 : 0 : ret = mlkem_keygen(&mlkem_keygen_test_vectors[i]);
4476 [ # # ]: 0 : if (ret == TEST_SUCCESS || ret == TEST_SKIPPED) {
4477 [ # # ]: 0 : printf(" %u) TestCase %s: %s\n", i, mlkem_keygen_test_vectors[i].name,
4478 : : (ret == TEST_SKIPPED) ? "skipped" : "passed");
4479 : 0 : continue;
4480 : : }
4481 : :
4482 : 0 : printf(" %u) TestCase %s: failed\n", i, mlkem_keygen_test_vectors[i].name);
4483 : : overall_status = TEST_FAILED;
4484 : : }
4485 : :
4486 : : return overall_status;
4487 : : }
4488 : :
4489 : : static int
4490 : 0 : test_mlkem_encap(void)
4491 : : {
4492 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
4493 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
4494 : : struct rte_cryptodev_asym_capability_idx idx;
4495 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
4496 : : int overall_status = TEST_SUCCESS;
4497 : : int ret;
4498 : :
4499 : : /* Check if ML-KEM is supported */
4500 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ML_KEM;
4501 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
4502 [ # # ]: 0 : if (capa == NULL) {
4503 : 0 : RTE_LOG(DEBUG, USER1,
4504 : : "Device doesn't support ML-KEM. Test skipped\n");
4505 : 0 : return TEST_SKIPPED;
4506 : : }
4507 : :
4508 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ML_KEM_OP_ENCAP))) {
4509 : 0 : RTE_LOG(DEBUG, USER1,
4510 : : "Device doesn't support ML-KEM encap operation. Test skipped\n");
4511 : 0 : return TEST_SKIPPED;
4512 : : }
4513 : :
4514 [ # # ]: 0 : for (uint8_t i = 0; i < RTE_DIM(mlkem_encap_test_vectors); i++) {
4515 : 0 : if (!(capa->mlkem_capa[RTE_CRYPTO_ML_KEM_OP_ENCAP] &
4516 [ # # ]: 0 : (1 << mlkem_encap_test_vectors[i].type))) {
4517 : 0 : RTE_LOG(DEBUG, USER1,
4518 : : "Device doesn't support ML-KEM param %u. TestCase %s skipped\n",
4519 : : mlkem_encap_test_vectors[i].type,
4520 : : mlkem_encap_test_vectors[i].name);
4521 : 0 : printf(" %u) TestCase %s: skipped\n", i,
4522 : : mlkem_encap_test_vectors[i].name);
4523 : 0 : continue;
4524 : : }
4525 : 0 : ret = mlkem_encap(&mlkem_encap_test_vectors[i]);
4526 [ # # ]: 0 : if (ret == TEST_SUCCESS || ret == TEST_SKIPPED) {
4527 [ # # ]: 0 : printf(" %u) TestCase %s: %s\n", i, mlkem_encap_test_vectors[i].name,
4528 : : (ret == TEST_SKIPPED) ? "skipped" : "passed");
4529 : 0 : continue;
4530 : : }
4531 : :
4532 : 0 : printf(" %u) TestCase %s: failed\n", i, mlkem_encap_test_vectors[i].name);
4533 : : overall_status = TEST_FAILED;
4534 : : }
4535 : :
4536 : : return overall_status;
4537 : : }
4538 : :
4539 : : static int
4540 : 0 : test_mlkem_decap(void)
4541 : : {
4542 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
4543 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
4544 : : struct rte_cryptodev_asym_capability_idx idx;
4545 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
4546 : : int overall_status = TEST_SUCCESS;
4547 : : int ret;
4548 : :
4549 : : /* Check if ML-KEM is supported */
4550 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ML_KEM;
4551 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
4552 [ # # ]: 0 : if (capa == NULL) {
4553 : 0 : RTE_LOG(DEBUG, USER1,
4554 : : "Device doesn't support ML-KEM. Test skipped\n");
4555 : 0 : return TEST_SKIPPED;
4556 : : }
4557 : :
4558 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ML_KEM_OP_DECAP))) {
4559 : 0 : RTE_LOG(DEBUG, USER1,
4560 : : "Device doesn't support ML-KEM decap operation. Test skipped\n");
4561 : 0 : return TEST_SKIPPED;
4562 : : }
4563 : :
4564 [ # # ]: 0 : for (uint8_t i = 0; i < RTE_DIM(mlkem_decap_test_vectors); i++) {
4565 : 0 : if (!(capa->mlkem_capa[RTE_CRYPTO_ML_KEM_OP_DECAP] &
4566 [ # # ]: 0 : (1 << mlkem_decap_test_vectors[i].type))) {
4567 : 0 : RTE_LOG(DEBUG, USER1,
4568 : : "Device doesn't support ML-KEM param %u. TestCase %s skipped\n",
4569 : : mlkem_decap_test_vectors[i].type,
4570 : : mlkem_decap_test_vectors[i].name);
4571 : 0 : printf(" %u) TestCase %s: skipped\n", i,
4572 : : mlkem_decap_test_vectors[i].name);
4573 : 0 : continue;
4574 : : }
4575 : 0 : ret = mlkem_decap(&mlkem_decap_test_vectors[i]);
4576 [ # # ]: 0 : if (ret == TEST_SUCCESS || ret == TEST_SKIPPED) {
4577 [ # # ]: 0 : printf(" %u) TestCase %s: %s\n", i, mlkem_decap_test_vectors[i].name,
4578 : : (ret == TEST_SKIPPED) ? "skipped" : "passed");
4579 : 0 : continue;
4580 : : }
4581 : :
4582 : 0 : printf(" %u) TestCase %s: failed\n", i, mlkem_decap_test_vectors[i].name);
4583 : : overall_status = TEST_FAILED;
4584 : : }
4585 : :
4586 : : return overall_status;
4587 : : }
4588 : :
4589 : : static int
4590 : 0 : test_mldsa_keygen(void)
4591 : : {
4592 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
4593 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
4594 : : struct rte_cryptodev_asym_capability_idx idx;
4595 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
4596 : : int overall_status = TEST_SUCCESS;
4597 : : int ret;
4598 : :
4599 : : /* Check if ML-DSA is supported */
4600 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ML_DSA;
4601 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
4602 [ # # ]: 0 : if (capa == NULL) {
4603 : 0 : RTE_LOG(DEBUG, USER1,
4604 : : "Device doesn't support ML-DSA. Test skipped\n");
4605 : 0 : return TEST_SKIPPED;
4606 : : }
4607 : :
4608 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ML_DSA_OP_KEYGEN))) {
4609 : 0 : RTE_LOG(DEBUG, USER1,
4610 : : "Device doesn't support ML-DSA keygen operation. Test skipped\n");
4611 : 0 : return TEST_SKIPPED;
4612 : : }
4613 : :
4614 [ # # ]: 0 : for (uint8_t i = 0; i < RTE_DIM(mldsa_keygen_test_vectors); i++) {
4615 : 0 : if (!(capa->mldsa_capa[RTE_CRYPTO_ML_DSA_OP_KEYGEN] &
4616 [ # # ]: 0 : (1 << mldsa_keygen_test_vectors[i].type))) {
4617 : 0 : RTE_LOG(DEBUG, USER1,
4618 : : "Device doesn't support ML-DSA param %u. TestCase %s skipped\n",
4619 : : mldsa_keygen_test_vectors[i].type,
4620 : : mldsa_keygen_test_vectors[i].name);
4621 : 0 : printf(" %u) TestCase %s: skipped\n", i,
4622 : : mldsa_keygen_test_vectors[i].name);
4623 : 0 : continue;
4624 : : }
4625 : 0 : ret = mldsa_keygen(&mldsa_keygen_test_vectors[i]);
4626 [ # # ]: 0 : if (ret == TEST_SUCCESS || ret == TEST_SKIPPED) {
4627 [ # # ]: 0 : printf(" %u) TestCase %s: %s\n", i, mldsa_keygen_test_vectors[i].name,
4628 : : (ret == TEST_SKIPPED) ? "skipped" : "passed");
4629 : 0 : continue;
4630 : : }
4631 : :
4632 : 0 : printf(" %u) TestCase %s: failed\n", i, mldsa_keygen_test_vectors[i].name);
4633 : : overall_status = TEST_FAILED;
4634 : : }
4635 : :
4636 : : return overall_status;
4637 : : }
4638 : :
4639 : : static int
4640 : 0 : test_mldsa_sign(void)
4641 : : {
4642 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
4643 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
4644 : : struct rte_cryptodev_asym_capability_idx idx;
4645 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
4646 : : int overall_status = TEST_SUCCESS;
4647 : : int ret;
4648 : :
4649 : : /* Check if ML-DSA is supported */
4650 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ML_DSA;
4651 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
4652 [ # # ]: 0 : if (capa == NULL) {
4653 : 0 : RTE_LOG(DEBUG, USER1,
4654 : : "Device doesn't support ML-DSA. Test skipped\n");
4655 : 0 : return TEST_SKIPPED;
4656 : : }
4657 : :
4658 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ML_DSA_OP_SIGN))) {
4659 : 0 : RTE_LOG(DEBUG, USER1,
4660 : : "Device doesn't support ML-DSA sign operation. Test skipped\n");
4661 : 0 : return TEST_SKIPPED;
4662 : : }
4663 : :
4664 [ # # ]: 0 : for (uint8_t i = 0; i < RTE_DIM(mldsa_sign_test_vectors); i++) {
4665 : 0 : if (!(capa->mldsa_capa[RTE_CRYPTO_ML_DSA_OP_SIGN] &
4666 [ # # ]: 0 : (1 << mldsa_sign_test_vectors[i].type))) {
4667 : 0 : RTE_LOG(DEBUG, USER1,
4668 : : "Device doesn't support ML-DSA param %u. TestCase %s skipped\n",
4669 : : mldsa_sign_test_vectors[i].type,
4670 : : mldsa_sign_test_vectors[i].name);
4671 : 0 : printf(" %u) TestCase %s: skipped\n", i,
4672 : : mldsa_sign_test_vectors[i].name);
4673 : 0 : continue;
4674 : : }
4675 : 0 : ret = mldsa_sign(&mldsa_sign_test_vectors[i]);
4676 [ # # ]: 0 : if (ret == TEST_SUCCESS || ret == TEST_SKIPPED) {
4677 [ # # ]: 0 : printf(" %u) TestCase %s: %s\n", i, mldsa_sign_test_vectors[i].name,
4678 : : (ret == TEST_SKIPPED) ? "skipped" : "passed");
4679 : 0 : continue;
4680 : : }
4681 : :
4682 : 0 : printf(" %u) TestCase %s: failed\n", i, mldsa_sign_test_vectors[i].name);
4683 : : overall_status = TEST_FAILED;
4684 : : }
4685 : :
4686 : : return overall_status;
4687 : : }
4688 : :
4689 : : static int
4690 : 0 : test_mldsa_verify(void)
4691 : : {
4692 : : struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
4693 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
4694 : : struct rte_cryptodev_asym_capability_idx idx;
4695 : 0 : uint8_t dev_id = ts_params->valid_devs[0];
4696 : : int overall_status = TEST_SUCCESS;
4697 : : int ret;
4698 : :
4699 : : /* Check if ML-DSA is supported */
4700 : 0 : idx.type = RTE_CRYPTO_ASYM_XFORM_ML_DSA;
4701 : 0 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
4702 [ # # ]: 0 : if (capa == NULL) {
4703 : 0 : RTE_LOG(DEBUG, USER1,
4704 : : "Device doesn't support ML-DSA. Test skipped\n");
4705 : 0 : return TEST_SKIPPED;
4706 : : }
4707 : :
4708 [ # # ]: 0 : if (!(capa->op_types & (1 << RTE_CRYPTO_ML_DSA_OP_VERIFY))) {
4709 : 0 : RTE_LOG(DEBUG, USER1,
4710 : : "Device doesn't support ML-DSA verify operation. Test skipped\n");
4711 : 0 : return TEST_SKIPPED;
4712 : : }
4713 : :
4714 [ # # ]: 0 : for (uint8_t i = 0; i < RTE_DIM(mldsa_verify_test_vectors); i++) {
4715 : 0 : if (!(capa->mldsa_capa[RTE_CRYPTO_ML_DSA_OP_VERIFY] &
4716 [ # # ]: 0 : (1 << mldsa_verify_test_vectors[i].type))) {
4717 : 0 : RTE_LOG(DEBUG, USER1,
4718 : : "Device doesn't support ML-DSA param %u. TestCase %s skipped\n",
4719 : : mldsa_verify_test_vectors[i].type,
4720 : : mldsa_verify_test_vectors[i].name);
4721 : 0 : printf(" %u) TestCase %s: skipped\n", i,
4722 : : mldsa_verify_test_vectors[i].name);
4723 : 0 : continue;
4724 : : }
4725 : 0 : ret = mldsa_verify(&mldsa_verify_test_vectors[i]);
4726 [ # # ]: 0 : if (ret == TEST_SUCCESS || ret == TEST_SKIPPED) {
4727 [ # # ]: 0 : printf(" %u) TestCase %s: %s\n", i, mldsa_verify_test_vectors[i].name,
4728 : : (ret == TEST_SKIPPED) ? "skipped" : "passed");
4729 : 0 : continue;
4730 : : }
4731 : :
4732 : 0 : printf(" %u) TestCase %s: failed\n", i, mldsa_verify_test_vectors[i].name);
4733 : : overall_status = TEST_FAILED;
4734 : : }
4735 : :
4736 : : return overall_status;
4737 : : }
4738 : :
4739 : : #define SET_RSA_PARAM(arg, vector, coef) \
4740 : : uint8_t coef[TEST_DATA_SIZE] = { }; \
4741 : : memcpy(coef, vector->coef.data, vector->coef.len); \
4742 : : arg.coef.data = coef; \
4743 : : arg.coef.length = vector->coef.len
4744 : :
4745 : : #define SET_RSA_PARAM_QT(arg, vector, coef) \
4746 : : uint8_t coef[TEST_DATA_SIZE] = { }; \
4747 : : memcpy(coef, vector->coef.data, vector->coef.len); \
4748 : : arg.qt.coef.data = coef; \
4749 : : arg.qt.coef.length = vector->coef.len
4750 : :
4751 : : static int
4752 : 2 : rsa_encrypt(const struct rsa_test_data_2 *vector, uint8_t *cipher_buf)
4753 : : {
4754 : 2 : self->result_op = NULL;
4755 : : /* Compute encryption on the test vector */
4756 : 2 : self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
4757 : 2 : self->op->asym->rsa.cipher.data = cipher_buf;
4758 : 2 : self->op->asym->rsa.cipher.length = 0;
4759 [ + - ]: 2 : SET_RSA_PARAM(self->op->asym->rsa, vector, message);
4760 : :
4761 [ + - ]: 2 : rte_crypto_op_attach_asym_session(self->op, self->sess);
4762 [ - + ]: 2 : TEST_ASSERT_SUCCESS(send_one(),
4763 : : "Failed to process crypto op (Enryption)");
4764 : :
4765 : : return 0;
4766 : : }
4767 : :
4768 : : static int
4769 : 2 : rsa_decrypt(const struct rsa_test_data_2 *vector, uint8_t *plaintext,
4770 : : const int use_op)
4771 : : {
4772 : 2 : uint8_t cipher[TEST_DATA_SIZE] = { 0 };
4773 : :
4774 [ + - ]: 2 : if (use_op == 0) {
4775 : 2 : memcpy(cipher, vector->cipher.data, vector->cipher.len);
4776 : 2 : self->op->asym->rsa.cipher.data = cipher;
4777 : 2 : self->op->asym->rsa.cipher.length = vector->cipher.len;
4778 : : }
4779 : 2 : self->result_op = NULL;
4780 : 2 : self->op->asym->rsa.message.data = plaintext;
4781 : 2 : self->op->asym->rsa.message.length = 0;
4782 : 2 : self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
4783 [ + - ]: 2 : rte_crypto_op_attach_asym_session(self->op, self->sess);
4784 [ - + ]: 2 : TEST_ASSERT_SUCCESS(send_one(),
4785 : : "Failed to process crypto op (Decryption)");
4786 : : return 0;
4787 : : }
4788 : :
4789 : : static int
4790 : 4 : rsa_init_session(struct rte_crypto_asym_xform *xform)
4791 : : {
4792 : 4 : const uint8_t dev_id = params->valid_devs[0];
4793 : : struct rte_cryptodev_info dev_info;
4794 : : int ret = 0;
4795 : :
4796 : 4 : xform->xform_type = RTE_CRYPTO_ASYM_XFORM_RSA;
4797 : :
4798 : 4 : rte_cryptodev_info_get(dev_id, &dev_info);
4799 [ - + ]: 4 : if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
4800 : 0 : RTE_LOG(INFO, USER1,
4801 : : "Device doesn't support decrypt op with quintuple key type. Test skipped\n");
4802 : 0 : return TEST_SKIPPED;
4803 : : }
4804 : 4 : ret = rte_cryptodev_asym_session_create(dev_id, xform,
4805 : 4 : params->session_mpool, &self->sess);
4806 [ - + ]: 4 : if (ret < 0) {
4807 : 0 : RTE_LOG(ERR, USER1,
4808 : : "Session creation failed for enc_dec_crt\n");
4809 [ # # ]: 0 : return (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
4810 : : }
4811 : : return 0;
4812 : : }
4813 : :
4814 : : static int
4815 : 1 : kat_rsa_encrypt(const void *data)
4816 : : {
4817 : 1 : uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
4818 : : const struct rsa_test_data_2 *vector = data;
4819 : 1 : struct rte_crypto_asym_xform xform = { };
4820 : :
4821 : 1 : SET_RSA_PARAM(xform.rsa, vector, n);
4822 : 1 : SET_RSA_PARAM(xform.rsa, vector, e);
4823 : 1 : SET_RSA_PARAM(xform.rsa, vector, d);
4824 : 1 : xform.rsa.padding.type = vector->padding;
4825 : : xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
4826 : 1 : int ret = rsa_init_session(&xform);
4827 : :
4828 [ - + ]: 1 : if (ret) {
4829 : 0 : RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
4830 : 0 : return ret;
4831 : : }
4832 [ - + ]: 1 : TEST_ASSERT_SUCCESS(rsa_encrypt(vector, cipher_buf),
4833 : : "RSA: Failed to encrypt");
4834 [ - + ]: 1 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data,
4835 : : self->result_op->asym->rsa.cipher.data,
4836 : : self->result_op->asym->rsa.cipher.length,
4837 : : "operation verification failed\n");
4838 : : return 0;
4839 : : }
4840 : :
4841 : : static int
4842 : 1 : kat_rsa_encrypt_crt(const void *data)
4843 : : {
4844 : 1 : uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
4845 : : const struct rsa_test_data_2 *vector = data;
4846 : 1 : struct rte_crypto_asym_xform xform = { };
4847 : :
4848 : 1 : SET_RSA_PARAM(xform.rsa, vector, n);
4849 : 1 : SET_RSA_PARAM(xform.rsa, vector, e);
4850 : 1 : SET_RSA_PARAM_QT(xform.rsa, vector, p);
4851 : 1 : SET_RSA_PARAM_QT(xform.rsa, vector, q);
4852 : 1 : SET_RSA_PARAM_QT(xform.rsa, vector, dP);
4853 : 1 : SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
4854 : 1 : SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
4855 : 1 : xform.rsa.padding.type = vector->padding;
4856 : 1 : xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
4857 : 1 : int ret = rsa_init_session(&xform);
4858 [ - + ]: 1 : if (ret) {
4859 : 0 : RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
4860 : 0 : return ret;
4861 : : }
4862 [ - + ]: 1 : TEST_ASSERT_SUCCESS(rsa_encrypt(vector, cipher_buf),
4863 : : "RSA: Failed to encrypt");
4864 [ - + ]: 1 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data,
4865 : : self->result_op->asym->rsa.cipher.data,
4866 : : self->result_op->asym->rsa.cipher.length,
4867 : : "operation verification failed\n");
4868 : : return 0;
4869 : : }
4870 : :
4871 : : static int
4872 : 1 : kat_rsa_decrypt(const void *data)
4873 : : {
4874 : 1 : uint8_t message[TEST_DATA_SIZE] = {0};
4875 : : const struct rsa_test_data_2 *vector = data;
4876 : 1 : struct rte_crypto_asym_xform xform = { };
4877 : :
4878 : 1 : SET_RSA_PARAM(xform.rsa, vector, n);
4879 : 1 : SET_RSA_PARAM(xform.rsa, vector, e);
4880 : 1 : SET_RSA_PARAM(xform.rsa, vector, d);
4881 : 1 : xform.rsa.padding.type = vector->padding;
4882 : : xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
4883 : 1 : int ret = rsa_init_session(&xform);
4884 : :
4885 [ - + ]: 1 : if (ret) {
4886 : 0 : RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
4887 : 0 : return ret;
4888 : : }
4889 [ - + ]: 1 : TEST_ASSERT_SUCCESS(rsa_decrypt(vector, message, 0),
4890 : : "RSA: Failed to encrypt");
4891 [ - + ]: 1 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->message.data,
4892 : : self->result_op->asym->rsa.message.data,
4893 : : self->result_op->asym->rsa.message.length,
4894 : : "operation verification failed\n");
4895 : : return 0;
4896 : : }
4897 : :
4898 : : static int
4899 : 1 : kat_rsa_decrypt_crt(const void *data)
4900 : : {
4901 : 1 : uint8_t message[TEST_DATA_SIZE] = {0};
4902 : : const struct rsa_test_data_2 *vector = data;
4903 : 1 : struct rte_crypto_asym_xform xform = { };
4904 : :
4905 : 1 : SET_RSA_PARAM(xform.rsa, vector, n);
4906 : 1 : SET_RSA_PARAM(xform.rsa, vector, e);
4907 : 1 : SET_RSA_PARAM_QT(xform.rsa, vector, p);
4908 : 1 : SET_RSA_PARAM_QT(xform.rsa, vector, q);
4909 : 1 : SET_RSA_PARAM_QT(xform.rsa, vector, dP);
4910 : 1 : SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
4911 : 1 : SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
4912 : 1 : xform.rsa.padding.type = vector->padding;
4913 : 1 : xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
4914 : 1 : int ret = rsa_init_session(&xform);
4915 [ - + ]: 1 : if (ret) {
4916 : 0 : RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
4917 : 0 : return ret;
4918 : : }
4919 [ - + ]: 1 : TEST_ASSERT_SUCCESS(rsa_decrypt(vector, message, 0),
4920 : : "RSA: Failed to encrypt");
4921 [ - + ]: 1 : TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->message.data,
4922 : : self->result_op->asym->rsa.message.data,
4923 : : self->result_op->asym->rsa.message.length,
4924 : : "operation verification failed\n");
4925 : : return 0;
4926 : : }
4927 : :
4928 : : static int
4929 : 1 : test_sm2_partial_encryption(const void *data)
4930 : : {
4931 : 1 : struct rte_crypto_asym_xform xform = { 0 };
4932 : 1 : const uint8_t dev_id = params->valid_devs[0];
4933 : : const struct crypto_testsuite_sm2_params *test_vector = data;
4934 : 1 : uint8_t result_C1_x1[TEST_DATA_SIZE] = { 0 };
4935 : 1 : uint8_t result_C1_y1[TEST_DATA_SIZE] = { 0 };
4936 : 1 : uint8_t result_kP_x1[TEST_DATA_SIZE] = { 0 };
4937 : 1 : uint8_t result_kP_y1[TEST_DATA_SIZE] = { 0 };
4938 : : struct rte_cryptodev_asym_capability_idx idx;
4939 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
4940 : :
4941 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
4942 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
4943 [ + - ]: 1 : if (capa == NULL)
4944 : : return TEST_SKIPPED;
4945 [ - + ]: 1 : if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
4946 : : RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_PARTIAL)) {
4947 : : return TEST_SKIPPED;
4948 : : }
4949 : :
4950 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
4951 : 0 : xform.ec.curve_id = RTE_CRYPTO_EC_GROUP_SM2;
4952 : 0 : xform.ec.q = test_vector->pubkey;
4953 : 0 : self->op->asym->sm2.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
4954 : 0 : self->op->asym->sm2.k = test_vector->k;
4955 [ # # ]: 0 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
4956 : 0 : params->session_mpool, &self->sess) < 0) {
4957 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
4958 : : __LINE__);
4959 : 0 : return TEST_FAILED;
4960 : : }
4961 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
4962 : :
4963 : 0 : self->op->asym->sm2.c1.x.data = result_C1_x1;
4964 : 0 : self->op->asym->sm2.c1.y.data = result_C1_y1;
4965 : 0 : self->op->asym->sm2.kp.x.data = result_kP_x1;
4966 : 0 : self->op->asym->sm2.kp.y.data = result_kP_y1;
4967 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
4968 : : "Failed to process crypto op");
4969 : :
4970 : 0 : debug_hexdump(stdout, "C1[x]", self->op->asym->sm2.c1.x.data,
4971 : 0 : self->op->asym->sm2.c1.x.length);
4972 : 0 : debug_hexdump(stdout, "C1[y]", self->op->asym->sm2.c1.y.data,
4973 : 0 : self->op->asym->sm2.c1.y.length);
4974 : 0 : debug_hexdump(stdout, "kP[x]", self->op->asym->sm2.kp.x.data,
4975 : 0 : self->op->asym->sm2.kp.x.length);
4976 : 0 : debug_hexdump(stdout, "kP[y]", self->op->asym->sm2.kp.y.data,
4977 : 0 : self->op->asym->sm2.kp.y.length);
4978 : :
4979 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(test_vector->C1.x.data,
4980 : : self->op->asym->sm2.c1.x.data,
4981 : : test_vector->C1.x.length,
4982 : : "Incorrect value of C1[x]\n");
4983 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(test_vector->C1.y.data,
4984 : : self->op->asym->sm2.c1.y.data,
4985 : : test_vector->C1.y.length,
4986 : : "Incorrect value of C1[y]\n");
4987 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(test_vector->kP.x.data,
4988 : : self->op->asym->sm2.kp.x.data,
4989 : : test_vector->kP.x.length,
4990 : : "Incorrect value of kP[x]\n");
4991 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(test_vector->kP.y.data,
4992 : : self->op->asym->sm2.kp.y.data,
4993 : : test_vector->kP.y.length,
4994 : : "Incorrect value of kP[y]\n");
4995 : :
4996 : : return TEST_SUCCESS;
4997 : : }
4998 : :
4999 : : static int
5000 : 1 : test_sm2_partial_decryption(const void *data)
5001 : : {
5002 : 1 : struct rte_crypto_asym_xform xform = {};
5003 : 1 : const uint8_t dev_id = params->valid_devs[0];
5004 : : const struct crypto_testsuite_sm2_params *test_vector = data;
5005 : 1 : uint8_t result_kP_x1[TEST_DATA_SIZE] = { 0 };
5006 : 1 : uint8_t result_kP_y1[TEST_DATA_SIZE] = { 0 };
5007 : : struct rte_cryptodev_asym_capability_idx idx;
5008 : : const struct rte_cryptodev_asymmetric_xform_capability *capa;
5009 : :
5010 : 1 : idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
5011 : 1 : capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
5012 [ + - ]: 1 : if (capa == NULL)
5013 : : return TEST_SKIPPED;
5014 [ - + ]: 1 : if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
5015 : : RTE_CRYPTO_ASYM_OP_DECRYPT, RTE_CRYPTO_SM2_PARTIAL)) {
5016 : : return TEST_SKIPPED;
5017 : : }
5018 : :
5019 : 0 : xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
5020 : 0 : xform.ec.pkey = test_vector->pkey;
5021 : 0 : self->op->asym->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
5022 : 0 : self->op->asym->sm2.c1 = test_vector->C1;
5023 : :
5024 [ # # ]: 0 : if (rte_cryptodev_asym_session_create(dev_id, &xform,
5025 : 0 : params->session_mpool, &self->sess) < 0) {
5026 : 0 : RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
5027 : : __LINE__);
5028 : 0 : return TEST_FAILED;
5029 : : }
5030 [ # # ]: 0 : rte_crypto_op_attach_asym_session(self->op, self->sess);
5031 : :
5032 : 0 : self->op->asym->sm2.kp.x.data = result_kP_x1;
5033 : 0 : self->op->asym->sm2.kp.y.data = result_kP_y1;
5034 [ # # ]: 0 : TEST_ASSERT_SUCCESS(send_one(),
5035 : : "Failed to process crypto op");
5036 : :
5037 : 0 : debug_hexdump(stdout, "kP[x]", self->op->asym->sm2.kp.x.data,
5038 : 0 : self->op->asym->sm2.c1.x.length);
5039 : 0 : debug_hexdump(stdout, "kP[y]", self->op->asym->sm2.kp.y.data,
5040 : 0 : self->op->asym->sm2.c1.y.length);
5041 : :
5042 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(test_vector->kP.x.data,
5043 : : self->op->asym->sm2.kp.x.data,
5044 : : test_vector->kP.x.length,
5045 : : "Incorrect value of kP[x]\n");
5046 [ # # ]: 0 : TEST_ASSERT_BUFFERS_ARE_EQUAL(test_vector->kP.y.data,
5047 : : self->op->asym->sm2.kp.y.data,
5048 : : test_vector->kP.y.length,
5049 : : "Incorrect value of kP[y]\n");
5050 : :
5051 : : return 0;
5052 : : }
5053 : :
5054 : : static int
5055 : : check_asym_capabilities_supported(const enum rte_crypto_asym_xform_type xform_type)
5056 : : {
5057 : 12 : uint8_t dev_id = testsuite_params.valid_devs[0];
5058 : 12 : struct rte_cryptodev_asym_capability_idx idx = {xform_type};
5059 : :
5060 [ - + - + : 12 : if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
+ - + - +
- + - + -
- + - + -
+ + - +
- ]
5061 : : return TEST_SKIPPED;
5062 : : return 0;
5063 : : }
5064 : :
5065 : : static int
5066 : 1 : crypto_asym_dh_testsuite_setup(void)
5067 : : {
5068 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_DH) != 0) {
5069 : 0 : RTE_LOG(INFO, USER1,
5070 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5071 : 0 : return TEST_SKIPPED;
5072 : : }
5073 : : return 0;
5074 : : }
5075 : :
5076 : : static int
5077 : 1 : crypto_asym_dsa_testsuite_setup(void)
5078 : : {
5079 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_DSA) != 0) {
5080 : 0 : RTE_LOG(INFO, USER1,
5081 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5082 : 0 : return TEST_SKIPPED;
5083 : : }
5084 : : return 0;
5085 : : }
5086 : :
5087 : : static int
5088 : 1 : crypto_asym_ecdh_testsuite_setup(void)
5089 : : {
5090 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_ECDH) != 0) {
5091 : 1 : RTE_LOG(INFO, USER1,
5092 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5093 : 1 : return TEST_SKIPPED;
5094 : : }
5095 : : return 0;
5096 : : }
5097 : :
5098 : : static int
5099 : 1 : crypto_asym_ecdsa_testsuite_setup(void)
5100 : : {
5101 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_ECDSA) != 0) {
5102 : 1 : RTE_LOG(INFO, USER1,
5103 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5104 : 1 : return TEST_SKIPPED;
5105 : : }
5106 : : return 0;
5107 : : }
5108 : :
5109 : : static int
5110 : 1 : crypto_asym_ecpm_testsuite_setup(void)
5111 : : {
5112 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_ECPM) != 0) {
5113 : 1 : RTE_LOG(INFO, USER1,
5114 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5115 : 1 : return TEST_SKIPPED;
5116 : : }
5117 : : return 0;
5118 : : }
5119 : :
5120 : : static int
5121 : 1 : crypto_asym_eddsa_testsuite_setup(void)
5122 : : {
5123 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_EDDSA) != 0) {
5124 : 0 : RTE_LOG(INFO, USER1,
5125 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5126 : 0 : return TEST_SKIPPED;
5127 : : }
5128 : : return 0;
5129 : : }
5130 : :
5131 : : static int
5132 : 1 : crypto_asym_mod_ex_testsuite_setup(void)
5133 : : {
5134 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_MODEX) != 0) {
5135 : 0 : RTE_LOG(INFO, USER1,
5136 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5137 : 0 : return TEST_SKIPPED;
5138 : : }
5139 : : return 0;
5140 : : }
5141 : :
5142 : : static int
5143 : 1 : crypto_asym_mod_inv_testsuite_setup(void)
5144 : : {
5145 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_MODINV) != 0) {
5146 : 0 : RTE_LOG(INFO, USER1,
5147 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5148 : 0 : return TEST_SKIPPED;
5149 : : }
5150 : : return 0;
5151 : : }
5152 : :
5153 : : static int
5154 : 1 : crypto_asym_rsa_testsuite_setup(void)
5155 : : {
5156 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_RSA) != 0) {
5157 : 0 : RTE_LOG(INFO, USER1,
5158 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5159 : 0 : return TEST_SKIPPED;
5160 : : }
5161 : : return 0;
5162 : : }
5163 : :
5164 : : static int
5165 : 1 : crypto_asym_sm2_testsuite_setup(void)
5166 : : {
5167 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_SM2) != 0) {
5168 : 0 : RTE_LOG(INFO, USER1,
5169 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5170 : 0 : return TEST_SKIPPED;
5171 : : }
5172 : : return 0;
5173 : : }
5174 : :
5175 : : static int
5176 : 1 : crypto_asym_ml_kem_testsuite_setup(void)
5177 : : {
5178 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_ML_KEM) != 0) {
5179 : 1 : RTE_LOG(INFO, USER1,
5180 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5181 : 1 : return TEST_SKIPPED;
5182 : : }
5183 : : return 0;
5184 : : }
5185 : :
5186 : : static int
5187 : 1 : crypto_asym_ml_dsa_testsuite_setup(void)
5188 : : {
5189 : : if (check_asym_capabilities_supported(RTE_CRYPTO_ASYM_XFORM_ML_DSA) != 0) {
5190 : 1 : RTE_LOG(INFO, USER1,
5191 : : "Device doesn't support required ASYM capabilities. Test skipped\n");
5192 : 1 : return TEST_SKIPPED;
5193 : : }
5194 : : return 0;
5195 : : }
5196 : :
5197 : : static struct unit_test_suite cryptodev_asym_gen_testsuite = {
5198 : : .suite_name = "Cryptodev ASYM General Unit Test Suite",
5199 : : .unit_test_cases = {
5200 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
5201 : : TEST_CASES_END()
5202 : : }
5203 : : };
5204 : :
5205 : : static struct unit_test_suite cryptodev_asym_dh_testsuite = {
5206 : : .suite_name = "Cryptodev ASYM DH Unit Test Suite",
5207 : : .setup = crypto_asym_dh_testsuite_setup,
5208 : : .unit_test_cases = {
5209 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dh_key_generation),
5210 : : TEST_CASES_END() /**< NULL terminate unit test array */
5211 : : }
5212 : : };
5213 : :
5214 : : static struct unit_test_suite cryptodev_asym_dsa_testsuite = {
5215 : : .suite_name = "Cryptodev ASYM DSA Unit Test Suite",
5216 : : .setup = crypto_asym_dsa_testsuite_setup,
5217 : : .unit_test_cases = {
5218 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dsa),
5219 : : TEST_CASES_END()
5220 : : }
5221 : : };
5222 : :
5223 : : static struct unit_test_suite cryptodev_asym_ecdh_testsuite = {
5224 : : .suite_name = "Cryptodev ASYM ECDH Unit Test Suite",
5225 : : .setup = crypto_asym_ecdh_testsuite_setup,
5226 : : .unit_test_cases = {
5227 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
5228 : : test_ecdh_all_curve),
5229 : : TEST_CASE_NAMED_ST(
5230 : : "ECDH Elliptic Curve tests",
5231 : : ut_setup_asym, ut_teardown_asym,
5232 : : test_ecdh_qat_curves),
5233 : : TEST_CASES_END()
5234 : : }
5235 : : };
5236 : :
5237 : : static struct unit_test_suite cryptodev_asym_ecdsa_testsuite = {
5238 : : .suite_name = "Cryptodev ASYM ECDSA Unit Test Suite",
5239 : : .setup = crypto_asym_ecdsa_testsuite_setup,
5240 : : .unit_test_cases = {
5241 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
5242 : : test_ecdsa_sign_verify_all_curve),
5243 : : TEST_CASE_NAMED_ST(
5244 : : "ECDSA Elliptic Curve tests",
5245 : : ut_setup_asym, ut_teardown_asym,
5246 : : test_ecdsa_sign_verify_qat_curves),
5247 : : TEST_CASES_END()
5248 : : }
5249 : : };
5250 : :
5251 : : static struct unit_test_suite cryptodev_asym_ecpm_testsuite = {
5252 : : .suite_name = "Cryptodev ASYM ECPM Unit Test Suite",
5253 : : .setup = crypto_asym_ecpm_testsuite_setup,
5254 : : .unit_test_cases = {
5255 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
5256 : : test_ecpm_all_curve),
5257 : : TEST_CASE_NAMED_ST(
5258 : : "ECPM Elliptic Curve tests",
5259 : : ut_setup_asym, ut_teardown_asym,
5260 : : test_ecpm_qat_curves),
5261 : : TEST_CASES_END()
5262 : : }
5263 : : };
5264 : :
5265 : : static struct unit_test_suite cryptodev_asym_eddsa_testsuite = {
5266 : : .suite_name = "Cryptodev ASYM EdDSA Unit Test Suite",
5267 : : .setup = crypto_asym_eddsa_testsuite_setup,
5268 : : .unit_test_cases = {
5269 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_eddsa_sign_verify_all_curve),
5270 : : TEST_CASES_END()
5271 : : }
5272 : : };
5273 : :
5274 : : static struct unit_test_suite cryptodev_asym_mod_ex_testsuite = {
5275 : : .suite_name = "Cryptodev ASYM MOD Ex Unit Test Suite",
5276 : : .setup = crypto_asym_mod_ex_testsuite_setup,
5277 : : .unit_test_cases = {
5278 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
5279 : : TEST_CASE_NAMED_WITH_DATA(
5280 : : "Modex test for zero padding",
5281 : : ut_setup_asym, ut_teardown_asym,
5282 : : modular_exponentiation, &modex_test_cases[0]),
5283 : : TEST_CASE_NAMED_WITH_DATA(
5284 : : "Modex test for zero padding (2)",
5285 : : ut_setup_asym, ut_teardown_asym,
5286 : : modular_exponentiation, &modex_test_cases[1]),
5287 : : TEST_CASE_NAMED_WITH_DATA(
5288 : : "Modex Group 5 test",
5289 : : ut_setup_asym, ut_teardown_asym,
5290 : : modular_exponentiation, &modex_group_test_cases[0]),
5291 : : TEST_CASE_NAMED_WITH_DATA(
5292 : : "Modex Group 14 test",
5293 : : ut_setup_asym, ut_teardown_asym,
5294 : : modular_exponentiation, &modex_group_test_cases[1]),
5295 : : TEST_CASE_NAMED_WITH_DATA(
5296 : : "Modex Group 15 test",
5297 : : ut_setup_asym, ut_teardown_asym,
5298 : : modular_exponentiation, &modex_group_test_cases[2]),
5299 : : TEST_CASE_NAMED_WITH_DATA(
5300 : : "Modex Group 16 test",
5301 : : ut_setup_asym, ut_teardown_asym,
5302 : : modular_exponentiation, &modex_group_test_cases[3]),
5303 : : TEST_CASE_NAMED_WITH_DATA(
5304 : : "Modex Group 17 test",
5305 : : ut_setup_asym, ut_teardown_asym,
5306 : : modular_exponentiation, &modex_group_test_cases[4]),
5307 : : TEST_CASE_NAMED_WITH_DATA(
5308 : : "Modex Group 18 test",
5309 : : ut_setup_asym, ut_teardown_asym,
5310 : : modular_exponentiation, &modex_group_test_cases[5]),
5311 : : TEST_CASE_NAMED_WITH_DATA(
5312 : : "Modex Group 24 test",
5313 : : ut_setup_asym, ut_teardown_asym,
5314 : : modular_exponentiation, &modex_group_test_cases[6]),
5315 : : TEST_CASE_NAMED_WITH_DATA(
5316 : : "Modex Group 24 subgroup test",
5317 : : ut_setup_asym, ut_teardown_asym,
5318 : : modular_exponentiation, &modex_group_test_cases[7]),
5319 : : TEST_CASE_NAMED_WITH_DATA(
5320 : : "Modular Exponentiation (mod=128, base=20, exp=3, res=128)",
5321 : : ut_setup_asym, ut_teardown_asym,
5322 : : modular_exponentiation, &modex_test_case_m128_b20_e3),
5323 : : TEST_CASES_END()
5324 : : }
5325 : : };
5326 : :
5327 : : static struct unit_test_suite cryptodev_asym_mod_inv_testsuite = {
5328 : : .suite_name = "Cryptodev ASYM MOD Inv Unit Test Suite",
5329 : : .setup = crypto_asym_mod_inv_testsuite_setup,
5330 : : .unit_test_cases = {
5331 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
5332 : : /* Modular Multiplicative Inverse */
5333 : : TEST_CASE_NAMED_WITH_DATA(
5334 : : "Modular Inverse (mod=128, base=20, exp=3, inv=128)",
5335 : : ut_setup_asym, ut_teardown_asym,
5336 : : modular_multiplicative_inverse, &modinv_test_case),
5337 : : TEST_CASES_END()
5338 : : }
5339 : : };
5340 : :
5341 : : static struct unit_test_suite cryptodev_asym_rsa_testsuite = {
5342 : : .suite_name = "Cryptodev ASYM RSA Unit Test Suite",
5343 : : .setup = crypto_asym_rsa_testsuite_setup,
5344 : : .unit_test_cases = {
5345 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
5346 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
5347 : : test_rsa_sign_verify),
5348 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
5349 : : test_rsa_enc_dec_crt),
5350 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
5351 : : test_rsa_sign_verify_crt),
5352 : : /* RSA EXP */
5353 : : TEST_CASE_NAMED_WITH_DATA(
5354 : : "RSA Encryption (n=128, pt=20, e=3) EXP, Padding: NONE",
5355 : : ut_setup_asym, ut_teardown_asym,
5356 : : kat_rsa_encrypt, &rsa_vector_128_20_3_none),
5357 : : TEST_CASE_NAMED_WITH_DATA(
5358 : : "RSA Decryption (n=128, pt=20, e=3) EXP, Padding: NONE",
5359 : : ut_setup_asym, ut_teardown_asym,
5360 : : kat_rsa_decrypt, &rsa_vector_128_20_3_none),
5361 : : /* RSA CRT */
5362 : : TEST_CASE_NAMED_WITH_DATA(
5363 : : "RSA Encryption (n=128, pt=20, e=3) CRT, Padding: NONE",
5364 : : ut_setup_asym, ut_teardown_asym,
5365 : : kat_rsa_encrypt_crt, &rsa_vector_128_20_3_none),
5366 : : TEST_CASE_NAMED_WITH_DATA(
5367 : : "RSA Decryption (n=128, pt=20, e=3) CRT, Padding: NONE",
5368 : : ut_setup_asym, ut_teardown_asym,
5369 : : kat_rsa_decrypt_crt, &rsa_vector_128_20_3_none),
5370 : : TEST_CASES_END()
5371 : : }
5372 : : };
5373 : :
5374 : : static struct unit_test_suite cryptodev_asym_sm2_testsuite = {
5375 : : .suite_name = "Cryptodev ASYM SM2 Unit Test Suite",
5376 : : .setup = crypto_asym_sm2_testsuite_setup,
5377 : : .unit_test_cases = {
5378 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign),
5379 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify),
5380 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_enc),
5381 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_dec),
5382 : : TEST_CASE_NAMED_WITH_DATA(
5383 : : "SM2 encryption - test case 1",
5384 : : ut_setup_asym, ut_teardown_asym,
5385 : : test_sm2_partial_encryption, &sm2_enc_hw_t1),
5386 : : TEST_CASE_NAMED_WITH_DATA(
5387 : : "SM2 decryption - test case 1",
5388 : : ut_setup_asym, ut_teardown_asym,
5389 : : test_sm2_partial_decryption, &sm2_enc_hw_t1),
5390 : : TEST_CASES_END()
5391 : : }
5392 : : };
5393 : :
5394 : : static struct unit_test_suite cryptodev_asym_ml_kem_testsuite = {
5395 : : .suite_name = "Cryptodev ASYM ML KEM Unit Test Suite",
5396 : : .setup = crypto_asym_ml_kem_testsuite_setup,
5397 : : .unit_test_cases = {
5398 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mlkem_keygen),
5399 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mlkem_encap),
5400 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mlkem_decap),
5401 : : TEST_CASES_END()
5402 : : }
5403 : : };
5404 : :
5405 : : static struct unit_test_suite cryptodev_asym_ml_dsa_testsuite = {
5406 : : .suite_name = "Cryptodev ASYM ML DSA Unit Test Suite",
5407 : : .setup = crypto_asym_ml_dsa_testsuite_setup,
5408 : : .unit_test_cases = {
5409 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mldsa_keygen),
5410 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mldsa_sign),
5411 : : TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mldsa_verify),
5412 : : TEST_CASES_END()
5413 : : }
5414 : : };
5415 : :
5416 : : static struct unit_test_suite end_testsuite = {
5417 : : .suite_name = NULL,
5418 : : .setup = NULL,
5419 : : .teardown = NULL,
5420 : : .unit_test_suites = NULL
5421 : : };
5422 : :
5423 : : static int
5424 : 1 : run_cryptodev_asym_testsuite(const char *pmd_name)
5425 : : {
5426 : : uint8_t ret, j, i = 0;
5427 : :
5428 : 1 : struct unit_test_suite *asym_suites[] = {
5429 : : &cryptodev_asym_gen_testsuite,
5430 : : &cryptodev_asym_dh_testsuite,
5431 : : &cryptodev_asym_dsa_testsuite,
5432 : : &cryptodev_asym_ecdh_testsuite,
5433 : : &cryptodev_asym_ecdsa_testsuite,
5434 : : &cryptodev_asym_ecpm_testsuite,
5435 : : &cryptodev_asym_eddsa_testsuite,
5436 : : &cryptodev_asym_mod_ex_testsuite,
5437 : : &cryptodev_asym_mod_inv_testsuite,
5438 : : &cryptodev_asym_rsa_testsuite,
5439 : : &cryptodev_asym_sm2_testsuite,
5440 : : &cryptodev_asym_ml_kem_testsuite,
5441 : : &cryptodev_asym_ml_dsa_testsuite,
5442 : : &end_testsuite
5443 : : };
5444 : :
5445 : : static struct unit_test_suite asym_ts = {
5446 : : .suite_name = "Cryptodev ASYM Unit Test Suite",
5447 : : .setup = testsuite_setup,
5448 : : .teardown = testsuite_teardown,
5449 : : .unit_test_cases = {TEST_CASES_END()}
5450 : : };
5451 : :
5452 : 1 : gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
5453 [ - + ]: 1 : if (gbl_driver_id == -1) {
5454 : 0 : RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
5455 : 0 : return TEST_SKIPPED;
5456 : : }
5457 : :
5458 : 1 : asym_ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) * RTE_DIM(asym_suites));
5459 [ - + ]: 1 : if (asym_ts.unit_test_suites == NULL) {
5460 : 0 : RTE_LOG(ERR, USER1,
5461 : : "Failed to allocate memory for unit test suites\n");
5462 : 0 : return TEST_FAILED;
5463 : : }
5464 : :
5465 [ + + ]: 15 : ADD_ASYM_TESTSUITE(i, asym_ts, asym_suites, RTE_DIM(asym_suites));
5466 : 1 : ret = unit_test_suite_runner(&asym_ts);
5467 : :
5468 : 1 : free(asym_ts.unit_test_suites);
5469 : :
5470 : 1 : return ret;
5471 : : }
5472 : :
5473 : : static int
5474 : 1 : test_cryptodev_openssl_asym(void)
5475 : : {
5476 : 1 : return run_cryptodev_asym_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
5477 : : }
5478 : :
5479 : : static int
5480 : 0 : test_cryptodev_qat_asym(void)
5481 : : {
5482 : 0 : return run_cryptodev_asym_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
5483 : : }
5484 : :
5485 : : static int
5486 : 0 : test_cryptodev_octeontx_asym(void)
5487 : : {
5488 : 0 : return run_cryptodev_asym_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
5489 : : }
5490 : :
5491 : : static int
5492 : 0 : test_cryptodev_cn9k_asym(void)
5493 : : {
5494 : 0 : return run_cryptodev_asym_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
5495 : : }
5496 : :
5497 : : static int
5498 : 0 : test_cryptodev_cn10k_asym(void)
5499 : : {
5500 : 0 : return run_cryptodev_asym_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
5501 : : }
5502 : :
5503 : : static int
5504 : 0 : test_cryptodev_cn20k_asym(void)
5505 : : {
5506 : 0 : return run_cryptodev_asym_testsuite(RTE_STR(CRYPTODEV_NAME_CN20K_PMD));
5507 : : }
5508 : :
5509 : : static int
5510 : 0 : test_cryptodev_virtio_asym(void)
5511 : : {
5512 : 0 : return run_cryptodev_asym_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
5513 : : }
5514 : :
5515 : : static int
5516 : 0 : test_cryptodev_virtio_user_asym(void)
5517 : : {
5518 : 0 : return run_cryptodev_asym_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_USER_PMD));
5519 : : }
5520 : :
5521 : 301 : REGISTER_DRIVER_TEST(cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);
5522 : 301 : REGISTER_DRIVER_TEST(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
5523 : 301 : REGISTER_DRIVER_TEST(cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);
5524 : 301 : REGISTER_DRIVER_TEST(cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);
5525 : 301 : REGISTER_DRIVER_TEST(cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);
5526 : 301 : REGISTER_DRIVER_TEST(cryptodev_cn20k_asym_autotest, test_cryptodev_cn20k_asym);
5527 : 301 : REGISTER_DRIVER_TEST(cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym);
5528 : 301 : REGISTER_DRIVER_TEST(cryptodev_virtio_user_asym_autotest, test_cryptodev_virtio_user_asym);
|