1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium Networks
3 * Copyright (c) 2019 Intel Corporation
6 #ifndef RTE_EXEC_ENV_WINDOWS
8 #include <rte_bus_vdev.h>
9 #include <rte_common.h>
10 #include <rte_hexdump.h>
12 #include <rte_malloc.h>
13 #include <rte_memcpy.h>
14 #include <rte_pause.h>
16 #include <rte_cryptodev.h>
17 #include <rte_crypto.h>
19 #include "test_cryptodev.h"
20 #include "test_cryptodev_dh_test_vectors.h"
21 #include "test_cryptodev_dsa_test_vectors.h"
22 #include "test_cryptodev_ecdsa_test_vectors.h"
23 #include "test_cryptodev_ecpm_test_vectors.h"
24 #include "test_cryptodev_mod_test_vectors.h"
25 #include "test_cryptodev_rsa_test_vectors.h"
26 #include "test_cryptodev_asym_util.h"
29 #define TEST_NUM_BUFS 10
30 #define TEST_NUM_SESSIONS 4
32 #ifndef TEST_DATA_SIZE
33 #define TEST_DATA_SIZE 4096
35 #define ASYM_TEST_MSG_LEN 256
36 #define TEST_VECTOR_SIZE 256
38 static int gbl_driver_id;
39 struct crypto_testsuite_params_asym {
40 struct rte_mempool *op_mpool;
41 struct rte_mempool *session_mpool;
42 struct rte_cryptodev_config conf;
43 struct rte_cryptodev_qp_conf qp_conf;
44 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
45 uint8_t valid_dev_count;
48 struct crypto_unittest_params {
49 struct rte_cryptodev_asym_session *sess;
50 struct rte_crypto_op *op;
53 union test_case_structure {
54 struct modex_test_data modex;
55 struct modinv_test_data modinv;
56 struct rsa_test_data_2 rsa_data;
59 struct test_cases_array {
61 const void *address[TEST_VECTOR_SIZE];
63 static struct test_cases_array test_vector = {0, { NULL } };
65 static uint32_t test_index;
67 static struct crypto_testsuite_params_asym testsuite_params = { NULL };
70 queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
72 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
73 struct rte_mempool *op_mpool = ts_params->op_mpool;
74 uint8_t dev_id = ts_params->valid_devs[0];
75 struct rte_crypto_op *op, *result_op;
76 struct rte_crypto_asym_op *asym_op;
77 uint8_t output_buf[TEST_DATA_SIZE];
78 int status = TEST_SUCCESS;
80 /* Set up crypto op data structure */
81 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
83 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
84 "operation struct\n");
90 /* Compute sign on the test vector */
91 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
93 asym_op->rsa.message.data = rsaplaintext.data;
94 asym_op->rsa.message.length = rsaplaintext.len;
95 asym_op->rsa.sign.length = 0;
96 asym_op->rsa.sign.data = output_buf;
97 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
99 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
100 asym_op->rsa.message.length);
102 /* Attach asymmetric crypto session to crypto operations */
103 rte_crypto_op_attach_asym_session(op, sess);
105 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
107 /* Process crypto operation */
108 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
109 RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
110 status = TEST_FAILED;
114 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
117 if (result_op == NULL) {
118 RTE_LOG(ERR, USER1, "Failed to process sign op\n");
119 status = TEST_FAILED;
123 debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
124 asym_op->rsa.sign.length);
125 asym_op = result_op->asym;
128 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
129 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
131 /* Process crypto operation */
132 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
133 RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
134 status = TEST_FAILED;
138 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
141 if (result_op == NULL) {
142 RTE_LOG(ERR, USER1, "Failed to process verify op\n");
143 status = TEST_FAILED;
147 status = TEST_SUCCESS;
148 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
149 RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
150 status = TEST_FAILED;
155 rte_crypto_op_free(op);
161 queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
163 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
164 struct rte_mempool *op_mpool = ts_params->op_mpool;
165 uint8_t dev_id = ts_params->valid_devs[0];
166 struct rte_crypto_op *op, *result_op;
167 struct rte_crypto_asym_op *asym_op;
168 uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
169 int ret, status = TEST_SUCCESS;
171 /* Set up crypto op data structure */
172 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
174 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
175 "operation struct\n");
181 /* Compute encryption on the test vector */
182 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
184 asym_op->rsa.message.data = rsaplaintext.data;
185 asym_op->rsa.cipher.data = cipher_buf;
186 asym_op->rsa.cipher.length = 0;
187 asym_op->rsa.message.length = rsaplaintext.len;
188 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
190 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
191 asym_op->rsa.message.length);
193 /* Attach asymmetric crypto session to crypto operations */
194 rte_crypto_op_attach_asym_session(op, sess);
196 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
198 /* Process crypto operation */
199 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
200 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
201 status = TEST_FAILED;
205 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
208 if (result_op == NULL) {
209 RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
210 status = TEST_FAILED;
213 debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
214 asym_op->rsa.message.length);
216 /* Use the resulted output as decryption Input vector*/
217 asym_op = result_op->asym;
218 asym_op->rsa.message.length = 0;
219 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
220 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
222 /* Process crypto operation */
223 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
224 RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
225 status = TEST_FAILED;
229 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
232 if (result_op == NULL) {
233 RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
234 status = TEST_FAILED;
237 status = TEST_SUCCESS;
238 ret = rsa_verify(&rsaplaintext, result_op);
240 status = TEST_FAILED;
244 rte_crypto_op_free(op);
249 test_cryptodev_asym_ver(struct rte_crypto_op *op,
250 struct rte_crypto_asym_xform *xform_tc,
251 union test_case_structure *data_tc,
252 struct rte_crypto_op *result_op)
254 int status = TEST_FAILED;
256 uint8_t *data_expected = NULL, *data_received = NULL;
257 size_t data_size = 0;
259 switch (data_tc->modex.xform_type) {
260 case RTE_CRYPTO_ASYM_XFORM_MODEX:
261 data_expected = data_tc->modex.reminder.data;
262 data_received = result_op->asym->modex.result.data;
263 data_size = result_op->asym->modex.result.length;
265 case RTE_CRYPTO_ASYM_XFORM_MODINV:
266 data_expected = data_tc->modinv.inverse.data;
267 data_received = result_op->asym->modinv.result.data;
268 data_size = result_op->asym->modinv.result.length;
270 case RTE_CRYPTO_ASYM_XFORM_RSA:
271 if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
272 data_size = xform_tc->rsa.n.length;
273 data_received = result_op->asym->rsa.cipher.data;
274 data_expected = data_tc->rsa_data.ct.data;
275 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
276 data_size = xform_tc->rsa.n.length;
277 data_expected = data_tc->rsa_data.pt.data;
278 data_received = result_op->asym->rsa.message.data;
279 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
280 data_size = xform_tc->rsa.n.length;
281 data_expected = data_tc->rsa_data.sign.data;
282 data_received = result_op->asym->rsa.sign.data;
283 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
284 data_size = xform_tc->rsa.n.length;
285 data_expected = data_tc->rsa_data.pt.data;
286 data_received = result_op->asym->rsa.cipher.data;
289 case RTE_CRYPTO_ASYM_XFORM_DH:
290 case RTE_CRYPTO_ASYM_XFORM_DSA:
291 case RTE_CRYPTO_ASYM_XFORM_NONE:
292 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
296 ret = memcmp(data_expected, data_received, data_size);
297 if (!ret && data_size)
298 status = TEST_SUCCESS;
304 test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
305 union test_case_structure *data_tc,
306 char *test_msg, int sessionless, enum rte_crypto_asym_op_type type,
307 enum rte_crypto_rsa_priv_key_type key_type)
309 struct rte_crypto_asym_op *asym_op = NULL;
310 struct rte_crypto_op *op = NULL;
311 struct rte_crypto_op *result_op = NULL;
312 struct rte_crypto_asym_xform xform_tc;
313 struct rte_cryptodev_asym_session *sess = NULL;
314 struct rte_cryptodev_asym_capability_idx cap_idx;
315 const struct rte_cryptodev_asymmetric_xform_capability *capability;
316 uint8_t dev_id = ts_params->valid_devs[0];
317 uint8_t input[TEST_DATA_SIZE] = {0};
318 uint8_t *result = NULL;
320 int status = TEST_SUCCESS;
322 xform_tc.next = NULL;
323 xform_tc.xform_type = data_tc->modex.xform_type;
325 cap_idx.type = xform_tc.xform_type;
326 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
328 if (capability == NULL) {
330 "Device doesn't support MODEX. Test Skipped\n");
334 /* Generate crypto op data structure */
335 op = rte_crypto_op_alloc(ts_params->op_mpool,
336 RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
339 snprintf(test_msg, ASYM_TEST_MSG_LEN,
340 "line %u FAILED: %s",
341 __LINE__, "Failed to allocate asymmetric crypto "
343 status = TEST_FAILED;
349 switch (xform_tc.xform_type) {
350 case RTE_CRYPTO_ASYM_XFORM_MODEX:
351 result = rte_zmalloc(NULL, data_tc->modex.result_len, 0);
352 xform_tc.modex.modulus.data = data_tc->modex.modulus.data;
353 xform_tc.modex.modulus.length = data_tc->modex.modulus.len;
354 xform_tc.modex.exponent.data = data_tc->modex.exponent.data;
355 xform_tc.modex.exponent.length = data_tc->modex.exponent.len;
356 memcpy(input, data_tc->modex.base.data,
357 data_tc->modex.base.len);
358 asym_op->modex.base.data = input;
359 asym_op->modex.base.length = data_tc->modex.base.len;
360 asym_op->modex.result.data = result;
361 asym_op->modex.result.length = data_tc->modex.result_len;
362 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
363 xform_tc.modex.modulus.length)) {
364 snprintf(test_msg, ASYM_TEST_MSG_LEN,
366 "FAILED: %s", __LINE__,
367 "Invalid MODULUS length specified");
368 status = TEST_FAILED;
372 case RTE_CRYPTO_ASYM_XFORM_MODINV:
373 result = rte_zmalloc(NULL, data_tc->modinv.result_len, 0);
374 xform_tc.modinv.modulus.data = data_tc->modinv.modulus.data;
375 xform_tc.modinv.modulus.length = data_tc->modinv.modulus.len;
376 memcpy(input, data_tc->modinv.base.data,
377 data_tc->modinv.base.len);
378 asym_op->modinv.base.data = input;
379 asym_op->modinv.base.length = data_tc->modinv.base.len;
380 asym_op->modinv.result.data = result;
381 asym_op->modinv.result.length = data_tc->modinv.result_len;
382 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
383 xform_tc.modinv.modulus.length)) {
384 snprintf(test_msg, ASYM_TEST_MSG_LEN,
386 "FAILED: %s", __LINE__,
387 "Invalid MODULUS length specified");
388 status = TEST_FAILED;
392 case RTE_CRYPTO_ASYM_XFORM_RSA:
393 result = rte_zmalloc(NULL, data_tc->rsa_data.n.len, 0);
394 op->asym->rsa.op_type = type;
395 xform_tc.rsa.e.data = data_tc->rsa_data.e.data;
396 xform_tc.rsa.e.length = data_tc->rsa_data.e.len;
397 xform_tc.rsa.n.data = data_tc->rsa_data.n.data;
398 xform_tc.rsa.n.length = data_tc->rsa_data.n.len;
400 if (key_type == RTE_RSA_KEY_TYPE_EXP) {
401 xform_tc.rsa.d.data = data_tc->rsa_data.d.data;
402 xform_tc.rsa.d.length = data_tc->rsa_data.d.len;
404 xform_tc.rsa.qt.p.data = data_tc->rsa_data.p.data;
405 xform_tc.rsa.qt.p.length = data_tc->rsa_data.p.len;
406 xform_tc.rsa.qt.q.data = data_tc->rsa_data.q.data;
407 xform_tc.rsa.qt.q.length = data_tc->rsa_data.q.len;
408 xform_tc.rsa.qt.dP.data = data_tc->rsa_data.dP.data;
409 xform_tc.rsa.qt.dP.length = data_tc->rsa_data.dP.len;
410 xform_tc.rsa.qt.dQ.data = data_tc->rsa_data.dQ.data;
411 xform_tc.rsa.qt.dQ.length = data_tc->rsa_data.dQ.len;
412 xform_tc.rsa.qt.qInv.data = data_tc->rsa_data.qInv.data;
413 xform_tc.rsa.qt.qInv.length = data_tc->rsa_data.qInv.len;
416 xform_tc.rsa.key_type = key_type;
417 op->asym->rsa.pad = data_tc->rsa_data.padding;
419 if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
420 asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
421 asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
422 asym_op->rsa.cipher.data = result;
423 asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
424 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
425 asym_op->rsa.message.data = result;
426 asym_op->rsa.message.length = data_tc->rsa_data.n.len;
427 asym_op->rsa.cipher.data = data_tc->rsa_data.ct.data;
428 asym_op->rsa.cipher.length = data_tc->rsa_data.ct.len;
429 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
430 asym_op->rsa.sign.data = result;
431 asym_op->rsa.sign.length = data_tc->rsa_data.n.len;
432 asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
433 asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
434 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
435 asym_op->rsa.cipher.data = result;
436 asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
437 asym_op->rsa.sign.data = data_tc->rsa_data.sign.data;
438 asym_op->rsa.sign.length = data_tc->rsa_data.sign.len;
441 case RTE_CRYPTO_ASYM_XFORM_DH:
442 case RTE_CRYPTO_ASYM_XFORM_DSA:
443 case RTE_CRYPTO_ASYM_XFORM_NONE:
444 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
446 snprintf(test_msg, ASYM_TEST_MSG_LEN,
448 "FAILED: %s", __LINE__,
449 "Invalid ASYM algorithm specified");
450 status = TEST_FAILED;
455 sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
457 snprintf(test_msg, ASYM_TEST_MSG_LEN,
459 "FAILED: %s", __LINE__,
460 "Session creation failed");
461 status = TEST_FAILED;
465 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
466 ts_params->session_mpool) < 0) {
467 snprintf(test_msg, ASYM_TEST_MSG_LEN,
468 "line %u FAILED: %s",
469 __LINE__, "unabled to config sym session");
470 status = TEST_FAILED;
474 rte_crypto_op_attach_asym_session(op, sess);
476 asym_op->xform = &xform_tc;
477 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
479 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
481 /* Process crypto operation */
482 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
483 snprintf(test_msg, ASYM_TEST_MSG_LEN,
484 "line %u FAILED: %s",
485 __LINE__, "Error sending packet for operation");
486 status = TEST_FAILED;
490 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
493 if (result_op == NULL) {
494 snprintf(test_msg, ASYM_TEST_MSG_LEN,
495 "line %u FAILED: %s",
496 __LINE__, "Failed to process asym crypto op");
497 status = TEST_FAILED;
501 if (test_cryptodev_asym_ver(op, &xform_tc, data_tc, result_op) != TEST_SUCCESS) {
502 snprintf(test_msg, ASYM_TEST_MSG_LEN,
503 "line %u FAILED: %s",
504 __LINE__, "Verification failed ");
505 status = TEST_FAILED;
510 snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
512 snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
516 rte_cryptodev_asym_session_clear(dev_id, sess);
517 rte_cryptodev_asym_session_free(sess);
521 rte_crypto_op_free(op);
529 test_one_case(const void *test_case, int sessionless)
531 int status = TEST_SUCCESS, i = 0;
532 char test_msg[ASYM_TEST_MSG_LEN + 1];
534 /* Map the case to union */
535 union test_case_structure tc;
536 memcpy(&tc, test_case, sizeof(tc));
538 if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX
539 || tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
540 status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg,
542 printf(" %u) TestCase %s %s\n", test_index++,
543 tc.modex.description, test_msg);
545 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
546 if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
547 if (tc.rsa_data.op_type_flags & (1 << i)) {
548 if (tc.rsa_data.key_exp) {
549 status = test_cryptodev_asym_op(
550 &testsuite_params, &tc,
551 test_msg, sessionless, i,
552 RTE_RSA_KEY_TYPE_EXP);
556 if (tc.rsa_data.key_qt && (i ==
557 RTE_CRYPTO_ASYM_OP_DECRYPT ||
558 i == RTE_CRYPTO_ASYM_OP_SIGN)) {
559 status = test_cryptodev_asym_op(
561 &tc, test_msg, sessionless, i,
562 RTE_RSA_KET_TYPE_QT);
569 printf(" %u) TestCase %s %s\n", test_index++,
570 tc.modex.description, test_msg);
577 load_test_vectors(void)
579 uint32_t i = 0, v_size = 0;
580 /* Load MODEX vector*/
581 v_size = RTE_DIM(modex_test_case);
582 for (i = 0; i < v_size; i++) {
583 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
584 RTE_LOG(DEBUG, USER1,
585 "TEST_VECTOR_SIZE too small\n");
588 test_vector.address[test_vector.size] = &modex_test_case[i];
591 /* Load MODINV vector*/
592 v_size = RTE_DIM(modinv_test_case);
593 for (i = 0; i < v_size; i++) {
594 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
595 RTE_LOG(DEBUG, USER1,
596 "TEST_VECTOR_SIZE too small\n");
599 test_vector.address[test_vector.size] = &modinv_test_case[i];
603 v_size = RTE_DIM(rsa_test_case_list);
604 for (i = 0; i < v_size; i++) {
605 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
606 RTE_LOG(DEBUG, USER1,
607 "TEST_VECTOR_SIZE too small\n");
610 test_vector.address[test_vector.size] = &rsa_test_case_list[i];
617 test_one_by_one(void)
619 int status = TEST_SUCCESS;
620 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
622 uint8_t dev_id = ts_params->valid_devs[0];
623 struct rte_cryptodev_info dev_info;
626 rte_cryptodev_info_get(dev_id, &dev_info);
627 if ((dev_info.feature_flags &
628 RTE_CRYPTODEV_FF_ASYM_SESSIONLESS)) {
632 /* Go through all test cases */
634 for (i = 0; i < test_vector.size; i++) {
635 if (test_one_case(test_vector.address[i], 0) != TEST_SUCCESS)
636 status = TEST_FAILED;
639 for (i = 0; i < test_vector.size; i++) {
640 if (test_one_case(test_vector.address[i], 1)
642 status = TEST_FAILED;
646 TEST_ASSERT_EQUAL(status, 0, "Test failed");
651 test_rsa_sign_verify(void)
653 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
654 struct rte_mempool *sess_mpool = ts_params->session_mpool;
655 uint8_t dev_id = ts_params->valid_devs[0];
656 struct rte_cryptodev_asym_session *sess;
657 struct rte_cryptodev_info dev_info;
658 int status = TEST_SUCCESS;
660 /* Test case supports op with exponent key only,
661 * Check in PMD feature flag for RSA exponent key type support.
663 rte_cryptodev_info_get(dev_id, &dev_info);
664 if (!(dev_info.feature_flags &
665 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
666 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
667 "exponent key type. Test Skipped\n");
671 sess = rte_cryptodev_asym_session_create(sess_mpool);
674 RTE_LOG(ERR, USER1, "Session creation failed for "
679 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
681 RTE_LOG(ERR, USER1, "Unable to config asym session for "
683 status = TEST_FAILED;
687 status = queue_ops_rsa_sign_verify(sess);
691 rte_cryptodev_asym_session_clear(dev_id, sess);
692 rte_cryptodev_asym_session_free(sess);
694 TEST_ASSERT_EQUAL(status, 0, "Test failed");
700 test_rsa_enc_dec(void)
702 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
703 struct rte_mempool *sess_mpool = ts_params->session_mpool;
704 uint8_t dev_id = ts_params->valid_devs[0];
705 struct rte_cryptodev_asym_session *sess;
706 struct rte_cryptodev_info dev_info;
707 int status = TEST_SUCCESS;
709 /* Test case supports op with exponent key only,
710 * Check in PMD feature flag for RSA exponent key type support.
712 rte_cryptodev_info_get(dev_id, &dev_info);
713 if (!(dev_info.feature_flags &
714 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
715 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
716 "exponent key type. Test skipped\n");
720 sess = rte_cryptodev_asym_session_create(sess_mpool);
723 RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
727 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
729 RTE_LOG(ERR, USER1, "Unable to config asym session for "
731 status = TEST_FAILED;
735 status = queue_ops_rsa_enc_dec(sess);
739 rte_cryptodev_asym_session_clear(dev_id, sess);
740 rte_cryptodev_asym_session_free(sess);
742 TEST_ASSERT_EQUAL(status, 0, "Test failed");
748 test_rsa_sign_verify_crt(void)
750 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
751 struct rte_mempool *sess_mpool = ts_params->session_mpool;
752 uint8_t dev_id = ts_params->valid_devs[0];
753 struct rte_cryptodev_asym_session *sess;
754 struct rte_cryptodev_info dev_info;
755 int status = TEST_SUCCESS;
757 /* Test case supports op with quintuple format key only,
758 * Check im PMD feature flag for RSA quintuple key type support.
760 rte_cryptodev_info_get(dev_id, &dev_info);
761 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
762 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
763 "quintuple key type. Test skipped\n");
767 sess = rte_cryptodev_asym_session_create(sess_mpool);
770 RTE_LOG(ERR, USER1, "Session creation failed for "
771 "sign_verify_crt\n");
772 status = TEST_FAILED;
776 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
778 RTE_LOG(ERR, USER1, "Unable to config asym session for "
779 "sign_verify_crt\n");
780 status = TEST_FAILED;
783 status = queue_ops_rsa_sign_verify(sess);
787 rte_cryptodev_asym_session_clear(dev_id, sess);
788 rte_cryptodev_asym_session_free(sess);
790 TEST_ASSERT_EQUAL(status, 0, "Test failed");
796 test_rsa_enc_dec_crt(void)
798 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
799 struct rte_mempool *sess_mpool = ts_params->session_mpool;
800 uint8_t dev_id = ts_params->valid_devs[0];
801 struct rte_cryptodev_asym_session *sess;
802 struct rte_cryptodev_info dev_info;
803 int status = TEST_SUCCESS;
805 /* Test case supports op with quintuple format key only,
806 * Check in PMD feature flag for RSA quintuple key type support.
808 rte_cryptodev_info_get(dev_id, &dev_info);
809 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
810 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
811 "quintuple key type. Test skipped\n");
815 sess = rte_cryptodev_asym_session_create(sess_mpool);
818 RTE_LOG(ERR, USER1, "Session creation failed for "
823 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
825 RTE_LOG(ERR, USER1, "Unable to config asym session for "
827 status = TEST_FAILED;
830 status = queue_ops_rsa_enc_dec(sess);
834 rte_cryptodev_asym_session_clear(dev_id, sess);
835 rte_cryptodev_asym_session_free(sess);
837 TEST_ASSERT_EQUAL(status, 0, "Test failed");
843 testsuite_setup(void)
845 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
846 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
847 struct rte_cryptodev_info info;
848 int ret, dev_id = -1;
852 memset(ts_params, 0, sizeof(*ts_params));
854 test_vector.size = 0;
857 /* Device, op pool and session configuration for asymmetric crypto. 8< */
858 ts_params->op_mpool = rte_crypto_op_pool_create(
859 "CRYPTO_ASYM_OP_POOL",
860 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
864 if (ts_params->op_mpool == NULL) {
865 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
869 /* Create an OPENSSL device if required */
870 if (gbl_driver_id == rte_cryptodev_driver_id_get(
871 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
872 nb_devs = rte_cryptodev_device_count_by_driver(
873 rte_cryptodev_driver_id_get(
874 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
877 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
880 TEST_ASSERT(ret == 0, "Failed to create "
881 "instance of pmd : %s",
882 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
886 /* Get list of valid crypto devs */
887 nb_devs = rte_cryptodev_devices_get(
888 rte_cryptodev_driver_name_get(gbl_driver_id),
889 valid_devs, RTE_CRYPTO_MAX_DEVS);
891 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
896 * Get first valid asymmetric device found in test suite param and
899 for (i = 0; i < nb_devs ; i++) {
900 rte_cryptodev_info_get(valid_devs[i], &info);
901 if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
902 dev_id = ts_params->valid_devs[0] = valid_devs[i];
908 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
913 /* Set valid device count */
914 ts_params->valid_dev_count = nb_devs;
916 /* configure device with num qp */
917 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
918 ts_params->conf.socket_id = SOCKET_ID_ANY;
919 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
920 RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
921 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
923 "Failed to configure cryptodev %u with %u qps",
924 dev_id, ts_params->conf.nb_queue_pairs);
927 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
928 ts_params->qp_conf.mp_session = ts_params->session_mpool;
929 ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
930 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
931 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
932 dev_id, qp_id, &ts_params->qp_conf,
933 rte_cryptodev_socket_id(dev_id)),
934 "Failed to setup queue pair %u on cryptodev %u ASYM",
938 /* setup asym session pool */
939 unsigned int session_size = RTE_MAX(
940 rte_cryptodev_asym_get_private_session_size(dev_id),
941 rte_cryptodev_asym_get_header_session_size());
943 * Create mempool with TEST_NUM_SESSIONS * 2,
944 * to include the session headers
946 ts_params->session_mpool = rte_mempool_create(
948 TEST_NUM_SESSIONS * 2,
950 0, 0, NULL, NULL, NULL,
954 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
955 "session mempool allocation failed");
956 /* >8 End of device, op pool and session configuration for asymmetric crypto section. */
961 testsuite_teardown(void)
963 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
965 if (ts_params->op_mpool != NULL) {
966 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
967 rte_mempool_avail_count(ts_params->op_mpool));
970 /* Free session mempools */
971 if (ts_params->session_mpool != NULL) {
972 rte_mempool_free(ts_params->session_mpool);
973 ts_params->session_mpool = NULL;
980 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
984 /* Reconfigure device to default parameters */
985 ts_params->conf.socket_id = SOCKET_ID_ANY;
987 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
989 "Failed to configure cryptodev %u",
990 ts_params->valid_devs[0]);
992 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
993 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
994 ts_params->valid_devs[0], qp_id,
996 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
997 "Failed to setup queue pair %u on cryptodev %u",
998 qp_id, ts_params->valid_devs[0]);
1001 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1003 /* Start the device */
1004 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1005 "Failed to start cryptodev %u",
1006 ts_params->valid_devs[0]);
1008 return TEST_SUCCESS;
1012 ut_teardown_asym(void)
1014 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1015 struct rte_cryptodev_stats stats;
1017 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1019 /* Stop the device */
1020 rte_cryptodev_stop(ts_params->valid_devs[0]);
1023 static inline void print_asym_capa(
1024 const struct rte_cryptodev_asymmetric_xform_capability *capa)
1028 printf("\nxform type: %s\n===================\n",
1029 rte_crypto_asym_xform_strings[capa->xform_type]);
1030 printf("operation supported -");
1032 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
1033 /* check supported operations */
1034 if (rte_cryptodev_asym_xform_capability_check_optype(capa, i))
1036 rte_crypto_asym_op_strings[i]);
1038 switch (capa->xform_type) {
1039 case RTE_CRYPTO_ASYM_XFORM_RSA:
1040 case RTE_CRYPTO_ASYM_XFORM_MODINV:
1041 case RTE_CRYPTO_ASYM_XFORM_MODEX:
1042 case RTE_CRYPTO_ASYM_XFORM_DH:
1043 case RTE_CRYPTO_ASYM_XFORM_DSA:
1044 printf(" modlen: min %d max %d increment %d",
1047 capa->modlen.increment);
1049 case RTE_CRYPTO_ASYM_XFORM_ECDSA:
1050 case RTE_CRYPTO_ASYM_XFORM_ECPM:
1058 test_capability(void)
1060 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1061 uint8_t dev_id = ts_params->valid_devs[0];
1062 struct rte_cryptodev_info dev_info;
1063 const struct rte_cryptodev_capabilities *dev_capa;
1065 struct rte_cryptodev_asym_capability_idx idx;
1066 const struct rte_cryptodev_asymmetric_xform_capability *capa;
1068 rte_cryptodev_info_get(dev_id, &dev_info);
1069 if (!(dev_info.feature_flags &
1070 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
1071 RTE_LOG(INFO, USER1,
1072 "Device doesn't support asymmetric. Test Skipped\n");
1073 return TEST_SUCCESS;
1076 /* print xform capability */
1078 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
1080 dev_capa = &(dev_info.capabilities[i]);
1081 if (dev_info.capabilities[i].op ==
1082 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1083 idx.type = dev_capa->asym.xform_capa.xform_type;
1085 capa = rte_cryptodev_asym_capability_get(dev_id,
1087 rte_cryptodev_asym_capability_idx *) &idx);
1088 print_asym_capa(capa);
1091 return TEST_SUCCESS;
1095 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
1097 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1098 struct rte_mempool *op_mpool = ts_params->op_mpool;
1099 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1100 uint8_t dev_id = ts_params->valid_devs[0];
1101 struct rte_crypto_asym_op *asym_op = NULL;
1102 struct rte_crypto_op *op = NULL, *result_op = NULL;
1103 struct rte_cryptodev_asym_session *sess = NULL;
1104 int status = TEST_SUCCESS;
1105 uint8_t output[TEST_DH_MOD_LEN];
1106 struct rte_crypto_asym_xform xform = *xfrm;
1107 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
1109 sess = rte_cryptodev_asym_session_create(sess_mpool);
1112 "line %u FAILED: %s", __LINE__,
1113 "Session creation failed");
1114 status = TEST_FAILED;
1117 /* set up crypto op data structure */
1118 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1121 "line %u FAILED: %s",
1122 __LINE__, "Failed to allocate asymmetric crypto "
1123 "operation struct");
1124 status = TEST_FAILED;
1129 /* Setup a xform and op to generate private key only */
1130 xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
1132 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
1133 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
1134 asym_op->dh.pub_key.data = (uint8_t *)peer;
1135 asym_op->dh.pub_key.length = sizeof(peer);
1136 asym_op->dh.shared_secret.data = output;
1137 asym_op->dh.shared_secret.length = sizeof(output);
1139 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1142 "line %u FAILED: %s",
1143 __LINE__, "unabled to config sym session");
1144 status = TEST_FAILED;
1148 /* attach asymmetric crypto session to crypto operations */
1149 rte_crypto_op_attach_asym_session(op, sess);
1151 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1153 /* Process crypto operation */
1154 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1156 "line %u FAILED: %s",
1157 __LINE__, "Error sending packet for operation");
1158 status = TEST_FAILED;
1162 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1165 if (result_op == NULL) {
1167 "line %u FAILED: %s",
1168 __LINE__, "Failed to process asym crypto op");
1169 status = TEST_FAILED;
1173 debug_hexdump(stdout, "shared secret:",
1174 asym_op->dh.shared_secret.data,
1175 asym_op->dh.shared_secret.length);
1179 rte_cryptodev_asym_session_clear(dev_id, sess);
1180 rte_cryptodev_asym_session_free(sess);
1183 rte_crypto_op_free(op);
1188 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1190 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1191 struct rte_mempool *op_mpool = ts_params->op_mpool;
1192 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1193 uint8_t dev_id = ts_params->valid_devs[0];
1194 struct rte_crypto_asym_op *asym_op = NULL;
1195 struct rte_crypto_op *op = NULL, *result_op = NULL;
1196 struct rte_cryptodev_asym_session *sess = NULL;
1197 int status = TEST_SUCCESS;
1198 uint8_t output[TEST_DH_MOD_LEN];
1199 struct rte_crypto_asym_xform xform = *xfrm;
1201 sess = rte_cryptodev_asym_session_create(sess_mpool);
1204 "line %u FAILED: %s", __LINE__,
1205 "Session creation failed");
1206 status = TEST_FAILED;
1209 /* set up crypto op data structure */
1210 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1213 "line %u FAILED: %s",
1214 __LINE__, "Failed to allocate asymmetric crypto "
1215 "operation struct");
1216 status = TEST_FAILED;
1221 /* Setup a xform and op to generate private key only */
1222 xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1224 asym_op->dh.priv_key.data = output;
1225 asym_op->dh.priv_key.length = sizeof(output);
1227 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1230 "line %u FAILED: %s",
1231 __LINE__, "unabled to config sym session");
1232 status = TEST_FAILED;
1236 /* attach asymmetric crypto session to crypto operations */
1237 rte_crypto_op_attach_asym_session(op, sess);
1239 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1241 /* Process crypto operation */
1242 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1244 "line %u FAILED: %s",
1245 __LINE__, "Error sending packet for operation");
1246 status = TEST_FAILED;
1250 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1253 if (result_op == NULL) {
1255 "line %u FAILED: %s",
1256 __LINE__, "Failed to process asym crypto op");
1257 status = TEST_FAILED;
1261 debug_hexdump(stdout, "private key:",
1262 asym_op->dh.priv_key.data,
1263 asym_op->dh.priv_key.length);
1268 rte_cryptodev_asym_session_clear(dev_id, sess);
1269 rte_cryptodev_asym_session_free(sess);
1272 rte_crypto_op_free(op);
1279 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1281 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1282 struct rte_mempool *op_mpool = ts_params->op_mpool;
1283 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1284 uint8_t dev_id = ts_params->valid_devs[0];
1285 struct rte_crypto_asym_op *asym_op = NULL;
1286 struct rte_crypto_op *op = NULL, *result_op = NULL;
1287 struct rte_cryptodev_asym_session *sess = NULL;
1288 int status = TEST_SUCCESS;
1289 uint8_t output[TEST_DH_MOD_LEN];
1290 struct rte_crypto_asym_xform xform = *xfrm;
1292 sess = rte_cryptodev_asym_session_create(sess_mpool);
1295 "line %u FAILED: %s", __LINE__,
1296 "Session creation failed");
1297 status = TEST_FAILED;
1300 /* set up crypto op data structure */
1301 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1304 "line %u FAILED: %s",
1305 __LINE__, "Failed to allocate asymmetric crypto "
1306 "operation struct");
1307 status = TEST_FAILED;
1311 /* Setup a xform chain to generate public key
1312 * using test private key
1315 xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1318 asym_op->dh.pub_key.data = output;
1319 asym_op->dh.pub_key.length = sizeof(output);
1320 /* load pre-defined private key */
1321 asym_op->dh.priv_key.data = rte_malloc(NULL,
1322 dh_test_params.priv_key.length,
1324 asym_op->dh.priv_key = dh_test_params.priv_key;
1326 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1329 "line %u FAILED: %s",
1330 __LINE__, "unabled to config sym session");
1331 status = TEST_FAILED;
1335 /* attach asymmetric crypto session to crypto operations */
1336 rte_crypto_op_attach_asym_session(op, sess);
1338 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1340 /* Process crypto operation */
1341 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1343 "line %u FAILED: %s",
1344 __LINE__, "Error sending packet for operation");
1345 status = TEST_FAILED;
1349 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1352 if (result_op == NULL) {
1354 "line %u FAILED: %s",
1355 __LINE__, "Failed to process asym crypto op");
1356 status = TEST_FAILED;
1360 debug_hexdump(stdout, "pub key:",
1361 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1363 debug_hexdump(stdout, "priv key:",
1364 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1368 rte_cryptodev_asym_session_clear(dev_id, sess);
1369 rte_cryptodev_asym_session_free(sess);
1372 rte_crypto_op_free(op);
1378 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1380 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1381 struct rte_mempool *op_mpool = ts_params->op_mpool;
1382 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1383 uint8_t dev_id = ts_params->valid_devs[0];
1384 struct rte_crypto_asym_op *asym_op = NULL;
1385 struct rte_crypto_op *op = NULL, *result_op = NULL;
1386 struct rte_cryptodev_asym_session *sess = NULL;
1387 int status = TEST_SUCCESS;
1388 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1389 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1390 struct rte_crypto_asym_xform pub_key_xform;
1391 struct rte_crypto_asym_xform xform = *xfrm;
1393 sess = rte_cryptodev_asym_session_create(sess_mpool);
1396 "line %u FAILED: %s", __LINE__,
1397 "Session creation failed");
1398 status = TEST_FAILED;
1402 /* set up crypto op data structure */
1403 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1406 "line %u FAILED: %s",
1407 __LINE__, "Failed to allocate asymmetric crypto "
1408 "operation struct");
1409 status = TEST_FAILED;
1413 /* Setup a xform chain to generate
1414 * private key first followed by
1416 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1417 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1418 pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1419 xform.next = &pub_key_xform;
1421 asym_op->dh.pub_key.data = out_pub_key;
1422 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1423 asym_op->dh.priv_key.data = out_prv_key;
1424 asym_op->dh.priv_key.length = sizeof(out_prv_key);
1425 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1428 "line %u FAILED: %s",
1429 __LINE__, "unabled to config sym session");
1430 status = TEST_FAILED;
1434 /* attach asymmetric crypto session to crypto operations */
1435 rte_crypto_op_attach_asym_session(op, sess);
1437 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1439 /* Process crypto operation */
1440 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1442 "line %u FAILED: %s",
1443 __LINE__, "Error sending packet for operation");
1444 status = TEST_FAILED;
1448 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1451 if (result_op == NULL) {
1453 "line %u FAILED: %s",
1454 __LINE__, "Failed to process asym crypto op");
1455 status = TEST_FAILED;
1458 debug_hexdump(stdout, "priv key:",
1459 out_prv_key, asym_op->dh.priv_key.length);
1460 debug_hexdump(stdout, "pub key:",
1461 out_pub_key, asym_op->dh.pub_key.length);
1465 rte_cryptodev_asym_session_clear(dev_id, sess);
1466 rte_cryptodev_asym_session_free(sess);
1469 rte_crypto_op_free(op);
1477 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1478 struct rte_mempool *op_mpool = ts_params->op_mpool;
1479 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1480 uint8_t dev_id = ts_params->valid_devs[0];
1481 struct rte_crypto_asym_op *asym_op = NULL;
1482 struct rte_crypto_op *op = NULL, *result_op = NULL;
1483 struct rte_cryptodev_asym_session *sess = NULL;
1484 int status = TEST_SUCCESS;
1485 struct rte_cryptodev_asym_capability_idx cap_idx;
1486 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1487 uint8_t input[TEST_DATA_SIZE] = {0};
1489 uint8_t result[sizeof(mod_p)] = { 0 };
1491 if (rte_cryptodev_asym_get_xform_enum(
1492 &modinv_xform.xform_type, "modinv") < 0) {
1494 "Invalid ASYM algorithm specified\n");
1498 cap_idx.type = modinv_xform.xform_type;
1499 capability = rte_cryptodev_asym_capability_get(dev_id,
1502 if (capability == NULL) {
1503 RTE_LOG(INFO, USER1,
1504 "Device doesn't support MOD INV. Test Skipped\n");
1505 return TEST_SKIPPED;
1508 if (rte_cryptodev_asym_xform_capability_check_modlen(
1510 modinv_xform.modinv.modulus.length)) {
1512 "Invalid MODULUS length specified\n");
1513 return TEST_SKIPPED;
1516 sess = rte_cryptodev_asym_session_create(sess_mpool);
1518 RTE_LOG(ERR, USER1, "line %u "
1519 "FAILED: %s", __LINE__,
1520 "Session creation failed");
1521 status = TEST_FAILED;
1525 if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
1528 "line %u FAILED: %s",
1529 __LINE__, "unabled to config sym session");
1530 status = TEST_FAILED;
1534 /* generate crypto op data structure */
1535 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1538 "line %u FAILED: %s",
1539 __LINE__, "Failed to allocate asymmetric crypto "
1540 "operation struct");
1541 status = TEST_FAILED;
1546 memcpy(input, base, sizeof(base));
1547 asym_op->modinv.base.data = input;
1548 asym_op->modinv.base.length = sizeof(base);
1549 asym_op->modinv.result.data = result;
1550 asym_op->modinv.result.length = sizeof(result);
1552 /* attach asymmetric crypto session to crypto operations */
1553 rte_crypto_op_attach_asym_session(op, sess);
1555 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1557 /* Process crypto operation */
1558 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1560 "line %u FAILED: %s",
1561 __LINE__, "Error sending packet for operation");
1562 status = TEST_FAILED;
1566 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1569 if (result_op == NULL) {
1571 "line %u FAILED: %s",
1572 __LINE__, "Failed to process asym crypto op");
1573 status = TEST_FAILED;
1577 ret = verify_modinv(mod_inv, result_op);
1580 "operation verification failed\n");
1581 status = TEST_FAILED;
1586 rte_cryptodev_asym_session_clear(dev_id, sess);
1587 rte_cryptodev_asym_session_free(sess);
1591 rte_crypto_op_free(op);
1593 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1601 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1602 struct rte_mempool *op_mpool = ts_params->op_mpool;
1603 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1604 uint8_t dev_id = ts_params->valid_devs[0];
1605 struct rte_crypto_asym_op *asym_op = NULL;
1606 struct rte_crypto_op *op = NULL, *result_op = NULL;
1607 struct rte_cryptodev_asym_session *sess = NULL;
1608 int status = TEST_SUCCESS;
1609 struct rte_cryptodev_asym_capability_idx cap_idx;
1610 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1611 uint8_t input[TEST_DATA_SIZE] = {0};
1613 uint8_t result[sizeof(mod_p)] = { 0 };
1615 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1619 "Invalid ASYM algorithm specified\n");
1623 /* check for modlen capability */
1624 cap_idx.type = modex_xform.xform_type;
1625 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1627 if (capability == NULL) {
1628 RTE_LOG(INFO, USER1,
1629 "Device doesn't support MOD EXP. Test Skipped\n");
1630 return TEST_SKIPPED;
1633 if (rte_cryptodev_asym_xform_capability_check_modlen(
1634 capability, modex_xform.modex.modulus.length)) {
1636 "Invalid MODULUS length specified\n");
1637 return TEST_SKIPPED;
1640 /* Create op, create session, and process packets. 8< */
1641 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1644 "line %u FAILED: %s",
1645 __LINE__, "Failed to allocate asymmetric crypto "
1646 "operation struct");
1647 status = TEST_FAILED;
1651 sess = rte_cryptodev_asym_session_create(sess_mpool);
1655 "FAILED: %s", __LINE__,
1656 "Session creation failed");
1657 status = TEST_FAILED;
1661 if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1664 "line %u FAILED: %s",
1665 __LINE__, "unabled to config sym session");
1666 status = TEST_FAILED;
1671 memcpy(input, base, sizeof(base));
1672 asym_op->modex.base.data = input;
1673 asym_op->modex.base.length = sizeof(base);
1674 asym_op->modex.result.data = result;
1675 asym_op->modex.result.length = sizeof(result);
1676 /* attach asymmetric crypto session to crypto operations */
1677 rte_crypto_op_attach_asym_session(op, sess);
1679 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1680 /* Process crypto operation */
1681 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1683 "line %u FAILED: %s",
1684 __LINE__, "Error sending packet for operation");
1685 status = TEST_FAILED;
1689 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1692 if (result_op == NULL) {
1694 "line %u FAILED: %s",
1695 __LINE__, "Failed to process asym crypto op");
1696 status = TEST_FAILED;
1699 /* >8 End of create op, create session, and process packets section. */
1700 ret = verify_modexp(mod_exp, result_op);
1703 "operation verification failed\n");
1704 status = TEST_FAILED;
1709 rte_cryptodev_asym_session_clear(dev_id, sess);
1710 rte_cryptodev_asym_session_free(sess);
1714 rte_crypto_op_free(op);
1716 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1722 test_dh_keygenration(void)
1726 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1727 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1728 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1729 dh_test_params.priv_key.length);
1731 RTE_LOG(INFO, USER1,
1732 "Test Public and Private key pair generation\n");
1734 status = test_dh_gen_kp(&dh_xform);
1735 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1737 RTE_LOG(INFO, USER1,
1738 "Test Public Key Generation using pre-defined priv key\n");
1740 status = test_dh_gen_pub_key(&dh_xform);
1741 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1743 RTE_LOG(INFO, USER1,
1744 "Test Private Key Generation only\n");
1746 status = test_dh_gen_priv_key(&dh_xform);
1747 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1749 RTE_LOG(INFO, USER1,
1750 "Test shared secret compute\n");
1752 status = test_dh_gen_shared_sec(&dh_xform);
1753 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1761 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1762 struct rte_mempool *op_mpool = ts_params->op_mpool;
1763 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1764 uint8_t dev_id = ts_params->valid_devs[0];
1765 struct rte_crypto_asym_op *asym_op = NULL;
1766 struct rte_crypto_op *op = NULL, *result_op = NULL;
1767 struct rte_cryptodev_asym_session *sess = NULL;
1768 int status = TEST_SUCCESS;
1769 uint8_t r[TEST_DH_MOD_LEN];
1770 uint8_t s[TEST_DH_MOD_LEN];
1771 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1773 sess = rte_cryptodev_asym_session_create(sess_mpool);
1776 "line %u FAILED: %s", __LINE__,
1777 "Session creation failed");
1778 status = TEST_FAILED;
1781 /* set up crypto op data structure */
1782 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1785 "line %u FAILED: %s",
1786 __LINE__, "Failed to allocate asymmetric crypto "
1787 "operation struct");
1788 status = TEST_FAILED;
1793 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1794 dsa_xform.dsa.p.length);
1795 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1796 dsa_xform.dsa.q.length);
1797 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1798 dsa_xform.dsa.g.length);
1799 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1800 dsa_xform.dsa.x.length);
1802 if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1805 "line %u FAILED: %s",
1806 __LINE__, "unabled to config sym session");
1807 status = TEST_FAILED;
1811 /* attach asymmetric crypto session to crypto operations */
1812 rte_crypto_op_attach_asym_session(op, sess);
1813 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1814 asym_op->dsa.message.data = dgst;
1815 asym_op->dsa.message.length = sizeof(dgst);
1816 asym_op->dsa.r.length = sizeof(r);
1817 asym_op->dsa.r.data = r;
1818 asym_op->dsa.s.length = sizeof(s);
1819 asym_op->dsa.s.data = s;
1821 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1823 /* Process crypto operation */
1824 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1826 "line %u FAILED: %s",
1827 __LINE__, "Error sending packet for operation");
1828 status = TEST_FAILED;
1832 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1835 if (result_op == NULL) {
1837 "line %u FAILED: %s",
1838 __LINE__, "Failed to process asym crypto op");
1839 status = TEST_FAILED;
1843 asym_op = result_op->asym;
1845 debug_hexdump(stdout, "r:",
1846 asym_op->dsa.r.data, asym_op->dsa.r.length);
1847 debug_hexdump(stdout, "s:",
1848 asym_op->dsa.s.data, asym_op->dsa.s.length);
1850 /* Test PMD DSA sign verification using signer public key */
1851 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1853 /* copy signer public key */
1854 asym_op->dsa.y.data = dsa_test_params.y.data;
1855 asym_op->dsa.y.length = dsa_test_params.y.length;
1857 /* Process crypto operation */
1858 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1860 "line %u FAILED: %s",
1861 __LINE__, "Error sending packet for operation");
1862 status = TEST_FAILED;
1866 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1869 if (result_op == NULL) {
1871 "line %u FAILED: %s",
1872 __LINE__, "Failed to process asym crypto op");
1873 status = TEST_FAILED;
1877 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1879 "line %u FAILED: %s",
1880 __LINE__, "Failed to process asym crypto op");
1881 status = TEST_FAILED;
1885 rte_cryptodev_asym_session_clear(dev_id, sess);
1886 rte_cryptodev_asym_session_free(sess);
1889 rte_crypto_op_free(op);
1897 status = test_dsa_sign();
1898 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1903 test_ecdsa_sign_verify(enum curve curve_id)
1905 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1906 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1907 struct rte_mempool *op_mpool = ts_params->op_mpool;
1908 struct crypto_testsuite_ecdsa_params input_params;
1909 struct rte_cryptodev_asym_session *sess = NULL;
1910 uint8_t dev_id = ts_params->valid_devs[0];
1911 struct rte_crypto_op *result_op = NULL;
1912 uint8_t output_buf_r[TEST_DATA_SIZE];
1913 uint8_t output_buf_s[TEST_DATA_SIZE];
1914 struct rte_crypto_asym_xform xform;
1915 struct rte_crypto_asym_op *asym_op;
1916 struct rte_cryptodev_info dev_info;
1917 struct rte_crypto_op *op = NULL;
1918 int status = TEST_SUCCESS, ret;
1922 input_params = ecdsa_param_secp192r1;
1925 input_params = ecdsa_param_secp224r1;
1928 input_params = ecdsa_param_secp256r1;
1931 input_params = ecdsa_param_secp384r1;
1934 input_params = ecdsa_param_secp521r1;
1938 "line %u FAILED: %s", __LINE__,
1939 "Unsupported curve id\n");
1940 status = TEST_FAILED;
1944 rte_cryptodev_info_get(dev_id, &dev_info);
1946 sess = rte_cryptodev_asym_session_create(sess_mpool);
1949 "line %u FAILED: %s", __LINE__,
1950 "Session creation failed\n");
1951 status = TEST_FAILED;
1955 /* Setup crypto op data structure */
1956 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1959 "line %u FAILED: %s", __LINE__,
1960 "Failed to allocate asymmetric crypto "
1961 "operation struct\n");
1962 status = TEST_FAILED;
1967 /* Setup asym xform */
1969 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
1970 xform.ec.curve_id = input_params.curve;
1972 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1975 "line %u FAILED: %s", __LINE__,
1976 "Unable to config asym session\n");
1977 status = TEST_FAILED;
1981 /* Attach asymmetric crypto session to crypto operations */
1982 rte_crypto_op_attach_asym_session(op, sess);
1986 /* Populate op with operational details */
1987 op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1988 op->asym->ecdsa.message.data = input_params.digest.data;
1989 op->asym->ecdsa.message.length = input_params.digest.length;
1990 op->asym->ecdsa.k.data = input_params.scalar.data;
1991 op->asym->ecdsa.k.length = input_params.scalar.length;
1992 op->asym->ecdsa.pkey.data = input_params.pkey.data;
1993 op->asym->ecdsa.pkey.length = input_params.pkey.length;
1996 op->asym->ecdsa.r.data = output_buf_r;
1997 op->asym->ecdsa.s.data = output_buf_s;
1999 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2001 /* Process crypto operation */
2002 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2004 "line %u FAILED: %s", __LINE__,
2005 "Error sending packet for operation\n");
2006 status = TEST_FAILED;
2010 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2013 if (result_op == NULL) {
2015 "line %u FAILED: %s", __LINE__,
2016 "Failed to process asym crypto op\n");
2017 status = TEST_FAILED;
2021 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2023 "line %u FAILED: %s", __LINE__,
2024 "Failed to process asym crypto op\n");
2025 status = TEST_FAILED;
2029 asym_op = result_op->asym;
2031 debug_hexdump(stdout, "r:",
2032 asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
2033 debug_hexdump(stdout, "s:",
2034 asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
2036 ret = verify_ecdsa_sign(input_params.sign_r.data,
2037 input_params.sign_s.data, result_op);
2039 status = TEST_FAILED;
2041 "line %u FAILED: %s", __LINE__,
2042 "ECDSA sign failed.\n");
2048 /* Populate op with operational details */
2049 op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
2050 op->asym->ecdsa.q.x.data = input_params.pubkey_qx.data;
2051 op->asym->ecdsa.q.x.length = input_params.pubkey_qx.length;
2052 op->asym->ecdsa.q.y.data = input_params.pubkey_qy.data;
2053 op->asym->ecdsa.q.y.length = input_params.pubkey_qx.length;
2054 op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
2055 op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
2056 op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
2057 op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
2059 /* Enqueue sign result for verify */
2060 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2061 status = TEST_FAILED;
2063 "line %u FAILED: %s", __LINE__,
2064 "Error sending packet for operation\n");
2068 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2071 if (result_op == NULL) {
2072 status = TEST_FAILED;
2075 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2076 status = TEST_FAILED;
2078 "line %u FAILED: %s", __LINE__,
2079 "ECDSA verify failed.\n");
2085 rte_cryptodev_asym_session_clear(dev_id, sess);
2086 rte_cryptodev_asym_session_free(sess);
2089 rte_crypto_op_free(op);
2094 test_ecdsa_sign_verify_all_curve(void)
2096 int status, overall_status = TEST_SUCCESS;
2097 enum curve curve_id;
2101 for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2102 status = test_ecdsa_sign_verify(curve_id);
2103 if (status == TEST_SUCCESS) {
2107 overall_status = status;
2109 printf(" %u) TestCase Sign/Veriy Curve %s %s\n",
2110 test_index ++, curve[curve_id], msg);
2112 return overall_status;
2116 test_ecpm(enum curve curve_id)
2118 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2119 struct rte_mempool *sess_mpool = ts_params->session_mpool;
2120 struct rte_mempool *op_mpool = ts_params->op_mpool;
2121 struct crypto_testsuite_ecpm_params input_params;
2122 struct rte_cryptodev_asym_session *sess = NULL;
2123 uint8_t dev_id = ts_params->valid_devs[0];
2124 struct rte_crypto_op *result_op = NULL;
2125 uint8_t output_buf_x[TEST_DATA_SIZE];
2126 uint8_t output_buf_y[TEST_DATA_SIZE];
2127 struct rte_crypto_asym_xform xform;
2128 struct rte_crypto_asym_op *asym_op;
2129 struct rte_cryptodev_info dev_info;
2130 struct rte_crypto_op *op = NULL;
2131 int status = TEST_SUCCESS, ret;
2135 input_params = ecpm_param_secp192r1;
2138 input_params = ecpm_param_secp224r1;
2141 input_params = ecpm_param_secp256r1;
2144 input_params = ecpm_param_secp384r1;
2147 input_params = ecpm_param_secp521r1;
2151 "line %u FAILED: %s", __LINE__,
2152 "Unsupported curve id\n");
2153 status = TEST_FAILED;
2157 rte_cryptodev_info_get(dev_id, &dev_info);
2159 sess = rte_cryptodev_asym_session_create(sess_mpool);
2162 "line %u FAILED: %s", __LINE__,
2163 "Session creation failed\n");
2164 status = TEST_FAILED;
2168 /* Setup crypto op data structure */
2169 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2172 "line %u FAILED: %s", __LINE__,
2173 "Failed to allocate asymmetric crypto "
2174 "operation struct\n");
2175 status = TEST_FAILED;
2180 /* Setup asym xform */
2182 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
2183 xform.ec.curve_id = input_params.curve;
2185 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
2188 "line %u FAILED: %s", __LINE__,
2189 "Unable to config asym session\n");
2190 status = TEST_FAILED;
2194 /* Attach asymmetric crypto session to crypto operations */
2195 rte_crypto_op_attach_asym_session(op, sess);
2197 /* Populate op with operational details */
2198 op->asym->ecpm.p.x.data = input_params.gen_x.data;
2199 op->asym->ecpm.p.x.length = input_params.gen_x.length;
2200 op->asym->ecpm.p.y.data = input_params.gen_y.data;
2201 op->asym->ecpm.p.y.length = input_params.gen_y.length;
2202 op->asym->ecpm.scalar.data = input_params.privkey.data;
2203 op->asym->ecpm.scalar.length = input_params.privkey.length;
2206 op->asym->ecpm.r.x.data = output_buf_x;
2207 op->asym->ecpm.r.y.data = output_buf_y;
2209 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2211 /* Process crypto operation */
2212 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2214 "line %u FAILED: %s", __LINE__,
2215 "Error sending packet for operation\n");
2216 status = TEST_FAILED;
2220 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2223 if (result_op == NULL) {
2225 "line %u FAILED: %s", __LINE__,
2226 "Failed to process asym crypto op\n");
2227 status = TEST_FAILED;
2231 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2233 "line %u FAILED: %s", __LINE__,
2234 "Failed to process asym crypto op\n");
2235 status = TEST_FAILED;
2239 asym_op = result_op->asym;
2241 debug_hexdump(stdout, "r x:",
2242 asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
2243 debug_hexdump(stdout, "r y:",
2244 asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
2246 ret = verify_ecpm(input_params.pubkey_x.data,
2247 input_params.pubkey_y.data, result_op);
2249 status = TEST_FAILED;
2251 "line %u FAILED: %s", __LINE__,
2252 "EC Point Multiplication failed.\n");
2258 rte_cryptodev_asym_session_clear(dev_id, sess);
2259 rte_cryptodev_asym_session_free(sess);
2262 rte_crypto_op_free(op);
2267 test_ecpm_all_curve(void)
2269 int status, overall_status = TEST_SUCCESS;
2270 enum curve curve_id;
2274 for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2275 status = test_ecpm(curve_id);
2276 if (status == TEST_SUCCESS) {
2280 overall_status = status;
2282 printf(" %u) TestCase EC Point Mul Curve %s %s\n",
2283 test_index ++, curve[curve_id], msg);
2285 return overall_status;
2288 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
2289 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
2290 .setup = testsuite_setup,
2291 .teardown = testsuite_teardown,
2292 .unit_test_cases = {
2293 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
2294 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dsa),
2295 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2296 test_dh_keygenration),
2297 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
2298 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2299 test_rsa_sign_verify),
2300 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2301 test_rsa_enc_dec_crt),
2302 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2303 test_rsa_sign_verify_crt),
2304 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
2305 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
2306 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_one_by_one),
2307 TEST_CASES_END() /**< NULL terminate unit test array */
2311 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
2312 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
2313 .setup = testsuite_setup,
2314 .teardown = testsuite_teardown,
2315 .unit_test_cases = {
2316 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_one_by_one),
2317 TEST_CASES_END() /**< NULL terminate unit test array */
2321 static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
2322 .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
2323 .setup = testsuite_setup,
2324 .teardown = testsuite_teardown,
2325 .unit_test_cases = {
2326 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
2327 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2328 test_rsa_enc_dec_crt),
2329 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2330 test_rsa_sign_verify_crt),
2331 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
2332 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2333 test_ecdsa_sign_verify_all_curve),
2334 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2335 test_ecpm_all_curve),
2336 TEST_CASES_END() /**< NULL terminate unit test array */
2341 test_cryptodev_openssl_asym(void)
2343 gbl_driver_id = rte_cryptodev_driver_id_get(
2344 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
2346 if (gbl_driver_id == -1) {
2347 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
2351 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
2355 test_cryptodev_qat_asym(void)
2357 gbl_driver_id = rte_cryptodev_driver_id_get(
2358 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
2360 if (gbl_driver_id == -1) {
2361 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
2365 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
2369 test_cryptodev_octeontx_asym(void)
2371 gbl_driver_id = rte_cryptodev_driver_id_get(
2372 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
2373 if (gbl_driver_id == -1) {
2374 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
2377 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2381 test_cryptodev_cn9k_asym(void)
2383 gbl_driver_id = rte_cryptodev_driver_id_get(
2384 RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
2385 if (gbl_driver_id == -1) {
2386 RTE_LOG(ERR, USER1, "CN9K PMD must be loaded.\n");
2390 /* Use test suite registered for crypto_octeontx PMD */
2391 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2395 test_cryptodev_cn10k_asym(void)
2397 gbl_driver_id = rte_cryptodev_driver_id_get(
2398 RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
2399 if (gbl_driver_id == -1) {
2400 RTE_LOG(ERR, USER1, "CN10K PMD must be loaded.\n");
2404 /* Use test suite registered for crypto_octeontx PMD */
2405 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2408 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
2409 test_cryptodev_openssl_asym);
2411 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
2413 REGISTER_TEST_COMMAND(cryptodev_octeontx_asym_autotest,
2414 test_cryptodev_octeontx_asym);
2415 REGISTER_TEST_COMMAND(cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);
2416 REGISTER_TEST_COMMAND(cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);
2418 #endif /* !RTE_EXEC_ENV_WINDOWS */