1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium Networks
3 * Copyright (c) 2019 Intel Corporation
6 #include <rte_bus_vdev.h>
7 #include <rte_common.h>
8 #include <rte_hexdump.h>
10 #include <rte_malloc.h>
11 #include <rte_memcpy.h>
12 #include <rte_pause.h>
14 #include <rte_cryptodev.h>
15 #include <rte_cryptodev_pmd.h>
16 #include <rte_crypto.h>
18 #include "test_cryptodev.h"
19 #include "test_cryptodev_dh_test_vectors.h"
20 #include "test_cryptodev_dsa_test_vectors.h"
21 #include "test_cryptodev_mod_test_vectors.h"
22 #include "test_cryptodev_rsa_test_vectors.h"
23 #include "test_cryptodev_asym_util.h"
26 #define TEST_NUM_BUFS 10
27 #define TEST_NUM_SESSIONS 4
29 #ifndef TEST_DATA_SIZE
30 #define TEST_DATA_SIZE 4096
32 #define ASYM_TEST_MSG_LEN 256
33 #define TEST_VECTOR_SIZE 256
35 static int gbl_driver_id;
36 struct crypto_testsuite_params {
37 struct rte_mempool *op_mpool;
38 struct rte_mempool *session_mpool;
39 struct rte_cryptodev_config conf;
40 struct rte_cryptodev_qp_conf qp_conf;
41 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
42 uint8_t valid_dev_count;
45 struct crypto_unittest_params {
46 struct rte_cryptodev_asym_session *sess;
47 struct rte_crypto_op *op;
50 union test_case_structure {
51 struct modex_test_data modex;
52 struct modinv_test_data modinv;
53 struct rsa_test_data_2 rsa_data;
56 struct test_cases_array {
58 const void *address[TEST_VECTOR_SIZE];
60 static struct test_cases_array test_vector = {0, { NULL } };
62 static uint32_t test_index;
64 static struct crypto_testsuite_params testsuite_params = { NULL };
67 queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
69 struct crypto_testsuite_params *ts_params = &testsuite_params;
70 struct rte_mempool *op_mpool = ts_params->op_mpool;
71 uint8_t dev_id = ts_params->valid_devs[0];
72 struct rte_crypto_op *op, *result_op;
73 struct rte_crypto_asym_op *asym_op;
74 uint8_t output_buf[TEST_DATA_SIZE];
75 int status = TEST_SUCCESS;
77 /* Set up crypto op data structure */
78 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
80 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
81 "operation struct\n");
87 /* Compute sign on the test vector */
88 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
90 asym_op->rsa.message.data = rsaplaintext.data;
91 asym_op->rsa.message.length = rsaplaintext.len;
92 asym_op->rsa.sign.length = 0;
93 asym_op->rsa.sign.data = output_buf;
94 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
96 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
97 asym_op->rsa.message.length);
99 /* Attach asymmetric crypto session to crypto operations */
100 rte_crypto_op_attach_asym_session(op, sess);
102 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
104 /* Process crypto operation */
105 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
106 RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
107 status = TEST_FAILED;
111 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
114 if (result_op == NULL) {
115 RTE_LOG(ERR, USER1, "Failed to process sign op\n");
116 status = TEST_FAILED;
120 debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
121 asym_op->rsa.sign.length);
122 asym_op = result_op->asym;
125 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
126 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
128 /* Process crypto operation */
129 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
130 RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
131 status = TEST_FAILED;
135 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
138 if (result_op == NULL) {
139 RTE_LOG(ERR, USER1, "Failed to process verify op\n");
140 status = TEST_FAILED;
144 status = TEST_SUCCESS;
145 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
146 RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
147 status = TEST_FAILED;
152 rte_crypto_op_free(op);
158 queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
160 struct crypto_testsuite_params *ts_params = &testsuite_params;
161 struct rte_mempool *op_mpool = ts_params->op_mpool;
162 uint8_t dev_id = ts_params->valid_devs[0];
163 struct rte_crypto_op *op, *result_op;
164 struct rte_crypto_asym_op *asym_op;
165 uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
166 int ret, status = TEST_SUCCESS;
168 /* Set up crypto op data structure */
169 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
171 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
172 "operation struct\n");
178 /* Compute encryption on the test vector */
179 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
181 asym_op->rsa.message.data = rsaplaintext.data;
182 asym_op->rsa.cipher.data = cipher_buf;
183 asym_op->rsa.cipher.length = 0;
184 asym_op->rsa.message.length = rsaplaintext.len;
185 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
187 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
188 asym_op->rsa.message.length);
190 /* Attach asymmetric crypto session to crypto operations */
191 rte_crypto_op_attach_asym_session(op, sess);
193 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
195 /* Process crypto operation */
196 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
197 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
198 status = TEST_FAILED;
202 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
205 if (result_op == NULL) {
206 RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
207 status = TEST_FAILED;
210 debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
211 asym_op->rsa.message.length);
213 /* Use the resulted output as decryption Input vector*/
214 asym_op = result_op->asym;
215 asym_op->rsa.message.length = 0;
216 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
217 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
219 /* Process crypto operation */
220 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
221 RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
222 status = TEST_FAILED;
226 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
229 if (result_op == NULL) {
230 RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
231 status = TEST_FAILED;
234 status = TEST_SUCCESS;
235 ret = rsa_verify(&rsaplaintext, result_op);
237 status = TEST_FAILED;
241 rte_crypto_op_free(op);
246 test_cryptodev_asym_ver(struct rte_crypto_op *op,
247 struct rte_crypto_asym_xform *xform_tc,
248 union test_case_structure *data_tc,
249 struct rte_crypto_op *result_op)
251 int status = TEST_FAILED;
253 uint8_t *data_expected = NULL, *data_received = NULL;
254 size_t data_size = 0;
256 switch (data_tc->modex.xform_type) {
257 case RTE_CRYPTO_ASYM_XFORM_MODEX:
258 data_expected = data_tc->modex.reminder.data;
259 data_received = result_op->asym->modex.result.data;
260 data_size = result_op->asym->modex.result.length;
262 case RTE_CRYPTO_ASYM_XFORM_MODINV:
263 data_expected = data_tc->modinv.inverse.data;
264 data_received = result_op->asym->modinv.result.data;
265 data_size = result_op->asym->modinv.result.length;
267 case RTE_CRYPTO_ASYM_XFORM_RSA:
268 if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
269 data_size = xform_tc->rsa.n.length;
270 data_received = result_op->asym->rsa.cipher.data;
271 data_expected = data_tc->rsa_data.ct.data;
272 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
273 data_size = xform_tc->rsa.n.length;
274 data_expected = data_tc->rsa_data.pt.data;
275 data_received = result_op->asym->rsa.message.data;
276 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
277 data_size = xform_tc->rsa.n.length;
278 data_expected = data_tc->rsa_data.sign.data;
279 data_received = result_op->asym->rsa.sign.data;
280 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
281 data_size = xform_tc->rsa.n.length;
282 data_expected = data_tc->rsa_data.pt.data;
283 data_received = result_op->asym->rsa.cipher.data;
286 case RTE_CRYPTO_ASYM_XFORM_DH:
287 case RTE_CRYPTO_ASYM_XFORM_DSA:
288 case RTE_CRYPTO_ASYM_XFORM_NONE:
289 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
293 ret = memcmp(data_expected, data_received, data_size);
294 if (!ret && data_size)
295 status = TEST_SUCCESS;
301 test_cryptodev_asym_op(struct crypto_testsuite_params *ts_params,
302 union test_case_structure *data_tc,
303 char *test_msg, int sessionless, enum rte_crypto_asym_op_type type,
304 enum rte_crypto_rsa_priv_key_type key_type)
306 struct rte_crypto_asym_op *asym_op = NULL;
307 struct rte_crypto_op *op = NULL;
308 struct rte_crypto_op *result_op = NULL;
309 struct rte_crypto_asym_xform xform_tc;
310 struct rte_cryptodev_asym_session *sess = NULL;
311 struct rte_cryptodev_asym_capability_idx cap_idx;
312 const struct rte_cryptodev_asymmetric_xform_capability *capability;
313 uint8_t dev_id = ts_params->valid_devs[0];
314 uint8_t input[TEST_DATA_SIZE] = {0};
315 uint8_t *result = NULL;
317 int status = TEST_SUCCESS;
319 xform_tc.next = NULL;
320 xform_tc.xform_type = data_tc->modex.xform_type;
322 cap_idx.type = xform_tc.xform_type;
323 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
325 if (capability == NULL) {
327 "Device doesn't support MODEX. Test Skipped\n");
331 /* Generate crypto op data structure */
332 op = rte_crypto_op_alloc(ts_params->op_mpool,
333 RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
336 snprintf(test_msg, ASYM_TEST_MSG_LEN,
337 "line %u FAILED: %s",
338 __LINE__, "Failed to allocate asymmetric crypto "
340 status = TEST_FAILED;
346 switch (xform_tc.xform_type) {
347 case RTE_CRYPTO_ASYM_XFORM_MODEX:
348 result = rte_zmalloc(NULL, data_tc->modex.result_len, 0);
349 xform_tc.modex.modulus.data = data_tc->modex.modulus.data;
350 xform_tc.modex.modulus.length = data_tc->modex.modulus.len;
351 xform_tc.modex.exponent.data = data_tc->modex.exponent.data;
352 xform_tc.modex.exponent.length = data_tc->modex.exponent.len;
353 memcpy(input, data_tc->modex.base.data,
354 data_tc->modex.base.len);
355 asym_op->modex.base.data = input;
356 asym_op->modex.base.length = data_tc->modex.base.len;
357 asym_op->modex.result.data = result;
358 asym_op->modex.result.length = data_tc->modex.result_len;
359 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
360 xform_tc.modex.modulus.length)) {
361 snprintf(test_msg, ASYM_TEST_MSG_LEN,
363 "FAILED: %s", __LINE__,
364 "Invalid MODULUS length specified");
365 status = TEST_FAILED;
369 case RTE_CRYPTO_ASYM_XFORM_MODINV:
370 result = rte_zmalloc(NULL, data_tc->modinv.result_len, 0);
371 xform_tc.modinv.modulus.data = data_tc->modinv.modulus.data;
372 xform_tc.modinv.modulus.length = data_tc->modinv.modulus.len;
373 memcpy(input, data_tc->modinv.base.data,
374 data_tc->modinv.base.len);
375 asym_op->modinv.base.data = input;
376 asym_op->modinv.base.length = data_tc->modinv.base.len;
377 asym_op->modinv.result.data = result;
378 asym_op->modinv.result.length = data_tc->modinv.result_len;
379 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
380 xform_tc.modinv.modulus.length)) {
381 snprintf(test_msg, ASYM_TEST_MSG_LEN,
383 "FAILED: %s", __LINE__,
384 "Invalid MODULUS length specified");
385 status = TEST_FAILED;
389 case RTE_CRYPTO_ASYM_XFORM_RSA:
390 result = rte_zmalloc(NULL, data_tc->rsa_data.n.len, 0);
391 op->asym->rsa.op_type = type;
392 xform_tc.rsa.e.data = data_tc->rsa_data.e.data;
393 xform_tc.rsa.e.length = data_tc->rsa_data.e.len;
394 xform_tc.rsa.n.data = data_tc->rsa_data.n.data;
395 xform_tc.rsa.n.length = data_tc->rsa_data.n.len;
397 if (key_type == RTE_RSA_KEY_TYPE_EXP) {
398 xform_tc.rsa.d.data = data_tc->rsa_data.d.data;
399 xform_tc.rsa.d.length = data_tc->rsa_data.d.len;
401 xform_tc.rsa.qt.p.data = data_tc->rsa_data.p.data;
402 xform_tc.rsa.qt.p.length = data_tc->rsa_data.p.len;
403 xform_tc.rsa.qt.q.data = data_tc->rsa_data.q.data;
404 xform_tc.rsa.qt.q.length = data_tc->rsa_data.q.len;
405 xform_tc.rsa.qt.dP.data = data_tc->rsa_data.dP.data;
406 xform_tc.rsa.qt.dP.length = data_tc->rsa_data.dP.len;
407 xform_tc.rsa.qt.dQ.data = data_tc->rsa_data.dQ.data;
408 xform_tc.rsa.qt.dQ.length = data_tc->rsa_data.dQ.len;
409 xform_tc.rsa.qt.qInv.data = data_tc->rsa_data.qInv.data;
410 xform_tc.rsa.qt.qInv.length = data_tc->rsa_data.qInv.len;
413 xform_tc.rsa.key_type = key_type;
414 op->asym->rsa.pad = data_tc->rsa_data.padding;
416 if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
417 asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
418 asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
419 asym_op->rsa.cipher.data = result;
420 asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
421 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
422 asym_op->rsa.message.data = result;
423 asym_op->rsa.message.length = data_tc->rsa_data.n.len;
424 asym_op->rsa.cipher.data = data_tc->rsa_data.ct.data;
425 asym_op->rsa.cipher.length = data_tc->rsa_data.ct.len;
426 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
427 asym_op->rsa.sign.data = result;
428 asym_op->rsa.sign.length = data_tc->rsa_data.n.len;
429 asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
430 asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
431 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
432 asym_op->rsa.cipher.data = result;
433 asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
434 asym_op->rsa.sign.data = data_tc->rsa_data.sign.data;
435 asym_op->rsa.sign.length = data_tc->rsa_data.sign.len;
438 case RTE_CRYPTO_ASYM_XFORM_DH:
439 case RTE_CRYPTO_ASYM_XFORM_DSA:
440 case RTE_CRYPTO_ASYM_XFORM_NONE:
441 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
443 snprintf(test_msg, ASYM_TEST_MSG_LEN,
445 "FAILED: %s", __LINE__,
446 "Invalid ASYM algorithm specified");
447 status = TEST_FAILED;
452 sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
454 snprintf(test_msg, ASYM_TEST_MSG_LEN,
456 "FAILED: %s", __LINE__,
457 "Session creation failed");
458 status = TEST_FAILED;
462 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
463 ts_params->session_mpool) < 0) {
464 snprintf(test_msg, ASYM_TEST_MSG_LEN,
465 "line %u FAILED: %s",
466 __LINE__, "unabled to config sym session");
467 status = TEST_FAILED;
471 rte_crypto_op_attach_asym_session(op, sess);
473 asym_op->xform = &xform_tc;
474 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
476 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
478 /* Process crypto operation */
479 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
480 snprintf(test_msg, ASYM_TEST_MSG_LEN,
481 "line %u FAILED: %s",
482 __LINE__, "Error sending packet for operation");
483 status = TEST_FAILED;
487 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
490 if (result_op == NULL) {
491 snprintf(test_msg, ASYM_TEST_MSG_LEN,
492 "line %u FAILED: %s",
493 __LINE__, "Failed to process asym crypto op");
494 status = TEST_FAILED;
498 if (test_cryptodev_asym_ver(op, &xform_tc, data_tc, result_op) != TEST_SUCCESS) {
499 snprintf(test_msg, ASYM_TEST_MSG_LEN,
500 "line %u FAILED: %s",
501 __LINE__, "Verification failed ");
502 status = TEST_FAILED;
507 snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
509 snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
513 rte_cryptodev_asym_session_clear(dev_id, sess);
514 rte_cryptodev_asym_session_free(sess);
518 rte_crypto_op_free(op);
527 test_one_case(const void *test_case, int sessionless)
529 int status = TEST_SUCCESS, i = 0;
530 char test_msg[ASYM_TEST_MSG_LEN + 1];
532 /* Map the case to union */
533 union test_case_structure tc;
534 memcpy(&tc, test_case, sizeof(tc));
536 if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX
537 || tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
538 status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg,
540 printf(" %u) TestCase %s %s\n", test_index++,
541 tc.modex.description, test_msg);
543 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
544 if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
545 if (tc.rsa_data.op_type_flags & (1 << i)) {
546 if (tc.rsa_data.key_exp) {
547 status = test_cryptodev_asym_op(
548 &testsuite_params, &tc,
549 test_msg, sessionless, i,
550 RTE_RSA_KEY_TYPE_EXP);
554 if (tc.rsa_data.key_qt && (i ==
555 RTE_CRYPTO_ASYM_OP_DECRYPT ||
556 i == RTE_CRYPTO_ASYM_OP_SIGN)) {
557 status = test_cryptodev_asym_op(
559 &tc, test_msg, sessionless, i,
560 RTE_RSA_KET_TYPE_QT);
567 printf(" %u) TestCase %s %s\n", test_index++,
568 tc.modex.description, test_msg);
575 load_test_vectors(void)
577 uint32_t i = 0, v_size = 0;
578 /* Load MODEX vector*/
579 v_size = RTE_DIM(modex_test_case);
580 for (i = 0; i < v_size; i++) {
581 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
582 RTE_LOG(DEBUG, USER1,
583 "TEST_VECTOR_SIZE too small\n");
586 test_vector.address[test_vector.size] = &modex_test_case[i];
589 /* Load MODINV vector*/
590 v_size = RTE_DIM(modinv_test_case);
591 for (i = 0; i < v_size; i++) {
592 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
593 RTE_LOG(DEBUG, USER1,
594 "TEST_VECTOR_SIZE too small\n");
597 test_vector.address[test_vector.size] = &modinv_test_case[i];
601 v_size = RTE_DIM(rsa_test_case_list);
602 for (i = 0; i < v_size; i++) {
603 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
604 RTE_LOG(DEBUG, USER1,
605 "TEST_VECTOR_SIZE too small\n");
608 test_vector.address[test_vector.size] = &rsa_test_case_list[i];
615 test_one_by_one(void)
617 int status = TEST_SUCCESS;
618 struct crypto_testsuite_params *ts_params = &testsuite_params;
620 uint8_t dev_id = ts_params->valid_devs[0];
621 struct rte_cryptodev_info dev_info;
624 rte_cryptodev_info_get(dev_id, &dev_info);
625 if ((dev_info.feature_flags &
626 RTE_CRYPTODEV_FF_ASYM_SESSIONLESS)) {
630 /* Go through all test cases */
632 for (i = 0; i < test_vector.size; i++) {
633 if (test_one_case(test_vector.address[i], 0) != TEST_SUCCESS)
634 status = TEST_FAILED;
637 for (i = 0; i < test_vector.size; i++) {
638 if (test_one_case(test_vector.address[i], 1)
640 status = TEST_FAILED;
644 TEST_ASSERT_EQUAL(status, 0, "Test failed");
649 test_rsa_sign_verify(void)
651 struct crypto_testsuite_params *ts_params = &testsuite_params;
652 struct rte_mempool *sess_mpool = ts_params->session_mpool;
653 uint8_t dev_id = ts_params->valid_devs[0];
654 struct rte_cryptodev_asym_session *sess;
655 struct rte_cryptodev_info dev_info;
656 int status = TEST_SUCCESS;
658 /* Test case supports op with exponent key only,
659 * Check in PMD feature flag for RSA exponent key type support.
661 rte_cryptodev_info_get(dev_id, &dev_info);
662 if (!(dev_info.feature_flags &
663 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
664 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
665 "exponent key type. Test Skipped\n");
669 sess = rte_cryptodev_asym_session_create(sess_mpool);
672 RTE_LOG(ERR, USER1, "Session creation failed for "
677 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
679 RTE_LOG(ERR, USER1, "Unable to config asym session for "
681 status = TEST_FAILED;
685 status = queue_ops_rsa_sign_verify(sess);
689 rte_cryptodev_asym_session_clear(dev_id, sess);
690 rte_cryptodev_asym_session_free(sess);
692 TEST_ASSERT_EQUAL(status, 0, "Test failed");
698 test_rsa_enc_dec(void)
700 struct crypto_testsuite_params *ts_params = &testsuite_params;
701 struct rte_mempool *sess_mpool = ts_params->session_mpool;
702 uint8_t dev_id = ts_params->valid_devs[0];
703 struct rte_cryptodev_asym_session *sess;
704 struct rte_cryptodev_info dev_info;
705 int status = TEST_SUCCESS;
707 /* Test case supports op with exponent key only,
708 * Check in PMD feature flag for RSA exponent key type support.
710 rte_cryptodev_info_get(dev_id, &dev_info);
711 if (!(dev_info.feature_flags &
712 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
713 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
714 "exponent key type. Test skipped\n");
718 sess = rte_cryptodev_asym_session_create(sess_mpool);
721 RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
725 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
727 RTE_LOG(ERR, USER1, "Unable to config asym session for "
729 status = TEST_FAILED;
733 status = queue_ops_rsa_enc_dec(sess);
737 rte_cryptodev_asym_session_clear(dev_id, sess);
738 rte_cryptodev_asym_session_free(sess);
740 TEST_ASSERT_EQUAL(status, 0, "Test failed");
746 test_rsa_sign_verify_crt(void)
748 struct crypto_testsuite_params *ts_params = &testsuite_params;
749 struct rte_mempool *sess_mpool = ts_params->session_mpool;
750 uint8_t dev_id = ts_params->valid_devs[0];
751 struct rte_cryptodev_asym_session *sess;
752 struct rte_cryptodev_info dev_info;
753 int status = TEST_SUCCESS;
755 /* Test case supports op with quintuple format key only,
756 * Check im PMD feature flag for RSA quintuple key type support.
758 rte_cryptodev_info_get(dev_id, &dev_info);
759 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
760 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
761 "quintuple key type. Test skipped\n");
765 sess = rte_cryptodev_asym_session_create(sess_mpool);
768 RTE_LOG(ERR, USER1, "Session creation failed for "
769 "sign_verify_crt\n");
770 status = TEST_FAILED;
774 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
776 RTE_LOG(ERR, USER1, "Unable to config asym session for "
777 "sign_verify_crt\n");
778 status = TEST_FAILED;
781 status = queue_ops_rsa_sign_verify(sess);
785 rte_cryptodev_asym_session_clear(dev_id, sess);
786 rte_cryptodev_asym_session_free(sess);
788 TEST_ASSERT_EQUAL(status, 0, "Test failed");
794 test_rsa_enc_dec_crt(void)
796 struct crypto_testsuite_params *ts_params = &testsuite_params;
797 struct rte_mempool *sess_mpool = ts_params->session_mpool;
798 uint8_t dev_id = ts_params->valid_devs[0];
799 struct rte_cryptodev_asym_session *sess;
800 struct rte_cryptodev_info dev_info;
801 int status = TEST_SUCCESS;
803 /* Test case supports op with quintuple format key only,
804 * Check in PMD feature flag for RSA quintuple key type support.
806 rte_cryptodev_info_get(dev_id, &dev_info);
807 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
808 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
809 "quintuple key type. Test skipped\n");
813 sess = rte_cryptodev_asym_session_create(sess_mpool);
816 RTE_LOG(ERR, USER1, "Session creation failed for "
821 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
823 RTE_LOG(ERR, USER1, "Unable to config asym session for "
825 status = TEST_FAILED;
828 status = queue_ops_rsa_enc_dec(sess);
832 rte_cryptodev_asym_session_clear(dev_id, sess);
833 rte_cryptodev_asym_session_free(sess);
835 TEST_ASSERT_EQUAL(status, 0, "Test failed");
841 testsuite_setup(void)
843 struct crypto_testsuite_params *ts_params = &testsuite_params;
844 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
845 struct rte_cryptodev_info info;
846 int ret, dev_id = -1;
850 memset(ts_params, 0, sizeof(*ts_params));
852 test_vector.size = 0;
855 ts_params->op_mpool = rte_crypto_op_pool_create(
856 "CRYPTO_ASYM_OP_POOL",
857 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
861 if (ts_params->op_mpool == NULL) {
862 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
866 /* Create an OPENSSL device if required */
867 if (gbl_driver_id == rte_cryptodev_driver_id_get(
868 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
869 nb_devs = rte_cryptodev_device_count_by_driver(
870 rte_cryptodev_driver_id_get(
871 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
874 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
877 TEST_ASSERT(ret == 0, "Failed to create "
878 "instance of pmd : %s",
879 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
883 /* Get list of valid crypto devs */
884 nb_devs = rte_cryptodev_devices_get(
885 rte_cryptodev_driver_name_get(gbl_driver_id),
886 valid_devs, RTE_CRYPTO_MAX_DEVS);
888 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
893 * Get first valid asymmetric device found in test suite param and
896 for (i = 0; i < nb_devs ; i++) {
897 rte_cryptodev_info_get(valid_devs[i], &info);
898 if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
899 dev_id = ts_params->valid_devs[0] = valid_devs[i];
905 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
910 /* Set valid device count */
911 ts_params->valid_dev_count = nb_devs;
913 /* configure device with num qp */
914 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
915 ts_params->conf.socket_id = SOCKET_ID_ANY;
916 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
917 RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
918 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
920 "Failed to configure cryptodev %u with %u qps",
921 dev_id, ts_params->conf.nb_queue_pairs);
924 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
925 ts_params->qp_conf.mp_session = ts_params->session_mpool;
926 ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
927 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
928 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
929 dev_id, qp_id, &ts_params->qp_conf,
930 rte_cryptodev_socket_id(dev_id)),
931 "Failed to setup queue pair %u on cryptodev %u ASYM",
935 /* setup asym session pool */
936 unsigned int session_size =
937 rte_cryptodev_asym_get_private_session_size(dev_id);
939 * Create mempool with TEST_NUM_SESSIONS * 2,
940 * to include the session headers
942 ts_params->session_mpool = rte_mempool_create(
944 TEST_NUM_SESSIONS * 2,
946 0, 0, NULL, NULL, NULL,
950 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
951 "session mempool allocation failed");
957 testsuite_teardown(void)
959 struct crypto_testsuite_params *ts_params = &testsuite_params;
961 if (ts_params->op_mpool != NULL) {
962 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
963 rte_mempool_avail_count(ts_params->op_mpool));
966 /* Free session mempools */
967 if (ts_params->session_mpool != NULL) {
968 rte_mempool_free(ts_params->session_mpool);
969 ts_params->session_mpool = NULL;
976 struct crypto_testsuite_params *ts_params = &testsuite_params;
980 /* Reconfigure device to default parameters */
981 ts_params->conf.socket_id = SOCKET_ID_ANY;
983 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
985 "Failed to configure cryptodev %u",
986 ts_params->valid_devs[0]);
988 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
989 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
990 ts_params->valid_devs[0], qp_id,
992 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
993 "Failed to setup queue pair %u on cryptodev %u",
994 qp_id, ts_params->valid_devs[0]);
997 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
999 /* Start the device */
1000 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1001 "Failed to start cryptodev %u",
1002 ts_params->valid_devs[0]);
1004 return TEST_SUCCESS;
1010 struct crypto_testsuite_params *ts_params = &testsuite_params;
1011 struct rte_cryptodev_stats stats;
1013 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1015 /* Stop the device */
1016 rte_cryptodev_stop(ts_params->valid_devs[0]);
1019 static inline void print_asym_capa(
1020 const struct rte_cryptodev_asymmetric_xform_capability *capa)
1024 printf("\nxform type: %s\n===================\n",
1025 rte_crypto_asym_xform_strings[capa->xform_type]);
1026 printf("operation supported -");
1028 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
1029 /* check supported operations */
1030 if (rte_cryptodev_asym_xform_capability_check_optype(capa, i))
1032 rte_crypto_asym_op_strings[i]);
1034 switch (capa->xform_type) {
1035 case RTE_CRYPTO_ASYM_XFORM_RSA:
1036 case RTE_CRYPTO_ASYM_XFORM_MODINV:
1037 case RTE_CRYPTO_ASYM_XFORM_MODEX:
1038 case RTE_CRYPTO_ASYM_XFORM_DH:
1039 case RTE_CRYPTO_ASYM_XFORM_DSA:
1040 printf(" modlen: min %d max %d increment %d\n",
1043 capa->modlen.increment);
1051 test_capability(void)
1053 struct crypto_testsuite_params *ts_params = &testsuite_params;
1054 uint8_t dev_id = ts_params->valid_devs[0];
1055 struct rte_cryptodev_info dev_info;
1056 const struct rte_cryptodev_capabilities *dev_capa;
1058 struct rte_cryptodev_asym_capability_idx idx;
1059 const struct rte_cryptodev_asymmetric_xform_capability *capa;
1061 rte_cryptodev_info_get(dev_id, &dev_info);
1062 if (!(dev_info.feature_flags &
1063 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
1064 RTE_LOG(INFO, USER1,
1065 "Device doesn't support asymmetric. Test Skipped\n");
1066 return TEST_SUCCESS;
1069 /* print xform capability */
1071 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
1073 dev_capa = &(dev_info.capabilities[i]);
1074 if (dev_info.capabilities[i].op ==
1075 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1076 idx.type = dev_capa->asym.xform_capa.xform_type;
1078 capa = rte_cryptodev_asym_capability_get(dev_id,
1080 rte_cryptodev_asym_capability_idx *) &idx);
1081 print_asym_capa(capa);
1084 return TEST_SUCCESS;
1088 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
1090 struct crypto_testsuite_params *ts_params = &testsuite_params;
1091 struct rte_mempool *op_mpool = ts_params->op_mpool;
1092 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1093 uint8_t dev_id = ts_params->valid_devs[0];
1094 struct rte_crypto_asym_op *asym_op = NULL;
1095 struct rte_crypto_op *op = NULL, *result_op = NULL;
1096 struct rte_cryptodev_asym_session *sess = NULL;
1097 int status = TEST_SUCCESS;
1098 uint8_t output[TEST_DH_MOD_LEN];
1099 struct rte_crypto_asym_xform xform = *xfrm;
1100 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
1102 sess = rte_cryptodev_asym_session_create(sess_mpool);
1105 "line %u FAILED: %s", __LINE__,
1106 "Session creation failed");
1107 status = TEST_FAILED;
1110 /* set up crypto op data structure */
1111 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1114 "line %u FAILED: %s",
1115 __LINE__, "Failed to allocate asymmetric crypto "
1116 "operation struct");
1117 status = TEST_FAILED;
1122 /* Setup a xform and op to generate private key only */
1123 xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
1125 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
1126 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
1127 asym_op->dh.pub_key.data = (uint8_t *)peer;
1128 asym_op->dh.pub_key.length = sizeof(peer);
1129 asym_op->dh.shared_secret.data = output;
1130 asym_op->dh.shared_secret.length = sizeof(output);
1132 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1135 "line %u FAILED: %s",
1136 __LINE__, "unabled to config sym session");
1137 status = TEST_FAILED;
1141 /* attach asymmetric crypto session to crypto operations */
1142 rte_crypto_op_attach_asym_session(op, sess);
1144 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1146 /* Process crypto operation */
1147 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1149 "line %u FAILED: %s",
1150 __LINE__, "Error sending packet for operation");
1151 status = TEST_FAILED;
1155 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1158 if (result_op == NULL) {
1160 "line %u FAILED: %s",
1161 __LINE__, "Failed to process asym crypto op");
1162 status = TEST_FAILED;
1166 debug_hexdump(stdout, "shared secret:",
1167 asym_op->dh.shared_secret.data,
1168 asym_op->dh.shared_secret.length);
1172 rte_cryptodev_asym_session_clear(dev_id, sess);
1173 rte_cryptodev_asym_session_free(sess);
1176 rte_crypto_op_free(op);
1181 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1183 struct crypto_testsuite_params *ts_params = &testsuite_params;
1184 struct rte_mempool *op_mpool = ts_params->op_mpool;
1185 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1186 uint8_t dev_id = ts_params->valid_devs[0];
1187 struct rte_crypto_asym_op *asym_op = NULL;
1188 struct rte_crypto_op *op = NULL, *result_op = NULL;
1189 struct rte_cryptodev_asym_session *sess = NULL;
1190 int status = TEST_SUCCESS;
1191 uint8_t output[TEST_DH_MOD_LEN];
1192 struct rte_crypto_asym_xform xform = *xfrm;
1194 sess = rte_cryptodev_asym_session_create(sess_mpool);
1197 "line %u FAILED: %s", __LINE__,
1198 "Session creation failed");
1199 status = TEST_FAILED;
1202 /* set up crypto op data structure */
1203 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1206 "line %u FAILED: %s",
1207 __LINE__, "Failed to allocate asymmetric crypto "
1208 "operation struct");
1209 status = TEST_FAILED;
1214 /* Setup a xform and op to generate private key only */
1215 xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1217 asym_op->dh.priv_key.data = output;
1218 asym_op->dh.priv_key.length = sizeof(output);
1220 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1223 "line %u FAILED: %s",
1224 __LINE__, "unabled to config sym session");
1225 status = TEST_FAILED;
1229 /* attach asymmetric crypto session to crypto operations */
1230 rte_crypto_op_attach_asym_session(op, sess);
1232 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1234 /* Process crypto operation */
1235 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1237 "line %u FAILED: %s",
1238 __LINE__, "Error sending packet for operation");
1239 status = TEST_FAILED;
1243 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1246 if (result_op == NULL) {
1248 "line %u FAILED: %s",
1249 __LINE__, "Failed to process asym crypto op");
1250 status = TEST_FAILED;
1254 debug_hexdump(stdout, "private key:",
1255 asym_op->dh.priv_key.data,
1256 asym_op->dh.priv_key.length);
1261 rte_cryptodev_asym_session_clear(dev_id, sess);
1262 rte_cryptodev_asym_session_free(sess);
1265 rte_crypto_op_free(op);
1272 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1274 struct crypto_testsuite_params *ts_params = &testsuite_params;
1275 struct rte_mempool *op_mpool = ts_params->op_mpool;
1276 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1277 uint8_t dev_id = ts_params->valid_devs[0];
1278 struct rte_crypto_asym_op *asym_op = NULL;
1279 struct rte_crypto_op *op = NULL, *result_op = NULL;
1280 struct rte_cryptodev_asym_session *sess = NULL;
1281 int status = TEST_SUCCESS;
1282 uint8_t output[TEST_DH_MOD_LEN];
1283 struct rte_crypto_asym_xform xform = *xfrm;
1285 sess = rte_cryptodev_asym_session_create(sess_mpool);
1288 "line %u FAILED: %s", __LINE__,
1289 "Session creation failed");
1290 status = TEST_FAILED;
1293 /* set up crypto op data structure */
1294 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1297 "line %u FAILED: %s",
1298 __LINE__, "Failed to allocate asymmetric crypto "
1299 "operation struct");
1300 status = TEST_FAILED;
1304 /* Setup a xform chain to generate public key
1305 * using test private key
1308 xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1311 asym_op->dh.pub_key.data = output;
1312 asym_op->dh.pub_key.length = sizeof(output);
1313 /* load pre-defined private key */
1314 asym_op->dh.priv_key.data = rte_malloc(NULL,
1315 dh_test_params.priv_key.length,
1317 asym_op->dh.priv_key = dh_test_params.priv_key;
1319 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1322 "line %u FAILED: %s",
1323 __LINE__, "unabled to config sym session");
1324 status = TEST_FAILED;
1328 /* attach asymmetric crypto session to crypto operations */
1329 rte_crypto_op_attach_asym_session(op, sess);
1331 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1333 /* Process crypto operation */
1334 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1336 "line %u FAILED: %s",
1337 __LINE__, "Error sending packet for operation");
1338 status = TEST_FAILED;
1342 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1345 if (result_op == NULL) {
1347 "line %u FAILED: %s",
1348 __LINE__, "Failed to process asym crypto op");
1349 status = TEST_FAILED;
1353 debug_hexdump(stdout, "pub key:",
1354 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1356 debug_hexdump(stdout, "priv key:",
1357 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1361 rte_cryptodev_asym_session_clear(dev_id, sess);
1362 rte_cryptodev_asym_session_free(sess);
1365 rte_crypto_op_free(op);
1371 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1373 struct crypto_testsuite_params *ts_params = &testsuite_params;
1374 struct rte_mempool *op_mpool = ts_params->op_mpool;
1375 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1376 uint8_t dev_id = ts_params->valid_devs[0];
1377 struct rte_crypto_asym_op *asym_op = NULL;
1378 struct rte_crypto_op *op = NULL, *result_op = NULL;
1379 struct rte_cryptodev_asym_session *sess = NULL;
1380 int status = TEST_SUCCESS;
1381 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1382 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1383 struct rte_crypto_asym_xform pub_key_xform;
1384 struct rte_crypto_asym_xform xform = *xfrm;
1386 sess = rte_cryptodev_asym_session_create(sess_mpool);
1389 "line %u FAILED: %s", __LINE__,
1390 "Session creation failed");
1391 status = TEST_FAILED;
1395 /* set up crypto op data structure */
1396 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1399 "line %u FAILED: %s",
1400 __LINE__, "Failed to allocate asymmetric crypto "
1401 "operation struct");
1402 status = TEST_FAILED;
1406 /* Setup a xform chain to generate
1407 * private key first followed by
1409 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1410 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1411 pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1412 xform.next = &pub_key_xform;
1414 asym_op->dh.pub_key.data = out_pub_key;
1415 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1416 asym_op->dh.priv_key.data = out_prv_key;
1417 asym_op->dh.priv_key.length = sizeof(out_prv_key);
1418 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1421 "line %u FAILED: %s",
1422 __LINE__, "unabled to config sym session");
1423 status = TEST_FAILED;
1427 /* attach asymmetric crypto session to crypto operations */
1428 rte_crypto_op_attach_asym_session(op, sess);
1430 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1432 /* Process crypto operation */
1433 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1435 "line %u FAILED: %s",
1436 __LINE__, "Error sending packet for operation");
1437 status = TEST_FAILED;
1441 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1444 if (result_op == NULL) {
1446 "line %u FAILED: %s",
1447 __LINE__, "Failed to process asym crypto op");
1448 status = TEST_FAILED;
1451 debug_hexdump(stdout, "priv key:",
1452 out_prv_key, asym_op->dh.priv_key.length);
1453 debug_hexdump(stdout, "pub key:",
1454 out_pub_key, asym_op->dh.pub_key.length);
1458 rte_cryptodev_asym_session_clear(dev_id, sess);
1459 rte_cryptodev_asym_session_free(sess);
1462 rte_crypto_op_free(op);
1470 struct crypto_testsuite_params *ts_params = &testsuite_params;
1471 struct rte_mempool *op_mpool = ts_params->op_mpool;
1472 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1473 uint8_t dev_id = ts_params->valid_devs[0];
1474 struct rte_crypto_asym_op *asym_op = NULL;
1475 struct rte_crypto_op *op = NULL, *result_op = NULL;
1476 struct rte_cryptodev_asym_session *sess = NULL;
1477 int status = TEST_SUCCESS;
1478 struct rte_cryptodev_asym_capability_idx cap_idx;
1479 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1480 uint8_t input[TEST_DATA_SIZE] = {0};
1482 uint8_t result[sizeof(mod_p)] = { 0 };
1484 if (rte_cryptodev_asym_get_xform_enum(
1485 &modinv_xform.xform_type, "modinv") < 0) {
1487 "Invalid ASYM algorithm specified\n");
1491 cap_idx.type = modinv_xform.xform_type;
1492 capability = rte_cryptodev_asym_capability_get(dev_id,
1495 if (capability == NULL) {
1496 RTE_LOG(INFO, USER1,
1497 "Device doesn't support MOD INV. Test Skipped\n");
1501 if (rte_cryptodev_asym_xform_capability_check_modlen(
1503 modinv_xform.modinv.modulus.length)) {
1505 "Invalid MODULUS length specified\n");
1509 sess = rte_cryptodev_asym_session_create(sess_mpool);
1511 RTE_LOG(ERR, USER1, "line %u "
1512 "FAILED: %s", __LINE__,
1513 "Session creation failed");
1514 status = TEST_FAILED;
1518 if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
1521 "line %u FAILED: %s",
1522 __LINE__, "unabled to config sym session");
1523 status = TEST_FAILED;
1527 /* generate crypto op data structure */
1528 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1531 "line %u FAILED: %s",
1532 __LINE__, "Failed to allocate asymmetric crypto "
1533 "operation struct");
1534 status = TEST_FAILED;
1539 memcpy(input, base, sizeof(base));
1540 asym_op->modinv.base.data = input;
1541 asym_op->modinv.base.length = sizeof(base);
1542 asym_op->modinv.result.data = result;
1543 asym_op->modinv.result.length = sizeof(result);
1545 /* attach asymmetric crypto session to crypto operations */
1546 rte_crypto_op_attach_asym_session(op, sess);
1548 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1550 /* Process crypto operation */
1551 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1553 "line %u FAILED: %s",
1554 __LINE__, "Error sending packet for operation");
1555 status = TEST_FAILED;
1559 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1562 if (result_op == NULL) {
1564 "line %u FAILED: %s",
1565 __LINE__, "Failed to process asym crypto op");
1566 status = TEST_FAILED;
1570 ret = verify_modinv(mod_inv, result_op);
1573 "operation verification failed\n");
1574 status = TEST_FAILED;
1579 rte_cryptodev_asym_session_clear(dev_id, sess);
1580 rte_cryptodev_asym_session_free(sess);
1584 rte_crypto_op_free(op);
1586 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1594 struct crypto_testsuite_params *ts_params = &testsuite_params;
1595 struct rte_mempool *op_mpool = ts_params->op_mpool;
1596 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1597 uint8_t dev_id = ts_params->valid_devs[0];
1598 struct rte_crypto_asym_op *asym_op = NULL;
1599 struct rte_crypto_op *op = NULL, *result_op = NULL;
1600 struct rte_cryptodev_asym_session *sess = NULL;
1601 int status = TEST_SUCCESS;
1602 struct rte_cryptodev_asym_capability_idx cap_idx;
1603 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1604 uint8_t input[TEST_DATA_SIZE] = {0};
1606 uint8_t result[sizeof(mod_p)] = { 0 };
1608 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1612 "Invalid ASYM algorithm specified\n");
1616 /* check for modlen capability */
1617 cap_idx.type = modex_xform.xform_type;
1618 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1620 if (capability == NULL) {
1621 RTE_LOG(INFO, USER1,
1622 "Device doesn't support MOD EXP. Test Skipped\n");
1626 if (rte_cryptodev_asym_xform_capability_check_modlen(
1627 capability, modex_xform.modex.modulus.length)) {
1629 "Invalid MODULUS length specified\n");
1633 /* generate crypto op data structure */
1634 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1637 "line %u FAILED: %s",
1638 __LINE__, "Failed to allocate asymmetric crypto "
1639 "operation struct");
1640 status = TEST_FAILED;
1644 sess = rte_cryptodev_asym_session_create(sess_mpool);
1648 "FAILED: %s", __LINE__,
1649 "Session creation failed");
1650 status = TEST_FAILED;
1654 if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1657 "line %u FAILED: %s",
1658 __LINE__, "unabled to config sym session");
1659 status = TEST_FAILED;
1664 memcpy(input, base, sizeof(base));
1665 asym_op->modex.base.data = input;
1666 asym_op->modex.base.length = sizeof(base);
1667 asym_op->modex.result.data = result;
1668 asym_op->modex.result.length = sizeof(result);
1669 /* attach asymmetric crypto session to crypto operations */
1670 rte_crypto_op_attach_asym_session(op, sess);
1672 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1673 /* Process crypto operation */
1674 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1676 "line %u FAILED: %s",
1677 __LINE__, "Error sending packet for operation");
1678 status = TEST_FAILED;
1682 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1685 if (result_op == NULL) {
1687 "line %u FAILED: %s",
1688 __LINE__, "Failed to process asym crypto op");
1689 status = TEST_FAILED;
1693 ret = verify_modexp(mod_exp, result_op);
1696 "operation verification failed\n");
1697 status = TEST_FAILED;
1702 rte_cryptodev_asym_session_clear(dev_id, sess);
1703 rte_cryptodev_asym_session_free(sess);
1707 rte_crypto_op_free(op);
1709 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1715 test_dh_keygenration(void)
1719 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1720 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1721 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1722 dh_test_params.priv_key.length);
1724 RTE_LOG(INFO, USER1,
1725 "Test Public and Private key pair generation\n");
1727 status = test_dh_gen_kp(&dh_xform);
1728 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1730 RTE_LOG(INFO, USER1,
1731 "Test Public Key Generation using pre-defined priv key\n");
1733 status = test_dh_gen_pub_key(&dh_xform);
1734 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1736 RTE_LOG(INFO, USER1,
1737 "Test Private Key Generation only\n");
1739 status = test_dh_gen_priv_key(&dh_xform);
1740 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1742 RTE_LOG(INFO, USER1,
1743 "Test shared secret compute\n");
1745 status = test_dh_gen_shared_sec(&dh_xform);
1746 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1754 struct crypto_testsuite_params *ts_params = &testsuite_params;
1755 struct rte_mempool *op_mpool = ts_params->op_mpool;
1756 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1757 uint8_t dev_id = ts_params->valid_devs[0];
1758 struct rte_crypto_asym_op *asym_op = NULL;
1759 struct rte_crypto_op *op = NULL, *result_op = NULL;
1760 struct rte_cryptodev_asym_session *sess = NULL;
1761 int status = TEST_SUCCESS;
1762 uint8_t r[TEST_DH_MOD_LEN];
1763 uint8_t s[TEST_DH_MOD_LEN];
1764 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1766 sess = rte_cryptodev_asym_session_create(sess_mpool);
1769 "line %u FAILED: %s", __LINE__,
1770 "Session creation failed");
1771 status = TEST_FAILED;
1774 /* set up crypto op data structure */
1775 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1778 "line %u FAILED: %s",
1779 __LINE__, "Failed to allocate asymmetric crypto "
1780 "operation struct");
1781 status = TEST_FAILED;
1786 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1787 dsa_xform.dsa.p.length);
1788 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1789 dsa_xform.dsa.q.length);
1790 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1791 dsa_xform.dsa.g.length);
1792 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1793 dsa_xform.dsa.x.length);
1795 if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1798 "line %u FAILED: %s",
1799 __LINE__, "unabled to config sym session");
1800 status = TEST_FAILED;
1804 /* attach asymmetric crypto session to crypto operations */
1805 rte_crypto_op_attach_asym_session(op, sess);
1806 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1807 asym_op->dsa.message.data = dgst;
1808 asym_op->dsa.message.length = sizeof(dgst);
1809 asym_op->dsa.r.length = sizeof(r);
1810 asym_op->dsa.r.data = r;
1811 asym_op->dsa.s.length = sizeof(s);
1812 asym_op->dsa.s.data = s;
1814 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1816 /* Process crypto operation */
1817 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1819 "line %u FAILED: %s",
1820 __LINE__, "Error sending packet for operation");
1821 status = TEST_FAILED;
1825 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1828 if (result_op == NULL) {
1830 "line %u FAILED: %s",
1831 __LINE__, "Failed to process asym crypto op");
1832 status = TEST_FAILED;
1836 asym_op = result_op->asym;
1838 debug_hexdump(stdout, "r:",
1839 asym_op->dsa.r.data, asym_op->dsa.r.length);
1840 debug_hexdump(stdout, "s:",
1841 asym_op->dsa.s.data, asym_op->dsa.s.length);
1843 /* Test PMD DSA sign verification using signer public key */
1844 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1846 /* copy signer public key */
1847 asym_op->dsa.y.data = dsa_test_params.y.data;
1848 asym_op->dsa.y.length = dsa_test_params.y.length;
1850 /* Process crypto operation */
1851 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1853 "line %u FAILED: %s",
1854 __LINE__, "Error sending packet for operation");
1855 status = TEST_FAILED;
1859 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1862 if (result_op == NULL) {
1864 "line %u FAILED: %s",
1865 __LINE__, "Failed to process asym crypto op");
1866 status = TEST_FAILED;
1870 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1872 "line %u FAILED: %s",
1873 __LINE__, "Failed to process asym crypto op");
1874 status = TEST_FAILED;
1878 rte_cryptodev_asym_session_clear(dev_id, sess);
1879 rte_cryptodev_asym_session_free(sess);
1882 rte_crypto_op_free(op);
1890 status = test_dsa_sign();
1891 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1896 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
1897 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
1898 .setup = testsuite_setup,
1899 .teardown = testsuite_teardown,
1900 .unit_test_cases = {
1901 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1902 TEST_CASE_ST(ut_setup, ut_teardown, test_dsa),
1903 TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
1904 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
1905 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
1906 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
1907 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
1908 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
1909 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1910 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1911 TEST_CASES_END() /**< NULL terminate unit test array */
1915 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
1916 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
1917 .setup = testsuite_setup,
1918 .teardown = testsuite_teardown,
1919 .unit_test_cases = {
1920 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1921 TEST_CASES_END() /**< NULL terminate unit test array */
1925 static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
1926 .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
1927 .setup = testsuite_setup,
1928 .teardown = testsuite_teardown,
1929 .unit_test_cases = {
1930 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1931 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
1932 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
1933 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1934 TEST_CASES_END() /**< NULL terminate unit test array */
1939 test_cryptodev_openssl_asym(void)
1941 gbl_driver_id = rte_cryptodev_driver_id_get(
1942 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
1944 if (gbl_driver_id == -1) {
1945 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
1946 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
1947 "in config file to run this testsuite.\n");
1951 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
1955 test_cryptodev_qat_asym(void)
1957 gbl_driver_id = rte_cryptodev_driver_id_get(
1958 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
1960 if (gbl_driver_id == -1) {
1961 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
1962 "CONFIG_RTE_LIBRTE_PMD_QAT_ASYM is enabled "
1963 "in config file to run this testsuite.\n");
1967 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
1971 test_cryptodev_octeontx_asym(void)
1973 gbl_driver_id = rte_cryptodev_driver_id_get(
1974 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
1975 if (gbl_driver_id == -1) {
1976 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded. Check if "
1977 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX_CRYPTO is "
1978 "enabled in config file to run this "
1982 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
1986 test_cryptodev_octeontx2_asym(void)
1988 gbl_driver_id = rte_cryptodev_driver_id_get(
1989 RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
1990 if (gbl_driver_id == -1) {
1991 RTE_LOG(ERR, USER1, "OCTEONTX2 PMD must be loaded. Check if "
1992 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX2_CRYPTO is "
1993 "enabled in config file to run this "
1998 /* Use test suite registered for crypto_octeontx PMD */
1999 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2002 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
2003 test_cryptodev_openssl_asym);
2005 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
2007 REGISTER_TEST_COMMAND(cryptodev_octeontx_asym_autotest,
2008 test_cryptodev_octeontx_asym);
2010 REGISTER_TEST_COMMAND(cryptodev_octeontx2_asym_autotest,
2011 test_cryptodev_octeontx2_asym);