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
30 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
33 #ifndef TEST_DATA_SIZE
34 #define TEST_DATA_SIZE 4096
36 #define ASYM_TEST_MSG_LEN 256
37 #define TEST_VECTOR_SIZE 256
39 static int gbl_driver_id;
40 struct crypto_testsuite_params {
41 struct rte_mempool *op_mpool;
42 struct rte_mempool *session_mpool;
43 struct rte_cryptodev_config conf;
44 struct rte_cryptodev_qp_conf qp_conf;
45 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
46 uint8_t valid_dev_count;
49 struct crypto_unittest_params {
50 struct rte_cryptodev_asym_session *sess;
51 struct rte_crypto_op *op;
54 union test_case_structure {
55 struct modex_test_data modex;
56 struct modinv_test_data modinv;
57 struct rsa_test_data_2 rsa_data;
60 struct test_cases_array {
62 const void *address[TEST_VECTOR_SIZE];
64 static struct test_cases_array test_vector = {0, { NULL } };
66 static uint32_t test_index;
68 static struct crypto_testsuite_params testsuite_params = { NULL };
71 queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
73 struct crypto_testsuite_params *ts_params = &testsuite_params;
74 struct rte_mempool *op_mpool = ts_params->op_mpool;
75 uint8_t dev_id = ts_params->valid_devs[0];
76 struct rte_crypto_op *op, *result_op;
77 struct rte_crypto_asym_op *asym_op;
78 uint8_t output_buf[TEST_DATA_SIZE];
79 int status = TEST_SUCCESS;
81 /* Set up crypto op data structure */
82 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
84 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
85 "operation struct\n");
91 /* Compute sign on the test vector */
92 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
94 asym_op->rsa.message.data = rsaplaintext.data;
95 asym_op->rsa.message.length = rsaplaintext.len;
96 asym_op->rsa.sign.length = 0;
97 asym_op->rsa.sign.data = output_buf;
98 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
100 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
101 asym_op->rsa.message.length);
103 /* Attach asymmetric crypto session to crypto operations */
104 rte_crypto_op_attach_asym_session(op, sess);
106 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
108 /* Process crypto operation */
109 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
110 RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
111 status = TEST_FAILED;
115 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
118 if (result_op == NULL) {
119 RTE_LOG(ERR, USER1, "Failed to process sign op\n");
120 status = TEST_FAILED;
124 debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
125 asym_op->rsa.sign.length);
126 asym_op = result_op->asym;
129 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
130 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
132 /* Process crypto operation */
133 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
134 RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
135 status = TEST_FAILED;
139 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
142 if (result_op == NULL) {
143 RTE_LOG(ERR, USER1, "Failed to process verify op\n");
144 status = TEST_FAILED;
148 status = TEST_SUCCESS;
149 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
150 RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
151 status = TEST_FAILED;
156 rte_crypto_op_free(op);
162 queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
164 struct crypto_testsuite_params *ts_params = &testsuite_params;
165 struct rte_mempool *op_mpool = ts_params->op_mpool;
166 uint8_t dev_id = ts_params->valid_devs[0];
167 struct rte_crypto_op *op, *result_op;
168 struct rte_crypto_asym_op *asym_op;
169 uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
170 int ret, status = TEST_SUCCESS;
172 /* Set up crypto op data structure */
173 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
175 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
176 "operation struct\n");
182 /* Compute encryption on the test vector */
183 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
185 asym_op->rsa.message.data = rsaplaintext.data;
186 asym_op->rsa.cipher.data = cipher_buf;
187 asym_op->rsa.cipher.length = 0;
188 asym_op->rsa.message.length = rsaplaintext.len;
189 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
191 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
192 asym_op->rsa.message.length);
194 /* Attach asymmetric crypto session to crypto operations */
195 rte_crypto_op_attach_asym_session(op, sess);
197 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
199 /* Process crypto operation */
200 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
201 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
202 status = TEST_FAILED;
206 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
209 if (result_op == NULL) {
210 RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
211 status = TEST_FAILED;
214 debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
215 asym_op->rsa.message.length);
217 /* Use the resulted output as decryption Input vector*/
218 asym_op = result_op->asym;
219 asym_op->rsa.message.length = 0;
220 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
221 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
223 /* Process crypto operation */
224 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
225 RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
226 status = TEST_FAILED;
230 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
233 if (result_op == NULL) {
234 RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
235 status = TEST_FAILED;
238 status = TEST_SUCCESS;
239 ret = rsa_verify(&rsaplaintext, result_op);
241 status = TEST_FAILED;
245 rte_crypto_op_free(op);
250 test_cryptodev_asym_ver(struct rte_crypto_op *op,
251 struct rte_crypto_asym_xform *xform_tc,
252 union test_case_structure *data_tc,
253 struct rte_crypto_op *result_op)
255 int status = TEST_FAILED;
257 uint8_t *data_expected = NULL, *data_received = NULL;
258 size_t data_size = 0;
260 switch (data_tc->modex.xform_type) {
261 case RTE_CRYPTO_ASYM_XFORM_MODEX:
262 data_expected = data_tc->modex.reminder.data;
263 data_received = result_op->asym->modex.result.data;
264 data_size = result_op->asym->modex.result.length;
266 case RTE_CRYPTO_ASYM_XFORM_MODINV:
267 data_expected = data_tc->modinv.inverse.data;
268 data_received = result_op->asym->modinv.result.data;
269 data_size = result_op->asym->modinv.result.length;
271 case RTE_CRYPTO_ASYM_XFORM_RSA:
272 if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
273 data_size = xform_tc->rsa.n.length;
274 data_received = result_op->asym->rsa.cipher.data;
275 data_expected = data_tc->rsa_data.ct.data;
276 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
277 data_size = xform_tc->rsa.n.length;
278 data_expected = data_tc->rsa_data.pt.data;
279 data_received = result_op->asym->rsa.message.data;
280 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
281 data_size = xform_tc->rsa.n.length;
282 data_expected = data_tc->rsa_data.sign.data;
283 data_received = result_op->asym->rsa.sign.data;
284 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
285 data_size = xform_tc->rsa.n.length;
286 data_expected = data_tc->rsa_data.pt.data;
287 data_received = result_op->asym->rsa.cipher.data;
290 case RTE_CRYPTO_ASYM_XFORM_DH:
291 case RTE_CRYPTO_ASYM_XFORM_DSA:
292 case RTE_CRYPTO_ASYM_XFORM_NONE:
293 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
297 ret = memcmp(data_expected, data_received, data_size);
298 if (!ret && data_size)
299 status = TEST_SUCCESS;
305 test_cryptodev_asym_op(struct crypto_testsuite_params *ts_params,
306 union test_case_structure *data_tc,
307 char *test_msg, int sessionless, enum rte_crypto_asym_op_type type,
308 enum rte_crypto_rsa_priv_key_type key_type)
310 struct rte_crypto_asym_op *asym_op = NULL;
311 struct rte_crypto_op *op = NULL;
312 struct rte_crypto_op *result_op = NULL;
313 struct rte_crypto_asym_xform xform_tc;
314 struct rte_cryptodev_asym_session *sess = NULL;
315 struct rte_cryptodev_asym_capability_idx cap_idx;
316 const struct rte_cryptodev_asymmetric_xform_capability *capability;
317 uint8_t dev_id = ts_params->valid_devs[0];
318 uint8_t input[TEST_DATA_SIZE] = {0};
319 uint8_t *result = NULL;
321 int status = TEST_SUCCESS;
323 xform_tc.next = NULL;
324 xform_tc.xform_type = data_tc->modex.xform_type;
326 cap_idx.type = xform_tc.xform_type;
327 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
329 if (capability == NULL) {
331 "Device doesn't support MODEX. Test Skipped\n");
335 /* Generate crypto op data structure */
336 op = rte_crypto_op_alloc(ts_params->op_mpool,
337 RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
340 snprintf(test_msg, ASYM_TEST_MSG_LEN,
341 "line %u FAILED: %s",
342 __LINE__, "Failed to allocate asymmetric crypto "
344 status = TEST_FAILED;
350 switch (xform_tc.xform_type) {
351 case RTE_CRYPTO_ASYM_XFORM_MODEX:
352 result = rte_zmalloc(NULL, data_tc->modex.result_len, 0);
353 xform_tc.modex.modulus.data = data_tc->modex.modulus.data;
354 xform_tc.modex.modulus.length = data_tc->modex.modulus.len;
355 xform_tc.modex.exponent.data = data_tc->modex.exponent.data;
356 xform_tc.modex.exponent.length = data_tc->modex.exponent.len;
357 memcpy(input, data_tc->modex.base.data,
358 data_tc->modex.base.len);
359 asym_op->modex.base.data = input;
360 asym_op->modex.base.length = data_tc->modex.base.len;
361 asym_op->modex.result.data = result;
362 asym_op->modex.result.length = data_tc->modex.result_len;
363 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
364 xform_tc.modex.modulus.length)) {
365 snprintf(test_msg, ASYM_TEST_MSG_LEN,
367 "FAILED: %s", __LINE__,
368 "Invalid MODULUS length specified");
369 status = TEST_FAILED;
373 case RTE_CRYPTO_ASYM_XFORM_MODINV:
374 result = rte_zmalloc(NULL, data_tc->modinv.result_len, 0);
375 xform_tc.modinv.modulus.data = data_tc->modinv.modulus.data;
376 xform_tc.modinv.modulus.length = data_tc->modinv.modulus.len;
377 memcpy(input, data_tc->modinv.base.data,
378 data_tc->modinv.base.len);
379 asym_op->modinv.base.data = input;
380 asym_op->modinv.base.length = data_tc->modinv.base.len;
381 asym_op->modinv.result.data = result;
382 asym_op->modinv.result.length = data_tc->modinv.result_len;
383 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
384 xform_tc.modinv.modulus.length)) {
385 snprintf(test_msg, ASYM_TEST_MSG_LEN,
387 "FAILED: %s", __LINE__,
388 "Invalid MODULUS length specified");
389 status = TEST_FAILED;
393 case RTE_CRYPTO_ASYM_XFORM_RSA:
394 result = rte_zmalloc(NULL, data_tc->rsa_data.n.len, 0);
395 op->asym->rsa.op_type = type;
396 xform_tc.rsa.e.data = data_tc->rsa_data.e.data;
397 xform_tc.rsa.e.length = data_tc->rsa_data.e.len;
398 xform_tc.rsa.n.data = data_tc->rsa_data.n.data;
399 xform_tc.rsa.n.length = data_tc->rsa_data.n.len;
401 if (key_type == RTE_RSA_KEY_TYPE_EXP) {
402 xform_tc.rsa.d.data = data_tc->rsa_data.d.data;
403 xform_tc.rsa.d.length = data_tc->rsa_data.d.len;
405 xform_tc.rsa.qt.p.data = data_tc->rsa_data.p.data;
406 xform_tc.rsa.qt.p.length = data_tc->rsa_data.p.len;
407 xform_tc.rsa.qt.q.data = data_tc->rsa_data.q.data;
408 xform_tc.rsa.qt.q.length = data_tc->rsa_data.q.len;
409 xform_tc.rsa.qt.dP.data = data_tc->rsa_data.dP.data;
410 xform_tc.rsa.qt.dP.length = data_tc->rsa_data.dP.len;
411 xform_tc.rsa.qt.dQ.data = data_tc->rsa_data.dQ.data;
412 xform_tc.rsa.qt.dQ.length = data_tc->rsa_data.dQ.len;
413 xform_tc.rsa.qt.qInv.data = data_tc->rsa_data.qInv.data;
414 xform_tc.rsa.qt.qInv.length = data_tc->rsa_data.qInv.len;
417 xform_tc.rsa.key_type = key_type;
418 op->asym->rsa.pad = data_tc->rsa_data.padding;
420 if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
421 asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
422 asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
423 asym_op->rsa.cipher.data = result;
424 asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
425 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
426 asym_op->rsa.message.data = result;
427 asym_op->rsa.message.length = data_tc->rsa_data.n.len;
428 asym_op->rsa.cipher.data = data_tc->rsa_data.ct.data;
429 asym_op->rsa.cipher.length = data_tc->rsa_data.ct.len;
430 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
431 asym_op->rsa.sign.data = result;
432 asym_op->rsa.sign.length = data_tc->rsa_data.n.len;
433 asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
434 asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
435 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
436 asym_op->rsa.cipher.data = result;
437 asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
438 asym_op->rsa.sign.data = data_tc->rsa_data.sign.data;
439 asym_op->rsa.sign.length = data_tc->rsa_data.sign.len;
442 case RTE_CRYPTO_ASYM_XFORM_DH:
443 case RTE_CRYPTO_ASYM_XFORM_DSA:
444 case RTE_CRYPTO_ASYM_XFORM_NONE:
445 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
447 snprintf(test_msg, ASYM_TEST_MSG_LEN,
449 "FAILED: %s", __LINE__,
450 "Invalid ASYM algorithm specified");
451 status = TEST_FAILED;
456 sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
458 snprintf(test_msg, ASYM_TEST_MSG_LEN,
460 "FAILED: %s", __LINE__,
461 "Session creation failed");
462 status = TEST_FAILED;
466 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
467 ts_params->session_mpool) < 0) {
468 snprintf(test_msg, ASYM_TEST_MSG_LEN,
469 "line %u FAILED: %s",
470 __LINE__, "unabled to config sym session");
471 status = TEST_FAILED;
475 rte_crypto_op_attach_asym_session(op, sess);
477 asym_op->xform = &xform_tc;
478 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
480 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
482 /* Process crypto operation */
483 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
484 snprintf(test_msg, ASYM_TEST_MSG_LEN,
485 "line %u FAILED: %s",
486 __LINE__, "Error sending packet for operation");
487 status = TEST_FAILED;
491 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
494 if (result_op == NULL) {
495 snprintf(test_msg, ASYM_TEST_MSG_LEN,
496 "line %u FAILED: %s",
497 __LINE__, "Failed to process asym crypto op");
498 status = TEST_FAILED;
502 if (test_cryptodev_asym_ver(op, &xform_tc, data_tc, result_op) != TEST_SUCCESS) {
503 snprintf(test_msg, ASYM_TEST_MSG_LEN,
504 "line %u FAILED: %s",
505 __LINE__, "Verification failed ");
506 status = TEST_FAILED;
511 snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
513 snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
517 rte_cryptodev_asym_session_clear(dev_id, sess);
518 rte_cryptodev_asym_session_free(sess);
522 rte_crypto_op_free(op);
531 test_one_case(const void *test_case, int sessionless)
533 int status = TEST_SUCCESS, i = 0;
534 char test_msg[ASYM_TEST_MSG_LEN + 1];
536 /* Map the case to union */
537 union test_case_structure tc;
538 memcpy(&tc, test_case, sizeof(tc));
540 if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX
541 || tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
542 status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg,
544 printf(" %u) TestCase %s %s\n", test_index++,
545 tc.modex.description, test_msg);
547 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
548 if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
549 if (tc.rsa_data.op_type_flags & (1 << i)) {
550 if (tc.rsa_data.key_exp) {
551 status = test_cryptodev_asym_op(
552 &testsuite_params, &tc,
553 test_msg, sessionless, i,
554 RTE_RSA_KEY_TYPE_EXP);
558 if (tc.rsa_data.key_qt && (i ==
559 RTE_CRYPTO_ASYM_OP_DECRYPT ||
560 i == RTE_CRYPTO_ASYM_OP_SIGN)) {
561 status = test_cryptodev_asym_op(
563 &tc, test_msg, sessionless, i,
564 RTE_RSA_KET_TYPE_QT);
571 printf(" %u) TestCase %s %s\n", test_index++,
572 tc.modex.description, test_msg);
579 load_test_vectors(void)
581 uint32_t i = 0, v_size = 0;
582 /* Load MODEX vector*/
583 v_size = ARRAY_SIZE(modex_test_case);
584 for (i = 0; i < v_size; i++) {
585 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
586 RTE_LOG(DEBUG, USER1,
587 "TEST_VECTOR_SIZE too small\n");
590 test_vector.address[test_vector.size] = &modex_test_case[i];
593 /* Load MODINV vector*/
594 v_size = ARRAY_SIZE(modinv_test_case);
595 for (i = 0; i < v_size; i++) {
596 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
597 RTE_LOG(DEBUG, USER1,
598 "TEST_VECTOR_SIZE too small\n");
601 test_vector.address[test_vector.size] = &modinv_test_case[i];
605 v_size = ARRAY_SIZE(rsa_test_case_list);
606 for (i = 0; i < v_size; i++) {
607 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
608 RTE_LOG(DEBUG, USER1,
609 "TEST_VECTOR_SIZE too small\n");
612 test_vector.address[test_vector.size] = &rsa_test_case_list[i];
619 test_one_by_one(void)
621 int status = TEST_SUCCESS;
622 struct crypto_testsuite_params *ts_params = &testsuite_params;
624 uint8_t dev_id = ts_params->valid_devs[0];
625 struct rte_cryptodev_info dev_info;
628 rte_cryptodev_info_get(dev_id, &dev_info);
629 if ((dev_info.feature_flags &
630 RTE_CRYPTODEV_FF_ASYM_SESSIONLESS)) {
634 /* Go through all test cases */
636 for (i = 0; i < test_vector.size; i++) {
637 if (test_one_case(test_vector.address[i], 0) != TEST_SUCCESS)
638 status = TEST_FAILED;
641 for (i = 0; i < test_vector.size; i++) {
642 if (test_one_case(test_vector.address[i], 1)
644 status = TEST_FAILED;
648 TEST_ASSERT_EQUAL(status, 0, "Test failed");
653 test_rsa_sign_verify(void)
655 struct crypto_testsuite_params *ts_params = &testsuite_params;
656 struct rte_mempool *sess_mpool = ts_params->session_mpool;
657 uint8_t dev_id = ts_params->valid_devs[0];
658 struct rte_cryptodev_asym_session *sess;
659 struct rte_cryptodev_info dev_info;
660 int status = TEST_SUCCESS;
662 /* Test case supports op with exponent key only,
663 * Check in PMD feature flag for RSA exponent key type support.
665 rte_cryptodev_info_get(dev_id, &dev_info);
666 if (!(dev_info.feature_flags &
667 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
668 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
669 "exponent key type. Test Skipped\n");
673 sess = rte_cryptodev_asym_session_create(sess_mpool);
676 RTE_LOG(ERR, USER1, "Session creation failed for "
681 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
683 RTE_LOG(ERR, USER1, "Unable to config asym session for "
685 status = TEST_FAILED;
689 status = queue_ops_rsa_sign_verify(sess);
693 rte_cryptodev_asym_session_clear(dev_id, sess);
694 rte_cryptodev_asym_session_free(sess);
696 TEST_ASSERT_EQUAL(status, 0, "Test failed");
702 test_rsa_enc_dec(void)
704 struct crypto_testsuite_params *ts_params = &testsuite_params;
705 struct rte_mempool *sess_mpool = ts_params->session_mpool;
706 uint8_t dev_id = ts_params->valid_devs[0];
707 struct rte_cryptodev_asym_session *sess;
708 struct rte_cryptodev_info dev_info;
709 int status = TEST_SUCCESS;
711 /* Test case supports op with exponent key only,
712 * Check in PMD feature flag for RSA exponent key type support.
714 rte_cryptodev_info_get(dev_id, &dev_info);
715 if (!(dev_info.feature_flags &
716 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
717 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
718 "exponent key type. Test skipped\n");
722 sess = rte_cryptodev_asym_session_create(sess_mpool);
725 RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
729 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
731 RTE_LOG(ERR, USER1, "Unable to config asym session for "
733 status = TEST_FAILED;
737 status = queue_ops_rsa_enc_dec(sess);
741 rte_cryptodev_asym_session_clear(dev_id, sess);
742 rte_cryptodev_asym_session_free(sess);
744 TEST_ASSERT_EQUAL(status, 0, "Test failed");
750 test_rsa_sign_verify_crt(void)
752 struct crypto_testsuite_params *ts_params = &testsuite_params;
753 struct rte_mempool *sess_mpool = ts_params->session_mpool;
754 uint8_t dev_id = ts_params->valid_devs[0];
755 struct rte_cryptodev_asym_session *sess;
756 struct rte_cryptodev_info dev_info;
757 int status = TEST_SUCCESS;
759 /* Test case supports op with quintuple format key only,
760 * Check im PMD feature flag for RSA quintuple key type support.
762 rte_cryptodev_info_get(dev_id, &dev_info);
763 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
764 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
765 "quintuple key type. Test skipped\n");
769 sess = rte_cryptodev_asym_session_create(sess_mpool);
772 RTE_LOG(ERR, USER1, "Session creation failed for "
773 "sign_verify_crt\n");
774 status = TEST_FAILED;
778 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
780 RTE_LOG(ERR, USER1, "Unable to config asym session for "
781 "sign_verify_crt\n");
782 status = TEST_FAILED;
785 status = queue_ops_rsa_sign_verify(sess);
789 rte_cryptodev_asym_session_clear(dev_id, sess);
790 rte_cryptodev_asym_session_free(sess);
792 TEST_ASSERT_EQUAL(status, 0, "Test failed");
798 test_rsa_enc_dec_crt(void)
800 struct crypto_testsuite_params *ts_params = &testsuite_params;
801 struct rte_mempool *sess_mpool = ts_params->session_mpool;
802 uint8_t dev_id = ts_params->valid_devs[0];
803 struct rte_cryptodev_asym_session *sess;
804 struct rte_cryptodev_info dev_info;
805 int status = TEST_SUCCESS;
807 /* Test case supports op with quintuple format key only,
808 * Check in PMD feature flag for RSA quintuple key type support.
810 rte_cryptodev_info_get(dev_id, &dev_info);
811 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
812 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
813 "quintuple key type. Test skipped\n");
817 sess = rte_cryptodev_asym_session_create(sess_mpool);
820 RTE_LOG(ERR, USER1, "Session creation failed for "
825 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
827 RTE_LOG(ERR, USER1, "Unable to config asym session for "
829 status = TEST_FAILED;
832 status = queue_ops_rsa_enc_dec(sess);
836 rte_cryptodev_asym_session_clear(dev_id, sess);
837 rte_cryptodev_asym_session_free(sess);
839 TEST_ASSERT_EQUAL(status, 0, "Test failed");
845 testsuite_setup(void)
847 struct crypto_testsuite_params *ts_params = &testsuite_params;
848 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
849 struct rte_cryptodev_info info;
850 int ret, dev_id = -1;
854 memset(ts_params, 0, sizeof(*ts_params));
856 test_vector.size = 0;
859 ts_params->op_mpool = rte_crypto_op_pool_create(
860 "CRYPTO_ASYM_OP_POOL",
861 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
865 if (ts_params->op_mpool == NULL) {
866 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
870 /* Create an OPENSSL device if required */
871 if (gbl_driver_id == rte_cryptodev_driver_id_get(
872 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
873 nb_devs = rte_cryptodev_device_count_by_driver(
874 rte_cryptodev_driver_id_get(
875 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
878 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
881 TEST_ASSERT(ret == 0, "Failed to create "
882 "instance of pmd : %s",
883 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
887 /* Get list of valid crypto devs */
888 nb_devs = rte_cryptodev_devices_get(
889 rte_cryptodev_driver_name_get(gbl_driver_id),
890 valid_devs, RTE_CRYPTO_MAX_DEVS);
892 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
897 * Get first valid asymmetric device found in test suite param and
900 for (i = 0; i < nb_devs ; i++) {
901 rte_cryptodev_info_get(valid_devs[i], &info);
902 if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
903 dev_id = ts_params->valid_devs[0] = valid_devs[i];
909 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
914 /* Set valid device count */
915 ts_params->valid_dev_count = nb_devs;
917 /* configure device with num qp */
918 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
919 ts_params->conf.socket_id = SOCKET_ID_ANY;
920 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
921 RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
922 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
924 "Failed to configure cryptodev %u with %u qps",
925 dev_id, ts_params->conf.nb_queue_pairs);
928 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
929 ts_params->qp_conf.mp_session = ts_params->session_mpool;
930 ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
931 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
932 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
933 dev_id, qp_id, &ts_params->qp_conf,
934 rte_cryptodev_socket_id(dev_id)),
935 "Failed to setup queue pair %u on cryptodev %u ASYM",
939 /* setup asym session pool */
940 unsigned int session_size =
941 rte_cryptodev_asym_get_private_session_size(dev_id);
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");
961 testsuite_teardown(void)
963 struct crypto_testsuite_params *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 *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;
1014 struct crypto_testsuite_params *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\n",
1047 capa->modlen.increment);
1055 test_capability(void)
1057 struct crypto_testsuite_params *ts_params = &testsuite_params;
1058 uint8_t dev_id = ts_params->valid_devs[0];
1059 struct rte_cryptodev_info dev_info;
1060 const struct rte_cryptodev_capabilities *dev_capa;
1062 struct rte_cryptodev_asym_capability_idx idx;
1063 const struct rte_cryptodev_asymmetric_xform_capability *capa;
1065 rte_cryptodev_info_get(dev_id, &dev_info);
1066 if (!(dev_info.feature_flags &
1067 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
1068 RTE_LOG(INFO, USER1,
1069 "Device doesn't support asymmetric. Test Skipped\n");
1070 return TEST_SUCCESS;
1073 /* print xform capability */
1075 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
1077 dev_capa = &(dev_info.capabilities[i]);
1078 if (dev_info.capabilities[i].op ==
1079 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1080 idx.type = dev_capa->asym.xform_capa.xform_type;
1082 capa = rte_cryptodev_asym_capability_get(dev_id,
1084 rte_cryptodev_asym_capability_idx *) &idx);
1085 print_asym_capa(capa);
1088 return TEST_SUCCESS;
1092 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
1094 struct crypto_testsuite_params *ts_params = &testsuite_params;
1095 struct rte_mempool *op_mpool = ts_params->op_mpool;
1096 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1097 uint8_t dev_id = ts_params->valid_devs[0];
1098 struct rte_crypto_asym_op *asym_op = NULL;
1099 struct rte_crypto_op *op = NULL, *result_op = NULL;
1100 struct rte_cryptodev_asym_session *sess = NULL;
1101 int status = TEST_SUCCESS;
1102 uint8_t output[TEST_DH_MOD_LEN];
1103 struct rte_crypto_asym_xform xform = *xfrm;
1104 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
1106 sess = rte_cryptodev_asym_session_create(sess_mpool);
1109 "line %u FAILED: %s", __LINE__,
1110 "Session creation failed");
1111 status = TEST_FAILED;
1114 /* set up crypto op data structure */
1115 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1118 "line %u FAILED: %s",
1119 __LINE__, "Failed to allocate asymmetric crypto "
1120 "operation struct");
1121 status = TEST_FAILED;
1126 /* Setup a xform and op to generate private key only */
1127 xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
1129 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
1130 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
1131 asym_op->dh.pub_key.data = (uint8_t *)peer;
1132 asym_op->dh.pub_key.length = sizeof(peer);
1133 asym_op->dh.shared_secret.data = output;
1134 asym_op->dh.shared_secret.length = sizeof(output);
1136 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1139 "line %u FAILED: %s",
1140 __LINE__, "unabled to config sym session");
1141 status = TEST_FAILED;
1145 /* attach asymmetric crypto session to crypto operations */
1146 rte_crypto_op_attach_asym_session(op, sess);
1148 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1150 /* Process crypto operation */
1151 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1153 "line %u FAILED: %s",
1154 __LINE__, "Error sending packet for operation");
1155 status = TEST_FAILED;
1159 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1162 if (result_op == NULL) {
1164 "line %u FAILED: %s",
1165 __LINE__, "Failed to process asym crypto op");
1166 status = TEST_FAILED;
1170 debug_hexdump(stdout, "shared secret:",
1171 asym_op->dh.shared_secret.data,
1172 asym_op->dh.shared_secret.length);
1176 rte_cryptodev_asym_session_clear(dev_id, sess);
1177 rte_cryptodev_asym_session_free(sess);
1180 rte_crypto_op_free(op);
1185 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1187 struct crypto_testsuite_params *ts_params = &testsuite_params;
1188 struct rte_mempool *op_mpool = ts_params->op_mpool;
1189 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1190 uint8_t dev_id = ts_params->valid_devs[0];
1191 struct rte_crypto_asym_op *asym_op = NULL;
1192 struct rte_crypto_op *op = NULL, *result_op = NULL;
1193 struct rte_cryptodev_asym_session *sess = NULL;
1194 int status = TEST_SUCCESS;
1195 uint8_t output[TEST_DH_MOD_LEN];
1196 struct rte_crypto_asym_xform xform = *xfrm;
1198 sess = rte_cryptodev_asym_session_create(sess_mpool);
1201 "line %u FAILED: %s", __LINE__,
1202 "Session creation failed");
1203 status = TEST_FAILED;
1206 /* set up crypto op data structure */
1207 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1210 "line %u FAILED: %s",
1211 __LINE__, "Failed to allocate asymmetric crypto "
1212 "operation struct");
1213 status = TEST_FAILED;
1218 /* Setup a xform and op to generate private key only */
1219 xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1221 asym_op->dh.priv_key.data = output;
1222 asym_op->dh.priv_key.length = sizeof(output);
1224 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1227 "line %u FAILED: %s",
1228 __LINE__, "unabled to config sym session");
1229 status = TEST_FAILED;
1233 /* attach asymmetric crypto session to crypto operations */
1234 rte_crypto_op_attach_asym_session(op, sess);
1236 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1238 /* Process crypto operation */
1239 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1241 "line %u FAILED: %s",
1242 __LINE__, "Error sending packet for operation");
1243 status = TEST_FAILED;
1247 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1250 if (result_op == NULL) {
1252 "line %u FAILED: %s",
1253 __LINE__, "Failed to process asym crypto op");
1254 status = TEST_FAILED;
1258 debug_hexdump(stdout, "private key:",
1259 asym_op->dh.priv_key.data,
1260 asym_op->dh.priv_key.length);
1265 rte_cryptodev_asym_session_clear(dev_id, sess);
1266 rte_cryptodev_asym_session_free(sess);
1269 rte_crypto_op_free(op);
1276 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1278 struct crypto_testsuite_params *ts_params = &testsuite_params;
1279 struct rte_mempool *op_mpool = ts_params->op_mpool;
1280 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1281 uint8_t dev_id = ts_params->valid_devs[0];
1282 struct rte_crypto_asym_op *asym_op = NULL;
1283 struct rte_crypto_op *op = NULL, *result_op = NULL;
1284 struct rte_cryptodev_asym_session *sess = NULL;
1285 int status = TEST_SUCCESS;
1286 uint8_t output[TEST_DH_MOD_LEN];
1287 struct rte_crypto_asym_xform xform = *xfrm;
1289 sess = rte_cryptodev_asym_session_create(sess_mpool);
1292 "line %u FAILED: %s", __LINE__,
1293 "Session creation failed");
1294 status = TEST_FAILED;
1297 /* set up crypto op data structure */
1298 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1301 "line %u FAILED: %s",
1302 __LINE__, "Failed to allocate asymmetric crypto "
1303 "operation struct");
1304 status = TEST_FAILED;
1308 /* Setup a xform chain to generate public key
1309 * using test private key
1312 xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1315 asym_op->dh.pub_key.data = output;
1316 asym_op->dh.pub_key.length = sizeof(output);
1317 /* load pre-defined private key */
1318 asym_op->dh.priv_key.data = rte_malloc(NULL,
1319 dh_test_params.priv_key.length,
1321 asym_op->dh.priv_key = dh_test_params.priv_key;
1323 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1326 "line %u FAILED: %s",
1327 __LINE__, "unabled to config sym session");
1328 status = TEST_FAILED;
1332 /* attach asymmetric crypto session to crypto operations */
1333 rte_crypto_op_attach_asym_session(op, sess);
1335 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1337 /* Process crypto operation */
1338 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1340 "line %u FAILED: %s",
1341 __LINE__, "Error sending packet for operation");
1342 status = TEST_FAILED;
1346 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1349 if (result_op == NULL) {
1351 "line %u FAILED: %s",
1352 __LINE__, "Failed to process asym crypto op");
1353 status = TEST_FAILED;
1357 debug_hexdump(stdout, "pub key:",
1358 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1360 debug_hexdump(stdout, "priv key:",
1361 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1365 rte_cryptodev_asym_session_clear(dev_id, sess);
1366 rte_cryptodev_asym_session_free(sess);
1369 rte_crypto_op_free(op);
1375 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1377 struct crypto_testsuite_params *ts_params = &testsuite_params;
1378 struct rte_mempool *op_mpool = ts_params->op_mpool;
1379 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1380 uint8_t dev_id = ts_params->valid_devs[0];
1381 struct rte_crypto_asym_op *asym_op = NULL;
1382 struct rte_crypto_op *op = NULL, *result_op = NULL;
1383 struct rte_cryptodev_asym_session *sess = NULL;
1384 int status = TEST_SUCCESS;
1385 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1386 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1387 struct rte_crypto_asym_xform pub_key_xform;
1388 struct rte_crypto_asym_xform xform = *xfrm;
1390 sess = rte_cryptodev_asym_session_create(sess_mpool);
1393 "line %u FAILED: %s", __LINE__,
1394 "Session creation failed");
1395 status = TEST_FAILED;
1399 /* set up crypto op data structure */
1400 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1403 "line %u FAILED: %s",
1404 __LINE__, "Failed to allocate asymmetric crypto "
1405 "operation struct");
1406 status = TEST_FAILED;
1410 /* Setup a xform chain to generate
1411 * private key first followed by
1413 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1414 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1415 pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1416 xform.next = &pub_key_xform;
1418 asym_op->dh.pub_key.data = out_pub_key;
1419 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1420 asym_op->dh.priv_key.data = out_prv_key;
1421 asym_op->dh.priv_key.length = sizeof(out_prv_key);
1422 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1425 "line %u FAILED: %s",
1426 __LINE__, "unabled to config sym session");
1427 status = TEST_FAILED;
1431 /* attach asymmetric crypto session to crypto operations */
1432 rte_crypto_op_attach_asym_session(op, sess);
1434 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1436 /* Process crypto operation */
1437 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1439 "line %u FAILED: %s",
1440 __LINE__, "Error sending packet for operation");
1441 status = TEST_FAILED;
1445 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1448 if (result_op == NULL) {
1450 "line %u FAILED: %s",
1451 __LINE__, "Failed to process asym crypto op");
1452 status = TEST_FAILED;
1455 debug_hexdump(stdout, "priv key:",
1456 out_prv_key, asym_op->dh.priv_key.length);
1457 debug_hexdump(stdout, "pub key:",
1458 out_pub_key, asym_op->dh.pub_key.length);
1462 rte_cryptodev_asym_session_clear(dev_id, sess);
1463 rte_cryptodev_asym_session_free(sess);
1466 rte_crypto_op_free(op);
1474 struct crypto_testsuite_params *ts_params = &testsuite_params;
1475 struct rte_mempool *op_mpool = ts_params->op_mpool;
1476 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1477 uint8_t dev_id = ts_params->valid_devs[0];
1478 struct rte_crypto_asym_op *asym_op = NULL;
1479 struct rte_crypto_op *op = NULL, *result_op = NULL;
1480 struct rte_cryptodev_asym_session *sess = NULL;
1481 int status = TEST_SUCCESS;
1482 struct rte_cryptodev_asym_capability_idx cap_idx;
1483 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1484 uint8_t input[TEST_DATA_SIZE] = {0};
1486 uint8_t result[sizeof(mod_p)] = { 0 };
1488 if (rte_cryptodev_asym_get_xform_enum(
1489 &modinv_xform.xform_type, "modinv") < 0) {
1491 "Invalid ASYM algorithm specified\n");
1495 cap_idx.type = modinv_xform.xform_type;
1496 capability = rte_cryptodev_asym_capability_get(dev_id,
1499 if (capability == NULL) {
1500 RTE_LOG(INFO, USER1,
1501 "Device doesn't support MOD INV. Test Skipped\n");
1505 if (rte_cryptodev_asym_xform_capability_check_modlen(
1507 modinv_xform.modinv.modulus.length)) {
1509 "Invalid MODULUS length specified\n");
1513 sess = rte_cryptodev_asym_session_create(sess_mpool);
1515 RTE_LOG(ERR, USER1, "line %u "
1516 "FAILED: %s", __LINE__,
1517 "Session creation failed");
1518 status = TEST_FAILED;
1522 if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
1525 "line %u FAILED: %s",
1526 __LINE__, "unabled to config sym session");
1527 status = TEST_FAILED;
1531 /* generate crypto op data structure */
1532 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1535 "line %u FAILED: %s",
1536 __LINE__, "Failed to allocate asymmetric crypto "
1537 "operation struct");
1538 status = TEST_FAILED;
1543 memcpy(input, base, sizeof(base));
1544 asym_op->modinv.base.data = input;
1545 asym_op->modinv.base.length = sizeof(base);
1546 asym_op->modinv.result.data = result;
1547 asym_op->modinv.result.length = sizeof(result);
1549 /* attach asymmetric crypto session to crypto operations */
1550 rte_crypto_op_attach_asym_session(op, sess);
1552 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1554 /* Process crypto operation */
1555 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1557 "line %u FAILED: %s",
1558 __LINE__, "Error sending packet for operation");
1559 status = TEST_FAILED;
1563 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1566 if (result_op == NULL) {
1568 "line %u FAILED: %s",
1569 __LINE__, "Failed to process asym crypto op");
1570 status = TEST_FAILED;
1574 ret = verify_modinv(mod_inv, result_op);
1577 "operation verification failed\n");
1578 status = TEST_FAILED;
1583 rte_cryptodev_asym_session_clear(dev_id, sess);
1584 rte_cryptodev_asym_session_free(sess);
1588 rte_crypto_op_free(op);
1590 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1598 struct crypto_testsuite_params *ts_params = &testsuite_params;
1599 struct rte_mempool *op_mpool = ts_params->op_mpool;
1600 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1601 uint8_t dev_id = ts_params->valid_devs[0];
1602 struct rte_crypto_asym_op *asym_op = NULL;
1603 struct rte_crypto_op *op = NULL, *result_op = NULL;
1604 struct rte_cryptodev_asym_session *sess = NULL;
1605 int status = TEST_SUCCESS;
1606 struct rte_cryptodev_asym_capability_idx cap_idx;
1607 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1608 uint8_t input[TEST_DATA_SIZE] = {0};
1610 uint8_t result[sizeof(mod_p)] = { 0 };
1612 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1616 "Invalid ASYM algorithm specified\n");
1620 /* check for modlen capability */
1621 cap_idx.type = modex_xform.xform_type;
1622 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1624 if (capability == NULL) {
1625 RTE_LOG(INFO, USER1,
1626 "Device doesn't support MOD EXP. Test Skipped\n");
1630 if (rte_cryptodev_asym_xform_capability_check_modlen(
1631 capability, modex_xform.modex.modulus.length)) {
1633 "Invalid MODULUS length specified\n");
1637 /* generate crypto op data structure */
1638 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1641 "line %u FAILED: %s",
1642 __LINE__, "Failed to allocate asymmetric crypto "
1643 "operation struct");
1644 status = TEST_FAILED;
1648 sess = rte_cryptodev_asym_session_create(sess_mpool);
1652 "FAILED: %s", __LINE__,
1653 "Session creation failed");
1654 status = TEST_FAILED;
1658 if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1661 "line %u FAILED: %s",
1662 __LINE__, "unabled to config sym session");
1663 status = TEST_FAILED;
1668 memcpy(input, base, sizeof(base));
1669 asym_op->modex.base.data = input;
1670 asym_op->modex.base.length = sizeof(base);
1671 asym_op->modex.result.data = result;
1672 asym_op->modex.result.length = sizeof(result);
1673 /* attach asymmetric crypto session to crypto operations */
1674 rte_crypto_op_attach_asym_session(op, sess);
1676 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1677 /* Process crypto operation */
1678 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1680 "line %u FAILED: %s",
1681 __LINE__, "Error sending packet for operation");
1682 status = TEST_FAILED;
1686 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1689 if (result_op == NULL) {
1691 "line %u FAILED: %s",
1692 __LINE__, "Failed to process asym crypto op");
1693 status = TEST_FAILED;
1697 ret = verify_modexp(mod_exp, result_op);
1700 "operation verification failed\n");
1701 status = TEST_FAILED;
1706 rte_cryptodev_asym_session_clear(dev_id, sess);
1707 rte_cryptodev_asym_session_free(sess);
1711 rte_crypto_op_free(op);
1713 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1719 test_dh_keygenration(void)
1723 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1724 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1725 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1726 dh_test_params.priv_key.length);
1728 RTE_LOG(INFO, USER1,
1729 "Test Public and Private key pair generation\n");
1731 status = test_dh_gen_kp(&dh_xform);
1732 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1734 RTE_LOG(INFO, USER1,
1735 "Test Public Key Generation using pre-defined priv key\n");
1737 status = test_dh_gen_pub_key(&dh_xform);
1738 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1740 RTE_LOG(INFO, USER1,
1741 "Test Private Key Generation only\n");
1743 status = test_dh_gen_priv_key(&dh_xform);
1744 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1746 RTE_LOG(INFO, USER1,
1747 "Test shared secret compute\n");
1749 status = test_dh_gen_shared_sec(&dh_xform);
1750 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1758 struct crypto_testsuite_params *ts_params = &testsuite_params;
1759 struct rte_mempool *op_mpool = ts_params->op_mpool;
1760 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1761 uint8_t dev_id = ts_params->valid_devs[0];
1762 struct rte_crypto_asym_op *asym_op = NULL;
1763 struct rte_crypto_op *op = NULL, *result_op = NULL;
1764 struct rte_cryptodev_asym_session *sess = NULL;
1765 int status = TEST_SUCCESS;
1766 uint8_t r[TEST_DH_MOD_LEN];
1767 uint8_t s[TEST_DH_MOD_LEN];
1768 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1770 sess = rte_cryptodev_asym_session_create(sess_mpool);
1773 "line %u FAILED: %s", __LINE__,
1774 "Session creation failed");
1775 status = TEST_FAILED;
1778 /* set up crypto op data structure */
1779 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1782 "line %u FAILED: %s",
1783 __LINE__, "Failed to allocate asymmetric crypto "
1784 "operation struct");
1785 status = TEST_FAILED;
1790 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1791 dsa_xform.dsa.p.length);
1792 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1793 dsa_xform.dsa.q.length);
1794 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1795 dsa_xform.dsa.g.length);
1796 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1797 dsa_xform.dsa.x.length);
1799 if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1802 "line %u FAILED: %s",
1803 __LINE__, "unabled to config sym session");
1804 status = TEST_FAILED;
1808 /* attach asymmetric crypto session to crypto operations */
1809 rte_crypto_op_attach_asym_session(op, sess);
1810 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1811 asym_op->dsa.message.data = dgst;
1812 asym_op->dsa.message.length = sizeof(dgst);
1813 asym_op->dsa.r.length = sizeof(r);
1814 asym_op->dsa.r.data = r;
1815 asym_op->dsa.s.length = sizeof(s);
1816 asym_op->dsa.s.data = s;
1818 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1820 /* Process crypto operation */
1821 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1823 "line %u FAILED: %s",
1824 __LINE__, "Error sending packet for operation");
1825 status = TEST_FAILED;
1829 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1832 if (result_op == NULL) {
1834 "line %u FAILED: %s",
1835 __LINE__, "Failed to process asym crypto op");
1836 status = TEST_FAILED;
1840 asym_op = result_op->asym;
1842 debug_hexdump(stdout, "r:",
1843 asym_op->dsa.r.data, asym_op->dsa.r.length);
1844 debug_hexdump(stdout, "s:",
1845 asym_op->dsa.s.data, asym_op->dsa.s.length);
1847 /* Test PMD DSA sign verification using signer public key */
1848 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1850 /* copy signer public key */
1851 asym_op->dsa.y.data = dsa_test_params.y.data;
1852 asym_op->dsa.y.length = dsa_test_params.y.length;
1854 /* Process crypto operation */
1855 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1857 "line %u FAILED: %s",
1858 __LINE__, "Error sending packet for operation");
1859 status = TEST_FAILED;
1863 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1866 if (result_op == NULL) {
1868 "line %u FAILED: %s",
1869 __LINE__, "Failed to process asym crypto op");
1870 status = TEST_FAILED;
1874 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1876 "line %u FAILED: %s",
1877 __LINE__, "Failed to process asym crypto op");
1878 status = TEST_FAILED;
1882 rte_cryptodev_asym_session_clear(dev_id, sess);
1883 rte_cryptodev_asym_session_free(sess);
1886 rte_crypto_op_free(op);
1894 status = test_dsa_sign();
1895 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1900 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
1901 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
1902 .setup = testsuite_setup,
1903 .teardown = testsuite_teardown,
1904 .unit_test_cases = {
1905 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1906 TEST_CASE_ST(ut_setup, ut_teardown, test_dsa),
1907 TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
1908 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
1909 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
1910 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
1911 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
1912 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
1913 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1914 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1915 TEST_CASES_END() /**< NULL terminate unit test array */
1919 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
1920 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
1921 .setup = testsuite_setup,
1922 .teardown = testsuite_teardown,
1923 .unit_test_cases = {
1924 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1925 TEST_CASES_END() /**< NULL terminate unit test array */
1929 static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
1930 .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
1931 .setup = testsuite_setup,
1932 .teardown = testsuite_teardown,
1933 .unit_test_cases = {
1934 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1935 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
1936 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
1937 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1938 TEST_CASES_END() /**< NULL terminate unit test array */
1943 test_cryptodev_openssl_asym(void)
1945 gbl_driver_id = rte_cryptodev_driver_id_get(
1946 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
1948 if (gbl_driver_id == -1) {
1949 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
1950 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
1951 "in config file to run this testsuite.\n");
1955 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
1959 test_cryptodev_qat_asym(void)
1961 gbl_driver_id = rte_cryptodev_driver_id_get(
1962 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
1964 if (gbl_driver_id == -1) {
1965 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
1966 "CONFIG_RTE_LIBRTE_PMD_QAT_ASYM is enabled "
1967 "in config file to run this testsuite.\n");
1971 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
1975 test_cryptodev_octeontx_asym(void)
1977 gbl_driver_id = rte_cryptodev_driver_id_get(
1978 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
1979 if (gbl_driver_id == -1) {
1980 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded. Check if "
1981 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX_CRYPTO is "
1982 "enabled in config file to run this "
1986 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
1990 test_cryptodev_octeontx2_asym(void)
1992 gbl_driver_id = rte_cryptodev_driver_id_get(
1993 RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
1994 if (gbl_driver_id == -1) {
1995 RTE_LOG(ERR, USER1, "OCTEONTX2 PMD must be loaded. Check if "
1996 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX2_CRYPTO is "
1997 "enabled in config file to run this "
2002 /* Use test suite registered for crypto_octeontx PMD */
2003 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2006 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
2007 test_cryptodev_openssl_asym);
2009 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
2011 REGISTER_TEST_COMMAND(cryptodev_octeontx_asym_autotest,
2012 test_cryptodev_octeontx_asym);
2014 REGISTER_TEST_COMMAND(cryptodev_octeontx2_asym_autotest,
2015 test_cryptodev_octeontx2_asym);