1a9de470cSBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2a9de470cSBruce Richardson * Copyright(c) 2018 Cavium Networks 3488f5a23SDamian Nowak * Copyright (c) 2019 Intel Corporation 4a9de470cSBruce Richardson */ 5a9de470cSBruce Richardson 6a9de470cSBruce Richardson #include <rte_bus_vdev.h> 7a9de470cSBruce Richardson #include <rte_common.h> 8a9de470cSBruce Richardson #include <rte_hexdump.h> 9a9de470cSBruce Richardson #include <rte_mbuf.h> 10a9de470cSBruce Richardson #include <rte_malloc.h> 11a9de470cSBruce Richardson #include <rte_memcpy.h> 12a9de470cSBruce Richardson #include <rte_pause.h> 13a9de470cSBruce Richardson 14a9de470cSBruce Richardson #include <rte_cryptodev.h> 15a9de470cSBruce Richardson #include <rte_crypto.h> 16a9de470cSBruce Richardson 17a9de470cSBruce Richardson #include "test_cryptodev.h" 18a9de470cSBruce Richardson #include "test_cryptodev_dh_test_vectors.h" 19a9de470cSBruce Richardson #include "test_cryptodev_dsa_test_vectors.h" 2031dd9ddfSGowrishankar Muthukrishnan #include "test_cryptodev_ecdh_test_vectors.h" 21d90e58a7SAyuj Verma #include "test_cryptodev_ecdsa_test_vectors.h" 22f225c040SSunila Sahu #include "test_cryptodev_ecpm_test_vectors.h" 232fba5232SGowrishankar Muthukrishnan #include "test_cryptodev_eddsa_test_vectors.h" 24a9de470cSBruce Richardson #include "test_cryptodev_mod_test_vectors.h" 25a9de470cSBruce Richardson #include "test_cryptodev_rsa_test_vectors.h" 262d970c66SGowrishankar Muthukrishnan #include "test_cryptodev_sm2_test_vectors.h" 27a9de470cSBruce Richardson #include "test_cryptodev_asym_util.h" 28a9de470cSBruce Richardson #include "test.h" 29a9de470cSBruce Richardson 30a9de470cSBruce Richardson #define TEST_NUM_BUFS 10 31a9de470cSBruce Richardson #define TEST_NUM_SESSIONS 4 32a9de470cSBruce Richardson 33488f5a23SDamian Nowak #ifndef TEST_DATA_SIZE 34488f5a23SDamian Nowak #define TEST_DATA_SIZE 4096 35488f5a23SDamian Nowak #endif 36488f5a23SDamian Nowak #define ASYM_TEST_MSG_LEN 256 37488f5a23SDamian Nowak #define TEST_VECTOR_SIZE 256 381ffefe00SArkadiusz Kusztal #define DEQ_TIMEOUT 50 39488f5a23SDamian Nowak 40a9de470cSBruce Richardson static int gbl_driver_id; 411ffefe00SArkadiusz Kusztal static struct crypto_testsuite_params_asym { 42a9de470cSBruce Richardson struct rte_mempool *op_mpool; 43a9de470cSBruce Richardson struct rte_mempool *session_mpool; 44a9de470cSBruce Richardson struct rte_cryptodev_config conf; 45a9de470cSBruce Richardson struct rte_cryptodev_qp_conf qp_conf; 46a9de470cSBruce Richardson uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS]; 47a9de470cSBruce Richardson uint8_t valid_dev_count; 481ffefe00SArkadiusz Kusztal } testsuite_params, *params = &testsuite_params; 49a9de470cSBruce Richardson 501ffefe00SArkadiusz Kusztal static struct ut_args { 51a29bb248SCiara Power void *sess; 52a9de470cSBruce Richardson struct rte_crypto_op *op; 531ffefe00SArkadiusz Kusztal struct rte_crypto_op *result_op; 541ffefe00SArkadiusz Kusztal } _args, *self = &_args; 55a9de470cSBruce Richardson 56a9de470cSBruce Richardson static int 57a29bb248SCiara Power queue_ops_rsa_sign_verify(void *sess) 585ae36995SAyuj Verma { 59da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 605ae36995SAyuj Verma struct rte_mempool *op_mpool = ts_params->op_mpool; 615ae36995SAyuj Verma uint8_t dev_id = ts_params->valid_devs[0]; 625ae36995SAyuj Verma struct rte_crypto_op *op, *result_op; 635ae36995SAyuj Verma struct rte_crypto_asym_op *asym_op; 645ae36995SAyuj Verma uint8_t output_buf[TEST_DATA_SIZE]; 655ae36995SAyuj Verma int status = TEST_SUCCESS; 665ae36995SAyuj Verma 675ae36995SAyuj Verma /* Set up crypto op data structure */ 685ae36995SAyuj Verma op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 695ae36995SAyuj Verma if (!op) { 705ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto " 715ae36995SAyuj Verma "operation struct\n"); 725ae36995SAyuj Verma return TEST_FAILED; 735ae36995SAyuj Verma } 745ae36995SAyuj Verma 755ae36995SAyuj Verma asym_op = op->asym; 765ae36995SAyuj Verma 775ae36995SAyuj Verma /* Compute sign on the test vector */ 785ae36995SAyuj Verma asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN; 795ae36995SAyuj Verma 805ae36995SAyuj Verma asym_op->rsa.message.data = rsaplaintext.data; 815ae36995SAyuj Verma asym_op->rsa.message.length = rsaplaintext.len; 82d3a913d9SGowrishankar Muthukrishnan asym_op->rsa.sign.length = RTE_DIM(rsa_n); 835ae36995SAyuj Verma asym_op->rsa.sign.data = output_buf; 845ae36995SAyuj Verma 855ae36995SAyuj Verma debug_hexdump(stdout, "message", asym_op->rsa.message.data, 865ae36995SAyuj Verma asym_op->rsa.message.length); 875ae36995SAyuj Verma 885ae36995SAyuj Verma /* Attach asymmetric crypto session to crypto operations */ 895ae36995SAyuj Verma rte_crypto_op_attach_asym_session(op, sess); 905ae36995SAyuj Verma 915ae36995SAyuj Verma RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 925ae36995SAyuj Verma 935ae36995SAyuj Verma /* Process crypto operation */ 945ae36995SAyuj Verma if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 955ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Error sending packet for sign\n"); 965ae36995SAyuj Verma status = TEST_FAILED; 975ae36995SAyuj Verma goto error_exit; 985ae36995SAyuj Verma } 995ae36995SAyuj Verma 1005ae36995SAyuj Verma while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 1015ae36995SAyuj Verma rte_pause(); 1025ae36995SAyuj Verma 1035ae36995SAyuj Verma if (result_op == NULL) { 1045ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Failed to process sign op\n"); 1055ae36995SAyuj Verma status = TEST_FAILED; 1065ae36995SAyuj Verma goto error_exit; 1075ae36995SAyuj Verma } 1085ae36995SAyuj Verma 1095ae36995SAyuj Verma debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data, 1105ae36995SAyuj Verma asym_op->rsa.sign.length); 1115ae36995SAyuj Verma asym_op = result_op->asym; 1125ae36995SAyuj Verma 1135ae36995SAyuj Verma /* Verify sign */ 1145ae36995SAyuj Verma asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY; 1155ae36995SAyuj Verma 1165ae36995SAyuj Verma /* Process crypto operation */ 1175ae36995SAyuj Verma if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 1185ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Error sending packet for verify\n"); 1195ae36995SAyuj Verma status = TEST_FAILED; 1205ae36995SAyuj Verma goto error_exit; 1215ae36995SAyuj Verma } 1225ae36995SAyuj Verma 1235ae36995SAyuj Verma while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 1245ae36995SAyuj Verma rte_pause(); 1255ae36995SAyuj Verma 1265ae36995SAyuj Verma if (result_op == NULL) { 1275ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Failed to process verify op\n"); 1285ae36995SAyuj Verma status = TEST_FAILED; 1295ae36995SAyuj Verma goto error_exit; 1305ae36995SAyuj Verma } 1315ae36995SAyuj Verma 1325ae36995SAyuj Verma status = TEST_SUCCESS; 1335ae36995SAyuj Verma if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 1345ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n"); 1355ae36995SAyuj Verma status = TEST_FAILED; 1365ae36995SAyuj Verma } 1375ae36995SAyuj Verma 1385ae36995SAyuj Verma error_exit: 1395ae36995SAyuj Verma 1405ae36995SAyuj Verma rte_crypto_op_free(op); 1415ae36995SAyuj Verma 1425ae36995SAyuj Verma return status; 1435ae36995SAyuj Verma } 1445ae36995SAyuj Verma 1455ae36995SAyuj Verma static int 146a29bb248SCiara Power queue_ops_rsa_enc_dec(void *sess) 1475ae36995SAyuj Verma { 148da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 1495ae36995SAyuj Verma struct rte_mempool *op_mpool = ts_params->op_mpool; 1505ae36995SAyuj Verma uint8_t dev_id = ts_params->valid_devs[0]; 1515ae36995SAyuj Verma struct rte_crypto_op *op, *result_op; 1525ae36995SAyuj Verma struct rte_crypto_asym_op *asym_op; 153501ed9c6SArek Kusztal uint8_t cipher_buf[TEST_DATA_SIZE] = {0}; 1545ae36995SAyuj Verma int ret, status = TEST_SUCCESS; 1555ae36995SAyuj Verma 1565ae36995SAyuj Verma /* Set up crypto op data structure */ 1575ae36995SAyuj Verma op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 1585ae36995SAyuj Verma if (!op) { 1595ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto " 1605ae36995SAyuj Verma "operation struct\n"); 1615ae36995SAyuj Verma return TEST_FAILED; 1625ae36995SAyuj Verma } 1635ae36995SAyuj Verma 1645ae36995SAyuj Verma asym_op = op->asym; 1655ae36995SAyuj Verma 1665ae36995SAyuj Verma /* Compute encryption on the test vector */ 1675ae36995SAyuj Verma asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT; 1685ae36995SAyuj Verma 1695ae36995SAyuj Verma asym_op->rsa.message.data = rsaplaintext.data; 170501ed9c6SArek Kusztal asym_op->rsa.cipher.data = cipher_buf; 171d3a913d9SGowrishankar Muthukrishnan asym_op->rsa.cipher.length = RTE_DIM(rsa_n); 1725ae36995SAyuj Verma asym_op->rsa.message.length = rsaplaintext.len; 1735ae36995SAyuj Verma 1745ae36995SAyuj Verma debug_hexdump(stdout, "message", asym_op->rsa.message.data, 1755ae36995SAyuj Verma asym_op->rsa.message.length); 1765ae36995SAyuj Verma 1775ae36995SAyuj Verma /* Attach asymmetric crypto session to crypto operations */ 1785ae36995SAyuj Verma rte_crypto_op_attach_asym_session(op, sess); 1795ae36995SAyuj Verma 1805ae36995SAyuj Verma RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 1815ae36995SAyuj Verma 1825ae36995SAyuj Verma /* Process crypto operation */ 1835ae36995SAyuj Verma if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 1845ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Error sending packet for encryption\n"); 1855ae36995SAyuj Verma status = TEST_FAILED; 1865ae36995SAyuj Verma goto error_exit; 1875ae36995SAyuj Verma } 1885ae36995SAyuj Verma 1895ae36995SAyuj Verma while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 1905ae36995SAyuj Verma rte_pause(); 1915ae36995SAyuj Verma 1925ae36995SAyuj Verma if (result_op == NULL) { 1935ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Failed to process encryption op\n"); 1945ae36995SAyuj Verma status = TEST_FAILED; 1955ae36995SAyuj Verma goto error_exit; 1965ae36995SAyuj Verma } 1971c6b77deSSunyang Wu debug_hexdump(stdout, "encrypted message", asym_op->rsa.cipher.data, 1981c6b77deSSunyang Wu asym_op->rsa.cipher.length); 1995ae36995SAyuj Verma 2005ae36995SAyuj Verma /* Use the resulted output as decryption Input vector*/ 2015ae36995SAyuj Verma asym_op = result_op->asym; 202d3a913d9SGowrishankar Muthukrishnan asym_op->rsa.message.length = RTE_DIM(rsa_n); 2035ae36995SAyuj Verma asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT; 2045ae36995SAyuj Verma 2055ae36995SAyuj Verma /* Process crypto operation */ 2065ae36995SAyuj Verma if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 2075ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Error sending packet for decryption\n"); 2085ae36995SAyuj Verma status = TEST_FAILED; 2095ae36995SAyuj Verma goto error_exit; 2105ae36995SAyuj Verma } 2115ae36995SAyuj Verma 2125ae36995SAyuj Verma while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 2135ae36995SAyuj Verma rte_pause(); 2145ae36995SAyuj Verma 2155ae36995SAyuj Verma if (result_op == NULL) { 2165ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Failed to process decryption op\n"); 2175ae36995SAyuj Verma status = TEST_FAILED; 2185ae36995SAyuj Verma goto error_exit; 2195ae36995SAyuj Verma } 2205ae36995SAyuj Verma status = TEST_SUCCESS; 2215ae36995SAyuj Verma ret = rsa_verify(&rsaplaintext, result_op); 2225ae36995SAyuj Verma if (ret) 2235ae36995SAyuj Verma status = TEST_FAILED; 2245ae36995SAyuj Verma 2255ae36995SAyuj Verma error_exit: 2265ae36995SAyuj Verma 2275ae36995SAyuj Verma rte_crypto_op_free(op); 2285ae36995SAyuj Verma 2295ae36995SAyuj Verma return status; 2305ae36995SAyuj Verma } 231488f5a23SDamian Nowak 232488f5a23SDamian Nowak static int 233a9de470cSBruce Richardson test_rsa_sign_verify(void) 234a9de470cSBruce Richardson { 235da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 236a9de470cSBruce Richardson struct rte_mempool *sess_mpool = ts_params->session_mpool; 237a9de470cSBruce Richardson uint8_t dev_id = ts_params->valid_devs[0]; 238a29bb248SCiara Power void *sess = NULL; 239e010ea06SAyuj Verma struct rte_cryptodev_info dev_info; 240757f40e2SCiara Power int ret, status = TEST_SUCCESS; 241a9de470cSBruce Richardson 2425ae36995SAyuj Verma /* Test case supports op with exponent key only, 243e010ea06SAyuj Verma * Check in PMD feature flag for RSA exponent key type support. 244e010ea06SAyuj Verma */ 245e010ea06SAyuj Verma rte_cryptodev_info_get(dev_id, &dev_info); 246e010ea06SAyuj Verma if (!(dev_info.feature_flags & 247e010ea06SAyuj Verma RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) { 2485ae36995SAyuj Verma RTE_LOG(INFO, USER1, "Device doesn't support sign op with " 249e010ea06SAyuj Verma "exponent key type. Test Skipped\n"); 250e68012f0SCiara Power return TEST_SKIPPED; 251e010ea06SAyuj Verma } 252e010ea06SAyuj Verma 253757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess); 254a9de470cSBruce Richardson 255757f40e2SCiara Power if (ret < 0) { 2565ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Session creation failed for " 2575ae36995SAyuj Verma "sign_verify\n"); 258757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 259a9de470cSBruce Richardson goto error_exit; 260a9de470cSBruce Richardson } 261a9de470cSBruce Richardson 2625ae36995SAyuj Verma status = queue_ops_rsa_sign_verify(sess); 263a9de470cSBruce Richardson 264a9de470cSBruce Richardson error_exit: 2651f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 266a9de470cSBruce Richardson 267a9de470cSBruce Richardson TEST_ASSERT_EQUAL(status, 0, "Test failed"); 268a9de470cSBruce Richardson 269a9de470cSBruce Richardson return status; 270a9de470cSBruce Richardson } 271a9de470cSBruce Richardson 272a9de470cSBruce Richardson static int 273a9de470cSBruce Richardson test_rsa_enc_dec(void) 274a9de470cSBruce Richardson { 275da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 276a9de470cSBruce Richardson struct rte_mempool *sess_mpool = ts_params->session_mpool; 277a9de470cSBruce Richardson uint8_t dev_id = ts_params->valid_devs[0]; 278a29bb248SCiara Power void *sess = NULL; 279e010ea06SAyuj Verma struct rte_cryptodev_info dev_info; 280757f40e2SCiara Power int ret, status = TEST_SUCCESS; 281a9de470cSBruce Richardson 2825ae36995SAyuj Verma /* Test case supports op with exponent key only, 283e010ea06SAyuj Verma * Check in PMD feature flag for RSA exponent key type support. 284e010ea06SAyuj Verma */ 285e010ea06SAyuj Verma rte_cryptodev_info_get(dev_id, &dev_info); 286e010ea06SAyuj Verma if (!(dev_info.feature_flags & 287e010ea06SAyuj Verma RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) { 2885ae36995SAyuj Verma RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with " 2895ae36995SAyuj Verma "exponent key type. Test skipped\n"); 290e68012f0SCiara Power return TEST_SKIPPED; 291e010ea06SAyuj Verma } 292e010ea06SAyuj Verma 293757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess); 294a9de470cSBruce Richardson 295757f40e2SCiara Power if (ret < 0) { 2965ae36995SAyuj Verma RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n"); 297757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 298a9de470cSBruce Richardson goto error_exit; 299a9de470cSBruce Richardson } 300a9de470cSBruce Richardson 3015ae36995SAyuj Verma status = queue_ops_rsa_enc_dec(sess); 302a9de470cSBruce Richardson 303a9de470cSBruce Richardson error_exit: 304a9de470cSBruce Richardson 3051f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 306a9de470cSBruce Richardson 307a9de470cSBruce Richardson TEST_ASSERT_EQUAL(status, 0, "Test failed"); 308a9de470cSBruce Richardson 309a9de470cSBruce Richardson return status; 310a9de470cSBruce Richardson } 311a9de470cSBruce Richardson 312a9de470cSBruce Richardson static int 313a379799cSAyuj Verma test_rsa_sign_verify_crt(void) 314a379799cSAyuj Verma { 315da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 316a379799cSAyuj Verma struct rte_mempool *sess_mpool = ts_params->session_mpool; 317a379799cSAyuj Verma uint8_t dev_id = ts_params->valid_devs[0]; 318a29bb248SCiara Power void *sess = NULL; 319a379799cSAyuj Verma struct rte_cryptodev_info dev_info; 320757f40e2SCiara Power int ret, status = TEST_SUCCESS; 321a379799cSAyuj Verma 322a379799cSAyuj Verma /* Test case supports op with quintuple format key only, 323a379799cSAyuj Verma * Check im PMD feature flag for RSA quintuple key type support. 324a379799cSAyuj Verma */ 325a379799cSAyuj Verma rte_cryptodev_info_get(dev_id, &dev_info); 326a379799cSAyuj Verma if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) { 327a379799cSAyuj Verma RTE_LOG(INFO, USER1, "Device doesn't support sign op with " 328a379799cSAyuj Verma "quintuple key type. Test skipped\n"); 329e68012f0SCiara Power return TEST_SKIPPED; 330a379799cSAyuj Verma } 331a379799cSAyuj Verma 332757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess); 333a379799cSAyuj Verma 334757f40e2SCiara Power if (ret < 0) { 335a379799cSAyuj Verma RTE_LOG(ERR, USER1, "Session creation failed for " 336a379799cSAyuj Verma "sign_verify_crt\n"); 337757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 338a379799cSAyuj Verma goto error_exit; 339a379799cSAyuj Verma } 3401f1e4b7cSCiara Power 341a379799cSAyuj Verma status = queue_ops_rsa_sign_verify(sess); 342a379799cSAyuj Verma 343a379799cSAyuj Verma error_exit: 344a379799cSAyuj Verma 3451f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 346a379799cSAyuj Verma 347a379799cSAyuj Verma TEST_ASSERT_EQUAL(status, 0, "Test failed"); 348a379799cSAyuj Verma 349a379799cSAyuj Verma return status; 350a379799cSAyuj Verma } 351a379799cSAyuj Verma 352a379799cSAyuj Verma static int 353a379799cSAyuj Verma test_rsa_enc_dec_crt(void) 354a379799cSAyuj Verma { 355da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 356a379799cSAyuj Verma struct rte_mempool *sess_mpool = ts_params->session_mpool; 357a379799cSAyuj Verma uint8_t dev_id = ts_params->valid_devs[0]; 358a29bb248SCiara Power void *sess = NULL; 359a379799cSAyuj Verma struct rte_cryptodev_info dev_info; 360757f40e2SCiara Power int ret, status = TEST_SUCCESS; 361a379799cSAyuj Verma 362a379799cSAyuj Verma /* Test case supports op with quintuple format key only, 363a379799cSAyuj Verma * Check in PMD feature flag for RSA quintuple key type support. 364a379799cSAyuj Verma */ 365a379799cSAyuj Verma rte_cryptodev_info_get(dev_id, &dev_info); 366a379799cSAyuj Verma if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) { 367a379799cSAyuj Verma RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with " 368a379799cSAyuj Verma "quintuple key type. Test skipped\n"); 369e68012f0SCiara Power return TEST_SKIPPED; 370a379799cSAyuj Verma } 371a379799cSAyuj Verma 372757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess); 373a379799cSAyuj Verma 374757f40e2SCiara Power if (ret < 0) { 375a379799cSAyuj Verma RTE_LOG(ERR, USER1, "Session creation failed for " 376a379799cSAyuj Verma "enc_dec_crt\n"); 377757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 378a379799cSAyuj Verma goto error_exit; 379a379799cSAyuj Verma } 3801f1e4b7cSCiara Power 381a379799cSAyuj Verma status = queue_ops_rsa_enc_dec(sess); 382a379799cSAyuj Verma 383a379799cSAyuj Verma error_exit: 384a379799cSAyuj Verma 3851f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 386a379799cSAyuj Verma 387a379799cSAyuj Verma TEST_ASSERT_EQUAL(status, 0, "Test failed"); 388a379799cSAyuj Verma 389a379799cSAyuj Verma return status; 390a379799cSAyuj Verma } 391a379799cSAyuj Verma 392a379799cSAyuj Verma static int 393a9de470cSBruce Richardson testsuite_setup(void) 394a9de470cSBruce Richardson { 395da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 396b01627d5SAyuj Verma uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS]; 397a9de470cSBruce Richardson struct rte_cryptodev_info info; 398b01627d5SAyuj Verma int ret, dev_id = -1; 399b01627d5SAyuj Verma uint32_t i, nb_devs; 400a9de470cSBruce Richardson uint16_t qp_id; 401a9de470cSBruce Richardson 402a9de470cSBruce Richardson memset(ts_params, 0, sizeof(*ts_params)); 403a9de470cSBruce Richardson 4040438b7dfSCiara Power /* Device, op pool and session configuration for asymmetric crypto. 8< */ 405a9de470cSBruce Richardson ts_params->op_mpool = rte_crypto_op_pool_create( 406a9de470cSBruce Richardson "CRYPTO_ASYM_OP_POOL", 407a9de470cSBruce Richardson RTE_CRYPTO_OP_TYPE_ASYMMETRIC, 408a9de470cSBruce Richardson TEST_NUM_BUFS, 0, 409a9de470cSBruce Richardson 0, 410a9de470cSBruce Richardson rte_socket_id()); 411a9de470cSBruce Richardson if (ts_params->op_mpool == NULL) { 412a9de470cSBruce Richardson RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n"); 413a9de470cSBruce Richardson return TEST_FAILED; 414a9de470cSBruce Richardson } 415a9de470cSBruce Richardson 416a9de470cSBruce Richardson /* Create an OPENSSL device if required */ 417a9de470cSBruce Richardson if (gbl_driver_id == rte_cryptodev_driver_id_get( 418a9de470cSBruce Richardson RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) { 419a9de470cSBruce Richardson nb_devs = rte_cryptodev_device_count_by_driver( 420a9de470cSBruce Richardson rte_cryptodev_driver_id_get( 421a9de470cSBruce Richardson RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))); 422a9de470cSBruce Richardson if (nb_devs < 1) { 423a9de470cSBruce Richardson ret = rte_vdev_init( 424a9de470cSBruce Richardson RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD), 425a9de470cSBruce Richardson NULL); 426a9de470cSBruce Richardson 427a9de470cSBruce Richardson TEST_ASSERT(ret == 0, "Failed to create " 428a9de470cSBruce Richardson "instance of pmd : %s", 429a9de470cSBruce Richardson RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 430a9de470cSBruce Richardson } 431a9de470cSBruce Richardson } 432a9de470cSBruce Richardson 433b01627d5SAyuj Verma /* Get list of valid crypto devs */ 434b01627d5SAyuj Verma nb_devs = rte_cryptodev_devices_get( 435b01627d5SAyuj Verma rte_cryptodev_driver_name_get(gbl_driver_id), 436b01627d5SAyuj Verma valid_devs, RTE_CRYPTO_MAX_DEVS); 437a9de470cSBruce Richardson if (nb_devs < 1) { 438a9de470cSBruce Richardson RTE_LOG(ERR, USER1, "No crypto devices found?\n"); 43977222f30SCiara Power return TEST_SKIPPED; 440a9de470cSBruce Richardson } 441a9de470cSBruce Richardson 442b01627d5SAyuj Verma /* 443b01627d5SAyuj Verma * Get first valid asymmetric device found in test suite param and 444b01627d5SAyuj Verma * break 445b01627d5SAyuj Verma */ 446a9de470cSBruce Richardson for (i = 0; i < nb_devs ; i++) { 447b01627d5SAyuj Verma rte_cryptodev_info_get(valid_devs[i], &info); 448b01627d5SAyuj Verma if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) { 449b01627d5SAyuj Verma dev_id = ts_params->valid_devs[0] = valid_devs[i]; 450b01627d5SAyuj Verma break; 451b01627d5SAyuj Verma } 452a9de470cSBruce Richardson } 453a9de470cSBruce Richardson 454b01627d5SAyuj Verma if (dev_id == -1) { 455a9de470cSBruce Richardson RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. " 456b01627d5SAyuj Verma "Test skipped.\n"); 457a9de470cSBruce Richardson return TEST_FAILED; 458a9de470cSBruce Richardson } 459a9de470cSBruce Richardson 460b01627d5SAyuj Verma /* Set valid device count */ 461b01627d5SAyuj Verma ts_params->valid_dev_count = nb_devs; 462b01627d5SAyuj Verma 463a9de470cSBruce Richardson /* configure device with num qp */ 464a9de470cSBruce Richardson ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs; 465a9de470cSBruce Richardson ts_params->conf.socket_id = SOCKET_ID_ANY; 4665ae36995SAyuj Verma ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY | 4675ae36995SAyuj Verma RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO; 468a9de470cSBruce Richardson TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, 469a9de470cSBruce Richardson &ts_params->conf), 470a9de470cSBruce Richardson "Failed to configure cryptodev %u with %u qps", 471a9de470cSBruce Richardson dev_id, ts_params->conf.nb_queue_pairs); 472a9de470cSBruce Richardson 473a9de470cSBruce Richardson /* configure qp */ 474a9de470cSBruce Richardson ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; 475a9de470cSBruce Richardson ts_params->qp_conf.mp_session = ts_params->session_mpool; 476a9de470cSBruce Richardson for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) { 477a9de470cSBruce Richardson TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 478a9de470cSBruce Richardson dev_id, qp_id, &ts_params->qp_conf, 479a9de470cSBruce Richardson rte_cryptodev_socket_id(dev_id)), 480a9de470cSBruce Richardson "Failed to setup queue pair %u on cryptodev %u ASYM", 481a9de470cSBruce Richardson qp_id, dev_id); 482a9de470cSBruce Richardson } 483a9de470cSBruce Richardson 4841f1e4b7cSCiara Power ts_params->session_mpool = rte_cryptodev_asym_session_pool_create( 48592d55afeSCiara Power "test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0, 4861f1e4b7cSCiara Power SOCKET_ID_ANY); 487a9de470cSBruce Richardson 488a9de470cSBruce Richardson TEST_ASSERT_NOT_NULL(ts_params->session_mpool, 489a9de470cSBruce Richardson "session mempool allocation failed"); 4900438b7dfSCiara Power /* >8 End of device, op pool and session configuration for asymmetric crypto section. */ 491a9de470cSBruce Richardson return TEST_SUCCESS; 492a9de470cSBruce Richardson } 493a9de470cSBruce Richardson 494a9de470cSBruce Richardson static void 495a9de470cSBruce Richardson testsuite_teardown(void) 496a9de470cSBruce Richardson { 497da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 498a9de470cSBruce Richardson 499c1f618b4SAnoob Joseph /* Reset device */ 500c1f618b4SAnoob Joseph ts_params->qp_conf.mp_session = NULL; 501c1f618b4SAnoob Joseph ts_params->conf.ff_disable = 0; 502c1f618b4SAnoob Joseph if (rte_cryptodev_configure(ts_params->valid_devs[0], &ts_params->conf)) 503c1f618b4SAnoob Joseph RTE_LOG(DEBUG, USER1, "Could not reset cryptodev\n"); 504c1f618b4SAnoob Joseph 505a9de470cSBruce Richardson if (ts_params->op_mpool != NULL) { 506a9de470cSBruce Richardson RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n", 507a9de470cSBruce Richardson rte_mempool_avail_count(ts_params->op_mpool)); 508a9de470cSBruce Richardson } 509a9de470cSBruce Richardson 510a9de470cSBruce Richardson /* Free session mempools */ 511a9de470cSBruce Richardson if (ts_params->session_mpool != NULL) { 512a9de470cSBruce Richardson rte_mempool_free(ts_params->session_mpool); 513a9de470cSBruce Richardson ts_params->session_mpool = NULL; 514a9de470cSBruce Richardson } 515a9de470cSBruce Richardson } 516a9de470cSBruce Richardson 517a9de470cSBruce Richardson static int 518da74df7dSCiara Power ut_setup_asym(void) 519a9de470cSBruce Richardson { 520da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 521a9de470cSBruce Richardson uint16_t qp_id; 522a9de470cSBruce Richardson 5231ffefe00SArkadiusz Kusztal memset(self, 0, sizeof(*self)); 5241ffefe00SArkadiusz Kusztal self->op = rte_crypto_op_alloc(params->op_mpool, 5251ffefe00SArkadiusz Kusztal RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 5261ffefe00SArkadiusz Kusztal TEST_ASSERT_NOT_NULL(self->op, 5271ffefe00SArkadiusz Kusztal "Failed to allocate asymmetric crypto operation struct" 5281ffefe00SArkadiusz Kusztal ); 5291ffefe00SArkadiusz Kusztal 530a9de470cSBruce Richardson /* Reconfigure device to default parameters */ 531a9de470cSBruce Richardson ts_params->conf.socket_id = SOCKET_ID_ANY; 532a9de470cSBruce Richardson 533a9de470cSBruce Richardson TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0], 534a9de470cSBruce Richardson &ts_params->conf), 535a9de470cSBruce Richardson "Failed to configure cryptodev %u", 536a9de470cSBruce Richardson ts_params->valid_devs[0]); 537a9de470cSBruce Richardson 538a9de470cSBruce Richardson for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) { 539a9de470cSBruce Richardson TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup( 540a9de470cSBruce Richardson ts_params->valid_devs[0], qp_id, 541a9de470cSBruce Richardson &ts_params->qp_conf, 542a9de470cSBruce Richardson rte_cryptodev_socket_id(ts_params->valid_devs[0])), 543a9de470cSBruce Richardson "Failed to setup queue pair %u on cryptodev %u", 544a9de470cSBruce Richardson qp_id, ts_params->valid_devs[0]); 545a9de470cSBruce Richardson } 546a9de470cSBruce Richardson 547a9de470cSBruce Richardson /* Start the device */ 548a9de470cSBruce Richardson TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]), 549a9de470cSBruce Richardson "Failed to start cryptodev %u", 550a9de470cSBruce Richardson ts_params->valid_devs[0]); 551a9de470cSBruce Richardson 552a9de470cSBruce Richardson return TEST_SUCCESS; 553a9de470cSBruce Richardson } 554a9de470cSBruce Richardson 555a9de470cSBruce Richardson static void 556da74df7dSCiara Power ut_teardown_asym(void) 557a9de470cSBruce Richardson { 558da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 5591ffefe00SArkadiusz Kusztal uint8_t dev_id = ts_params->valid_devs[0]; 5601ffefe00SArkadiusz Kusztal 5611ffefe00SArkadiusz Kusztal if (self->sess != NULL) 5621ffefe00SArkadiusz Kusztal rte_cryptodev_asym_session_free(dev_id, self->sess); 5631ffefe00SArkadiusz Kusztal rte_crypto_op_free(self->op); 5641ffefe00SArkadiusz Kusztal self->sess = NULL; 5651ffefe00SArkadiusz Kusztal self->op = NULL; 5661ffefe00SArkadiusz Kusztal self->result_op = NULL; 567a9de470cSBruce Richardson 568a9de470cSBruce Richardson /* Stop the device */ 569a9de470cSBruce Richardson rte_cryptodev_stop(ts_params->valid_devs[0]); 570a9de470cSBruce Richardson } 571a9de470cSBruce Richardson 572a9de470cSBruce Richardson static inline void print_asym_capa( 573a9de470cSBruce Richardson const struct rte_cryptodev_asymmetric_xform_capability *capa) 574a9de470cSBruce Richardson { 575a9de470cSBruce Richardson int i = 0; 576a9de470cSBruce Richardson 577a9de470cSBruce Richardson printf("\nxform type: %s\n===================\n", 5787e1e1277SAkhil Goyal rte_cryptodev_asym_get_xform_string(capa->xform_type)); 579a9de470cSBruce Richardson printf("operation supported -"); 580a9de470cSBruce Richardson 581a9de470cSBruce Richardson for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) { 582a9de470cSBruce Richardson /* check supported operations */ 5835fa1fb29SArek Kusztal if (rte_cryptodev_asym_xform_capability_check_optype(capa, i)) { 5845fa1fb29SArek Kusztal if (capa->xform_type == RTE_CRYPTO_ASYM_XFORM_DH) 5855fa1fb29SArek Kusztal printf(" %s", rte_crypto_asym_ke_strings[i]); 5865fa1fb29SArek Kusztal else 5875fa1fb29SArek Kusztal printf(" %s", rte_crypto_asym_op_strings[i]); 5885fa1fb29SArek Kusztal } 589a9de470cSBruce Richardson } 590a9de470cSBruce Richardson switch (capa->xform_type) { 591a9de470cSBruce Richardson case RTE_CRYPTO_ASYM_XFORM_RSA: 592a9de470cSBruce Richardson case RTE_CRYPTO_ASYM_XFORM_MODINV: 593a9de470cSBruce Richardson case RTE_CRYPTO_ASYM_XFORM_MODEX: 594a9de470cSBruce Richardson case RTE_CRYPTO_ASYM_XFORM_DH: 595a9de470cSBruce Richardson case RTE_CRYPTO_ASYM_XFORM_DSA: 596d90e58a7SAyuj Verma printf(" modlen: min %d max %d increment %d", 597a9de470cSBruce Richardson capa->modlen.min, 598a9de470cSBruce Richardson capa->modlen.max, 599a9de470cSBruce Richardson capa->modlen.increment); 600a9de470cSBruce Richardson break; 601d90e58a7SAyuj Verma case RTE_CRYPTO_ASYM_XFORM_ECDSA: 602f225c040SSunila Sahu case RTE_CRYPTO_ASYM_XFORM_ECPM: 6032eef1a64SGowrishankar Muthukrishnan case RTE_CRYPTO_ASYM_XFORM_SM2: 604a9de470cSBruce Richardson default: 605a9de470cSBruce Richardson break; 606a9de470cSBruce Richardson } 607d90e58a7SAyuj Verma printf("\n"); 608a9de470cSBruce Richardson } 609a9de470cSBruce Richardson 610a9de470cSBruce Richardson static int 611a9de470cSBruce Richardson test_capability(void) 612a9de470cSBruce Richardson { 613da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 614a9de470cSBruce Richardson uint8_t dev_id = ts_params->valid_devs[0]; 615a9de470cSBruce Richardson struct rte_cryptodev_info dev_info; 616a9de470cSBruce Richardson const struct rte_cryptodev_capabilities *dev_capa; 617a9de470cSBruce Richardson int i = 0; 618a9de470cSBruce Richardson struct rte_cryptodev_asym_capability_idx idx; 619a9de470cSBruce Richardson const struct rte_cryptodev_asymmetric_xform_capability *capa; 620a9de470cSBruce Richardson 621a9de470cSBruce Richardson rte_cryptodev_info_get(dev_id, &dev_info); 622a9de470cSBruce Richardson if (!(dev_info.feature_flags & 623a9de470cSBruce Richardson RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) { 624a9de470cSBruce Richardson RTE_LOG(INFO, USER1, 625a9de470cSBruce Richardson "Device doesn't support asymmetric. Test Skipped\n"); 626624ce7e3SGowrishankar Muthukrishnan return TEST_SKIPPED; 627a9de470cSBruce Richardson } 628a9de470cSBruce Richardson 629a9de470cSBruce Richardson /* print xform capability */ 630a9de470cSBruce Richardson for (i = 0; 631a9de470cSBruce Richardson dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED; 632a9de470cSBruce Richardson i++) { 633a9de470cSBruce Richardson dev_capa = &(dev_info.capabilities[i]); 634a9de470cSBruce Richardson if (dev_info.capabilities[i].op == 635a9de470cSBruce Richardson RTE_CRYPTO_OP_TYPE_ASYMMETRIC) { 636a9de470cSBruce Richardson idx.type = dev_capa->asym.xform_capa.xform_type; 637a9de470cSBruce Richardson 638a9de470cSBruce Richardson capa = rte_cryptodev_asym_capability_get(dev_id, 639a9de470cSBruce Richardson (const struct 640a9de470cSBruce Richardson rte_cryptodev_asym_capability_idx *) &idx); 641624ce7e3SGowrishankar Muthukrishnan TEST_ASSERT_NOT_NULL(capa, "Failed to get asymmetric capability"); 642a9de470cSBruce Richardson print_asym_capa(capa); 643a9de470cSBruce Richardson } 644a9de470cSBruce Richardson } 645a9de470cSBruce Richardson return TEST_SUCCESS; 646a9de470cSBruce Richardson } 647a9de470cSBruce Richardson 648a9de470cSBruce Richardson static int 649a9de470cSBruce Richardson test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm) 650a9de470cSBruce Richardson { 651da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 652a9de470cSBruce Richardson struct rte_mempool *op_mpool = ts_params->op_mpool; 653a9de470cSBruce Richardson struct rte_mempool *sess_mpool = ts_params->session_mpool; 654a9de470cSBruce Richardson uint8_t dev_id = ts_params->valid_devs[0]; 655a9de470cSBruce Richardson struct rte_crypto_asym_op *asym_op = NULL; 656a9de470cSBruce Richardson struct rte_crypto_op *op = NULL, *result_op = NULL; 657a29bb248SCiara Power void *sess = NULL; 658757f40e2SCiara Power int ret, status = TEST_SUCCESS; 659a9de470cSBruce Richardson uint8_t output[TEST_DH_MOD_LEN]; 660a9de470cSBruce Richardson struct rte_crypto_asym_xform xform = *xfrm; 661a9de470cSBruce Richardson uint8_t peer[] = "01234567890123456789012345678901234567890123456789"; 662a9de470cSBruce Richardson 663a9de470cSBruce Richardson /* set up crypto op data structure */ 664a9de470cSBruce Richardson op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 665a9de470cSBruce Richardson if (!op) { 666a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 667a9de470cSBruce Richardson "line %u FAILED: %s", 668a9de470cSBruce Richardson __LINE__, "Failed to allocate asymmetric crypto " 669a9de470cSBruce Richardson "operation struct"); 670a9de470cSBruce Richardson status = TEST_FAILED; 671a9de470cSBruce Richardson goto error_exit; 672a9de470cSBruce Richardson } 673a9de470cSBruce Richardson asym_op = op->asym; 674a9de470cSBruce Richardson 675a9de470cSBruce Richardson /* Setup a xform and op to generate private key only */ 676a9de470cSBruce Richardson xform.next = NULL; 677515a704dSArek Kusztal asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE; 678a9de470cSBruce Richardson asym_op->dh.priv_key.data = dh_test_params.priv_key.data; 679a9de470cSBruce Richardson asym_op->dh.priv_key.length = dh_test_params.priv_key.length; 680a9de470cSBruce Richardson asym_op->dh.pub_key.data = (uint8_t *)peer; 681a9de470cSBruce Richardson asym_op->dh.pub_key.length = sizeof(peer); 682a9de470cSBruce Richardson asym_op->dh.shared_secret.data = output; 683a9de470cSBruce Richardson asym_op->dh.shared_secret.length = sizeof(output); 684a9de470cSBruce Richardson 685757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 686757f40e2SCiara Power if (ret < 0) { 687a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 6881f1e4b7cSCiara Power "line %u FAILED: %s", __LINE__, 6891f1e4b7cSCiara Power "Session creation failed"); 690757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 691a9de470cSBruce Richardson goto error_exit; 692a9de470cSBruce Richardson } 693a9de470cSBruce Richardson 694a9de470cSBruce Richardson /* attach asymmetric crypto session to crypto operations */ 695a9de470cSBruce Richardson rte_crypto_op_attach_asym_session(op, sess); 696a9de470cSBruce Richardson 697a9de470cSBruce Richardson RTE_LOG(DEBUG, USER1, "Process ASYM operation"); 698a9de470cSBruce Richardson 699a9de470cSBruce Richardson /* Process crypto operation */ 700a9de470cSBruce Richardson if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 701a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 702a9de470cSBruce Richardson "line %u FAILED: %s", 703a9de470cSBruce Richardson __LINE__, "Error sending packet for operation"); 704a9de470cSBruce Richardson status = TEST_FAILED; 705a9de470cSBruce Richardson goto error_exit; 706a9de470cSBruce Richardson } 707a9de470cSBruce Richardson 708a9de470cSBruce Richardson while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 709a9de470cSBruce Richardson rte_pause(); 710a9de470cSBruce Richardson 711a9de470cSBruce Richardson if (result_op == NULL) { 712a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 713a9de470cSBruce Richardson "line %u FAILED: %s", 714a9de470cSBruce Richardson __LINE__, "Failed to process asym crypto op"); 715a9de470cSBruce Richardson status = TEST_FAILED; 716a9de470cSBruce Richardson goto error_exit; 717a9de470cSBruce Richardson } 718a9de470cSBruce Richardson 719a9de470cSBruce Richardson debug_hexdump(stdout, "shared secret:", 720a9de470cSBruce Richardson asym_op->dh.shared_secret.data, 721a9de470cSBruce Richardson asym_op->dh.shared_secret.length); 722a9de470cSBruce Richardson 723a9de470cSBruce Richardson error_exit: 7241f1e4b7cSCiara Power if (sess != NULL) 7251f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 726a9de470cSBruce Richardson rte_crypto_op_free(op); 727a9de470cSBruce Richardson return status; 728a9de470cSBruce Richardson } 729a9de470cSBruce Richardson 730a9de470cSBruce Richardson static int 731a9de470cSBruce Richardson test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm) 732a9de470cSBruce Richardson { 733da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 734a9de470cSBruce Richardson struct rte_mempool *op_mpool = ts_params->op_mpool; 735a9de470cSBruce Richardson struct rte_mempool *sess_mpool = ts_params->session_mpool; 736a9de470cSBruce Richardson uint8_t dev_id = ts_params->valid_devs[0]; 737a9de470cSBruce Richardson struct rte_crypto_asym_op *asym_op = NULL; 738a9de470cSBruce Richardson struct rte_crypto_op *op = NULL, *result_op = NULL; 739a29bb248SCiara Power void *sess = NULL; 740757f40e2SCiara Power int ret, status = TEST_SUCCESS; 741a9de470cSBruce Richardson uint8_t output[TEST_DH_MOD_LEN]; 742a9de470cSBruce Richardson struct rte_crypto_asym_xform xform = *xfrm; 743a9de470cSBruce Richardson 744a9de470cSBruce Richardson /* set up crypto op data structure */ 745a9de470cSBruce Richardson op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 746a9de470cSBruce Richardson if (!op) { 747a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 748a9de470cSBruce Richardson "line %u FAILED: %s", 749a9de470cSBruce Richardson __LINE__, "Failed to allocate asymmetric crypto " 750a9de470cSBruce Richardson "operation struct"); 751a9de470cSBruce Richardson status = TEST_FAILED; 752a9de470cSBruce Richardson goto error_exit; 753a9de470cSBruce Richardson } 754a9de470cSBruce Richardson asym_op = op->asym; 755a9de470cSBruce Richardson 756a9de470cSBruce Richardson /* Setup a xform and op to generate private key only */ 757a9de470cSBruce Richardson xform.next = NULL; 758515a704dSArek Kusztal asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE; 759a9de470cSBruce Richardson asym_op->dh.priv_key.data = output; 760a9de470cSBruce Richardson asym_op->dh.priv_key.length = sizeof(output); 761a9de470cSBruce Richardson 762757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 763757f40e2SCiara Power if (ret < 0) { 764a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 7651f1e4b7cSCiara Power "line %u FAILED: %s", __LINE__, 7661f1e4b7cSCiara Power "Session creation failed"); 767757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 768a9de470cSBruce Richardson goto error_exit; 769a9de470cSBruce Richardson } 770a9de470cSBruce Richardson 771a9de470cSBruce Richardson /* attach asymmetric crypto session to crypto operations */ 772a9de470cSBruce Richardson rte_crypto_op_attach_asym_session(op, sess); 773a9de470cSBruce Richardson 774a9de470cSBruce Richardson RTE_LOG(DEBUG, USER1, "Process ASYM operation"); 775a9de470cSBruce Richardson 776a9de470cSBruce Richardson /* Process crypto operation */ 777a9de470cSBruce Richardson if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 778a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 779a9de470cSBruce Richardson "line %u FAILED: %s", 780a9de470cSBruce Richardson __LINE__, "Error sending packet for operation"); 781a9de470cSBruce Richardson status = TEST_FAILED; 782a9de470cSBruce Richardson goto error_exit; 783a9de470cSBruce Richardson } 784a9de470cSBruce Richardson 785a9de470cSBruce Richardson while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 786a9de470cSBruce Richardson rte_pause(); 787a9de470cSBruce Richardson 788a9de470cSBruce Richardson if (result_op == NULL) { 789a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 790a9de470cSBruce Richardson "line %u FAILED: %s", 791a9de470cSBruce Richardson __LINE__, "Failed to process asym crypto op"); 792a9de470cSBruce Richardson status = TEST_FAILED; 793a9de470cSBruce Richardson goto error_exit; 794a9de470cSBruce Richardson } 795a9de470cSBruce Richardson 796a9de470cSBruce Richardson debug_hexdump(stdout, "private key:", 797a9de470cSBruce Richardson asym_op->dh.priv_key.data, 798a9de470cSBruce Richardson asym_op->dh.priv_key.length); 799a9de470cSBruce Richardson 800a9de470cSBruce Richardson 801a9de470cSBruce Richardson error_exit: 8021f1e4b7cSCiara Power if (sess != NULL) 8031f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 804a9de470cSBruce Richardson rte_crypto_op_free(op); 805a9de470cSBruce Richardson 806a9de470cSBruce Richardson return status; 807a9de470cSBruce Richardson } 808a9de470cSBruce Richardson 809a9de470cSBruce Richardson 810a9de470cSBruce Richardson static int 811a9de470cSBruce Richardson test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm) 812a9de470cSBruce Richardson { 813da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 814a9de470cSBruce Richardson struct rte_mempool *op_mpool = ts_params->op_mpool; 815a9de470cSBruce Richardson struct rte_mempool *sess_mpool = ts_params->session_mpool; 816a9de470cSBruce Richardson uint8_t dev_id = ts_params->valid_devs[0]; 817a9de470cSBruce Richardson struct rte_crypto_asym_op *asym_op = NULL; 818a9de470cSBruce Richardson struct rte_crypto_op *op = NULL, *result_op = NULL; 819a29bb248SCiara Power void *sess = NULL; 820757f40e2SCiara Power int ret, status = TEST_SUCCESS; 821a9de470cSBruce Richardson uint8_t output[TEST_DH_MOD_LEN]; 822a9de470cSBruce Richardson struct rte_crypto_asym_xform xform = *xfrm; 823a9de470cSBruce Richardson 824a9de470cSBruce Richardson /* set up crypto op data structure */ 825a9de470cSBruce Richardson op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 826a9de470cSBruce Richardson if (!op) { 827a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 828a9de470cSBruce Richardson "line %u FAILED: %s", 829a9de470cSBruce Richardson __LINE__, "Failed to allocate asymmetric crypto " 830a9de470cSBruce Richardson "operation struct"); 831a9de470cSBruce Richardson status = TEST_FAILED; 832a9de470cSBruce Richardson goto error_exit; 833a9de470cSBruce Richardson } 834a9de470cSBruce Richardson asym_op = op->asym; 835a9de470cSBruce Richardson /* Setup a xform chain to generate public key 836a9de470cSBruce Richardson * using test private key 837a9de470cSBruce Richardson * 838a9de470cSBruce Richardson */ 839a9de470cSBruce Richardson xform.next = NULL; 840a9de470cSBruce Richardson 841515a704dSArek Kusztal asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE; 842a9de470cSBruce Richardson asym_op->dh.pub_key.data = output; 843a9de470cSBruce Richardson asym_op->dh.pub_key.length = sizeof(output); 844a9de470cSBruce Richardson /* load pre-defined private key */ 845a9de470cSBruce Richardson asym_op->dh.priv_key.data = rte_malloc(NULL, 846a9de470cSBruce Richardson dh_test_params.priv_key.length, 847a9de470cSBruce Richardson 0); 848a9de470cSBruce Richardson asym_op->dh.priv_key = dh_test_params.priv_key; 849a9de470cSBruce Richardson 850757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 851757f40e2SCiara Power if (ret < 0) { 852a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 8531f1e4b7cSCiara Power "line %u FAILED: %s", __LINE__, 8541f1e4b7cSCiara Power "Session creation failed"); 855757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 856a9de470cSBruce Richardson goto error_exit; 857a9de470cSBruce Richardson } 858a9de470cSBruce Richardson 859a9de470cSBruce Richardson /* attach asymmetric crypto session to crypto operations */ 860a9de470cSBruce Richardson rte_crypto_op_attach_asym_session(op, sess); 861a9de470cSBruce Richardson 862a9de470cSBruce Richardson RTE_LOG(DEBUG, USER1, "Process ASYM operation"); 863a9de470cSBruce Richardson 864a9de470cSBruce Richardson /* Process crypto operation */ 865a9de470cSBruce Richardson if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 866a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 867a9de470cSBruce Richardson "line %u FAILED: %s", 868a9de470cSBruce Richardson __LINE__, "Error sending packet for operation"); 869a9de470cSBruce Richardson status = TEST_FAILED; 870a9de470cSBruce Richardson goto error_exit; 871a9de470cSBruce Richardson } 872a9de470cSBruce Richardson 873a9de470cSBruce Richardson while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 874a9de470cSBruce Richardson rte_pause(); 875a9de470cSBruce Richardson 876a9de470cSBruce Richardson if (result_op == NULL) { 877a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 878a9de470cSBruce Richardson "line %u FAILED: %s", 879a9de470cSBruce Richardson __LINE__, "Failed to process asym crypto op"); 880a9de470cSBruce Richardson status = TEST_FAILED; 881a9de470cSBruce Richardson goto error_exit; 882a9de470cSBruce Richardson } 883a9de470cSBruce Richardson 884a9de470cSBruce Richardson debug_hexdump(stdout, "pub key:", 885a9de470cSBruce Richardson asym_op->dh.pub_key.data, asym_op->dh.pub_key.length); 886a9de470cSBruce Richardson 887a9de470cSBruce Richardson debug_hexdump(stdout, "priv key:", 888a9de470cSBruce Richardson asym_op->dh.priv_key.data, asym_op->dh.priv_key.length); 889a9de470cSBruce Richardson 890a9de470cSBruce Richardson error_exit: 8911f1e4b7cSCiara Power if (sess != NULL) 8921f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 893a9de470cSBruce Richardson rte_crypto_op_free(op); 894a9de470cSBruce Richardson 895a9de470cSBruce Richardson return status; 896a9de470cSBruce Richardson } 897a9de470cSBruce Richardson 898a9de470cSBruce Richardson static int 899a9de470cSBruce Richardson test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm) 900a9de470cSBruce Richardson { 901da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 902a9de470cSBruce Richardson struct rte_mempool *op_mpool = ts_params->op_mpool; 903a9de470cSBruce Richardson struct rte_mempool *sess_mpool = ts_params->session_mpool; 904a9de470cSBruce Richardson uint8_t dev_id = ts_params->valid_devs[0]; 905a9de470cSBruce Richardson struct rte_crypto_asym_op *asym_op = NULL; 906a9de470cSBruce Richardson struct rte_crypto_op *op = NULL, *result_op = NULL; 907a29bb248SCiara Power void *sess = NULL; 908757f40e2SCiara Power int ret, status = TEST_SUCCESS; 909a9de470cSBruce Richardson uint8_t out_pub_key[TEST_DH_MOD_LEN]; 910a9de470cSBruce Richardson uint8_t out_prv_key[TEST_DH_MOD_LEN]; 911a9de470cSBruce Richardson struct rte_crypto_asym_xform pub_key_xform; 912a9de470cSBruce Richardson struct rte_crypto_asym_xform xform = *xfrm; 913a9de470cSBruce Richardson 914a9de470cSBruce Richardson /* set up crypto op data structure */ 915a9de470cSBruce Richardson op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 916a9de470cSBruce Richardson if (!op) { 917a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 918a9de470cSBruce Richardson "line %u FAILED: %s", 919a9de470cSBruce Richardson __LINE__, "Failed to allocate asymmetric crypto " 920a9de470cSBruce Richardson "operation struct"); 921a9de470cSBruce Richardson status = TEST_FAILED; 922a9de470cSBruce Richardson goto error_exit; 923a9de470cSBruce Richardson } 924a9de470cSBruce Richardson asym_op = op->asym; 925a9de470cSBruce Richardson /* Setup a xform chain to generate 926a9de470cSBruce Richardson * private key first followed by 927a9de470cSBruce Richardson * public key 9285fa1fb29SArek Kusztal */ 929a9de470cSBruce Richardson pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH; 930a9de470cSBruce Richardson xform.next = &pub_key_xform; 931a9de470cSBruce Richardson 932515a704dSArek Kusztal asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE; 933a9de470cSBruce Richardson asym_op->dh.pub_key.data = out_pub_key; 934a9de470cSBruce Richardson asym_op->dh.pub_key.length = sizeof(out_pub_key); 935a9de470cSBruce Richardson asym_op->dh.priv_key.data = out_prv_key; 936515a704dSArek Kusztal asym_op->dh.priv_key.length = 0; 9371f1e4b7cSCiara Power 938757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 939757f40e2SCiara Power if (ret < 0) { 940a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 9411f1e4b7cSCiara Power "line %u FAILED: %s", __LINE__, 9421f1e4b7cSCiara Power "Session creation failed"); 943757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 944a9de470cSBruce Richardson goto error_exit; 945a9de470cSBruce Richardson } 946a9de470cSBruce Richardson 947a9de470cSBruce Richardson /* attach asymmetric crypto session to crypto operations */ 948a9de470cSBruce Richardson rte_crypto_op_attach_asym_session(op, sess); 949a9de470cSBruce Richardson 950a9de470cSBruce Richardson RTE_LOG(DEBUG, USER1, "Process ASYM operation"); 951a9de470cSBruce Richardson 952a9de470cSBruce Richardson /* Process crypto operation */ 953a9de470cSBruce Richardson if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 954a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 955a9de470cSBruce Richardson "line %u FAILED: %s", 956a9de470cSBruce Richardson __LINE__, "Error sending packet for operation"); 957a9de470cSBruce Richardson status = TEST_FAILED; 958a9de470cSBruce Richardson goto error_exit; 959a9de470cSBruce Richardson } 960a9de470cSBruce Richardson 961a9de470cSBruce Richardson while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 962a9de470cSBruce Richardson rte_pause(); 963a9de470cSBruce Richardson 964a9de470cSBruce Richardson if (result_op == NULL) { 965a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 966a9de470cSBruce Richardson "line %u FAILED: %s", 967a9de470cSBruce Richardson __LINE__, "Failed to process asym crypto op"); 968a9de470cSBruce Richardson status = TEST_FAILED; 969a9de470cSBruce Richardson goto error_exit; 970a9de470cSBruce Richardson } 971a9de470cSBruce Richardson debug_hexdump(stdout, "priv key:", 972a9de470cSBruce Richardson out_prv_key, asym_op->dh.priv_key.length); 973a9de470cSBruce Richardson debug_hexdump(stdout, "pub key:", 974a9de470cSBruce Richardson out_pub_key, asym_op->dh.pub_key.length); 975a9de470cSBruce Richardson 976a9de470cSBruce Richardson error_exit: 9771f1e4b7cSCiara Power if (sess != NULL) 9781f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 979a9de470cSBruce Richardson rte_crypto_op_free(op); 980a9de470cSBruce Richardson 981a9de470cSBruce Richardson return status; 982a9de470cSBruce Richardson } 983a9de470cSBruce Richardson 984a9de470cSBruce Richardson static int 985a9de470cSBruce Richardson test_mod_inv(void) 986a9de470cSBruce Richardson { 987da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 988a9de470cSBruce Richardson struct rte_mempool *op_mpool = ts_params->op_mpool; 989a9de470cSBruce Richardson struct rte_mempool *sess_mpool = ts_params->session_mpool; 990a9de470cSBruce Richardson uint8_t dev_id = ts_params->valid_devs[0]; 991a9de470cSBruce Richardson struct rte_crypto_asym_op *asym_op = NULL; 992a9de470cSBruce Richardson struct rte_crypto_op *op = NULL, *result_op = NULL; 993a29bb248SCiara Power void *sess = NULL; 994a9de470cSBruce Richardson int status = TEST_SUCCESS; 995a9de470cSBruce Richardson struct rte_cryptodev_asym_capability_idx cap_idx; 996a9de470cSBruce Richardson const struct rte_cryptodev_asymmetric_xform_capability *capability; 997a9de470cSBruce Richardson uint8_t input[TEST_DATA_SIZE] = {0}; 998a9de470cSBruce Richardson int ret = 0; 9995e4fb861SArek Kusztal uint8_t result[sizeof(mod_p)] = { 0 }; 1000a9de470cSBruce Richardson 1001a9de470cSBruce Richardson if (rte_cryptodev_asym_get_xform_enum( 1002a9de470cSBruce Richardson &modinv_xform.xform_type, "modinv") < 0) { 1003a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 10047e94c8bcSAyuj Verma "Invalid ASYM algorithm specified\n"); 1005a9de470cSBruce Richardson return -1; 1006a9de470cSBruce Richardson } 1007a9de470cSBruce Richardson 1008a9de470cSBruce Richardson cap_idx.type = modinv_xform.xform_type; 1009a9de470cSBruce Richardson capability = rte_cryptodev_asym_capability_get(dev_id, 1010a9de470cSBruce Richardson &cap_idx); 1011a9de470cSBruce Richardson 10127e94c8bcSAyuj Verma if (capability == NULL) { 10137e94c8bcSAyuj Verma RTE_LOG(INFO, USER1, 10147e94c8bcSAyuj Verma "Device doesn't support MOD INV. Test Skipped\n"); 1015e68012f0SCiara Power return TEST_SKIPPED; 10167e94c8bcSAyuj Verma } 10177e94c8bcSAyuj Verma 1018a9de470cSBruce Richardson if (rte_cryptodev_asym_xform_capability_check_modlen( 1019a9de470cSBruce Richardson capability, 1020a9de470cSBruce Richardson modinv_xform.modinv.modulus.length)) { 1021a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 10227e94c8bcSAyuj Verma "Invalid MODULUS length specified\n"); 1023e68012f0SCiara Power return TEST_SKIPPED; 1024a9de470cSBruce Richardson } 1025a9de470cSBruce Richardson 1026757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess); 1027757f40e2SCiara Power if (ret < 0) { 1028a9de470cSBruce Richardson RTE_LOG(ERR, USER1, "line %u " 1029a9de470cSBruce Richardson "FAILED: %s", __LINE__, 1030a9de470cSBruce Richardson "Session creation failed"); 1031757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 1032a9de470cSBruce Richardson goto error_exit; 1033a9de470cSBruce Richardson } 1034a9de470cSBruce Richardson 1035a9de470cSBruce Richardson /* generate crypto op data structure */ 1036a9de470cSBruce Richardson op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 1037a9de470cSBruce Richardson if (!op) { 1038a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1039a9de470cSBruce Richardson "line %u FAILED: %s", 1040a9de470cSBruce Richardson __LINE__, "Failed to allocate asymmetric crypto " 1041a9de470cSBruce Richardson "operation struct"); 1042a9de470cSBruce Richardson status = TEST_FAILED; 1043a9de470cSBruce Richardson goto error_exit; 1044a9de470cSBruce Richardson } 1045a9de470cSBruce Richardson 1046a9de470cSBruce Richardson asym_op = op->asym; 1047a9de470cSBruce Richardson memcpy(input, base, sizeof(base)); 1048a9de470cSBruce Richardson asym_op->modinv.base.data = input; 1049a9de470cSBruce Richardson asym_op->modinv.base.length = sizeof(base); 10505e4fb861SArek Kusztal asym_op->modinv.result.data = result; 10515e4fb861SArek Kusztal asym_op->modinv.result.length = sizeof(result); 1052a9de470cSBruce Richardson 1053a9de470cSBruce Richardson /* attach asymmetric crypto session to crypto operations */ 1054a9de470cSBruce Richardson rte_crypto_op_attach_asym_session(op, sess); 1055a9de470cSBruce Richardson 1056a9de470cSBruce Richardson RTE_LOG(DEBUG, USER1, "Process ASYM operation"); 1057a9de470cSBruce Richardson 1058a9de470cSBruce Richardson /* Process crypto operation */ 1059a9de470cSBruce Richardson if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 1060a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1061a9de470cSBruce Richardson "line %u FAILED: %s", 1062a9de470cSBruce Richardson __LINE__, "Error sending packet for operation"); 1063a9de470cSBruce Richardson status = TEST_FAILED; 1064a9de470cSBruce Richardson goto error_exit; 1065a9de470cSBruce Richardson } 1066a9de470cSBruce Richardson 1067a9de470cSBruce Richardson while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 1068a9de470cSBruce Richardson rte_pause(); 1069a9de470cSBruce Richardson 1070a9de470cSBruce Richardson if (result_op == NULL) { 1071a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1072a9de470cSBruce Richardson "line %u FAILED: %s", 1073a9de470cSBruce Richardson __LINE__, "Failed to process asym crypto op"); 1074a9de470cSBruce Richardson status = TEST_FAILED; 1075a9de470cSBruce Richardson goto error_exit; 1076a9de470cSBruce Richardson } 1077a9de470cSBruce Richardson 1078a9de470cSBruce Richardson ret = verify_modinv(mod_inv, result_op); 1079a9de470cSBruce Richardson if (ret) { 1080a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1081a9de470cSBruce Richardson "operation verification failed\n"); 1082a9de470cSBruce Richardson status = TEST_FAILED; 1083a9de470cSBruce Richardson } 1084a9de470cSBruce Richardson 1085a9de470cSBruce Richardson error_exit: 10861f1e4b7cSCiara Power if (sess) 10871f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 1088a9de470cSBruce Richardson 1089a9de470cSBruce Richardson rte_crypto_op_free(op); 1090a9de470cSBruce Richardson 1091a9de470cSBruce Richardson TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1092a9de470cSBruce Richardson 1093a9de470cSBruce Richardson return status; 1094a9de470cSBruce Richardson } 1095a9de470cSBruce Richardson 1096a9de470cSBruce Richardson static int 1097a9de470cSBruce Richardson test_mod_exp(void) 1098a9de470cSBruce Richardson { 1099da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 1100a9de470cSBruce Richardson struct rte_mempool *op_mpool = ts_params->op_mpool; 1101a9de470cSBruce Richardson struct rte_mempool *sess_mpool = ts_params->session_mpool; 1102a9de470cSBruce Richardson uint8_t dev_id = ts_params->valid_devs[0]; 1103a9de470cSBruce Richardson struct rte_crypto_asym_op *asym_op = NULL; 1104a9de470cSBruce Richardson struct rte_crypto_op *op = NULL, *result_op = NULL; 1105a29bb248SCiara Power void *sess = NULL; 1106a9de470cSBruce Richardson int status = TEST_SUCCESS; 1107a9de470cSBruce Richardson struct rte_cryptodev_asym_capability_idx cap_idx; 1108a9de470cSBruce Richardson const struct rte_cryptodev_asymmetric_xform_capability *capability; 1109a9de470cSBruce Richardson uint8_t input[TEST_DATA_SIZE] = {0}; 1110a9de470cSBruce Richardson int ret = 0; 11115e4fb861SArek Kusztal uint8_t result[sizeof(mod_p)] = { 0 }; 1112a9de470cSBruce Richardson 1113a9de470cSBruce Richardson if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type, 1114a9de470cSBruce Richardson "modexp") 1115a9de470cSBruce Richardson < 0) { 1116a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 11177e94c8bcSAyuj Verma "Invalid ASYM algorithm specified\n"); 1118a9de470cSBruce Richardson return -1; 1119a9de470cSBruce Richardson } 1120a9de470cSBruce Richardson 1121a9de470cSBruce Richardson /* check for modlen capability */ 1122a9de470cSBruce Richardson cap_idx.type = modex_xform.xform_type; 1123a9de470cSBruce Richardson capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx); 1124a9de470cSBruce Richardson 11257e94c8bcSAyuj Verma if (capability == NULL) { 11267e94c8bcSAyuj Verma RTE_LOG(INFO, USER1, 11277e94c8bcSAyuj Verma "Device doesn't support MOD EXP. Test Skipped\n"); 1128e68012f0SCiara Power return TEST_SKIPPED; 11297e94c8bcSAyuj Verma } 11307e94c8bcSAyuj Verma 1131a9de470cSBruce Richardson if (rte_cryptodev_asym_xform_capability_check_modlen( 1132a9de470cSBruce Richardson capability, modex_xform.modex.modulus.length)) { 1133a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 11347e94c8bcSAyuj Verma "Invalid MODULUS length specified\n"); 1135e68012f0SCiara Power return TEST_SKIPPED; 1136a9de470cSBruce Richardson } 1137a9de470cSBruce Richardson 11380438b7dfSCiara Power /* Create op, create session, and process packets. 8< */ 1139a9de470cSBruce Richardson op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 1140a9de470cSBruce Richardson if (!op) { 1141a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1142a9de470cSBruce Richardson "line %u FAILED: %s", 1143a9de470cSBruce Richardson __LINE__, "Failed to allocate asymmetric crypto " 1144a9de470cSBruce Richardson "operation struct"); 1145a9de470cSBruce Richardson status = TEST_FAILED; 1146a9de470cSBruce Richardson goto error_exit; 1147a9de470cSBruce Richardson } 1148a9de470cSBruce Richardson 1149757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess); 1150757f40e2SCiara Power if (ret < 0) { 1151a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1152a9de470cSBruce Richardson "line %u " 1153a9de470cSBruce Richardson "FAILED: %s", __LINE__, 1154a9de470cSBruce Richardson "Session creation failed"); 1155757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 1156a9de470cSBruce Richardson goto error_exit; 1157a9de470cSBruce Richardson } 1158a9de470cSBruce Richardson 1159a9de470cSBruce Richardson asym_op = op->asym; 1160a9de470cSBruce Richardson memcpy(input, base, sizeof(base)); 1161a9de470cSBruce Richardson asym_op->modex.base.data = input; 1162a9de470cSBruce Richardson asym_op->modex.base.length = sizeof(base); 11635e4fb861SArek Kusztal asym_op->modex.result.data = result; 11645e4fb861SArek Kusztal asym_op->modex.result.length = sizeof(result); 1165a9de470cSBruce Richardson /* attach asymmetric crypto session to crypto operations */ 1166a9de470cSBruce Richardson rte_crypto_op_attach_asym_session(op, sess); 1167a9de470cSBruce Richardson 1168a9de470cSBruce Richardson RTE_LOG(DEBUG, USER1, "Process ASYM operation"); 1169a9de470cSBruce Richardson /* Process crypto operation */ 1170a9de470cSBruce Richardson if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 1171a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1172a9de470cSBruce Richardson "line %u FAILED: %s", 1173a9de470cSBruce Richardson __LINE__, "Error sending packet for operation"); 1174a9de470cSBruce Richardson status = TEST_FAILED; 1175a9de470cSBruce Richardson goto error_exit; 1176a9de470cSBruce Richardson } 1177a9de470cSBruce Richardson 1178a9de470cSBruce Richardson while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 1179a9de470cSBruce Richardson rte_pause(); 1180a9de470cSBruce Richardson 1181a9de470cSBruce Richardson if (result_op == NULL) { 1182a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1183a9de470cSBruce Richardson "line %u FAILED: %s", 1184a9de470cSBruce Richardson __LINE__, "Failed to process asym crypto op"); 1185a9de470cSBruce Richardson status = TEST_FAILED; 1186a9de470cSBruce Richardson goto error_exit; 1187a9de470cSBruce Richardson } 11880438b7dfSCiara Power /* >8 End of create op, create session, and process packets section. */ 1189a9de470cSBruce Richardson ret = verify_modexp(mod_exp, result_op); 1190a9de470cSBruce Richardson if (ret) { 1191a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1192a9de470cSBruce Richardson "operation verification failed\n"); 1193a9de470cSBruce Richardson status = TEST_FAILED; 1194a9de470cSBruce Richardson } 1195a9de470cSBruce Richardson 1196a9de470cSBruce Richardson error_exit: 11971f1e4b7cSCiara Power if (sess != NULL) 11981f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 1199a9de470cSBruce Richardson 1200a9de470cSBruce Richardson rte_crypto_op_free(op); 1201a9de470cSBruce Richardson 1202a9de470cSBruce Richardson TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1203a9de470cSBruce Richardson 1204a9de470cSBruce Richardson return status; 1205a9de470cSBruce Richardson } 1206a9de470cSBruce Richardson 1207a9de470cSBruce Richardson static int 1208ea7b0e1aSSivaramakrishnan Venkat test_dh_key_generation(void) 1209a9de470cSBruce Richardson { 1210a9de470cSBruce Richardson int status; 1211a9de470cSBruce Richardson 1212a9de470cSBruce Richardson debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length); 1213a9de470cSBruce Richardson debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length); 1214a9de470cSBruce Richardson debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data, 1215a9de470cSBruce Richardson dh_test_params.priv_key.length); 1216a9de470cSBruce Richardson 1217a9de470cSBruce Richardson RTE_LOG(INFO, USER1, 1218a9de470cSBruce Richardson "Test Public and Private key pair generation\n"); 1219a9de470cSBruce Richardson 1220a9de470cSBruce Richardson status = test_dh_gen_kp(&dh_xform); 1221a9de470cSBruce Richardson TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1222a9de470cSBruce Richardson 1223a9de470cSBruce Richardson RTE_LOG(INFO, USER1, 1224a9de470cSBruce Richardson "Test Public Key Generation using pre-defined priv key\n"); 1225a9de470cSBruce Richardson 1226a9de470cSBruce Richardson status = test_dh_gen_pub_key(&dh_xform); 1227a9de470cSBruce Richardson TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1228a9de470cSBruce Richardson 1229a9de470cSBruce Richardson RTE_LOG(INFO, USER1, 1230a9de470cSBruce Richardson "Test Private Key Generation only\n"); 1231a9de470cSBruce Richardson 1232a9de470cSBruce Richardson status = test_dh_gen_priv_key(&dh_xform); 1233a9de470cSBruce Richardson TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1234a9de470cSBruce Richardson 1235a9de470cSBruce Richardson RTE_LOG(INFO, USER1, 1236a9de470cSBruce Richardson "Test shared secret compute\n"); 1237a9de470cSBruce Richardson 1238a9de470cSBruce Richardson status = test_dh_gen_shared_sec(&dh_xform); 1239a9de470cSBruce Richardson TEST_ASSERT_EQUAL(status, 0, "Test failed"); 1240a9de470cSBruce Richardson 1241a9de470cSBruce Richardson return status; 1242a9de470cSBruce Richardson } 1243a9de470cSBruce Richardson 1244a9de470cSBruce Richardson static int 12454c7ae22fSKai Ji test_dsa_sign(struct rte_crypto_dsa_op_param *dsa_op) 1246a9de470cSBruce Richardson { 1247da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 1248a9de470cSBruce Richardson struct rte_mempool *op_mpool = ts_params->op_mpool; 1249a9de470cSBruce Richardson struct rte_mempool *sess_mpool = ts_params->session_mpool; 1250a9de470cSBruce Richardson uint8_t dev_id = ts_params->valid_devs[0]; 1251a9de470cSBruce Richardson struct rte_crypto_asym_op *asym_op = NULL; 1252a9de470cSBruce Richardson struct rte_crypto_op *op = NULL, *result_op = NULL; 1253a29bb248SCiara Power void *sess = NULL; 1254a9de470cSBruce Richardson int status = TEST_SUCCESS; 1255757f40e2SCiara Power int ret; 1256a9de470cSBruce Richardson 1257757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess); 1258757f40e2SCiara Power if (ret < 0) { 1259a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1260a9de470cSBruce Richardson "line %u FAILED: %s", __LINE__, 1261a9de470cSBruce Richardson "Session creation failed"); 1262757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 1263a9de470cSBruce Richardson goto error_exit; 1264a9de470cSBruce Richardson } 1265a9de470cSBruce Richardson /* set up crypto op data structure */ 1266a9de470cSBruce Richardson op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 1267a9de470cSBruce Richardson if (!op) { 1268a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1269a9de470cSBruce Richardson "line %u FAILED: %s", 1270a9de470cSBruce Richardson __LINE__, "Failed to allocate asymmetric crypto " 1271a9de470cSBruce Richardson "operation struct"); 1272a9de470cSBruce Richardson status = TEST_FAILED; 1273a9de470cSBruce Richardson goto error_exit; 1274a9de470cSBruce Richardson } 1275a9de470cSBruce Richardson asym_op = op->asym; 12764c7ae22fSKai Ji asym_op->dsa = *dsa_op; 1277a9de470cSBruce Richardson 1278a9de470cSBruce Richardson debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data, 1279a9de470cSBruce Richardson dsa_xform.dsa.p.length); 1280a9de470cSBruce Richardson debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data, 1281a9de470cSBruce Richardson dsa_xform.dsa.q.length); 1282a9de470cSBruce Richardson debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data, 1283a9de470cSBruce Richardson dsa_xform.dsa.g.length); 1284a9de470cSBruce Richardson debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data, 1285a9de470cSBruce Richardson dsa_xform.dsa.x.length); 1286a9de470cSBruce Richardson 1287a9de470cSBruce Richardson /* attach asymmetric crypto session to crypto operations */ 1288a9de470cSBruce Richardson rte_crypto_op_attach_asym_session(op, sess); 1289a9de470cSBruce Richardson asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN; 1290a9de470cSBruce Richardson RTE_LOG(DEBUG, USER1, "Process ASYM operation"); 1291a9de470cSBruce Richardson 1292a9de470cSBruce Richardson /* Process crypto operation */ 1293a9de470cSBruce Richardson if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 1294a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1295a9de470cSBruce Richardson "line %u FAILED: %s", 1296a9de470cSBruce Richardson __LINE__, "Error sending packet for operation"); 1297a9de470cSBruce Richardson status = TEST_FAILED; 1298a9de470cSBruce Richardson goto error_exit; 1299a9de470cSBruce Richardson } 1300a9de470cSBruce Richardson 1301a9de470cSBruce Richardson while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 1302a9de470cSBruce Richardson rte_pause(); 1303a9de470cSBruce Richardson 1304a9de470cSBruce Richardson if (result_op == NULL) { 1305a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1306a9de470cSBruce Richardson "line %u FAILED: %s", 1307a9de470cSBruce Richardson __LINE__, "Failed to process asym crypto op"); 1308a9de470cSBruce Richardson status = TEST_FAILED; 1309a9de470cSBruce Richardson goto error_exit; 1310a9de470cSBruce Richardson } 1311a9de470cSBruce Richardson 1312a9de470cSBruce Richardson asym_op = result_op->asym; 13134c7ae22fSKai Ji dsa_op->r.length = asym_op->dsa.r.length; 13144c7ae22fSKai Ji dsa_op->s.length = asym_op->dsa.s.length; 13154c7ae22fSKai Ji 13164c7ae22fSKai Ji debug_hexdump(stdout, "r:", 13174c7ae22fSKai Ji asym_op->dsa.r.data, asym_op->dsa.r.length); 13184c7ae22fSKai Ji debug_hexdump(stdout, "s:", 13194c7ae22fSKai Ji asym_op->dsa.s.data, asym_op->dsa.s.length); 13204c7ae22fSKai Ji error_exit: 13214c7ae22fSKai Ji if (sess != NULL) 13224c7ae22fSKai Ji rte_cryptodev_asym_session_free(dev_id, sess); 13234c7ae22fSKai Ji rte_crypto_op_free(op); 13244c7ae22fSKai Ji return status; 13254c7ae22fSKai Ji } 13264c7ae22fSKai Ji 13274c7ae22fSKai Ji static int 13284c7ae22fSKai Ji test_dsa_verify(struct rte_crypto_dsa_op_param *dsa_op) 13294c7ae22fSKai Ji { 13304c7ae22fSKai Ji struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 13314c7ae22fSKai Ji struct rte_mempool *op_mpool = ts_params->op_mpool; 13324c7ae22fSKai Ji struct rte_mempool *sess_mpool = ts_params->session_mpool; 13334c7ae22fSKai Ji uint8_t dev_id = ts_params->valid_devs[0]; 13344c7ae22fSKai Ji struct rte_crypto_asym_op *asym_op = NULL; 13354c7ae22fSKai Ji struct rte_crypto_op *op = NULL, *result_op = NULL; 13364c7ae22fSKai Ji void *sess = NULL; 13374c7ae22fSKai Ji int status = TEST_SUCCESS; 13384c7ae22fSKai Ji int ret; 13394c7ae22fSKai Ji 13404c7ae22fSKai Ji ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess); 13414c7ae22fSKai Ji if (ret < 0) { 13424c7ae22fSKai Ji RTE_LOG(ERR, USER1, 13434c7ae22fSKai Ji "line %u FAILED: %s", __LINE__, 13444c7ae22fSKai Ji "Session creation failed"); 13454c7ae22fSKai Ji status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 13464c7ae22fSKai Ji goto error_exit; 13474c7ae22fSKai Ji } 13484c7ae22fSKai Ji /* set up crypto op data structure */ 13494c7ae22fSKai Ji op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 13504c7ae22fSKai Ji if (!op) { 13514c7ae22fSKai Ji RTE_LOG(ERR, USER1, 13524c7ae22fSKai Ji "line %u FAILED: %s", 13534c7ae22fSKai Ji __LINE__, "Failed to allocate asymmetric crypto " 13544c7ae22fSKai Ji "operation struct"); 13554c7ae22fSKai Ji status = TEST_FAILED; 13564c7ae22fSKai Ji goto error_exit; 13574c7ae22fSKai Ji } 13584c7ae22fSKai Ji asym_op = op->asym; 13594c7ae22fSKai Ji asym_op->dsa = *dsa_op; 13604c7ae22fSKai Ji 13614c7ae22fSKai Ji debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data, 13624c7ae22fSKai Ji dsa_xform.dsa.p.length); 13634c7ae22fSKai Ji debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data, 13644c7ae22fSKai Ji dsa_xform.dsa.q.length); 13654c7ae22fSKai Ji debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data, 13664c7ae22fSKai Ji dsa_xform.dsa.g.length); 13674c7ae22fSKai Ji 13684c7ae22fSKai Ji /* attach asymmetric crypto session to crypto operations */ 13694c7ae22fSKai Ji rte_crypto_op_attach_asym_session(op, sess); 1370a9de470cSBruce Richardson 1371a9de470cSBruce Richardson debug_hexdump(stdout, "r:", 1372a9de470cSBruce Richardson asym_op->dsa.r.data, asym_op->dsa.r.length); 1373a9de470cSBruce Richardson debug_hexdump(stdout, "s:", 1374a9de470cSBruce Richardson asym_op->dsa.s.data, asym_op->dsa.s.length); 1375a9de470cSBruce Richardson 13764c7ae22fSKai Ji RTE_LOG(DEBUG, USER1, "Process ASYM verify operation"); 1377a9de470cSBruce Richardson /* Test PMD DSA sign verification using signer public key */ 1378a9de470cSBruce Richardson asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY; 1379a9de470cSBruce Richardson 1380a9de470cSBruce Richardson /* copy signer public key */ 1381a9de470cSBruce Richardson asym_op->dsa.y.data = dsa_test_params.y.data; 1382a9de470cSBruce Richardson asym_op->dsa.y.length = dsa_test_params.y.length; 1383a9de470cSBruce Richardson 1384a9de470cSBruce Richardson /* Process crypto operation */ 1385a9de470cSBruce Richardson if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 1386a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1387a9de470cSBruce Richardson "line %u FAILED: %s", 1388a9de470cSBruce Richardson __LINE__, "Error sending packet for operation"); 1389a9de470cSBruce Richardson status = TEST_FAILED; 1390a9de470cSBruce Richardson goto error_exit; 1391a9de470cSBruce Richardson } 1392a9de470cSBruce Richardson 1393a9de470cSBruce Richardson while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 1394a9de470cSBruce Richardson rte_pause(); 1395a9de470cSBruce Richardson 1396a9de470cSBruce Richardson if (result_op == NULL) { 1397a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1398a9de470cSBruce Richardson "line %u FAILED: %s", 1399a9de470cSBruce Richardson __LINE__, "Failed to process asym crypto op"); 1400a9de470cSBruce Richardson status = TEST_FAILED; 1401a9de470cSBruce Richardson goto error_exit; 1402a9de470cSBruce Richardson } 1403a9de470cSBruce Richardson 1404a9de470cSBruce Richardson if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 1405a9de470cSBruce Richardson RTE_LOG(ERR, USER1, 1406a9de470cSBruce Richardson "line %u FAILED: %s", 1407a9de470cSBruce Richardson __LINE__, "Failed to process asym crypto op"); 1408a9de470cSBruce Richardson status = TEST_FAILED; 1409a9de470cSBruce Richardson } 1410a9de470cSBruce Richardson error_exit: 14111f1e4b7cSCiara Power if (sess != NULL) 14121f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 1413a9de470cSBruce Richardson rte_crypto_op_free(op); 1414a9de470cSBruce Richardson return status; 1415a9de470cSBruce Richardson } 1416a9de470cSBruce Richardson 1417a9de470cSBruce Richardson static int 1418a9de470cSBruce Richardson test_dsa(void) 1419a9de470cSBruce Richardson { 1420a9de470cSBruce Richardson int status; 14214c7ae22fSKai Ji uint8_t r[TEST_DH_MOD_LEN]; 14224c7ae22fSKai Ji uint8_t s[TEST_DH_MOD_LEN]; 14234c7ae22fSKai Ji struct rte_crypto_dsa_op_param dsa_op; 14244c7ae22fSKai Ji uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344"; 14254c7ae22fSKai Ji 14264c7ae22fSKai Ji dsa_op.message.data = dgst; 14274c7ae22fSKai Ji dsa_op.message.length = sizeof(dgst); 14284c7ae22fSKai Ji dsa_op.r.data = r; 14294c7ae22fSKai Ji dsa_op.s.data = s; 14304c7ae22fSKai Ji dsa_op.r.length = sizeof(r); 14314c7ae22fSKai Ji dsa_op.s.length = sizeof(s); 14324c7ae22fSKai Ji 14334c7ae22fSKai Ji status = test_dsa_sign(&dsa_op); 14344c7ae22fSKai Ji TEST_ASSERT_EQUAL(status, 0, "DSA sign test failed"); 14354c7ae22fSKai Ji status = test_dsa_verify(&dsa_op); 14364c7ae22fSKai Ji TEST_ASSERT_EQUAL(status, 0, "DSA verify test failed"); 1437a9de470cSBruce Richardson return status; 1438a9de470cSBruce Richardson } 1439a9de470cSBruce Richardson 1440d90e58a7SAyuj Verma static int 1441d90e58a7SAyuj Verma test_ecdsa_sign_verify(enum curve curve_id) 1442d90e58a7SAyuj Verma { 1443da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 1444d90e58a7SAyuj Verma struct rte_mempool *sess_mpool = ts_params->session_mpool; 1445d90e58a7SAyuj Verma struct rte_mempool *op_mpool = ts_params->op_mpool; 1446d90e58a7SAyuj Verma struct crypto_testsuite_ecdsa_params input_params; 1447a29bb248SCiara Power void *sess = NULL; 1448d90e58a7SAyuj Verma uint8_t dev_id = ts_params->valid_devs[0]; 1449d90e58a7SAyuj Verma struct rte_crypto_op *result_op = NULL; 1450d90e58a7SAyuj Verma uint8_t output_buf_r[TEST_DATA_SIZE]; 1451d90e58a7SAyuj Verma uint8_t output_buf_s[TEST_DATA_SIZE]; 1452d90e58a7SAyuj Verma struct rte_crypto_asym_xform xform; 1453d90e58a7SAyuj Verma struct rte_crypto_asym_op *asym_op; 1454d90e58a7SAyuj Verma struct rte_cryptodev_info dev_info; 1455d90e58a7SAyuj Verma struct rte_crypto_op *op = NULL; 1456757f40e2SCiara Power int ret, status = TEST_SUCCESS; 1457d90e58a7SAyuj Verma 1458d90e58a7SAyuj Verma switch (curve_id) { 1459d90e58a7SAyuj Verma case SECP192R1: 1460d90e58a7SAyuj Verma input_params = ecdsa_param_secp192r1; 1461d90e58a7SAyuj Verma break; 1462d90e58a7SAyuj Verma case SECP224R1: 1463d90e58a7SAyuj Verma input_params = ecdsa_param_secp224r1; 1464d90e58a7SAyuj Verma break; 1465d90e58a7SAyuj Verma case SECP256R1: 1466d90e58a7SAyuj Verma input_params = ecdsa_param_secp256r1; 1467d90e58a7SAyuj Verma break; 1468d90e58a7SAyuj Verma case SECP384R1: 1469d90e58a7SAyuj Verma input_params = ecdsa_param_secp384r1; 1470d90e58a7SAyuj Verma break; 1471d90e58a7SAyuj Verma case SECP521R1: 1472d90e58a7SAyuj Verma input_params = ecdsa_param_secp521r1; 1473d90e58a7SAyuj Verma break; 14746631867dSGowrishankar Muthukrishnan case SECP521R1_UA: 14756631867dSGowrishankar Muthukrishnan input_params = ecdsa_param_secp521r1_ua; 14766631867dSGowrishankar Muthukrishnan break; 1477d90e58a7SAyuj Verma default: 1478d90e58a7SAyuj Verma RTE_LOG(ERR, USER1, 1479d90e58a7SAyuj Verma "line %u FAILED: %s", __LINE__, 1480d90e58a7SAyuj Verma "Unsupported curve id\n"); 1481d90e58a7SAyuj Verma status = TEST_FAILED; 1482d90e58a7SAyuj Verma goto exit; 1483d90e58a7SAyuj Verma } 1484d90e58a7SAyuj Verma 1485d90e58a7SAyuj Verma rte_cryptodev_info_get(dev_id, &dev_info); 1486d90e58a7SAyuj Verma 1487d90e58a7SAyuj Verma /* Setup crypto op data structure */ 1488d90e58a7SAyuj Verma op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 1489d90e58a7SAyuj Verma if (op == NULL) { 1490d90e58a7SAyuj Verma RTE_LOG(ERR, USER1, 1491d90e58a7SAyuj Verma "line %u FAILED: %s", __LINE__, 1492d90e58a7SAyuj Verma "Failed to allocate asymmetric crypto " 1493d90e58a7SAyuj Verma "operation struct\n"); 1494d90e58a7SAyuj Verma status = TEST_FAILED; 1495d90e58a7SAyuj Verma goto exit; 1496d90e58a7SAyuj Verma } 1497d90e58a7SAyuj Verma asym_op = op->asym; 1498d90e58a7SAyuj Verma 1499d90e58a7SAyuj Verma /* Setup asym xform */ 1500d90e58a7SAyuj Verma xform.next = NULL; 1501d90e58a7SAyuj Verma xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA; 1502d90e58a7SAyuj Verma xform.ec.curve_id = input_params.curve; 1503badc0c6fSGowrishankar Muthukrishnan xform.ec.pkey.data = input_params.pkey.data; 1504badc0c6fSGowrishankar Muthukrishnan xform.ec.pkey.length = input_params.pkey.length; 1505badc0c6fSGowrishankar Muthukrishnan xform.ec.q.x.data = input_params.pubkey_qx.data; 1506badc0c6fSGowrishankar Muthukrishnan xform.ec.q.x.length = input_params.pubkey_qx.length; 1507badc0c6fSGowrishankar Muthukrishnan xform.ec.q.y.data = input_params.pubkey_qy.data; 1508badc0c6fSGowrishankar Muthukrishnan xform.ec.q.y.length = input_params.pubkey_qy.length; 1509d90e58a7SAyuj Verma 1510757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 1511757f40e2SCiara Power if (ret < 0) { 1512d90e58a7SAyuj Verma RTE_LOG(ERR, USER1, 1513d90e58a7SAyuj Verma "line %u FAILED: %s", __LINE__, 15141f1e4b7cSCiara Power "Session creation failed\n"); 1515757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 1516d90e58a7SAyuj Verma goto exit; 1517d90e58a7SAyuj Verma } 1518d90e58a7SAyuj Verma 1519d90e58a7SAyuj Verma /* Attach asymmetric crypto session to crypto operations */ 1520d90e58a7SAyuj Verma rte_crypto_op_attach_asym_session(op, sess); 1521d90e58a7SAyuj Verma 1522d90e58a7SAyuj Verma /* Compute sign */ 1523d90e58a7SAyuj Verma 1524d90e58a7SAyuj Verma /* Populate op with operational details */ 1525d90e58a7SAyuj Verma op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN; 1526d90e58a7SAyuj Verma op->asym->ecdsa.message.data = input_params.digest.data; 1527d90e58a7SAyuj Verma op->asym->ecdsa.message.length = input_params.digest.length; 1528d90e58a7SAyuj Verma op->asym->ecdsa.k.data = input_params.scalar.data; 1529d90e58a7SAyuj Verma op->asym->ecdsa.k.length = input_params.scalar.length; 1530d90e58a7SAyuj Verma 1531d90e58a7SAyuj Verma /* Init out buf */ 1532d90e58a7SAyuj Verma op->asym->ecdsa.r.data = output_buf_r; 1533d90e58a7SAyuj Verma op->asym->ecdsa.s.data = output_buf_s; 1534d90e58a7SAyuj Verma 1535d90e58a7SAyuj Verma RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 1536d90e58a7SAyuj Verma 1537d90e58a7SAyuj Verma /* Process crypto operation */ 1538d90e58a7SAyuj Verma if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 1539d90e58a7SAyuj Verma RTE_LOG(ERR, USER1, 1540d90e58a7SAyuj Verma "line %u FAILED: %s", __LINE__, 1541d90e58a7SAyuj Verma "Error sending packet for operation\n"); 1542d90e58a7SAyuj Verma status = TEST_FAILED; 1543d90e58a7SAyuj Verma goto exit; 1544d90e58a7SAyuj Verma } 1545d90e58a7SAyuj Verma 1546d90e58a7SAyuj Verma while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 1547d90e58a7SAyuj Verma rte_pause(); 1548d90e58a7SAyuj Verma 1549d90e58a7SAyuj Verma if (result_op == NULL) { 1550d90e58a7SAyuj Verma RTE_LOG(ERR, USER1, 1551d90e58a7SAyuj Verma "line %u FAILED: %s", __LINE__, 1552d90e58a7SAyuj Verma "Failed to process asym crypto op\n"); 1553d90e58a7SAyuj Verma status = TEST_FAILED; 1554d90e58a7SAyuj Verma goto exit; 1555d90e58a7SAyuj Verma } 1556d90e58a7SAyuj Verma 1557d90e58a7SAyuj Verma if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 1558d90e58a7SAyuj Verma RTE_LOG(ERR, USER1, 1559d90e58a7SAyuj Verma "line %u FAILED: %s", __LINE__, 1560d90e58a7SAyuj Verma "Failed to process asym crypto op\n"); 1561d90e58a7SAyuj Verma status = TEST_FAILED; 1562d90e58a7SAyuj Verma goto exit; 1563d90e58a7SAyuj Verma } 1564d90e58a7SAyuj Verma 1565d90e58a7SAyuj Verma asym_op = result_op->asym; 1566d90e58a7SAyuj Verma 1567d90e58a7SAyuj Verma debug_hexdump(stdout, "r:", 1568d90e58a7SAyuj Verma asym_op->ecdsa.r.data, asym_op->ecdsa.r.length); 1569d90e58a7SAyuj Verma debug_hexdump(stdout, "s:", 1570d90e58a7SAyuj Verma asym_op->ecdsa.s.data, asym_op->ecdsa.s.length); 1571d90e58a7SAyuj Verma 1572d90e58a7SAyuj Verma ret = verify_ecdsa_sign(input_params.sign_r.data, 1573d90e58a7SAyuj Verma input_params.sign_s.data, result_op); 1574d90e58a7SAyuj Verma if (ret) { 1575d90e58a7SAyuj Verma status = TEST_FAILED; 1576d90e58a7SAyuj Verma RTE_LOG(ERR, USER1, 1577d90e58a7SAyuj Verma "line %u FAILED: %s", __LINE__, 1578d90e58a7SAyuj Verma "ECDSA sign failed.\n"); 1579d90e58a7SAyuj Verma goto exit; 1580d90e58a7SAyuj Verma } 1581d90e58a7SAyuj Verma 1582d90e58a7SAyuj Verma /* Verify sign */ 1583d90e58a7SAyuj Verma 1584d90e58a7SAyuj Verma /* Populate op with operational details */ 1585d90e58a7SAyuj Verma op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY; 1586d90e58a7SAyuj Verma op->asym->ecdsa.r.data = asym_op->ecdsa.r.data; 1587d90e58a7SAyuj Verma op->asym->ecdsa.r.length = asym_op->ecdsa.r.length; 1588d90e58a7SAyuj Verma op->asym->ecdsa.s.data = asym_op->ecdsa.s.data; 1589d90e58a7SAyuj Verma op->asym->ecdsa.s.length = asym_op->ecdsa.s.length; 1590d90e58a7SAyuj Verma 1591d90e58a7SAyuj Verma /* Enqueue sign result for verify */ 1592d90e58a7SAyuj Verma if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 1593d90e58a7SAyuj Verma status = TEST_FAILED; 1594d90e58a7SAyuj Verma RTE_LOG(ERR, USER1, 1595d90e58a7SAyuj Verma "line %u FAILED: %s", __LINE__, 1596d90e58a7SAyuj Verma "Error sending packet for operation\n"); 1597d90e58a7SAyuj Verma goto exit; 1598d90e58a7SAyuj Verma } 1599d90e58a7SAyuj Verma 1600d90e58a7SAyuj Verma while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 1601d90e58a7SAyuj Verma rte_pause(); 1602d90e58a7SAyuj Verma 1603d90e58a7SAyuj Verma if (result_op == NULL) { 1604d90e58a7SAyuj Verma status = TEST_FAILED; 1605d90e58a7SAyuj Verma goto exit; 1606d90e58a7SAyuj Verma } 1607d90e58a7SAyuj Verma if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 1608d90e58a7SAyuj Verma status = TEST_FAILED; 1609d90e58a7SAyuj Verma RTE_LOG(ERR, USER1, 1610d90e58a7SAyuj Verma "line %u FAILED: %s", __LINE__, 1611d90e58a7SAyuj Verma "ECDSA verify failed.\n"); 1612d90e58a7SAyuj Verma goto exit; 1613d90e58a7SAyuj Verma } 1614d90e58a7SAyuj Verma 1615d90e58a7SAyuj Verma exit: 16161f1e4b7cSCiara Power if (sess != NULL) 16171f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 1618d90e58a7SAyuj Verma rte_crypto_op_free(op); 1619d90e58a7SAyuj Verma return status; 1620d90e58a7SAyuj Verma }; 1621d90e58a7SAyuj Verma 1622d90e58a7SAyuj Verma static int 1623d90e58a7SAyuj Verma test_ecdsa_sign_verify_all_curve(void) 1624d90e58a7SAyuj Verma { 1625d90e58a7SAyuj Verma int status, overall_status = TEST_SUCCESS; 1626d90e58a7SAyuj Verma enum curve curve_id; 1627d90e58a7SAyuj Verma int test_index = 0; 1628d90e58a7SAyuj Verma const char *msg; 1629d90e58a7SAyuj Verma 1630d90e58a7SAyuj Verma for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { 16312fba5232SGowrishankar Muthukrishnan if (curve_id == ED25519 || curve_id == ED448) 16322fba5232SGowrishankar Muthukrishnan continue; 16332fba5232SGowrishankar Muthukrishnan 1634d90e58a7SAyuj Verma status = test_ecdsa_sign_verify(curve_id); 1635d90e58a7SAyuj Verma if (status == TEST_SUCCESS) { 1636d90e58a7SAyuj Verma msg = "succeeded"; 1637d90e58a7SAyuj Verma } else { 1638d90e58a7SAyuj Verma msg = "failed"; 1639d90e58a7SAyuj Verma overall_status = status; 1640d90e58a7SAyuj Verma } 1641d90e58a7SAyuj Verma printf(" %u) TestCase Sign/Veriy Curve %s %s\n", 1642d90e58a7SAyuj Verma test_index ++, curve[curve_id], msg); 1643d90e58a7SAyuj Verma } 1644d90e58a7SAyuj Verma return overall_status; 1645d90e58a7SAyuj Verma } 1646a9de470cSBruce Richardson 1647f225c040SSunila Sahu static int 1648f225c040SSunila Sahu test_ecpm(enum curve curve_id) 1649f225c040SSunila Sahu { 1650da74df7dSCiara Power struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 1651f225c040SSunila Sahu struct rte_mempool *sess_mpool = ts_params->session_mpool; 1652f225c040SSunila Sahu struct rte_mempool *op_mpool = ts_params->op_mpool; 1653f225c040SSunila Sahu struct crypto_testsuite_ecpm_params input_params; 1654a29bb248SCiara Power void *sess = NULL; 1655f225c040SSunila Sahu uint8_t dev_id = ts_params->valid_devs[0]; 1656f225c040SSunila Sahu struct rte_crypto_op *result_op = NULL; 1657f225c040SSunila Sahu uint8_t output_buf_x[TEST_DATA_SIZE]; 1658f225c040SSunila Sahu uint8_t output_buf_y[TEST_DATA_SIZE]; 1659f225c040SSunila Sahu struct rte_crypto_asym_xform xform; 1660f225c040SSunila Sahu struct rte_crypto_asym_op *asym_op; 1661f225c040SSunila Sahu struct rte_cryptodev_info dev_info; 1662f225c040SSunila Sahu struct rte_crypto_op *op = NULL; 1663757f40e2SCiara Power int ret, status = TEST_SUCCESS; 1664f225c040SSunila Sahu 1665f225c040SSunila Sahu switch (curve_id) { 1666f225c040SSunila Sahu case SECP192R1: 1667f225c040SSunila Sahu input_params = ecpm_param_secp192r1; 1668f225c040SSunila Sahu break; 1669f225c040SSunila Sahu case SECP224R1: 1670f225c040SSunila Sahu input_params = ecpm_param_secp224r1; 1671f225c040SSunila Sahu break; 1672f225c040SSunila Sahu case SECP256R1: 1673f225c040SSunila Sahu input_params = ecpm_param_secp256r1; 1674f225c040SSunila Sahu break; 1675f225c040SSunila Sahu case SECP384R1: 1676f225c040SSunila Sahu input_params = ecpm_param_secp384r1; 1677f225c040SSunila Sahu break; 1678f225c040SSunila Sahu case SECP521R1: 1679f225c040SSunila Sahu input_params = ecpm_param_secp521r1; 1680f225c040SSunila Sahu break; 1681f225c040SSunila Sahu default: 1682f225c040SSunila Sahu RTE_LOG(ERR, USER1, 1683f225c040SSunila Sahu "line %u FAILED: %s", __LINE__, 1684f225c040SSunila Sahu "Unsupported curve id\n"); 1685f225c040SSunila Sahu status = TEST_FAILED; 1686f225c040SSunila Sahu goto exit; 1687f225c040SSunila Sahu } 1688f225c040SSunila Sahu 1689f225c040SSunila Sahu rte_cryptodev_info_get(dev_id, &dev_info); 1690f225c040SSunila Sahu 1691f225c040SSunila Sahu /* Setup crypto op data structure */ 1692f225c040SSunila Sahu op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 1693f225c040SSunila Sahu if (op == NULL) { 1694f225c040SSunila Sahu RTE_LOG(ERR, USER1, 1695f225c040SSunila Sahu "line %u FAILED: %s", __LINE__, 1696f225c040SSunila Sahu "Failed to allocate asymmetric crypto " 1697f225c040SSunila Sahu "operation struct\n"); 1698f225c040SSunila Sahu status = TEST_FAILED; 1699f225c040SSunila Sahu goto exit; 1700f225c040SSunila Sahu } 1701f225c040SSunila Sahu asym_op = op->asym; 1702f225c040SSunila Sahu 1703f225c040SSunila Sahu /* Setup asym xform */ 1704f225c040SSunila Sahu xform.next = NULL; 1705f225c040SSunila Sahu xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM; 1706f225c040SSunila Sahu xform.ec.curve_id = input_params.curve; 1707f225c040SSunila Sahu 1708757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 1709757f40e2SCiara Power if (ret < 0) { 1710f225c040SSunila Sahu RTE_LOG(ERR, USER1, 1711f225c040SSunila Sahu "line %u FAILED: %s", __LINE__, 17121f1e4b7cSCiara Power "Session creation failed\n"); 1713757f40e2SCiara Power status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 1714f225c040SSunila Sahu goto exit; 1715f225c040SSunila Sahu } 1716f225c040SSunila Sahu 1717f225c040SSunila Sahu /* Attach asymmetric crypto session to crypto operations */ 1718f225c040SSunila Sahu rte_crypto_op_attach_asym_session(op, sess); 1719f225c040SSunila Sahu 1720f225c040SSunila Sahu /* Populate op with operational details */ 1721f225c040SSunila Sahu op->asym->ecpm.p.x.data = input_params.gen_x.data; 1722f225c040SSunila Sahu op->asym->ecpm.p.x.length = input_params.gen_x.length; 1723f225c040SSunila Sahu op->asym->ecpm.p.y.data = input_params.gen_y.data; 1724f225c040SSunila Sahu op->asym->ecpm.p.y.length = input_params.gen_y.length; 1725f225c040SSunila Sahu op->asym->ecpm.scalar.data = input_params.privkey.data; 1726f225c040SSunila Sahu op->asym->ecpm.scalar.length = input_params.privkey.length; 1727f225c040SSunila Sahu 1728f225c040SSunila Sahu /* Init out buf */ 1729f225c040SSunila Sahu op->asym->ecpm.r.x.data = output_buf_x; 1730f225c040SSunila Sahu op->asym->ecpm.r.y.data = output_buf_y; 1731f225c040SSunila Sahu 1732f225c040SSunila Sahu RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 1733f225c040SSunila Sahu 1734f225c040SSunila Sahu /* Process crypto operation */ 1735f225c040SSunila Sahu if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 1736f225c040SSunila Sahu RTE_LOG(ERR, USER1, 1737f225c040SSunila Sahu "line %u FAILED: %s", __LINE__, 1738f225c040SSunila Sahu "Error sending packet for operation\n"); 1739f225c040SSunila Sahu status = TEST_FAILED; 1740f225c040SSunila Sahu goto exit; 1741f225c040SSunila Sahu } 1742f225c040SSunila Sahu 1743f225c040SSunila Sahu while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 1744f225c040SSunila Sahu rte_pause(); 1745f225c040SSunila Sahu 1746f225c040SSunila Sahu if (result_op == NULL) { 1747f225c040SSunila Sahu RTE_LOG(ERR, USER1, 1748f225c040SSunila Sahu "line %u FAILED: %s", __LINE__, 1749f225c040SSunila Sahu "Failed to process asym crypto op\n"); 1750f225c040SSunila Sahu status = TEST_FAILED; 1751f225c040SSunila Sahu goto exit; 1752f225c040SSunila Sahu } 1753f225c040SSunila Sahu 1754f225c040SSunila Sahu if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 1755f225c040SSunila Sahu RTE_LOG(ERR, USER1, 1756f225c040SSunila Sahu "line %u FAILED: %s", __LINE__, 1757f225c040SSunila Sahu "Failed to process asym crypto op\n"); 1758f225c040SSunila Sahu status = TEST_FAILED; 1759f225c040SSunila Sahu goto exit; 1760f225c040SSunila Sahu } 1761f225c040SSunila Sahu 1762f225c040SSunila Sahu asym_op = result_op->asym; 1763f225c040SSunila Sahu 1764f225c040SSunila Sahu debug_hexdump(stdout, "r x:", 1765f225c040SSunila Sahu asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length); 1766f225c040SSunila Sahu debug_hexdump(stdout, "r y:", 1767f225c040SSunila Sahu asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length); 1768f225c040SSunila Sahu 1769f225c040SSunila Sahu ret = verify_ecpm(input_params.pubkey_x.data, 1770f225c040SSunila Sahu input_params.pubkey_y.data, result_op); 1771f225c040SSunila Sahu if (ret) { 1772f225c040SSunila Sahu status = TEST_FAILED; 1773f225c040SSunila Sahu RTE_LOG(ERR, USER1, 1774f225c040SSunila Sahu "line %u FAILED: %s", __LINE__, 1775f225c040SSunila Sahu "EC Point Multiplication failed.\n"); 1776f225c040SSunila Sahu goto exit; 1777f225c040SSunila Sahu } 1778f225c040SSunila Sahu 1779f225c040SSunila Sahu exit: 17801f1e4b7cSCiara Power if (sess != NULL) 17811f1e4b7cSCiara Power rte_cryptodev_asym_session_free(dev_id, sess); 1782f225c040SSunila Sahu rte_crypto_op_free(op); 1783f225c040SSunila Sahu return status; 1784f225c040SSunila Sahu } 1785f225c040SSunila Sahu 1786f225c040SSunila Sahu static int 1787f225c040SSunila Sahu test_ecpm_all_curve(void) 1788f225c040SSunila Sahu { 1789f225c040SSunila Sahu int status, overall_status = TEST_SUCCESS; 1790f225c040SSunila Sahu enum curve curve_id; 1791f225c040SSunila Sahu int test_index = 0; 1792f225c040SSunila Sahu const char *msg; 1793f225c040SSunila Sahu 1794f225c040SSunila Sahu for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { 17952fba5232SGowrishankar Muthukrishnan if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448) 17966631867dSGowrishankar Muthukrishnan continue; 17976631867dSGowrishankar Muthukrishnan 1798f225c040SSunila Sahu status = test_ecpm(curve_id); 1799f225c040SSunila Sahu if (status == TEST_SUCCESS) { 1800f225c040SSunila Sahu msg = "succeeded"; 1801f225c040SSunila Sahu } else { 1802f225c040SSunila Sahu msg = "failed"; 1803f225c040SSunila Sahu overall_status = status; 1804f225c040SSunila Sahu } 1805f225c040SSunila Sahu printf(" %u) TestCase EC Point Mul Curve %s %s\n", 1806f225c040SSunila Sahu test_index ++, curve[curve_id], msg); 1807f225c040SSunila Sahu } 1808f225c040SSunila Sahu return overall_status; 1809f225c040SSunila Sahu } 1810f225c040SSunila Sahu 18112d970c66SGowrishankar Muthukrishnan static int 181231dd9ddfSGowrishankar Muthukrishnan test_ecdh_priv_key_generate(enum curve curve_id) 181331dd9ddfSGowrishankar Muthukrishnan { 181431dd9ddfSGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 181531dd9ddfSGowrishankar Muthukrishnan const struct rte_cryptodev_asymmetric_xform_capability *capa; 181631dd9ddfSGowrishankar Muthukrishnan struct rte_mempool *sess_mpool = ts_params->session_mpool; 181731dd9ddfSGowrishankar Muthukrishnan struct rte_mempool *op_mpool = ts_params->op_mpool; 181831dd9ddfSGowrishankar Muthukrishnan struct rte_cryptodev_asym_capability_idx idx; 181931dd9ddfSGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 182031dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_asym_xform xform = {0}; 182131dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_op *result_op = NULL; 182231dd9ddfSGowrishankar Muthukrishnan uint8_t output_buf[TEST_DATA_SIZE]; 182331dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op; 182431dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_op *op = NULL; 182531dd9ddfSGowrishankar Muthukrishnan int ret, status = TEST_SUCCESS; 182631dd9ddfSGowrishankar Muthukrishnan uint16_t output_buflen = 0; 182731dd9ddfSGowrishankar Muthukrishnan void *sess = NULL; 182831dd9ddfSGowrishankar Muthukrishnan int curve; 182931dd9ddfSGowrishankar Muthukrishnan 183031dd9ddfSGowrishankar Muthukrishnan /* Check ECDH capability */ 183131dd9ddfSGowrishankar Muthukrishnan idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH; 183231dd9ddfSGowrishankar Muthukrishnan capa = rte_cryptodev_asym_capability_get(dev_id, &idx); 183331dd9ddfSGowrishankar Muthukrishnan if (capa == NULL) 183431dd9ddfSGowrishankar Muthukrishnan return -ENOTSUP; 183531dd9ddfSGowrishankar Muthukrishnan 183631dd9ddfSGowrishankar Muthukrishnan if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE))) 183731dd9ddfSGowrishankar Muthukrishnan return -ENOTSUP; 183831dd9ddfSGowrishankar Muthukrishnan 183931dd9ddfSGowrishankar Muthukrishnan switch (curve_id) { 184031dd9ddfSGowrishankar Muthukrishnan case SECP192R1: 184131dd9ddfSGowrishankar Muthukrishnan curve = RTE_CRYPTO_EC_GROUP_SECP192R1; 184231dd9ddfSGowrishankar Muthukrishnan output_buflen = 24; 184331dd9ddfSGowrishankar Muthukrishnan break; 184431dd9ddfSGowrishankar Muthukrishnan case SECP224R1: 184531dd9ddfSGowrishankar Muthukrishnan curve = RTE_CRYPTO_EC_GROUP_SECP224R1; 184631dd9ddfSGowrishankar Muthukrishnan output_buflen = 28; 184731dd9ddfSGowrishankar Muthukrishnan break; 184831dd9ddfSGowrishankar Muthukrishnan case SECP256R1: 184931dd9ddfSGowrishankar Muthukrishnan curve = RTE_CRYPTO_EC_GROUP_SECP256R1; 185031dd9ddfSGowrishankar Muthukrishnan output_buflen = 32; 185131dd9ddfSGowrishankar Muthukrishnan break; 185231dd9ddfSGowrishankar Muthukrishnan case SECP384R1: 185331dd9ddfSGowrishankar Muthukrishnan curve = RTE_CRYPTO_EC_GROUP_SECP384R1; 185431dd9ddfSGowrishankar Muthukrishnan output_buflen = 48; 185531dd9ddfSGowrishankar Muthukrishnan break; 185631dd9ddfSGowrishankar Muthukrishnan case SECP521R1: 185731dd9ddfSGowrishankar Muthukrishnan curve = RTE_CRYPTO_EC_GROUP_SECP521R1; 185831dd9ddfSGowrishankar Muthukrishnan output_buflen = 66; 185931dd9ddfSGowrishankar Muthukrishnan break; 186031dd9ddfSGowrishankar Muthukrishnan default: 186131dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 186231dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 186331dd9ddfSGowrishankar Muthukrishnan "Unsupported curve id\n"); 186431dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 186531dd9ddfSGowrishankar Muthukrishnan goto exit; 186631dd9ddfSGowrishankar Muthukrishnan } 186731dd9ddfSGowrishankar Muthukrishnan 186831dd9ddfSGowrishankar Muthukrishnan /* Setup crypto op data structure */ 186931dd9ddfSGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 187031dd9ddfSGowrishankar Muthukrishnan if (op == NULL) { 187131dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 187231dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 187331dd9ddfSGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 187431dd9ddfSGowrishankar Muthukrishnan "operation struct\n"); 187531dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 187631dd9ddfSGowrishankar Muthukrishnan goto exit; 187731dd9ddfSGowrishankar Muthukrishnan } 187831dd9ddfSGowrishankar Muthukrishnan asym_op = op->asym; 187931dd9ddfSGowrishankar Muthukrishnan 188031dd9ddfSGowrishankar Muthukrishnan /* Setup asym xform */ 188131dd9ddfSGowrishankar Muthukrishnan xform.next = NULL; 188231dd9ddfSGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH; 188331dd9ddfSGowrishankar Muthukrishnan xform.ec.curve_id = curve; 188431dd9ddfSGowrishankar Muthukrishnan 188531dd9ddfSGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 188631dd9ddfSGowrishankar Muthukrishnan if (ret < 0) { 188731dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 188831dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 188931dd9ddfSGowrishankar Muthukrishnan "Session creation failed\n"); 189031dd9ddfSGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 189131dd9ddfSGowrishankar Muthukrishnan goto exit; 189231dd9ddfSGowrishankar Muthukrishnan } 189331dd9ddfSGowrishankar Muthukrishnan 189431dd9ddfSGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 189531dd9ddfSGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 189631dd9ddfSGowrishankar Muthukrishnan 189731dd9ddfSGowrishankar Muthukrishnan /* Populate op with operational details */ 189831dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE; 189931dd9ddfSGowrishankar Muthukrishnan 190031dd9ddfSGowrishankar Muthukrishnan /* Init out buf */ 190131dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.priv_key.data = output_buf; 190231dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.priv_key.length = output_buflen; 190331dd9ddfSGowrishankar Muthukrishnan 190431dd9ddfSGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 190531dd9ddfSGowrishankar Muthukrishnan 190631dd9ddfSGowrishankar Muthukrishnan /* Process crypto operation */ 190731dd9ddfSGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 190831dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 190931dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 191031dd9ddfSGowrishankar Muthukrishnan "Error sending packet for operation\n"); 191131dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 191231dd9ddfSGowrishankar Muthukrishnan goto exit; 191331dd9ddfSGowrishankar Muthukrishnan } 191431dd9ddfSGowrishankar Muthukrishnan 191531dd9ddfSGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 191631dd9ddfSGowrishankar Muthukrishnan rte_pause(); 191731dd9ddfSGowrishankar Muthukrishnan 191831dd9ddfSGowrishankar Muthukrishnan if (result_op == NULL) { 191931dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 192031dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 192131dd9ddfSGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 192231dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 192331dd9ddfSGowrishankar Muthukrishnan goto exit; 192431dd9ddfSGowrishankar Muthukrishnan } 192531dd9ddfSGowrishankar Muthukrishnan 192631dd9ddfSGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 192731dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 192831dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 192931dd9ddfSGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 193031dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 193131dd9ddfSGowrishankar Muthukrishnan goto exit; 193231dd9ddfSGowrishankar Muthukrishnan } 193331dd9ddfSGowrishankar Muthukrishnan 193431dd9ddfSGowrishankar Muthukrishnan asym_op = result_op->asym; 193531dd9ddfSGowrishankar Muthukrishnan 193631dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "priv_key:", 193731dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.priv_key.data, asym_op->ecdh.priv_key.length); 193831dd9ddfSGowrishankar Muthukrishnan 193931dd9ddfSGowrishankar Muthukrishnan exit: 194031dd9ddfSGowrishankar Muthukrishnan if (sess != NULL) 194131dd9ddfSGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 194231dd9ddfSGowrishankar Muthukrishnan rte_crypto_op_free(op); 194331dd9ddfSGowrishankar Muthukrishnan return status; 194431dd9ddfSGowrishankar Muthukrishnan } 194531dd9ddfSGowrishankar Muthukrishnan 194631dd9ddfSGowrishankar Muthukrishnan static int 194731dd9ddfSGowrishankar Muthukrishnan test_ecdh_pub_key_generate(enum curve curve_id) 194831dd9ddfSGowrishankar Muthukrishnan { 194931dd9ddfSGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 195031dd9ddfSGowrishankar Muthukrishnan const struct rte_cryptodev_asymmetric_xform_capability *capa; 195131dd9ddfSGowrishankar Muthukrishnan struct rte_mempool *sess_mpool = ts_params->session_mpool; 195231dd9ddfSGowrishankar Muthukrishnan struct rte_mempool *op_mpool = ts_params->op_mpool; 195331dd9ddfSGowrishankar Muthukrishnan struct crypto_testsuite_ecdh_params input_params; 195431dd9ddfSGowrishankar Muthukrishnan struct rte_cryptodev_asym_capability_idx idx; 195531dd9ddfSGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 195631dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_asym_xform xform = {0}; 195731dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_op *result_op = NULL; 195831dd9ddfSGowrishankar Muthukrishnan uint8_t output_buf_x[TEST_DATA_SIZE]; 195931dd9ddfSGowrishankar Muthukrishnan uint8_t output_buf_y[TEST_DATA_SIZE]; 196031dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op; 196131dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_op *op = NULL; 196231dd9ddfSGowrishankar Muthukrishnan int ret, status = TEST_SUCCESS; 196331dd9ddfSGowrishankar Muthukrishnan void *sess = NULL; 196431dd9ddfSGowrishankar Muthukrishnan 196531dd9ddfSGowrishankar Muthukrishnan /* Check ECDH capability */ 196631dd9ddfSGowrishankar Muthukrishnan idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH; 196731dd9ddfSGowrishankar Muthukrishnan capa = rte_cryptodev_asym_capability_get(dev_id, &idx); 196831dd9ddfSGowrishankar Muthukrishnan if (capa == NULL) 19692fba5232SGowrishankar Muthukrishnan return TEST_SKIPPED; 197031dd9ddfSGowrishankar Muthukrishnan 197131dd9ddfSGowrishankar Muthukrishnan if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE))) 19722fba5232SGowrishankar Muthukrishnan return TEST_SKIPPED; 19732fba5232SGowrishankar Muthukrishnan 19742fba5232SGowrishankar Muthukrishnan if (curve_id == ED25519 || curve_id == ED448) { 19752fba5232SGowrishankar Muthukrishnan /* Check EdDSA capability */ 19762fba5232SGowrishankar Muthukrishnan idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA; 19772fba5232SGowrishankar Muthukrishnan capa = rte_cryptodev_asym_capability_get(dev_id, &idx); 19782fba5232SGowrishankar Muthukrishnan if (capa == NULL) 19792fba5232SGowrishankar Muthukrishnan return TEST_SKIPPED; 19802fba5232SGowrishankar Muthukrishnan } 198131dd9ddfSGowrishankar Muthukrishnan 198231dd9ddfSGowrishankar Muthukrishnan switch (curve_id) { 198331dd9ddfSGowrishankar Muthukrishnan case SECP192R1: 198431dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp192r1; 198531dd9ddfSGowrishankar Muthukrishnan break; 198631dd9ddfSGowrishankar Muthukrishnan case SECP224R1: 198731dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp224r1; 198831dd9ddfSGowrishankar Muthukrishnan break; 198931dd9ddfSGowrishankar Muthukrishnan case SECP256R1: 199031dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp256r1; 199131dd9ddfSGowrishankar Muthukrishnan break; 199231dd9ddfSGowrishankar Muthukrishnan case SECP384R1: 199331dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp384r1; 199431dd9ddfSGowrishankar Muthukrishnan break; 199531dd9ddfSGowrishankar Muthukrishnan case SECP521R1: 199631dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp521r1; 199731dd9ddfSGowrishankar Muthukrishnan break; 19982fba5232SGowrishankar Muthukrishnan case ED25519: 19992fba5232SGowrishankar Muthukrishnan input_params = ecdh_param_ed25519; 20002fba5232SGowrishankar Muthukrishnan break; 20012fba5232SGowrishankar Muthukrishnan case ED448: 20022fba5232SGowrishankar Muthukrishnan input_params = ecdh_param_ed448; 20032fba5232SGowrishankar Muthukrishnan break; 200431dd9ddfSGowrishankar Muthukrishnan default: 200531dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 200631dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 200731dd9ddfSGowrishankar Muthukrishnan "Unsupported curve id\n"); 200831dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 200931dd9ddfSGowrishankar Muthukrishnan goto exit; 201031dd9ddfSGowrishankar Muthukrishnan } 201131dd9ddfSGowrishankar Muthukrishnan 201231dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "pkey:", 201331dd9ddfSGowrishankar Muthukrishnan input_params.pkey_A.data, input_params.pkey_A.length); 201431dd9ddfSGowrishankar Muthukrishnan 201531dd9ddfSGowrishankar Muthukrishnan /* Setup crypto op data structure */ 201631dd9ddfSGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 201731dd9ddfSGowrishankar Muthukrishnan if (op == NULL) { 201831dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 201931dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 202031dd9ddfSGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 202131dd9ddfSGowrishankar Muthukrishnan "operation struct\n"); 202231dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 202331dd9ddfSGowrishankar Muthukrishnan goto exit; 202431dd9ddfSGowrishankar Muthukrishnan } 202531dd9ddfSGowrishankar Muthukrishnan asym_op = op->asym; 202631dd9ddfSGowrishankar Muthukrishnan 202731dd9ddfSGowrishankar Muthukrishnan /* Setup asym xform */ 202831dd9ddfSGowrishankar Muthukrishnan xform.next = NULL; 202931dd9ddfSGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH; 203031dd9ddfSGowrishankar Muthukrishnan xform.ec.curve_id = input_params.curve; 203131dd9ddfSGowrishankar Muthukrishnan xform.ec.pkey.data = input_params.pkey_A.data; 203231dd9ddfSGowrishankar Muthukrishnan xform.ec.pkey.length = input_params.pkey_A.length; 203331dd9ddfSGowrishankar Muthukrishnan 203431dd9ddfSGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 203531dd9ddfSGowrishankar Muthukrishnan if (ret < 0) { 203631dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 203731dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 203831dd9ddfSGowrishankar Muthukrishnan "Session creation failed\n"); 203931dd9ddfSGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 204031dd9ddfSGowrishankar Muthukrishnan goto exit; 204131dd9ddfSGowrishankar Muthukrishnan } 204231dd9ddfSGowrishankar Muthukrishnan 204331dd9ddfSGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 204431dd9ddfSGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 204531dd9ddfSGowrishankar Muthukrishnan 204631dd9ddfSGowrishankar Muthukrishnan /* Populate op with operational details */ 204731dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE; 20482fba5232SGowrishankar Muthukrishnan if (curve_id == ED25519 || curve_id == ED448) 20492fba5232SGowrishankar Muthukrishnan asym_op->flags |= RTE_CRYPTO_ASYM_FLAG_PUB_KEY_COMPRESSED; 205031dd9ddfSGowrishankar Muthukrishnan 205131dd9ddfSGowrishankar Muthukrishnan /* Init out buf */ 205231dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.pub_key.x.data = output_buf_x; 20532fba5232SGowrishankar Muthukrishnan if (curve_id == ED25519 || curve_id == ED448) 20542fba5232SGowrishankar Muthukrishnan asym_op->ecdh.pub_key.y.data = NULL; 20552fba5232SGowrishankar Muthukrishnan else 205631dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.pub_key.y.data = output_buf_y; 205731dd9ddfSGowrishankar Muthukrishnan 205831dd9ddfSGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 205931dd9ddfSGowrishankar Muthukrishnan 206031dd9ddfSGowrishankar Muthukrishnan /* Process crypto operation */ 206131dd9ddfSGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 206231dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 206331dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 206431dd9ddfSGowrishankar Muthukrishnan "Error sending packet for operation\n"); 206531dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 206631dd9ddfSGowrishankar Muthukrishnan goto exit; 206731dd9ddfSGowrishankar Muthukrishnan } 206831dd9ddfSGowrishankar Muthukrishnan 206931dd9ddfSGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 207031dd9ddfSGowrishankar Muthukrishnan rte_pause(); 207131dd9ddfSGowrishankar Muthukrishnan 207231dd9ddfSGowrishankar Muthukrishnan if (result_op == NULL) { 207331dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 207431dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 207531dd9ddfSGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 207631dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 207731dd9ddfSGowrishankar Muthukrishnan goto exit; 207831dd9ddfSGowrishankar Muthukrishnan } 207931dd9ddfSGowrishankar Muthukrishnan 208031dd9ddfSGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 208131dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 208231dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 208331dd9ddfSGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 208431dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 208531dd9ddfSGowrishankar Muthukrishnan goto exit; 208631dd9ddfSGowrishankar Muthukrishnan } 208731dd9ddfSGowrishankar Muthukrishnan 208831dd9ddfSGowrishankar Muthukrishnan asym_op = result_op->asym; 208931dd9ddfSGowrishankar Muthukrishnan 209031dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "qx:", 209131dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.pub_key.x.data, asym_op->ecdh.pub_key.x.length); 209231dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "qy:", 209331dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.pub_key.y.data, asym_op->ecdh.pub_key.y.length); 209431dd9ddfSGowrishankar Muthukrishnan 20952fba5232SGowrishankar Muthukrishnan if (curve_id == ED25519 || curve_id == ED448) 20962fba5232SGowrishankar Muthukrishnan ret = memcmp(input_params.pubkey_qA_x.data, result_op->asym->ecdh.pub_key.x.data, 20972fba5232SGowrishankar Muthukrishnan result_op->asym->ecdh.pub_key.x.length); 20982fba5232SGowrishankar Muthukrishnan else 209931dd9ddfSGowrishankar Muthukrishnan ret = verify_ecdh_secret(input_params.pubkey_qA_x.data, 210031dd9ddfSGowrishankar Muthukrishnan input_params.pubkey_qA_y.data, result_op); 21012fba5232SGowrishankar Muthukrishnan 210231dd9ddfSGowrishankar Muthukrishnan if (ret) { 210331dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 210431dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 210531dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 210631dd9ddfSGowrishankar Muthukrishnan "ECDH public key generation failed.\n"); 210731dd9ddfSGowrishankar Muthukrishnan goto exit; 210831dd9ddfSGowrishankar Muthukrishnan } 210931dd9ddfSGowrishankar Muthukrishnan 211031dd9ddfSGowrishankar Muthukrishnan exit: 211131dd9ddfSGowrishankar Muthukrishnan if (sess != NULL) 211231dd9ddfSGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 211331dd9ddfSGowrishankar Muthukrishnan rte_crypto_op_free(op); 211431dd9ddfSGowrishankar Muthukrishnan return status; 211531dd9ddfSGowrishankar Muthukrishnan } 211631dd9ddfSGowrishankar Muthukrishnan 211731dd9ddfSGowrishankar Muthukrishnan static int 211831dd9ddfSGowrishankar Muthukrishnan test_ecdh_pub_key_verify(enum curve curve_id) 211931dd9ddfSGowrishankar Muthukrishnan { 212031dd9ddfSGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 212131dd9ddfSGowrishankar Muthukrishnan const struct rte_cryptodev_asymmetric_xform_capability *capa; 212231dd9ddfSGowrishankar Muthukrishnan struct rte_mempool *sess_mpool = ts_params->session_mpool; 212331dd9ddfSGowrishankar Muthukrishnan struct rte_mempool *op_mpool = ts_params->op_mpool; 212431dd9ddfSGowrishankar Muthukrishnan struct crypto_testsuite_ecdh_params input_params; 212531dd9ddfSGowrishankar Muthukrishnan struct rte_cryptodev_asym_capability_idx idx; 212631dd9ddfSGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 212731dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_asym_xform xform = {0}; 212831dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_op *result_op = NULL; 212931dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op; 213031dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_op *op = NULL; 213131dd9ddfSGowrishankar Muthukrishnan int ret, status = TEST_SUCCESS; 213231dd9ddfSGowrishankar Muthukrishnan void *sess = NULL; 213331dd9ddfSGowrishankar Muthukrishnan 213431dd9ddfSGowrishankar Muthukrishnan /* Check ECDH capability */ 213531dd9ddfSGowrishankar Muthukrishnan idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH; 213631dd9ddfSGowrishankar Muthukrishnan capa = rte_cryptodev_asym_capability_get(dev_id, &idx); 213731dd9ddfSGowrishankar Muthukrishnan if (capa == NULL) 213831dd9ddfSGowrishankar Muthukrishnan return -ENOTSUP; 213931dd9ddfSGowrishankar Muthukrishnan 214031dd9ddfSGowrishankar Muthukrishnan if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY))) 214131dd9ddfSGowrishankar Muthukrishnan return -ENOTSUP; 214231dd9ddfSGowrishankar Muthukrishnan 214331dd9ddfSGowrishankar Muthukrishnan switch (curve_id) { 214431dd9ddfSGowrishankar Muthukrishnan case SECP192R1: 214531dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp192r1; 214631dd9ddfSGowrishankar Muthukrishnan break; 214731dd9ddfSGowrishankar Muthukrishnan case SECP224R1: 214831dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp224r1; 214931dd9ddfSGowrishankar Muthukrishnan break; 215031dd9ddfSGowrishankar Muthukrishnan case SECP256R1: 215131dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp256r1; 215231dd9ddfSGowrishankar Muthukrishnan break; 215331dd9ddfSGowrishankar Muthukrishnan case SECP384R1: 215431dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp384r1; 215531dd9ddfSGowrishankar Muthukrishnan break; 215631dd9ddfSGowrishankar Muthukrishnan case SECP521R1: 215731dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp521r1; 215831dd9ddfSGowrishankar Muthukrishnan break; 215931dd9ddfSGowrishankar Muthukrishnan default: 216031dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 216131dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 216231dd9ddfSGowrishankar Muthukrishnan "Unsupported curve id\n"); 216331dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 216431dd9ddfSGowrishankar Muthukrishnan goto exit; 216531dd9ddfSGowrishankar Muthukrishnan } 216631dd9ddfSGowrishankar Muthukrishnan 216731dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "qx:", 216831dd9ddfSGowrishankar Muthukrishnan input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length); 216931dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "qy:", 217031dd9ddfSGowrishankar Muthukrishnan input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length); 217131dd9ddfSGowrishankar Muthukrishnan 217231dd9ddfSGowrishankar Muthukrishnan /* Setup crypto op data structure */ 217331dd9ddfSGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 217431dd9ddfSGowrishankar Muthukrishnan if (op == NULL) { 217531dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 217631dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 217731dd9ddfSGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 217831dd9ddfSGowrishankar Muthukrishnan "operation struct\n"); 217931dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 218031dd9ddfSGowrishankar Muthukrishnan goto exit; 218131dd9ddfSGowrishankar Muthukrishnan } 218231dd9ddfSGowrishankar Muthukrishnan asym_op = op->asym; 218331dd9ddfSGowrishankar Muthukrishnan 218431dd9ddfSGowrishankar Muthukrishnan /* Setup asym xform */ 218531dd9ddfSGowrishankar Muthukrishnan xform.next = NULL; 218631dd9ddfSGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH; 218731dd9ddfSGowrishankar Muthukrishnan xform.ec.curve_id = input_params.curve; 218831dd9ddfSGowrishankar Muthukrishnan 218931dd9ddfSGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 219031dd9ddfSGowrishankar Muthukrishnan if (ret < 0) { 219131dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 219231dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 219331dd9ddfSGowrishankar Muthukrishnan "Session creation failed\n"); 219431dd9ddfSGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 219531dd9ddfSGowrishankar Muthukrishnan goto exit; 219631dd9ddfSGowrishankar Muthukrishnan } 219731dd9ddfSGowrishankar Muthukrishnan 219831dd9ddfSGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 219931dd9ddfSGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 220031dd9ddfSGowrishankar Muthukrishnan 220131dd9ddfSGowrishankar Muthukrishnan /* Populate op with operational details */ 220231dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY; 220331dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.pub_key.x.data = input_params.pubkey_qA_x.data; 220431dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.pub_key.x.length = input_params.pubkey_qA_x.length; 220531dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.pub_key.y.data = input_params.pubkey_qA_y.data; 220631dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.pub_key.y.length = input_params.pubkey_qA_y.length; 220731dd9ddfSGowrishankar Muthukrishnan 220831dd9ddfSGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 220931dd9ddfSGowrishankar Muthukrishnan 221031dd9ddfSGowrishankar Muthukrishnan /* Process crypto operation */ 221131dd9ddfSGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 221231dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 221331dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 221431dd9ddfSGowrishankar Muthukrishnan "Error sending packet for operation\n"); 221531dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 221631dd9ddfSGowrishankar Muthukrishnan goto exit; 221731dd9ddfSGowrishankar Muthukrishnan } 221831dd9ddfSGowrishankar Muthukrishnan 221931dd9ddfSGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 222031dd9ddfSGowrishankar Muthukrishnan rte_pause(); 222131dd9ddfSGowrishankar Muthukrishnan 222231dd9ddfSGowrishankar Muthukrishnan if (result_op == NULL) { 222331dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 222431dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 222531dd9ddfSGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 222631dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 222731dd9ddfSGowrishankar Muthukrishnan goto exit; 222831dd9ddfSGowrishankar Muthukrishnan } 222931dd9ddfSGowrishankar Muthukrishnan 223031dd9ddfSGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 223131dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 223231dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 223331dd9ddfSGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 223431dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 223531dd9ddfSGowrishankar Muthukrishnan goto exit; 223631dd9ddfSGowrishankar Muthukrishnan } 223731dd9ddfSGowrishankar Muthukrishnan 223831dd9ddfSGowrishankar Muthukrishnan exit: 223931dd9ddfSGowrishankar Muthukrishnan if (sess != NULL) 224031dd9ddfSGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 224131dd9ddfSGowrishankar Muthukrishnan rte_crypto_op_free(op); 224231dd9ddfSGowrishankar Muthukrishnan return status; 224331dd9ddfSGowrishankar Muthukrishnan } 224431dd9ddfSGowrishankar Muthukrishnan 224531dd9ddfSGowrishankar Muthukrishnan static int 224631dd9ddfSGowrishankar Muthukrishnan test_ecdh_shared_secret(enum curve curve_id) 224731dd9ddfSGowrishankar Muthukrishnan { 224831dd9ddfSGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 224931dd9ddfSGowrishankar Muthukrishnan const struct rte_cryptodev_asymmetric_xform_capability *capa; 225031dd9ddfSGowrishankar Muthukrishnan struct rte_mempool *sess_mpool = ts_params->session_mpool; 225131dd9ddfSGowrishankar Muthukrishnan struct rte_mempool *op_mpool = ts_params->op_mpool; 225231dd9ddfSGowrishankar Muthukrishnan struct crypto_testsuite_ecdh_params input_params; 225331dd9ddfSGowrishankar Muthukrishnan struct rte_cryptodev_asym_capability_idx idx; 225431dd9ddfSGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 225531dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_asym_xform xform = {0}; 225631dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_op *result_op = NULL; 225731dd9ddfSGowrishankar Muthukrishnan uint8_t output_buf_x[TEST_DATA_SIZE]; 225831dd9ddfSGowrishankar Muthukrishnan uint8_t output_buf_y[TEST_DATA_SIZE]; 225931dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op; 226031dd9ddfSGowrishankar Muthukrishnan struct rte_crypto_op *op = NULL; 226131dd9ddfSGowrishankar Muthukrishnan int ret, status = TEST_SUCCESS; 226231dd9ddfSGowrishankar Muthukrishnan void *sess = NULL; 226331dd9ddfSGowrishankar Muthukrishnan 226431dd9ddfSGowrishankar Muthukrishnan /* Check ECDH capability */ 226531dd9ddfSGowrishankar Muthukrishnan idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH; 226631dd9ddfSGowrishankar Muthukrishnan capa = rte_cryptodev_asym_capability_get(dev_id, &idx); 226731dd9ddfSGowrishankar Muthukrishnan if (capa == NULL) 226831dd9ddfSGowrishankar Muthukrishnan return -ENOTSUP; 226931dd9ddfSGowrishankar Muthukrishnan 227031dd9ddfSGowrishankar Muthukrishnan if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE))) 227131dd9ddfSGowrishankar Muthukrishnan return -ENOTSUP; 227231dd9ddfSGowrishankar Muthukrishnan 227331dd9ddfSGowrishankar Muthukrishnan switch (curve_id) { 227431dd9ddfSGowrishankar Muthukrishnan case SECP192R1: 227531dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp192r1; 227631dd9ddfSGowrishankar Muthukrishnan break; 227731dd9ddfSGowrishankar Muthukrishnan case SECP224R1: 227831dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp224r1; 227931dd9ddfSGowrishankar Muthukrishnan break; 228031dd9ddfSGowrishankar Muthukrishnan case SECP256R1: 228131dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp256r1; 228231dd9ddfSGowrishankar Muthukrishnan break; 228331dd9ddfSGowrishankar Muthukrishnan case SECP384R1: 228431dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp384r1; 228531dd9ddfSGowrishankar Muthukrishnan break; 228631dd9ddfSGowrishankar Muthukrishnan case SECP521R1: 228731dd9ddfSGowrishankar Muthukrishnan input_params = ecdh_param_secp521r1; 228831dd9ddfSGowrishankar Muthukrishnan break; 228931dd9ddfSGowrishankar Muthukrishnan default: 229031dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 229131dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 229231dd9ddfSGowrishankar Muthukrishnan "Unsupported curve id\n"); 229331dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 229431dd9ddfSGowrishankar Muthukrishnan goto exit; 229531dd9ddfSGowrishankar Muthukrishnan } 229631dd9ddfSGowrishankar Muthukrishnan 229731dd9ddfSGowrishankar Muthukrishnan /* zA = dA.QB */ 229831dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "pkey:", 229931dd9ddfSGowrishankar Muthukrishnan input_params.pkey_A.data, input_params.pkey_A.length); 230031dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "qx:", 230131dd9ddfSGowrishankar Muthukrishnan input_params.pubkey_qB_x.data, input_params.pubkey_qB_x.length); 230231dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "qy:", 230331dd9ddfSGowrishankar Muthukrishnan input_params.pubkey_qB_y.data, input_params.pubkey_qB_y.length); 230431dd9ddfSGowrishankar Muthukrishnan 230531dd9ddfSGowrishankar Muthukrishnan /* Setup crypto op data structure */ 230631dd9ddfSGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 230731dd9ddfSGowrishankar Muthukrishnan if (op == NULL) { 230831dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 230931dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 231031dd9ddfSGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 231131dd9ddfSGowrishankar Muthukrishnan "operation struct\n"); 231231dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 231331dd9ddfSGowrishankar Muthukrishnan goto exit; 231431dd9ddfSGowrishankar Muthukrishnan } 231531dd9ddfSGowrishankar Muthukrishnan asym_op = op->asym; 231631dd9ddfSGowrishankar Muthukrishnan 231731dd9ddfSGowrishankar Muthukrishnan /* Setup asym xform */ 231831dd9ddfSGowrishankar Muthukrishnan xform.next = NULL; 231931dd9ddfSGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH; 232031dd9ddfSGowrishankar Muthukrishnan xform.ec.curve_id = input_params.curve; 232131dd9ddfSGowrishankar Muthukrishnan xform.ec.pkey.data = input_params.pkey_A.data; 232231dd9ddfSGowrishankar Muthukrishnan xform.ec.pkey.length = input_params.pkey_A.length; 232331dd9ddfSGowrishankar Muthukrishnan xform.ec.q.x.data = input_params.pubkey_qB_x.data; 232431dd9ddfSGowrishankar Muthukrishnan xform.ec.q.x.length = input_params.pubkey_qB_x.length; 232531dd9ddfSGowrishankar Muthukrishnan xform.ec.q.y.data = input_params.pubkey_qB_y.data; 232631dd9ddfSGowrishankar Muthukrishnan xform.ec.q.y.length = input_params.pubkey_qB_y.length; 232731dd9ddfSGowrishankar Muthukrishnan 232831dd9ddfSGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 232931dd9ddfSGowrishankar Muthukrishnan if (ret < 0) { 233031dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 233131dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 233231dd9ddfSGowrishankar Muthukrishnan "Session creation failed\n"); 233331dd9ddfSGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 233431dd9ddfSGowrishankar Muthukrishnan goto exit; 233531dd9ddfSGowrishankar Muthukrishnan } 233631dd9ddfSGowrishankar Muthukrishnan 233731dd9ddfSGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 233831dd9ddfSGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 233931dd9ddfSGowrishankar Muthukrishnan 234031dd9ddfSGowrishankar Muthukrishnan /* Populate op with operational details */ 234131dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE; 234231dd9ddfSGowrishankar Muthukrishnan 234331dd9ddfSGowrishankar Muthukrishnan /* Init out buf */ 234431dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.shared_secret.x.data = output_buf_x; 234531dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.shared_secret.y.data = output_buf_y; 234631dd9ddfSGowrishankar Muthukrishnan 234731dd9ddfSGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 234831dd9ddfSGowrishankar Muthukrishnan 234931dd9ddfSGowrishankar Muthukrishnan /* Process crypto operation */ 235031dd9ddfSGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 235131dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 235231dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 235331dd9ddfSGowrishankar Muthukrishnan "Error sending packet for operation\n"); 235431dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 235531dd9ddfSGowrishankar Muthukrishnan goto exit; 235631dd9ddfSGowrishankar Muthukrishnan } 235731dd9ddfSGowrishankar Muthukrishnan 235831dd9ddfSGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 235931dd9ddfSGowrishankar Muthukrishnan rte_pause(); 236031dd9ddfSGowrishankar Muthukrishnan 236131dd9ddfSGowrishankar Muthukrishnan if (result_op == NULL) { 236231dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 236331dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 236431dd9ddfSGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 236531dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 236631dd9ddfSGowrishankar Muthukrishnan goto exit; 236731dd9ddfSGowrishankar Muthukrishnan } 236831dd9ddfSGowrishankar Muthukrishnan 236931dd9ddfSGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 237031dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 237131dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 237231dd9ddfSGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 237331dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 237431dd9ddfSGowrishankar Muthukrishnan goto exit; 237531dd9ddfSGowrishankar Muthukrishnan } 237631dd9ddfSGowrishankar Muthukrishnan 237731dd9ddfSGowrishankar Muthukrishnan asym_op = result_op->asym; 237831dd9ddfSGowrishankar Muthukrishnan 237931dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "secret_x:", 238031dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length); 238131dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "secret_y:", 238231dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length); 238331dd9ddfSGowrishankar Muthukrishnan 238431dd9ddfSGowrishankar Muthukrishnan ret = verify_ecdh_secret(input_params.secret_x.data, 238531dd9ddfSGowrishankar Muthukrishnan input_params.secret_y.data, result_op); 238631dd9ddfSGowrishankar Muthukrishnan if (ret) { 238731dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 238831dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 238931dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 239031dd9ddfSGowrishankar Muthukrishnan "ECDH shared secret compute failed.\n"); 239131dd9ddfSGowrishankar Muthukrishnan goto exit; 239231dd9ddfSGowrishankar Muthukrishnan } 239331dd9ddfSGowrishankar Muthukrishnan 239431dd9ddfSGowrishankar Muthukrishnan if (sess != NULL) 239531dd9ddfSGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 239631dd9ddfSGowrishankar Muthukrishnan rte_crypto_op_free(op); 239731dd9ddfSGowrishankar Muthukrishnan 239831dd9ddfSGowrishankar Muthukrishnan /* zB = dB.QA */ 239931dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "pkey:", 240031dd9ddfSGowrishankar Muthukrishnan input_params.pkey_B.data, input_params.pkey_B.length); 240131dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "qx:", 240231dd9ddfSGowrishankar Muthukrishnan input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length); 240331dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "qy:", 240431dd9ddfSGowrishankar Muthukrishnan input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length); 240531dd9ddfSGowrishankar Muthukrishnan 240631dd9ddfSGowrishankar Muthukrishnan /* Setup crypto op data structure */ 240731dd9ddfSGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 240831dd9ddfSGowrishankar Muthukrishnan if (op == NULL) { 240931dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 241031dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 241131dd9ddfSGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 241231dd9ddfSGowrishankar Muthukrishnan "operation struct\n"); 241331dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 241431dd9ddfSGowrishankar Muthukrishnan goto exit; 241531dd9ddfSGowrishankar Muthukrishnan } 241631dd9ddfSGowrishankar Muthukrishnan asym_op = op->asym; 241731dd9ddfSGowrishankar Muthukrishnan 241831dd9ddfSGowrishankar Muthukrishnan /* Setup asym xform */ 241931dd9ddfSGowrishankar Muthukrishnan xform.next = NULL; 242031dd9ddfSGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH; 242131dd9ddfSGowrishankar Muthukrishnan xform.ec.curve_id = input_params.curve; 242231dd9ddfSGowrishankar Muthukrishnan xform.ec.pkey.data = input_params.pkey_B.data; 242331dd9ddfSGowrishankar Muthukrishnan xform.ec.pkey.length = input_params.pkey_B.length; 242431dd9ddfSGowrishankar Muthukrishnan xform.ec.q.x.data = input_params.pubkey_qA_x.data; 242531dd9ddfSGowrishankar Muthukrishnan xform.ec.q.x.length = input_params.pubkey_qA_x.length; 242631dd9ddfSGowrishankar Muthukrishnan xform.ec.q.y.data = input_params.pubkey_qA_y.data; 242731dd9ddfSGowrishankar Muthukrishnan xform.ec.q.y.length = input_params.pubkey_qA_y.length; 242831dd9ddfSGowrishankar Muthukrishnan 242931dd9ddfSGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 243031dd9ddfSGowrishankar Muthukrishnan if (ret < 0) { 243131dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 243231dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 243331dd9ddfSGowrishankar Muthukrishnan "Session creation failed\n"); 243431dd9ddfSGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 243531dd9ddfSGowrishankar Muthukrishnan goto exit; 243631dd9ddfSGowrishankar Muthukrishnan } 243731dd9ddfSGowrishankar Muthukrishnan 243831dd9ddfSGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 243931dd9ddfSGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 244031dd9ddfSGowrishankar Muthukrishnan 244131dd9ddfSGowrishankar Muthukrishnan /* Populate op with operational details */ 244231dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE; 244331dd9ddfSGowrishankar Muthukrishnan 244431dd9ddfSGowrishankar Muthukrishnan /* Init out buf */ 244531dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.shared_secret.x.data = output_buf_x; 244631dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.shared_secret.y.data = output_buf_y; 244731dd9ddfSGowrishankar Muthukrishnan 244831dd9ddfSGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 244931dd9ddfSGowrishankar Muthukrishnan 245031dd9ddfSGowrishankar Muthukrishnan /* Process crypto operation */ 245131dd9ddfSGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 245231dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 245331dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 245431dd9ddfSGowrishankar Muthukrishnan "Error sending packet for operation\n"); 245531dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 245631dd9ddfSGowrishankar Muthukrishnan goto exit; 245731dd9ddfSGowrishankar Muthukrishnan } 245831dd9ddfSGowrishankar Muthukrishnan 245931dd9ddfSGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 246031dd9ddfSGowrishankar Muthukrishnan rte_pause(); 246131dd9ddfSGowrishankar Muthukrishnan 246231dd9ddfSGowrishankar Muthukrishnan if (result_op == NULL) { 246331dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 246431dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 246531dd9ddfSGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 246631dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 246731dd9ddfSGowrishankar Muthukrishnan goto exit; 246831dd9ddfSGowrishankar Muthukrishnan } 246931dd9ddfSGowrishankar Muthukrishnan 247031dd9ddfSGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 247131dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 247231dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 247331dd9ddfSGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 247431dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 247531dd9ddfSGowrishankar Muthukrishnan goto exit; 247631dd9ddfSGowrishankar Muthukrishnan } 247731dd9ddfSGowrishankar Muthukrishnan 247831dd9ddfSGowrishankar Muthukrishnan asym_op = result_op->asym; 247931dd9ddfSGowrishankar Muthukrishnan 248031dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "secret_x:", 248131dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length); 248231dd9ddfSGowrishankar Muthukrishnan debug_hexdump(stdout, "secret_y:", 248331dd9ddfSGowrishankar Muthukrishnan asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length); 248431dd9ddfSGowrishankar Muthukrishnan 248531dd9ddfSGowrishankar Muthukrishnan ret = verify_ecdh_secret(input_params.secret_x.data, 248631dd9ddfSGowrishankar Muthukrishnan input_params.secret_y.data, result_op); 248731dd9ddfSGowrishankar Muthukrishnan if (ret) { 248831dd9ddfSGowrishankar Muthukrishnan status = TEST_FAILED; 248931dd9ddfSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 249031dd9ddfSGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 249131dd9ddfSGowrishankar Muthukrishnan "ECDH shared secret compute failed.\n"); 249231dd9ddfSGowrishankar Muthukrishnan goto exit; 249331dd9ddfSGowrishankar Muthukrishnan } 249431dd9ddfSGowrishankar Muthukrishnan 249531dd9ddfSGowrishankar Muthukrishnan exit: 249631dd9ddfSGowrishankar Muthukrishnan if (sess != NULL) 249731dd9ddfSGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 249831dd9ddfSGowrishankar Muthukrishnan rte_crypto_op_free(op); 249931dd9ddfSGowrishankar Muthukrishnan return status; 250031dd9ddfSGowrishankar Muthukrishnan } 250131dd9ddfSGowrishankar Muthukrishnan 250231dd9ddfSGowrishankar Muthukrishnan static int 250331dd9ddfSGowrishankar Muthukrishnan test_ecdh_all_curve(void) 250431dd9ddfSGowrishankar Muthukrishnan { 250531dd9ddfSGowrishankar Muthukrishnan int status, overall_status = TEST_SUCCESS; 250631dd9ddfSGowrishankar Muthukrishnan enum curve curve_id; 250731dd9ddfSGowrishankar Muthukrishnan int test_index = 0; 250831dd9ddfSGowrishankar Muthukrishnan const char *msg; 250931dd9ddfSGowrishankar Muthukrishnan 251031dd9ddfSGowrishankar Muthukrishnan for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { 25112fba5232SGowrishankar Muthukrishnan if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448) 251231dd9ddfSGowrishankar Muthukrishnan continue; 251331dd9ddfSGowrishankar Muthukrishnan 251431dd9ddfSGowrishankar Muthukrishnan status = test_ecdh_priv_key_generate(curve_id); 251531dd9ddfSGowrishankar Muthukrishnan if (status == TEST_SUCCESS) { 251631dd9ddfSGowrishankar Muthukrishnan msg = "succeeded"; 251731dd9ddfSGowrishankar Muthukrishnan } else { 251831dd9ddfSGowrishankar Muthukrishnan msg = "failed"; 251931dd9ddfSGowrishankar Muthukrishnan overall_status = status; 252031dd9ddfSGowrishankar Muthukrishnan } 252131dd9ddfSGowrishankar Muthukrishnan printf(" %u) TestCase ECDH private key generation for Curve %s %s\n", 252231dd9ddfSGowrishankar Muthukrishnan test_index ++, curve[curve_id], msg); 252331dd9ddfSGowrishankar Muthukrishnan } 252431dd9ddfSGowrishankar Muthukrishnan 252531dd9ddfSGowrishankar Muthukrishnan for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { 252631dd9ddfSGowrishankar Muthukrishnan if (curve_id == SECP521R1_UA) 252731dd9ddfSGowrishankar Muthukrishnan continue; 252831dd9ddfSGowrishankar Muthukrishnan 252931dd9ddfSGowrishankar Muthukrishnan status = test_ecdh_pub_key_generate(curve_id); 253031dd9ddfSGowrishankar Muthukrishnan if (status == TEST_SUCCESS) { 253131dd9ddfSGowrishankar Muthukrishnan msg = "succeeded"; 25322fba5232SGowrishankar Muthukrishnan } else if (status == TEST_SKIPPED) { 25332fba5232SGowrishankar Muthukrishnan msg = "skipped"; 253431dd9ddfSGowrishankar Muthukrishnan } else { 253531dd9ddfSGowrishankar Muthukrishnan msg = "failed"; 253631dd9ddfSGowrishankar Muthukrishnan overall_status = status; 253731dd9ddfSGowrishankar Muthukrishnan } 253831dd9ddfSGowrishankar Muthukrishnan printf(" %u) TestCase ECDH public key generation for Curve %s %s\n", 253931dd9ddfSGowrishankar Muthukrishnan test_index ++, curve[curve_id], msg); 254031dd9ddfSGowrishankar Muthukrishnan } 254131dd9ddfSGowrishankar Muthukrishnan 254231dd9ddfSGowrishankar Muthukrishnan for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { 25432fba5232SGowrishankar Muthukrishnan if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448) 254431dd9ddfSGowrishankar Muthukrishnan continue; 254531dd9ddfSGowrishankar Muthukrishnan 254631dd9ddfSGowrishankar Muthukrishnan status = test_ecdh_pub_key_verify(curve_id); 254731dd9ddfSGowrishankar Muthukrishnan if (status == TEST_SUCCESS) { 254831dd9ddfSGowrishankar Muthukrishnan msg = "succeeded"; 254931dd9ddfSGowrishankar Muthukrishnan } else { 255031dd9ddfSGowrishankar Muthukrishnan msg = "failed"; 255131dd9ddfSGowrishankar Muthukrishnan overall_status = status; 255231dd9ddfSGowrishankar Muthukrishnan } 255331dd9ddfSGowrishankar Muthukrishnan printf(" %u) TestCase ECDH public key verification for Curve %s %s\n", 255431dd9ddfSGowrishankar Muthukrishnan test_index ++, curve[curve_id], msg); 255531dd9ddfSGowrishankar Muthukrishnan } 255631dd9ddfSGowrishankar Muthukrishnan 255731dd9ddfSGowrishankar Muthukrishnan for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { 25582fba5232SGowrishankar Muthukrishnan if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448) 255931dd9ddfSGowrishankar Muthukrishnan continue; 256031dd9ddfSGowrishankar Muthukrishnan 256131dd9ddfSGowrishankar Muthukrishnan status = test_ecdh_shared_secret(curve_id); 256231dd9ddfSGowrishankar Muthukrishnan if (status == TEST_SUCCESS) { 256331dd9ddfSGowrishankar Muthukrishnan msg = "succeeded"; 256431dd9ddfSGowrishankar Muthukrishnan } else { 256531dd9ddfSGowrishankar Muthukrishnan msg = "failed"; 256631dd9ddfSGowrishankar Muthukrishnan overall_status = status; 256731dd9ddfSGowrishankar Muthukrishnan } 256831dd9ddfSGowrishankar Muthukrishnan printf(" %u) TestCase ECDH shared secret compute for Curve %s %s\n", 256931dd9ddfSGowrishankar Muthukrishnan test_index ++, curve[curve_id], msg); 257031dd9ddfSGowrishankar Muthukrishnan } 257131dd9ddfSGowrishankar Muthukrishnan 257231dd9ddfSGowrishankar Muthukrishnan return overall_status; 257331dd9ddfSGowrishankar Muthukrishnan } 257431dd9ddfSGowrishankar Muthukrishnan 257531dd9ddfSGowrishankar Muthukrishnan static int 25762eef1a64SGowrishankar Muthukrishnan test_sm2_sign(void) 25772d970c66SGowrishankar Muthukrishnan { 25782d970c66SGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 25792d970c66SGowrishankar Muthukrishnan struct crypto_testsuite_sm2_params input_params = sm2_param_fp256; 25806f8ef8b6SGowrishankar Muthukrishnan const struct rte_cryptodev_asymmetric_xform_capability *capa; 25812d970c66SGowrishankar Muthukrishnan struct rte_mempool *sess_mpool = ts_params->session_mpool; 25822d970c66SGowrishankar Muthukrishnan struct rte_mempool *op_mpool = ts_params->op_mpool; 25836f8ef8b6SGowrishankar Muthukrishnan struct rte_cryptodev_asym_capability_idx idx; 25842d970c66SGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 25852d970c66SGowrishankar Muthukrishnan struct rte_crypto_op *result_op = NULL; 25862d970c66SGowrishankar Muthukrishnan uint8_t output_buf_r[TEST_DATA_SIZE]; 25872d970c66SGowrishankar Muthukrishnan uint8_t output_buf_s[TEST_DATA_SIZE]; 25882d970c66SGowrishankar Muthukrishnan struct rte_crypto_asym_xform xform; 25892d970c66SGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op; 25902d970c66SGowrishankar Muthukrishnan struct rte_crypto_op *op = NULL; 25912d970c66SGowrishankar Muthukrishnan int ret, status = TEST_SUCCESS; 25922d970c66SGowrishankar Muthukrishnan void *sess = NULL; 25932d970c66SGowrishankar Muthukrishnan 25946f8ef8b6SGowrishankar Muthukrishnan /* Check SM2 capability */ 25956f8ef8b6SGowrishankar Muthukrishnan idx.type = RTE_CRYPTO_ASYM_XFORM_SM2; 25966f8ef8b6SGowrishankar Muthukrishnan capa = rte_cryptodev_asym_capability_get(dev_id, &idx); 25976f8ef8b6SGowrishankar Muthukrishnan if (capa == NULL) 25986f8ef8b6SGowrishankar Muthukrishnan return -ENOTSUP; 25996f8ef8b6SGowrishankar Muthukrishnan 26002d970c66SGowrishankar Muthukrishnan /* Setup crypto op data structure */ 26012d970c66SGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 26022d970c66SGowrishankar Muthukrishnan if (op == NULL) { 26032d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 26042d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 26052d970c66SGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 26062d970c66SGowrishankar Muthukrishnan "operation struct\n"); 26072d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 26082d970c66SGowrishankar Muthukrishnan goto exit; 26092d970c66SGowrishankar Muthukrishnan } 26102d970c66SGowrishankar Muthukrishnan 26112d970c66SGowrishankar Muthukrishnan asym_op = op->asym; 26122d970c66SGowrishankar Muthukrishnan 26132d970c66SGowrishankar Muthukrishnan /* Setup asym xform */ 26142d970c66SGowrishankar Muthukrishnan xform.next = NULL; 26152d970c66SGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2; 2616f8ca1d61SGowrishankar Muthukrishnan xform.ec.curve_id = input_params.curve; 2617badc0c6fSGowrishankar Muthukrishnan xform.ec.pkey.data = input_params.pkey.data; 2618badc0c6fSGowrishankar Muthukrishnan xform.ec.pkey.length = input_params.pkey.length; 2619badc0c6fSGowrishankar Muthukrishnan xform.ec.q.x.data = input_params.pubkey_qx.data; 2620badc0c6fSGowrishankar Muthukrishnan xform.ec.q.x.length = input_params.pubkey_qx.length; 2621badc0c6fSGowrishankar Muthukrishnan xform.ec.q.y.data = input_params.pubkey_qy.data; 2622badc0c6fSGowrishankar Muthukrishnan xform.ec.q.y.length = input_params.pubkey_qy.length; 26232d970c66SGowrishankar Muthukrishnan 26242d970c66SGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 26252d970c66SGowrishankar Muthukrishnan if (ret < 0) { 26262d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 26272d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 26282d970c66SGowrishankar Muthukrishnan "Session creation failed\n"); 26292d970c66SGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 26302d970c66SGowrishankar Muthukrishnan goto exit; 26312d970c66SGowrishankar Muthukrishnan } 26322d970c66SGowrishankar Muthukrishnan 26332d970c66SGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 26342d970c66SGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 26352d970c66SGowrishankar Muthukrishnan 26362d970c66SGowrishankar Muthukrishnan /* Compute sign */ 26372d970c66SGowrishankar Muthukrishnan 26382d970c66SGowrishankar Muthukrishnan /* Populate op with operational details */ 26392d970c66SGowrishankar Muthukrishnan asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_SIGN; 2640*53c65a3cSGowrishankar Muthukrishnan if (rte_cryptodev_asym_xform_capability_check_opcap(capa, 2641*53c65a3cSGowrishankar Muthukrishnan RTE_CRYPTO_ASYM_OP_SIGN, RTE_CRYPTO_SM2_PH)) 2642f8ca1d61SGowrishankar Muthukrishnan asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3; 2643f8ca1d61SGowrishankar Muthukrishnan else 2644f8ca1d61SGowrishankar Muthukrishnan asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL; 2645f8ca1d61SGowrishankar Muthukrishnan 26462eef1a64SGowrishankar Muthukrishnan if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) { 26472d970c66SGowrishankar Muthukrishnan asym_op->sm2.message.data = input_params.message.data; 26482d970c66SGowrishankar Muthukrishnan asym_op->sm2.message.length = input_params.message.length; 26492d970c66SGowrishankar Muthukrishnan asym_op->sm2.id.data = input_params.id.data; 26502d970c66SGowrishankar Muthukrishnan asym_op->sm2.id.length = input_params.id.length; 26512eef1a64SGowrishankar Muthukrishnan } else { 26522eef1a64SGowrishankar Muthukrishnan asym_op->sm2.message.data = input_params.digest.data; 26532eef1a64SGowrishankar Muthukrishnan asym_op->sm2.message.length = input_params.digest.length; 26542eef1a64SGowrishankar Muthukrishnan asym_op->sm2.id.data = NULL; 26552eef1a64SGowrishankar Muthukrishnan asym_op->sm2.id.length = 0; 26562eef1a64SGowrishankar Muthukrishnan } 26572eef1a64SGowrishankar Muthukrishnan 2658*53c65a3cSGowrishankar Muthukrishnan if (rte_cryptodev_asym_xform_capability_check_opcap(capa, 2659*53c65a3cSGowrishankar Muthukrishnan RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) { 26602d970c66SGowrishankar Muthukrishnan asym_op->sm2.k.data = NULL; 26612d970c66SGowrishankar Muthukrishnan asym_op->sm2.k.length = 0; 26622d970c66SGowrishankar Muthukrishnan } else { 26632d970c66SGowrishankar Muthukrishnan asym_op->sm2.k.data = input_params.k.data; 26642d970c66SGowrishankar Muthukrishnan asym_op->sm2.k.length = input_params.k.length; 26652d970c66SGowrishankar Muthukrishnan } 26662d970c66SGowrishankar Muthukrishnan 26672d970c66SGowrishankar Muthukrishnan /* Init out buf */ 26682d970c66SGowrishankar Muthukrishnan asym_op->sm2.r.data = output_buf_r; 26692d970c66SGowrishankar Muthukrishnan asym_op->sm2.s.data = output_buf_s; 26702d970c66SGowrishankar Muthukrishnan 26712d970c66SGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 26722d970c66SGowrishankar Muthukrishnan 26732d970c66SGowrishankar Muthukrishnan /* Process crypto operation */ 26742d970c66SGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 26752d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 26762d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 26772d970c66SGowrishankar Muthukrishnan "Error sending packet for operation\n"); 26782d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 26792d970c66SGowrishankar Muthukrishnan goto exit; 26802d970c66SGowrishankar Muthukrishnan } 26812d970c66SGowrishankar Muthukrishnan 26822d970c66SGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 26832d970c66SGowrishankar Muthukrishnan rte_pause(); 26842d970c66SGowrishankar Muthukrishnan 26852d970c66SGowrishankar Muthukrishnan if (result_op == NULL) { 26862d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 26872d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 26882d970c66SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 26892d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 26902d970c66SGowrishankar Muthukrishnan goto exit; 26912d970c66SGowrishankar Muthukrishnan } 26922d970c66SGowrishankar Muthukrishnan 26932d970c66SGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 26942d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 26952d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 26962d970c66SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 26972d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 26982d970c66SGowrishankar Muthukrishnan goto exit; 26992d970c66SGowrishankar Muthukrishnan } 27002d970c66SGowrishankar Muthukrishnan 27012d970c66SGowrishankar Muthukrishnan asym_op = result_op->asym; 27022d970c66SGowrishankar Muthukrishnan 27032d970c66SGowrishankar Muthukrishnan debug_hexdump(stdout, "r:", 27042d970c66SGowrishankar Muthukrishnan asym_op->sm2.r.data, asym_op->sm2.r.length); 27052d970c66SGowrishankar Muthukrishnan debug_hexdump(stdout, "s:", 27062d970c66SGowrishankar Muthukrishnan asym_op->sm2.s.data, asym_op->sm2.s.length); 27072d970c66SGowrishankar Muthukrishnan 2708*53c65a3cSGowrishankar Muthukrishnan if (!rte_cryptodev_asym_xform_capability_check_opcap(capa, 2709*53c65a3cSGowrishankar Muthukrishnan RTE_CRYPTO_ASYM_OP_SIGN, RTE_CRYPTO_SM2_RNG)) { 27102d970c66SGowrishankar Muthukrishnan /* Verify sign (by comparison). */ 27112d970c66SGowrishankar Muthukrishnan if (memcmp(input_params.sign_r.data, asym_op->sm2.r.data, 27122d970c66SGowrishankar Muthukrishnan asym_op->sm2.r.length) != 0) { 27132d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 27142d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 27152d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 27162d970c66SGowrishankar Muthukrishnan "SM2 sign failed.\n"); 27172d970c66SGowrishankar Muthukrishnan goto exit; 27182d970c66SGowrishankar Muthukrishnan } 27192d970c66SGowrishankar Muthukrishnan if (memcmp(input_params.sign_s.data, asym_op->sm2.s.data, 27202d970c66SGowrishankar Muthukrishnan asym_op->sm2.s.length) != 0) { 27212d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 27222d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 27232d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 27242d970c66SGowrishankar Muthukrishnan "SM2 sign failed.\n"); 27252d970c66SGowrishankar Muthukrishnan goto exit; 27262d970c66SGowrishankar Muthukrishnan } 27272d970c66SGowrishankar Muthukrishnan } else { 27282d970c66SGowrishankar Muthukrishnan /* Verify sign (in roundtrip). 27292d970c66SGowrishankar Muthukrishnan * Due to random number used per message, sign op 27302d970c66SGowrishankar Muthukrishnan * would produce different output for same message 27312d970c66SGowrishankar Muthukrishnan * every time. Hence, we can't have expected output 27322d970c66SGowrishankar Muthukrishnan * to match, instead reverse op to verify. 27332d970c66SGowrishankar Muthukrishnan */ 27342d970c66SGowrishankar Muthukrishnan 27352d970c66SGowrishankar Muthukrishnan /* Populate op with operational details */ 27362d970c66SGowrishankar Muthukrishnan asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY; 27372d970c66SGowrishankar Muthukrishnan 27382d970c66SGowrishankar Muthukrishnan /* Enqueue sign result for verify */ 27392d970c66SGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 27402d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 27412d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 27422d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 27432d970c66SGowrishankar Muthukrishnan "Error sending packet for operation\n"); 27442d970c66SGowrishankar Muthukrishnan goto exit; 27452d970c66SGowrishankar Muthukrishnan } 27462d970c66SGowrishankar Muthukrishnan 27472d970c66SGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 27482d970c66SGowrishankar Muthukrishnan rte_pause(); 27492d970c66SGowrishankar Muthukrishnan 27502d970c66SGowrishankar Muthukrishnan if (result_op == NULL) { 27512d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 27522d970c66SGowrishankar Muthukrishnan goto exit; 27532d970c66SGowrishankar Muthukrishnan } 27542d970c66SGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 27552d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 27562d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 27572d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 27582d970c66SGowrishankar Muthukrishnan "SM2 verify failed.\n"); 27592d970c66SGowrishankar Muthukrishnan goto exit; 27602d970c66SGowrishankar Muthukrishnan } 27612d970c66SGowrishankar Muthukrishnan } 27622d970c66SGowrishankar Muthukrishnan 27632d970c66SGowrishankar Muthukrishnan exit: 27642d970c66SGowrishankar Muthukrishnan if (sess != NULL) 27652d970c66SGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 27662d970c66SGowrishankar Muthukrishnan rte_crypto_op_free(op); 27672d970c66SGowrishankar Muthukrishnan return status; 27682d970c66SGowrishankar Muthukrishnan }; 27692d970c66SGowrishankar Muthukrishnan 27702d970c66SGowrishankar Muthukrishnan static int 27712d970c66SGowrishankar Muthukrishnan test_sm2_verify(void) 27722d970c66SGowrishankar Muthukrishnan { 27732d970c66SGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 27742d970c66SGowrishankar Muthukrishnan struct crypto_testsuite_sm2_params input_params = sm2_param_fp256; 27756f8ef8b6SGowrishankar Muthukrishnan const struct rte_cryptodev_asymmetric_xform_capability *capa; 27762d970c66SGowrishankar Muthukrishnan struct rte_mempool *sess_mpool = ts_params->session_mpool; 27772d970c66SGowrishankar Muthukrishnan struct rte_mempool *op_mpool = ts_params->op_mpool; 27786f8ef8b6SGowrishankar Muthukrishnan struct rte_cryptodev_asym_capability_idx idx; 27792d970c66SGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 27802d970c66SGowrishankar Muthukrishnan struct rte_crypto_op *result_op = NULL; 27812d970c66SGowrishankar Muthukrishnan struct rte_crypto_asym_xform xform; 27822d970c66SGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op; 27832d970c66SGowrishankar Muthukrishnan struct rte_crypto_op *op = NULL; 27842d970c66SGowrishankar Muthukrishnan int ret, status = TEST_SUCCESS; 27852d970c66SGowrishankar Muthukrishnan void *sess = NULL; 27862d970c66SGowrishankar Muthukrishnan 27876f8ef8b6SGowrishankar Muthukrishnan /* Check SM2 capability */ 27886f8ef8b6SGowrishankar Muthukrishnan idx.type = RTE_CRYPTO_ASYM_XFORM_SM2; 27896f8ef8b6SGowrishankar Muthukrishnan capa = rte_cryptodev_asym_capability_get(dev_id, &idx); 27906f8ef8b6SGowrishankar Muthukrishnan if (capa == NULL) 27916f8ef8b6SGowrishankar Muthukrishnan return -ENOTSUP; 27926f8ef8b6SGowrishankar Muthukrishnan 27932d970c66SGowrishankar Muthukrishnan /* Setup crypto op data structure */ 27942d970c66SGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 27952d970c66SGowrishankar Muthukrishnan if (op == NULL) { 27962d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 27972d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 27982d970c66SGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 27992d970c66SGowrishankar Muthukrishnan "operation struct\n"); 28002d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 28012d970c66SGowrishankar Muthukrishnan goto exit; 28022d970c66SGowrishankar Muthukrishnan } 28032d970c66SGowrishankar Muthukrishnan 28042d970c66SGowrishankar Muthukrishnan asym_op = op->asym; 28052d970c66SGowrishankar Muthukrishnan 28062d970c66SGowrishankar Muthukrishnan /* Setup asym xform */ 28072d970c66SGowrishankar Muthukrishnan xform.next = NULL; 28082d970c66SGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2; 2809f8ca1d61SGowrishankar Muthukrishnan xform.ec.curve_id = input_params.curve; 2810badc0c6fSGowrishankar Muthukrishnan xform.ec.pkey.data = input_params.pkey.data; 2811badc0c6fSGowrishankar Muthukrishnan xform.ec.pkey.length = input_params.pkey.length; 2812badc0c6fSGowrishankar Muthukrishnan xform.ec.q.x.data = input_params.pubkey_qx.data; 2813badc0c6fSGowrishankar Muthukrishnan xform.ec.q.x.length = input_params.pubkey_qx.length; 2814badc0c6fSGowrishankar Muthukrishnan xform.ec.q.y.data = input_params.pubkey_qy.data; 2815badc0c6fSGowrishankar Muthukrishnan xform.ec.q.y.length = input_params.pubkey_qy.length; 28162d970c66SGowrishankar Muthukrishnan 28172d970c66SGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 28182d970c66SGowrishankar Muthukrishnan if (ret < 0) { 28192d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 28202d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 28212d970c66SGowrishankar Muthukrishnan "Session creation failed\n"); 28222d970c66SGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 28232d970c66SGowrishankar Muthukrishnan goto exit; 28242d970c66SGowrishankar Muthukrishnan } 28252d970c66SGowrishankar Muthukrishnan 28262d970c66SGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 28272d970c66SGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 28282d970c66SGowrishankar Muthukrishnan 28292d970c66SGowrishankar Muthukrishnan /* Verify given sign */ 28302d970c66SGowrishankar Muthukrishnan 28312d970c66SGowrishankar Muthukrishnan /* Populate op with operational details */ 28322d970c66SGowrishankar Muthukrishnan asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY; 28332eef1a64SGowrishankar Muthukrishnan 2834*53c65a3cSGowrishankar Muthukrishnan if (rte_cryptodev_asym_xform_capability_check_opcap(capa, 2835*53c65a3cSGowrishankar Muthukrishnan RTE_CRYPTO_ASYM_OP_VERIFY, RTE_CRYPTO_SM2_PH)) 2836f8ca1d61SGowrishankar Muthukrishnan asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3; 2837f8ca1d61SGowrishankar Muthukrishnan else 2838f8ca1d61SGowrishankar Muthukrishnan asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL; 2839f8ca1d61SGowrishankar Muthukrishnan 28402eef1a64SGowrishankar Muthukrishnan if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) { 28412d970c66SGowrishankar Muthukrishnan asym_op->sm2.message.data = input_params.message.data; 28422d970c66SGowrishankar Muthukrishnan asym_op->sm2.message.length = input_params.message.length; 28432eef1a64SGowrishankar Muthukrishnan asym_op->sm2.id.data = input_params.id.data; 28442eef1a64SGowrishankar Muthukrishnan asym_op->sm2.id.length = input_params.id.length; 28452eef1a64SGowrishankar Muthukrishnan } else { 28462eef1a64SGowrishankar Muthukrishnan asym_op->sm2.message.data = input_params.digest.data; 28472eef1a64SGowrishankar Muthukrishnan asym_op->sm2.message.length = input_params.digest.length; 28482eef1a64SGowrishankar Muthukrishnan asym_op->sm2.id.data = NULL; 28492eef1a64SGowrishankar Muthukrishnan asym_op->sm2.id.length = 0; 28502eef1a64SGowrishankar Muthukrishnan } 28512eef1a64SGowrishankar Muthukrishnan 28522d970c66SGowrishankar Muthukrishnan asym_op->sm2.r.data = input_params.sign_r.data; 28532d970c66SGowrishankar Muthukrishnan asym_op->sm2.r.length = input_params.sign_r.length; 28542d970c66SGowrishankar Muthukrishnan asym_op->sm2.s.data = input_params.sign_s.data; 28552d970c66SGowrishankar Muthukrishnan asym_op->sm2.s.length = input_params.sign_s.length; 28562d970c66SGowrishankar Muthukrishnan 28572d970c66SGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 28582d970c66SGowrishankar Muthukrishnan 28592d970c66SGowrishankar Muthukrishnan /* Process crypto operation */ 28602d970c66SGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 28612d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 28622d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 28632d970c66SGowrishankar Muthukrishnan "Error sending packet for operation\n"); 28642d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 28652d970c66SGowrishankar Muthukrishnan goto exit; 28662d970c66SGowrishankar Muthukrishnan } 28672d970c66SGowrishankar Muthukrishnan 28682d970c66SGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 28692d970c66SGowrishankar Muthukrishnan rte_pause(); 28702d970c66SGowrishankar Muthukrishnan 28712d970c66SGowrishankar Muthukrishnan if (result_op == NULL) { 28722d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 28732d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 28742d970c66SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 28752d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 28762d970c66SGowrishankar Muthukrishnan goto exit; 28772d970c66SGowrishankar Muthukrishnan } 28782d970c66SGowrishankar Muthukrishnan 28792d970c66SGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 28802d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 28812d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 28822d970c66SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 28832d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 28842d970c66SGowrishankar Muthukrishnan goto exit; 28852d970c66SGowrishankar Muthukrishnan } 28862d970c66SGowrishankar Muthukrishnan 28872d970c66SGowrishankar Muthukrishnan exit: 28882d970c66SGowrishankar Muthukrishnan if (sess != NULL) 28892d970c66SGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 28902d970c66SGowrishankar Muthukrishnan rte_crypto_op_free(op); 28912d970c66SGowrishankar Muthukrishnan return status; 28922d970c66SGowrishankar Muthukrishnan }; 28932d970c66SGowrishankar Muthukrishnan 28942d970c66SGowrishankar Muthukrishnan static int 28952eef1a64SGowrishankar Muthukrishnan test_sm2_enc(void) 28962d970c66SGowrishankar Muthukrishnan { 28972d970c66SGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 28982d970c66SGowrishankar Muthukrishnan struct crypto_testsuite_sm2_params input_params = sm2_param_fp256; 28996f8ef8b6SGowrishankar Muthukrishnan const struct rte_cryptodev_asymmetric_xform_capability *capa; 29002d970c66SGowrishankar Muthukrishnan struct rte_mempool *sess_mpool = ts_params->session_mpool; 29012d970c66SGowrishankar Muthukrishnan struct rte_mempool *op_mpool = ts_params->op_mpool; 29022d970c66SGowrishankar Muthukrishnan uint8_t output_buf[TEST_DATA_SIZE], *pbuf = NULL; 29036f8ef8b6SGowrishankar Muthukrishnan struct rte_cryptodev_asym_capability_idx idx; 29042d970c66SGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 29052d970c66SGowrishankar Muthukrishnan struct rte_crypto_op *result_op = NULL; 29062d970c66SGowrishankar Muthukrishnan struct rte_crypto_asym_xform xform; 29072d970c66SGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op; 29082d970c66SGowrishankar Muthukrishnan struct rte_crypto_op *op = NULL; 29092d970c66SGowrishankar Muthukrishnan int ret, status = TEST_SUCCESS; 29102d970c66SGowrishankar Muthukrishnan void *sess = NULL; 29112d970c66SGowrishankar Muthukrishnan 29126f8ef8b6SGowrishankar Muthukrishnan /* Check SM2 capability */ 29136f8ef8b6SGowrishankar Muthukrishnan idx.type = RTE_CRYPTO_ASYM_XFORM_SM2; 29146f8ef8b6SGowrishankar Muthukrishnan capa = rte_cryptodev_asym_capability_get(dev_id, &idx); 29156f8ef8b6SGowrishankar Muthukrishnan if (capa == NULL) 29166f8ef8b6SGowrishankar Muthukrishnan return -ENOTSUP; 29176f8ef8b6SGowrishankar Muthukrishnan 29182d970c66SGowrishankar Muthukrishnan /* Setup crypto op data structure */ 29192d970c66SGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 29202d970c66SGowrishankar Muthukrishnan if (op == NULL) { 29212d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 29222d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 29232d970c66SGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 29242d970c66SGowrishankar Muthukrishnan "operation struct\n"); 29252d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 29262d970c66SGowrishankar Muthukrishnan goto exit; 29272d970c66SGowrishankar Muthukrishnan } 29282d970c66SGowrishankar Muthukrishnan asym_op = op->asym; 29292d970c66SGowrishankar Muthukrishnan 29302d970c66SGowrishankar Muthukrishnan /* Setup asym xform */ 29312d970c66SGowrishankar Muthukrishnan xform.next = NULL; 29322d970c66SGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2; 2933f8ca1d61SGowrishankar Muthukrishnan xform.ec.curve_id = input_params.curve; 2934badc0c6fSGowrishankar Muthukrishnan xform.ec.pkey.data = input_params.pkey.data; 2935badc0c6fSGowrishankar Muthukrishnan xform.ec.pkey.length = input_params.pkey.length; 2936badc0c6fSGowrishankar Muthukrishnan xform.ec.q.x.data = input_params.pubkey_qx.data; 2937badc0c6fSGowrishankar Muthukrishnan xform.ec.q.x.length = input_params.pubkey_qx.length; 2938badc0c6fSGowrishankar Muthukrishnan xform.ec.q.y.data = input_params.pubkey_qy.data; 2939badc0c6fSGowrishankar Muthukrishnan xform.ec.q.y.length = input_params.pubkey_qy.length; 29402d970c66SGowrishankar Muthukrishnan 29412d970c66SGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 29422d970c66SGowrishankar Muthukrishnan if (ret < 0) { 29432d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 29442d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 29452d970c66SGowrishankar Muthukrishnan "Session creation failed\n"); 29462d970c66SGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 29472d970c66SGowrishankar Muthukrishnan goto exit; 29482d970c66SGowrishankar Muthukrishnan } 29492d970c66SGowrishankar Muthukrishnan 29502d970c66SGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 29512d970c66SGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 29522d970c66SGowrishankar Muthukrishnan 29532d970c66SGowrishankar Muthukrishnan /* Compute encrypt */ 29542d970c66SGowrishankar Muthukrishnan 29552d970c66SGowrishankar Muthukrishnan /* Populate op with operational details */ 29562d970c66SGowrishankar Muthukrishnan asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT; 2957*53c65a3cSGowrishankar Muthukrishnan if (rte_cryptodev_asym_xform_capability_check_opcap(capa, 2958*53c65a3cSGowrishankar Muthukrishnan RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_PH)) 2959f8ca1d61SGowrishankar Muthukrishnan asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3; 2960f8ca1d61SGowrishankar Muthukrishnan else 2961f8ca1d61SGowrishankar Muthukrishnan asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL; 2962f8ca1d61SGowrishankar Muthukrishnan 29632d970c66SGowrishankar Muthukrishnan asym_op->sm2.message.data = input_params.message.data; 29642d970c66SGowrishankar Muthukrishnan asym_op->sm2.message.length = input_params.message.length; 29652eef1a64SGowrishankar Muthukrishnan 2966*53c65a3cSGowrishankar Muthukrishnan if (rte_cryptodev_asym_xform_capability_check_opcap(capa, 2967*53c65a3cSGowrishankar Muthukrishnan RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) { 29682d970c66SGowrishankar Muthukrishnan asym_op->sm2.k.data = NULL; 29692d970c66SGowrishankar Muthukrishnan asym_op->sm2.k.length = 0; 29702d970c66SGowrishankar Muthukrishnan } else { 29712d970c66SGowrishankar Muthukrishnan asym_op->sm2.k.data = input_params.k.data; 29722d970c66SGowrishankar Muthukrishnan asym_op->sm2.k.length = input_params.k.length; 29732d970c66SGowrishankar Muthukrishnan } 29742d970c66SGowrishankar Muthukrishnan 29752d970c66SGowrishankar Muthukrishnan /* Init out buf */ 29762d970c66SGowrishankar Muthukrishnan asym_op->sm2.cipher.data = output_buf; 29772d970c66SGowrishankar Muthukrishnan 29782d970c66SGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 29792d970c66SGowrishankar Muthukrishnan 29802d970c66SGowrishankar Muthukrishnan /* Process crypto operation */ 29812d970c66SGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 29822d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 29832d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 29842d970c66SGowrishankar Muthukrishnan "Error sending packet for operation\n"); 29852d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 29862d970c66SGowrishankar Muthukrishnan goto exit; 29872d970c66SGowrishankar Muthukrishnan } 29882d970c66SGowrishankar Muthukrishnan 29892d970c66SGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 29902d970c66SGowrishankar Muthukrishnan rte_pause(); 29912d970c66SGowrishankar Muthukrishnan 29922d970c66SGowrishankar Muthukrishnan if (result_op == NULL) { 29932d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 29942d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 29952d970c66SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 29962d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 29972d970c66SGowrishankar Muthukrishnan goto exit; 29982d970c66SGowrishankar Muthukrishnan } 29992d970c66SGowrishankar Muthukrishnan 30002d970c66SGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 30012d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 30022d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 30032d970c66SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 30042d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 30052d970c66SGowrishankar Muthukrishnan goto exit; 30062d970c66SGowrishankar Muthukrishnan } 30072d970c66SGowrishankar Muthukrishnan 30082d970c66SGowrishankar Muthukrishnan asym_op = result_op->asym; 30092d970c66SGowrishankar Muthukrishnan 30102d970c66SGowrishankar Muthukrishnan debug_hexdump(stdout, "cipher:", 30112d970c66SGowrishankar Muthukrishnan asym_op->sm2.cipher.data, asym_op->sm2.cipher.length); 30122d970c66SGowrishankar Muthukrishnan 3013*53c65a3cSGowrishankar Muthukrishnan if (!rte_cryptodev_asym_xform_capability_check_opcap(capa, 3014*53c65a3cSGowrishankar Muthukrishnan RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) { 30152d970c66SGowrishankar Muthukrishnan if (memcmp(input_params.cipher.data, asym_op->sm2.cipher.data, 30162d970c66SGowrishankar Muthukrishnan asym_op->sm2.cipher.length) != 0) { 30172d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 30182d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__, 30192d970c66SGowrishankar Muthukrishnan "SM2 encrypt failed.\n"); 30202d970c66SGowrishankar Muthukrishnan goto exit; 30212d970c66SGowrishankar Muthukrishnan } 30222d970c66SGowrishankar Muthukrishnan } else { 30232d970c66SGowrishankar Muthukrishnan /* Verify cipher (in roundtrip). 30242d970c66SGowrishankar Muthukrishnan * Due to random number used per message, encrypt op 30252d970c66SGowrishankar Muthukrishnan * would produce different output for same message 30262d970c66SGowrishankar Muthukrishnan * every time. Hence, we can't have expected output 30272d970c66SGowrishankar Muthukrishnan * to match, instead reverse op to decrypt. 30282d970c66SGowrishankar Muthukrishnan */ 30292d970c66SGowrishankar Muthukrishnan 30302d970c66SGowrishankar Muthukrishnan /* Populate op with operational details */ 30312d970c66SGowrishankar Muthukrishnan op->asym->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT; 30322d970c66SGowrishankar Muthukrishnan pbuf = rte_malloc(NULL, TEST_DATA_SIZE, 0); 30332d970c66SGowrishankar Muthukrishnan op->asym->sm2.message.data = pbuf; 30342d970c66SGowrishankar Muthukrishnan op->asym->sm2.message.length = TEST_DATA_SIZE; 30352d970c66SGowrishankar Muthukrishnan 30362d970c66SGowrishankar Muthukrishnan /* Enqueue cipher result for decrypt */ 30372d970c66SGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 30382d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 30392d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 30402d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 30412d970c66SGowrishankar Muthukrishnan "Error sending packet for operation\n"); 30422d970c66SGowrishankar Muthukrishnan goto exit; 30432d970c66SGowrishankar Muthukrishnan } 30442d970c66SGowrishankar Muthukrishnan 30452d970c66SGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 30462d970c66SGowrishankar Muthukrishnan rte_pause(); 30472d970c66SGowrishankar Muthukrishnan 30482d970c66SGowrishankar Muthukrishnan if (result_op == NULL) { 30492d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 30502d970c66SGowrishankar Muthukrishnan goto exit; 30512d970c66SGowrishankar Muthukrishnan } 30522d970c66SGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 30532d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 30542d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 30552d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 30562d970c66SGowrishankar Muthukrishnan "SM2 encrypt failed.\n"); 30572d970c66SGowrishankar Muthukrishnan goto exit; 30582d970c66SGowrishankar Muthukrishnan } 30592d970c66SGowrishankar Muthukrishnan 30602d970c66SGowrishankar Muthukrishnan asym_op = result_op->asym; 30612d970c66SGowrishankar Muthukrishnan if (memcmp(input_params.message.data, asym_op->sm2.message.data, 30622d970c66SGowrishankar Muthukrishnan asym_op->sm2.message.length) != 0) { 30632d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 30642d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__, 30652d970c66SGowrishankar Muthukrishnan "SM2 encrypt failed.\n"); 30662d970c66SGowrishankar Muthukrishnan goto exit; 30672d970c66SGowrishankar Muthukrishnan } 30682d970c66SGowrishankar Muthukrishnan } 30692d970c66SGowrishankar Muthukrishnan exit: 30702d970c66SGowrishankar Muthukrishnan rte_free(pbuf); 30712d970c66SGowrishankar Muthukrishnan 30722d970c66SGowrishankar Muthukrishnan if (sess != NULL) 30732d970c66SGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 30742d970c66SGowrishankar Muthukrishnan rte_crypto_op_free(op); 30752d970c66SGowrishankar Muthukrishnan return status; 30762d970c66SGowrishankar Muthukrishnan }; 30772d970c66SGowrishankar Muthukrishnan 30782d970c66SGowrishankar Muthukrishnan static int 30792d970c66SGowrishankar Muthukrishnan test_sm2_dec(void) 30802d970c66SGowrishankar Muthukrishnan { 30812d970c66SGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 30822d970c66SGowrishankar Muthukrishnan struct crypto_testsuite_sm2_params input_params = sm2_param_fp256; 30836f8ef8b6SGowrishankar Muthukrishnan const struct rte_cryptodev_asymmetric_xform_capability *capa; 30842d970c66SGowrishankar Muthukrishnan struct rte_mempool *sess_mpool = ts_params->session_mpool; 30852d970c66SGowrishankar Muthukrishnan struct rte_mempool *op_mpool = ts_params->op_mpool; 30866f8ef8b6SGowrishankar Muthukrishnan struct rte_cryptodev_asym_capability_idx idx; 30872d970c66SGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 30882d970c66SGowrishankar Muthukrishnan struct rte_crypto_op *result_op = NULL; 30892d970c66SGowrishankar Muthukrishnan uint8_t output_buf_m[TEST_DATA_SIZE]; 30902d970c66SGowrishankar Muthukrishnan struct rte_crypto_asym_xform xform; 30912d970c66SGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op; 30922d970c66SGowrishankar Muthukrishnan struct rte_crypto_op *op = NULL; 30932d970c66SGowrishankar Muthukrishnan int ret, status = TEST_SUCCESS; 30942d970c66SGowrishankar Muthukrishnan void *sess = NULL; 30952d970c66SGowrishankar Muthukrishnan 30966f8ef8b6SGowrishankar Muthukrishnan /* Check SM2 capability */ 30976f8ef8b6SGowrishankar Muthukrishnan idx.type = RTE_CRYPTO_ASYM_XFORM_SM2; 30986f8ef8b6SGowrishankar Muthukrishnan capa = rte_cryptodev_asym_capability_get(dev_id, &idx); 30996f8ef8b6SGowrishankar Muthukrishnan if (capa == NULL) 31006f8ef8b6SGowrishankar Muthukrishnan return -ENOTSUP; 31016f8ef8b6SGowrishankar Muthukrishnan 31022d970c66SGowrishankar Muthukrishnan /* Setup crypto op data structure */ 31032d970c66SGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 31042d970c66SGowrishankar Muthukrishnan if (op == NULL) { 31052d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 31062d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 31072d970c66SGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 31082d970c66SGowrishankar Muthukrishnan "operation struct\n"); 31092d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 31102d970c66SGowrishankar Muthukrishnan goto exit; 31112d970c66SGowrishankar Muthukrishnan } 31122d970c66SGowrishankar Muthukrishnan asym_op = op->asym; 31132d970c66SGowrishankar Muthukrishnan 31142d970c66SGowrishankar Muthukrishnan /* Setup asym xform */ 31152d970c66SGowrishankar Muthukrishnan xform.next = NULL; 31162d970c66SGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2; 3117f8ca1d61SGowrishankar Muthukrishnan xform.ec.curve_id = input_params.curve; 3118badc0c6fSGowrishankar Muthukrishnan xform.ec.pkey.data = input_params.pkey.data; 3119badc0c6fSGowrishankar Muthukrishnan xform.ec.pkey.length = input_params.pkey.length; 3120badc0c6fSGowrishankar Muthukrishnan xform.ec.q.x.data = input_params.pubkey_qx.data; 3121badc0c6fSGowrishankar Muthukrishnan xform.ec.q.x.length = input_params.pubkey_qx.length; 3122badc0c6fSGowrishankar Muthukrishnan xform.ec.q.y.data = input_params.pubkey_qy.data; 3123badc0c6fSGowrishankar Muthukrishnan xform.ec.q.y.length = input_params.pubkey_qy.length; 31242d970c66SGowrishankar Muthukrishnan 31252d970c66SGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 31262d970c66SGowrishankar Muthukrishnan if (ret < 0) { 31272d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 31282d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 31292d970c66SGowrishankar Muthukrishnan "Session creation failed\n"); 31302d970c66SGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 31312d970c66SGowrishankar Muthukrishnan goto exit; 31322d970c66SGowrishankar Muthukrishnan } 31332d970c66SGowrishankar Muthukrishnan 31342d970c66SGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 31352d970c66SGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 31362d970c66SGowrishankar Muthukrishnan 31372d970c66SGowrishankar Muthukrishnan /* Compute decrypt */ 31382d970c66SGowrishankar Muthukrishnan 31392d970c66SGowrishankar Muthukrishnan /* Populate op with operational details */ 31402d970c66SGowrishankar Muthukrishnan asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT; 3141*53c65a3cSGowrishankar Muthukrishnan if (rte_cryptodev_asym_xform_capability_check_opcap(capa, 3142*53c65a3cSGowrishankar Muthukrishnan RTE_CRYPTO_ASYM_OP_DECRYPT, RTE_CRYPTO_SM2_PH)) 3143f8ca1d61SGowrishankar Muthukrishnan asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3; 3144f8ca1d61SGowrishankar Muthukrishnan else 3145f8ca1d61SGowrishankar Muthukrishnan asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL; 3146f8ca1d61SGowrishankar Muthukrishnan 31472d970c66SGowrishankar Muthukrishnan asym_op->sm2.cipher.data = input_params.cipher.data; 31482d970c66SGowrishankar Muthukrishnan asym_op->sm2.cipher.length = input_params.cipher.length; 31492d970c66SGowrishankar Muthukrishnan 31502d970c66SGowrishankar Muthukrishnan /* Init out buf */ 31512d970c66SGowrishankar Muthukrishnan asym_op->sm2.message.data = output_buf_m; 31522d970c66SGowrishankar Muthukrishnan asym_op->sm2.message.length = RTE_DIM(output_buf_m); 31532d970c66SGowrishankar Muthukrishnan 31542d970c66SGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 31552d970c66SGowrishankar Muthukrishnan 31562d970c66SGowrishankar Muthukrishnan /* Process crypto operation */ 31572d970c66SGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 31582d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 31592d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 31602d970c66SGowrishankar Muthukrishnan "Error sending packet for operation\n"); 31612d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 31622d970c66SGowrishankar Muthukrishnan goto exit; 31632d970c66SGowrishankar Muthukrishnan } 31642d970c66SGowrishankar Muthukrishnan 31652d970c66SGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 31662d970c66SGowrishankar Muthukrishnan rte_pause(); 31672d970c66SGowrishankar Muthukrishnan 31682d970c66SGowrishankar Muthukrishnan if (result_op == NULL) { 31692d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 31702d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 31712d970c66SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 31722d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 31732d970c66SGowrishankar Muthukrishnan goto exit; 31742d970c66SGowrishankar Muthukrishnan } 31752d970c66SGowrishankar Muthukrishnan 31762d970c66SGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 31772d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 31782d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 31792d970c66SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 31802d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 31812d970c66SGowrishankar Muthukrishnan goto exit; 31822d970c66SGowrishankar Muthukrishnan } 31832d970c66SGowrishankar Muthukrishnan 31842d970c66SGowrishankar Muthukrishnan asym_op = result_op->asym; 31852d970c66SGowrishankar Muthukrishnan 31862d970c66SGowrishankar Muthukrishnan debug_hexdump(stdout, "message:", 31872d970c66SGowrishankar Muthukrishnan asym_op->sm2.message.data, asym_op->sm2.message.length); 31882d970c66SGowrishankar Muthukrishnan 31892d970c66SGowrishankar Muthukrishnan if (memcmp(input_params.message.data, asym_op->sm2.message.data, 31902d970c66SGowrishankar Muthukrishnan op->asym->sm2.message.length)) { 31912d970c66SGowrishankar Muthukrishnan status = TEST_FAILED; 31922d970c66SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 31932d970c66SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 31942d970c66SGowrishankar Muthukrishnan "SM2 decrypt failed.\n"); 31952d970c66SGowrishankar Muthukrishnan goto exit; 31962d970c66SGowrishankar Muthukrishnan } 31972d970c66SGowrishankar Muthukrishnan exit: 31982d970c66SGowrishankar Muthukrishnan if (sess != NULL) 31992d970c66SGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 32002d970c66SGowrishankar Muthukrishnan rte_crypto_op_free(op); 32012d970c66SGowrishankar Muthukrishnan return status; 32022d970c66SGowrishankar Muthukrishnan }; 32032d970c66SGowrishankar Muthukrishnan 32042fba5232SGowrishankar Muthukrishnan static int 32052fba5232SGowrishankar Muthukrishnan test_eddsa_sign(struct crypto_testsuite_eddsa_params *input_params) 32062fba5232SGowrishankar Muthukrishnan { 32072fba5232SGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 32082fba5232SGowrishankar Muthukrishnan enum rte_crypto_edward_instance instance = input_params->instance; 32092fba5232SGowrishankar Muthukrishnan struct rte_mempool *sess_mpool = ts_params->session_mpool; 32102fba5232SGowrishankar Muthukrishnan struct rte_mempool *op_mpool = ts_params->op_mpool; 32112fba5232SGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 32122fba5232SGowrishankar Muthukrishnan struct rte_crypto_op *result_op = NULL; 32132fba5232SGowrishankar Muthukrishnan uint8_t output_buf_r[TEST_DATA_SIZE]; 32142fba5232SGowrishankar Muthukrishnan struct rte_crypto_asym_xform xform; 32152fba5232SGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op; 32162fba5232SGowrishankar Muthukrishnan struct rte_crypto_op *op = NULL; 32172fba5232SGowrishankar Muthukrishnan int ret, status = TEST_FAILED; 32182fba5232SGowrishankar Muthukrishnan void *sess = NULL; 32192fba5232SGowrishankar Muthukrishnan bool ctx = false; 32202fba5232SGowrishankar Muthukrishnan 32212fba5232SGowrishankar Muthukrishnan if (instance == RTE_CRYPTO_EDCURVE_25519CTX) 32222fba5232SGowrishankar Muthukrishnan ctx = true; 32232fba5232SGowrishankar Muthukrishnan 32242fba5232SGowrishankar Muthukrishnan /* Setup crypto op data structure */ 32252fba5232SGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 32262fba5232SGowrishankar Muthukrishnan if (op == NULL) { 32272fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 32282fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 32292fba5232SGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 32302fba5232SGowrishankar Muthukrishnan "operation struct\n"); 32312fba5232SGowrishankar Muthukrishnan status = TEST_FAILED; 32322fba5232SGowrishankar Muthukrishnan goto exit; 32332fba5232SGowrishankar Muthukrishnan } 32342fba5232SGowrishankar Muthukrishnan 32352fba5232SGowrishankar Muthukrishnan asym_op = op->asym; 32362fba5232SGowrishankar Muthukrishnan 32372fba5232SGowrishankar Muthukrishnan /* Setup asym xform */ 32382fba5232SGowrishankar Muthukrishnan xform.next = NULL; 32392fba5232SGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA; 32402fba5232SGowrishankar Muthukrishnan xform.ec.curve_id = input_params->curve; 32412fba5232SGowrishankar Muthukrishnan xform.ec.pkey.data = input_params->pkey.data; 32422fba5232SGowrishankar Muthukrishnan xform.ec.pkey.length = input_params->pkey.length; 32432fba5232SGowrishankar Muthukrishnan xform.ec.q.x.data = input_params->pubkey.data; 32442fba5232SGowrishankar Muthukrishnan xform.ec.q.x.length = input_params->pubkey.length; 32452fba5232SGowrishankar Muthukrishnan 32462fba5232SGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 32472fba5232SGowrishankar Muthukrishnan if (ret < 0) { 32482fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 32492fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 32502fba5232SGowrishankar Muthukrishnan "Session creation failed\n"); 32512fba5232SGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 32522fba5232SGowrishankar Muthukrishnan goto exit; 32532fba5232SGowrishankar Muthukrishnan } 32542fba5232SGowrishankar Muthukrishnan 32552fba5232SGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 32562fba5232SGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 32572fba5232SGowrishankar Muthukrishnan 32582fba5232SGowrishankar Muthukrishnan /* Compute sign */ 32592fba5232SGowrishankar Muthukrishnan 32602fba5232SGowrishankar Muthukrishnan /* Populate op with operational details */ 32612fba5232SGowrishankar Muthukrishnan asym_op->eddsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN; 32622fba5232SGowrishankar Muthukrishnan asym_op->eddsa.instance = input_params->instance; 32632fba5232SGowrishankar Muthukrishnan asym_op->eddsa.message.data = input_params->message.data; 32642fba5232SGowrishankar Muthukrishnan asym_op->eddsa.message.length = input_params->message.length; 32652fba5232SGowrishankar Muthukrishnan asym_op->eddsa.context.length = 0; 32662fba5232SGowrishankar Muthukrishnan if (ctx) { 32672fba5232SGowrishankar Muthukrishnan asym_op->eddsa.context.data = input_params->context.data; 32682fba5232SGowrishankar Muthukrishnan asym_op->eddsa.context.length = input_params->context.length; 32692fba5232SGowrishankar Muthukrishnan } 32702fba5232SGowrishankar Muthukrishnan 32712fba5232SGowrishankar Muthukrishnan /* Init out buf */ 32722fba5232SGowrishankar Muthukrishnan asym_op->eddsa.sign.data = output_buf_r; 32732fba5232SGowrishankar Muthukrishnan 32742fba5232SGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 32752fba5232SGowrishankar Muthukrishnan 32762fba5232SGowrishankar Muthukrishnan /* Process crypto operation */ 32772fba5232SGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 32782fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 32792fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 32802fba5232SGowrishankar Muthukrishnan "Error sending packet for operation\n"); 32812fba5232SGowrishankar Muthukrishnan goto exit; 32822fba5232SGowrishankar Muthukrishnan } 32832fba5232SGowrishankar Muthukrishnan 32842fba5232SGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 32852fba5232SGowrishankar Muthukrishnan rte_pause(); 32862fba5232SGowrishankar Muthukrishnan 32872fba5232SGowrishankar Muthukrishnan if (result_op == NULL) { 32882fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 32892fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 32902fba5232SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 32912fba5232SGowrishankar Muthukrishnan goto exit; 32922fba5232SGowrishankar Muthukrishnan } 32932fba5232SGowrishankar Muthukrishnan 32942fba5232SGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 32952fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 32962fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 32972fba5232SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 32982fba5232SGowrishankar Muthukrishnan goto exit; 32992fba5232SGowrishankar Muthukrishnan } 33002fba5232SGowrishankar Muthukrishnan 33012fba5232SGowrishankar Muthukrishnan asym_op = result_op->asym; 33022fba5232SGowrishankar Muthukrishnan 33032fba5232SGowrishankar Muthukrishnan debug_hexdump(stdout, "sign:", 33042fba5232SGowrishankar Muthukrishnan asym_op->eddsa.sign.data, asym_op->eddsa.sign.length); 33052fba5232SGowrishankar Muthukrishnan 33062fba5232SGowrishankar Muthukrishnan /* Verify sign (by comparison). */ 33072fba5232SGowrishankar Muthukrishnan if (memcmp(input_params->sign.data, asym_op->eddsa.sign.data, 33082fba5232SGowrishankar Muthukrishnan asym_op->eddsa.sign.length) != 0) { 33092fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 33102fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 33112fba5232SGowrishankar Muthukrishnan "EdDSA sign failed.\n"); 33122fba5232SGowrishankar Muthukrishnan goto exit; 33132fba5232SGowrishankar Muthukrishnan } 33142fba5232SGowrishankar Muthukrishnan 33152fba5232SGowrishankar Muthukrishnan status = TEST_SUCCESS; 33162fba5232SGowrishankar Muthukrishnan exit: 33172fba5232SGowrishankar Muthukrishnan if (sess != NULL) 33182fba5232SGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 33192fba5232SGowrishankar Muthukrishnan rte_crypto_op_free(op); 33202fba5232SGowrishankar Muthukrishnan return status; 33212fba5232SGowrishankar Muthukrishnan }; 33222fba5232SGowrishankar Muthukrishnan 33232fba5232SGowrishankar Muthukrishnan static int 33242fba5232SGowrishankar Muthukrishnan test_eddsa_verify(struct crypto_testsuite_eddsa_params *input_params) 33252fba5232SGowrishankar Muthukrishnan { 33262fba5232SGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 33272fba5232SGowrishankar Muthukrishnan enum rte_crypto_edward_instance instance = input_params->instance; 33282fba5232SGowrishankar Muthukrishnan struct rte_mempool *sess_mpool = ts_params->session_mpool; 33292fba5232SGowrishankar Muthukrishnan struct rte_mempool *op_mpool = ts_params->op_mpool; 33302fba5232SGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 33312fba5232SGowrishankar Muthukrishnan struct rte_crypto_op *result_op = NULL; 33322fba5232SGowrishankar Muthukrishnan struct rte_crypto_asym_xform xform; 33332fba5232SGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op; 33342fba5232SGowrishankar Muthukrishnan struct rte_crypto_op *op = NULL; 33352fba5232SGowrishankar Muthukrishnan int ret, status = TEST_FAILED; 33362fba5232SGowrishankar Muthukrishnan void *sess = NULL; 33372fba5232SGowrishankar Muthukrishnan bool ctx = false; 33382fba5232SGowrishankar Muthukrishnan 33392fba5232SGowrishankar Muthukrishnan if (instance == RTE_CRYPTO_EDCURVE_25519CTX) 33402fba5232SGowrishankar Muthukrishnan ctx = true; 33412fba5232SGowrishankar Muthukrishnan 33422fba5232SGowrishankar Muthukrishnan /* Setup crypto op data structure */ 33432fba5232SGowrishankar Muthukrishnan op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); 33442fba5232SGowrishankar Muthukrishnan if (op == NULL) { 33452fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 33462fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 33472fba5232SGowrishankar Muthukrishnan "Failed to allocate asymmetric crypto " 33482fba5232SGowrishankar Muthukrishnan "operation struct\n"); 33492fba5232SGowrishankar Muthukrishnan goto exit; 33502fba5232SGowrishankar Muthukrishnan } 33512fba5232SGowrishankar Muthukrishnan 33522fba5232SGowrishankar Muthukrishnan asym_op = op->asym; 33532fba5232SGowrishankar Muthukrishnan 33542fba5232SGowrishankar Muthukrishnan /* Setup asym xform */ 33552fba5232SGowrishankar Muthukrishnan xform.next = NULL; 33562fba5232SGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA; 33572fba5232SGowrishankar Muthukrishnan xform.ec.curve_id = input_params->curve; 33582fba5232SGowrishankar Muthukrishnan xform.ec.pkey.length = 0; 33592fba5232SGowrishankar Muthukrishnan xform.ec.q.x.data = input_params->pubkey.data; 33602fba5232SGowrishankar Muthukrishnan xform.ec.q.x.length = input_params->pubkey.length; 33612fba5232SGowrishankar Muthukrishnan 33622fba5232SGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); 33632fba5232SGowrishankar Muthukrishnan if (ret < 0) { 33642fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 33652fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 33662fba5232SGowrishankar Muthukrishnan "Session creation failed\n"); 33672fba5232SGowrishankar Muthukrishnan status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 33682fba5232SGowrishankar Muthukrishnan goto exit; 33692fba5232SGowrishankar Muthukrishnan } 33702fba5232SGowrishankar Muthukrishnan 33712fba5232SGowrishankar Muthukrishnan /* Attach asymmetric crypto session to crypto operations */ 33722fba5232SGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(op, sess); 33732fba5232SGowrishankar Muthukrishnan 33742fba5232SGowrishankar Muthukrishnan /* Compute sign */ 33752fba5232SGowrishankar Muthukrishnan 33762fba5232SGowrishankar Muthukrishnan /* Populate op with operational details */ 33772fba5232SGowrishankar Muthukrishnan asym_op->eddsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY; 33782fba5232SGowrishankar Muthukrishnan asym_op->eddsa.instance = input_params->instance; 33792fba5232SGowrishankar Muthukrishnan asym_op->eddsa.message.data = input_params->message.data; 33802fba5232SGowrishankar Muthukrishnan asym_op->eddsa.message.length = input_params->message.length; 33812fba5232SGowrishankar Muthukrishnan asym_op->eddsa.context.length = 0; 33822fba5232SGowrishankar Muthukrishnan if (ctx) { 33832fba5232SGowrishankar Muthukrishnan asym_op->eddsa.context.data = input_params->context.data; 33842fba5232SGowrishankar Muthukrishnan asym_op->eddsa.context.length = input_params->context.length; 33852fba5232SGowrishankar Muthukrishnan } 33862fba5232SGowrishankar Muthukrishnan 33872fba5232SGowrishankar Muthukrishnan asym_op->eddsa.sign.data = input_params->sign.data; 33882fba5232SGowrishankar Muthukrishnan asym_op->eddsa.sign.length = input_params->sign.length; 33892fba5232SGowrishankar Muthukrishnan 33902fba5232SGowrishankar Muthukrishnan RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); 33912fba5232SGowrishankar Muthukrishnan 33922fba5232SGowrishankar Muthukrishnan /* Process crypto operation */ 33932fba5232SGowrishankar Muthukrishnan if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { 33942fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 33952fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 33962fba5232SGowrishankar Muthukrishnan "Error sending packet for operation\n"); 33972fba5232SGowrishankar Muthukrishnan goto exit; 33982fba5232SGowrishankar Muthukrishnan } 33992fba5232SGowrishankar Muthukrishnan 34002fba5232SGowrishankar Muthukrishnan while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) 34012fba5232SGowrishankar Muthukrishnan rte_pause(); 34022fba5232SGowrishankar Muthukrishnan 34032fba5232SGowrishankar Muthukrishnan if (result_op == NULL) { 34042fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 34052fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 34062fba5232SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 34072fba5232SGowrishankar Muthukrishnan goto exit; 34082fba5232SGowrishankar Muthukrishnan } 34092fba5232SGowrishankar Muthukrishnan 34102fba5232SGowrishankar Muthukrishnan if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { 34112fba5232SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, 34122fba5232SGowrishankar Muthukrishnan "line %u FAILED: %s", __LINE__, 34132fba5232SGowrishankar Muthukrishnan "Failed to process asym crypto op\n"); 34142fba5232SGowrishankar Muthukrishnan goto exit; 34152fba5232SGowrishankar Muthukrishnan } 34162fba5232SGowrishankar Muthukrishnan 34172fba5232SGowrishankar Muthukrishnan status = TEST_SUCCESS; 34182fba5232SGowrishankar Muthukrishnan exit: 34192fba5232SGowrishankar Muthukrishnan if (sess != NULL) 34202fba5232SGowrishankar Muthukrishnan rte_cryptodev_asym_session_free(dev_id, sess); 34212fba5232SGowrishankar Muthukrishnan rte_crypto_op_free(op); 34222fba5232SGowrishankar Muthukrishnan return status; 34232fba5232SGowrishankar Muthukrishnan }; 34242fba5232SGowrishankar Muthukrishnan 34252fba5232SGowrishankar Muthukrishnan static int 34262fba5232SGowrishankar Muthukrishnan test_eddsa_sign_verify_all_curve(void) 34272fba5232SGowrishankar Muthukrishnan { 34282fba5232SGowrishankar Muthukrishnan struct crypto_testsuite_params_asym *ts_params = &testsuite_params; 34292fba5232SGowrishankar Muthukrishnan const struct rte_cryptodev_asymmetric_xform_capability *capa; 34302fba5232SGowrishankar Muthukrishnan struct crypto_testsuite_eddsa_params input_params; 34312fba5232SGowrishankar Muthukrishnan struct rte_cryptodev_asym_capability_idx idx; 34322fba5232SGowrishankar Muthukrishnan int status, overall_status = TEST_SUCCESS; 34332fba5232SGowrishankar Muthukrishnan uint8_t dev_id = ts_params->valid_devs[0]; 34342fba5232SGowrishankar Muthukrishnan uint8_t i, tc = 0; 34352fba5232SGowrishankar Muthukrishnan const char *msg; 34362fba5232SGowrishankar Muthukrishnan 34372fba5232SGowrishankar Muthukrishnan /* Check EdDSA capability */ 34382fba5232SGowrishankar Muthukrishnan idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA; 34392fba5232SGowrishankar Muthukrishnan capa = rte_cryptodev_asym_capability_get(dev_id, &idx); 34402fba5232SGowrishankar Muthukrishnan if (capa == NULL) 34412fba5232SGowrishankar Muthukrishnan return TEST_SKIPPED; 34422fba5232SGowrishankar Muthukrishnan 34432fba5232SGowrishankar Muthukrishnan /* Sign tests */ 34442fba5232SGowrishankar Muthukrishnan for (i = 0; i < RTE_DIM(eddsa_test_params); i++) { 34452fba5232SGowrishankar Muthukrishnan memcpy(&input_params, &eddsa_test_params[i], 34462fba5232SGowrishankar Muthukrishnan sizeof(input_params)); 34472fba5232SGowrishankar Muthukrishnan status = test_eddsa_sign(&input_params); 34482fba5232SGowrishankar Muthukrishnan if (status == TEST_SUCCESS) { 34492fba5232SGowrishankar Muthukrishnan msg = "succeeded"; 34502fba5232SGowrishankar Muthukrishnan } else { 34512fba5232SGowrishankar Muthukrishnan msg = "failed"; 34522fba5232SGowrishankar Muthukrishnan overall_status = status; 34532fba5232SGowrishankar Muthukrishnan } 34542fba5232SGowrishankar Muthukrishnan printf(" %u) TestCase Sign %s %s\n", 34552fba5232SGowrishankar Muthukrishnan tc++, input_params.description, msg); 34562fba5232SGowrishankar Muthukrishnan } 34572fba5232SGowrishankar Muthukrishnan 34582fba5232SGowrishankar Muthukrishnan /* Verify tests */ 34592fba5232SGowrishankar Muthukrishnan for (i = 0; i < RTE_DIM(eddsa_test_params); i++) { 34602fba5232SGowrishankar Muthukrishnan memcpy(&input_params, &eddsa_test_params[i], 34612fba5232SGowrishankar Muthukrishnan sizeof(input_params)); 34622fba5232SGowrishankar Muthukrishnan status = test_eddsa_verify(&input_params); 34632fba5232SGowrishankar Muthukrishnan if (status == TEST_SUCCESS) { 34642fba5232SGowrishankar Muthukrishnan msg = "succeeded"; 34652fba5232SGowrishankar Muthukrishnan } else { 34662fba5232SGowrishankar Muthukrishnan msg = "failed"; 34672fba5232SGowrishankar Muthukrishnan overall_status = status; 34682fba5232SGowrishankar Muthukrishnan } 34692fba5232SGowrishankar Muthukrishnan printf(" %u) TestCase Verify %s %s\n", 34702fba5232SGowrishankar Muthukrishnan tc++, input_params.description, msg); 34712fba5232SGowrishankar Muthukrishnan } 34722fba5232SGowrishankar Muthukrishnan 34732fba5232SGowrishankar Muthukrishnan /* Negative tests */ 34742fba5232SGowrishankar Muthukrishnan memcpy(&input_params, &eddsa_test_params[1], 34752fba5232SGowrishankar Muthukrishnan sizeof(input_params)); 34762fba5232SGowrishankar Muthukrishnan input_params.pubkey.data[0] ^= 0x01; 34772fba5232SGowrishankar Muthukrishnan 34782fba5232SGowrishankar Muthukrishnan status = test_eddsa_sign(&input_params); 34792fba5232SGowrishankar Muthukrishnan if (status == TEST_FAILED) { 34802fba5232SGowrishankar Muthukrishnan msg = "succeeded"; 34812fba5232SGowrishankar Muthukrishnan } else { 34822fba5232SGowrishankar Muthukrishnan msg = "failed"; 34832fba5232SGowrishankar Muthukrishnan overall_status = status; 34842fba5232SGowrishankar Muthukrishnan } 34852fba5232SGowrishankar Muthukrishnan printf(" %u) TestCase Negative Sign %s %s\n", 34862fba5232SGowrishankar Muthukrishnan tc++, input_params.description, msg); 34872fba5232SGowrishankar Muthukrishnan 34882fba5232SGowrishankar Muthukrishnan status = test_eddsa_verify(&input_params); 34892fba5232SGowrishankar Muthukrishnan if (status == TEST_FAILED) { 34902fba5232SGowrishankar Muthukrishnan msg = "succeeded"; 34912fba5232SGowrishankar Muthukrishnan } else { 34922fba5232SGowrishankar Muthukrishnan msg = "failed"; 34932fba5232SGowrishankar Muthukrishnan overall_status = status; 34942fba5232SGowrishankar Muthukrishnan } 34952fba5232SGowrishankar Muthukrishnan printf(" %u) TestCase Negative Verify %s %s\n", 34962fba5232SGowrishankar Muthukrishnan tc++, input_params.description, msg); 34972fba5232SGowrishankar Muthukrishnan 34982fba5232SGowrishankar Muthukrishnan return overall_status; 34992fba5232SGowrishankar Muthukrishnan } 35002fba5232SGowrishankar Muthukrishnan 35011ffefe00SArkadiusz Kusztal static int send_one(void) 35021ffefe00SArkadiusz Kusztal { 35031ffefe00SArkadiusz Kusztal int ticks = 0; 35041ffefe00SArkadiusz Kusztal 35051ffefe00SArkadiusz Kusztal if (rte_cryptodev_enqueue_burst(params->valid_devs[0], 0, 35061ffefe00SArkadiusz Kusztal &self->op, 1) != 1) { 35071ffefe00SArkadiusz Kusztal RTE_LOG(ERR, USER1, 35081ffefe00SArkadiusz Kusztal "line %u FAILED: Error sending packet for operation on device %d", 35091ffefe00SArkadiusz Kusztal __LINE__, params->valid_devs[0]); 35101ffefe00SArkadiusz Kusztal return TEST_FAILED; 35111ffefe00SArkadiusz Kusztal } 35121ffefe00SArkadiusz Kusztal while (rte_cryptodev_dequeue_burst(params->valid_devs[0], 0, 35131ffefe00SArkadiusz Kusztal &self->result_op, 1) == 0) { 35141ffefe00SArkadiusz Kusztal rte_delay_ms(1); 35151ffefe00SArkadiusz Kusztal ticks++; 35161ffefe00SArkadiusz Kusztal if (ticks >= DEQ_TIMEOUT) { 35171ffefe00SArkadiusz Kusztal RTE_LOG(ERR, USER1, 35181ffefe00SArkadiusz Kusztal "line %u FAILED: Cannot dequeue the crypto op on device %d", 35191ffefe00SArkadiusz Kusztal __LINE__, params->valid_devs[0]); 35201ffefe00SArkadiusz Kusztal return TEST_FAILED; 35211ffefe00SArkadiusz Kusztal } 35221ffefe00SArkadiusz Kusztal } 35231ffefe00SArkadiusz Kusztal TEST_ASSERT_NOT_NULL(self->result_op, 35241ffefe00SArkadiusz Kusztal "Failed to process asym crypto op"); 35251ffefe00SArkadiusz Kusztal TEST_ASSERT_SUCCESS(self->result_op->status, 35261ffefe00SArkadiusz Kusztal "Failed to process asym crypto op, error status received"); 35271ffefe00SArkadiusz Kusztal return TEST_SUCCESS; 35281ffefe00SArkadiusz Kusztal } 35291ffefe00SArkadiusz Kusztal 35301ffefe00SArkadiusz Kusztal static int 3531cc42abd1SGowrishankar Muthukrishnan modular_cmpeq(const uint8_t *a, size_t a_len, const uint8_t *b, size_t b_len) 35322162d32cSGowrishankar Muthukrishnan { 3533cc42abd1SGowrishankar Muthukrishnan const uint8_t *new_a, *new_b; 35342162d32cSGowrishankar Muthukrishnan size_t i, j; 35352162d32cSGowrishankar Muthukrishnan 35362162d32cSGowrishankar Muthukrishnan /* Strip leading NUL bytes */ 3537cc42abd1SGowrishankar Muthukrishnan for (i = 0; i < a_len; i++) 35382162d32cSGowrishankar Muthukrishnan if (a[i] != 0) 3539cc42abd1SGowrishankar Muthukrishnan break; 35402162d32cSGowrishankar Muthukrishnan 3541cc42abd1SGowrishankar Muthukrishnan for (j = 0; j < b_len; j++) 35422162d32cSGowrishankar Muthukrishnan if (b[j] != 0) 3543cc42abd1SGowrishankar Muthukrishnan break; 35442162d32cSGowrishankar Muthukrishnan 3545cc42abd1SGowrishankar Muthukrishnan if (a_len - i != b_len - j) 3546cc42abd1SGowrishankar Muthukrishnan return 1; 3547cc42abd1SGowrishankar Muthukrishnan 3548cc42abd1SGowrishankar Muthukrishnan new_a = &a[i]; 3549cc42abd1SGowrishankar Muthukrishnan new_b = &b[j]; 3550cc42abd1SGowrishankar Muthukrishnan if (memcmp(new_a, new_b, a_len - i)) 35512162d32cSGowrishankar Muthukrishnan return 1; 35522162d32cSGowrishankar Muthukrishnan 35532162d32cSGowrishankar Muthukrishnan return 0; 35542162d32cSGowrishankar Muthukrishnan } 35552162d32cSGowrishankar Muthukrishnan 35562162d32cSGowrishankar Muthukrishnan static int 35571ffefe00SArkadiusz Kusztal modular_exponentiation(const void *test_data) 35581ffefe00SArkadiusz Kusztal { 35591ffefe00SArkadiusz Kusztal const struct modex_test_data *vector = test_data; 35601ffefe00SArkadiusz Kusztal uint8_t input[TEST_DATA_SIZE] = { 0 }; 35611ffefe00SArkadiusz Kusztal uint8_t exponent[TEST_DATA_SIZE] = { 0 }; 35621ffefe00SArkadiusz Kusztal uint8_t modulus[TEST_DATA_SIZE] = { 0 }; 35631ffefe00SArkadiusz Kusztal uint8_t result[TEST_DATA_SIZE] = { 0 }; 35641ffefe00SArkadiusz Kusztal struct rte_crypto_asym_xform xform = { }; 35651ffefe00SArkadiusz Kusztal const uint8_t dev_id = params->valid_devs[0]; 35661ffefe00SArkadiusz Kusztal 35671ffefe00SArkadiusz Kusztal memcpy(input, vector->base.data, vector->base.len); 35681ffefe00SArkadiusz Kusztal memcpy(exponent, vector->exponent.data, vector->exponent.len); 35691ffefe00SArkadiusz Kusztal memcpy(modulus, vector->modulus.data, vector->modulus.len); 35701ffefe00SArkadiusz Kusztal 35711ffefe00SArkadiusz Kusztal xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX; 35721ffefe00SArkadiusz Kusztal xform.modex.exponent.data = exponent; 35731ffefe00SArkadiusz Kusztal xform.modex.exponent.length = vector->exponent.len; 35741ffefe00SArkadiusz Kusztal xform.modex.modulus.data = modulus; 35751ffefe00SArkadiusz Kusztal xform.modex.modulus.length = vector->modulus.len; 35761ffefe00SArkadiusz Kusztal 35771ffefe00SArkadiusz Kusztal if (rte_cryptodev_asym_session_create(dev_id, &xform, 35781ffefe00SArkadiusz Kusztal params->session_mpool, &self->sess) < 0) { 35791ffefe00SArkadiusz Kusztal RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed", 35801ffefe00SArkadiusz Kusztal __LINE__); 35811ffefe00SArkadiusz Kusztal return TEST_FAILED; 35821ffefe00SArkadiusz Kusztal } 35831ffefe00SArkadiusz Kusztal rte_crypto_op_attach_asym_session(self->op, self->sess); 35841ffefe00SArkadiusz Kusztal self->op->asym->modex.base.data = input; 35851ffefe00SArkadiusz Kusztal self->op->asym->modex.base.length = vector->base.len; 35861ffefe00SArkadiusz Kusztal self->op->asym->modex.result.data = result; 35871ffefe00SArkadiusz Kusztal 35881ffefe00SArkadiusz Kusztal TEST_ASSERT_SUCCESS(send_one(), 35891ffefe00SArkadiusz Kusztal "Failed to process crypto op"); 3590cc42abd1SGowrishankar Muthukrishnan TEST_ASSERT_SUCCESS(modular_cmpeq(vector->reminder.data, vector->reminder.len, 35911ffefe00SArkadiusz Kusztal self->result_op->asym->modex.result.data, 35922162d32cSGowrishankar Muthukrishnan self->result_op->asym->modex.result.length), 35931ffefe00SArkadiusz Kusztal "operation verification failed\n"); 35941ffefe00SArkadiusz Kusztal 35951ffefe00SArkadiusz Kusztal return TEST_SUCCESS; 35961ffefe00SArkadiusz Kusztal } 35971ffefe00SArkadiusz Kusztal 35981ffefe00SArkadiusz Kusztal static int 35991ffefe00SArkadiusz Kusztal modular_multiplicative_inverse(const void *test_data) 36001ffefe00SArkadiusz Kusztal { 36011ffefe00SArkadiusz Kusztal const struct modinv_test_data *vector = test_data; 36021ffefe00SArkadiusz Kusztal uint8_t input[TEST_DATA_SIZE] = { 0 }; 36031ffefe00SArkadiusz Kusztal uint8_t modulus[TEST_DATA_SIZE] = { 0 }; 36041ffefe00SArkadiusz Kusztal uint8_t result[TEST_DATA_SIZE] = { 0 }; 36051ffefe00SArkadiusz Kusztal struct rte_crypto_asym_xform xform = { }; 36061ffefe00SArkadiusz Kusztal const uint8_t dev_id = params->valid_devs[0]; 36071ffefe00SArkadiusz Kusztal 36081ffefe00SArkadiusz Kusztal memcpy(input, vector->base.data, vector->base.len); 36091ffefe00SArkadiusz Kusztal memcpy(modulus, vector->modulus.data, vector->modulus.len); 36101ffefe00SArkadiusz Kusztal xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODINV; 36111ffefe00SArkadiusz Kusztal xform.modex.modulus.data = modulus; 36121ffefe00SArkadiusz Kusztal xform.modex.modulus.length = vector->modulus.len; 36131ffefe00SArkadiusz Kusztal if (rte_cryptodev_asym_session_create(dev_id, &xform, 36141ffefe00SArkadiusz Kusztal params->session_mpool, &self->sess) < 0) { 36151ffefe00SArkadiusz Kusztal RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed", 36161ffefe00SArkadiusz Kusztal __LINE__); 36171ffefe00SArkadiusz Kusztal return TEST_FAILED; 36181ffefe00SArkadiusz Kusztal } 36191ffefe00SArkadiusz Kusztal rte_crypto_op_attach_asym_session(self->op, self->sess); 36201ffefe00SArkadiusz Kusztal 36211ffefe00SArkadiusz Kusztal self->op->asym->modinv.base.data = input; 36221ffefe00SArkadiusz Kusztal self->op->asym->modinv.base.length = vector->base.len; 36231ffefe00SArkadiusz Kusztal self->op->asym->modinv.result.data = result; 36241ffefe00SArkadiusz Kusztal self->op->asym->modinv.result.length = vector->modulus.len; 36251ffefe00SArkadiusz Kusztal 36261ffefe00SArkadiusz Kusztal TEST_ASSERT_SUCCESS(send_one(), 36271ffefe00SArkadiusz Kusztal "Failed to process crypto op"); 36281ffefe00SArkadiusz Kusztal TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->inverse.data, 36291ffefe00SArkadiusz Kusztal self->result_op->asym->modinv.result.data, 36301ffefe00SArkadiusz Kusztal self->result_op->asym->modinv.result.length, 36311ffefe00SArkadiusz Kusztal "Incorrect reminder\n"); 36321ffefe00SArkadiusz Kusztal 36331ffefe00SArkadiusz Kusztal return TEST_SUCCESS; 36341ffefe00SArkadiusz Kusztal } 36351ffefe00SArkadiusz Kusztal 36369b546586SArkadiusz Kusztal #define SET_RSA_PARAM(arg, vector, coef) \ 36379b546586SArkadiusz Kusztal uint8_t coef[TEST_DATA_SIZE] = { }; \ 36389b546586SArkadiusz Kusztal memcpy(coef, vector->coef.data, vector->coef.len); \ 36399b546586SArkadiusz Kusztal arg.coef.data = coef; \ 36409b546586SArkadiusz Kusztal arg.coef.length = vector->coef.len 36419b546586SArkadiusz Kusztal 36429b546586SArkadiusz Kusztal #define SET_RSA_PARAM_QT(arg, vector, coef) \ 36439b546586SArkadiusz Kusztal uint8_t coef[TEST_DATA_SIZE] = { }; \ 36449b546586SArkadiusz Kusztal memcpy(coef, vector->coef.data, vector->coef.len); \ 36459b546586SArkadiusz Kusztal arg.qt.coef.data = coef; \ 36469b546586SArkadiusz Kusztal arg.qt.coef.length = vector->coef.len 36479b546586SArkadiusz Kusztal 36489b546586SArkadiusz Kusztal static int 3649226f1ca0SArkadiusz Kusztal rsa_encrypt(const struct rsa_test_data_2 *vector, uint8_t *cipher_buf) 36509b546586SArkadiusz Kusztal { 36519b546586SArkadiusz Kusztal self->result_op = NULL; 36529b546586SArkadiusz Kusztal /* Compute encryption on the test vector */ 36539b546586SArkadiusz Kusztal self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT; 36549b546586SArkadiusz Kusztal self->op->asym->rsa.cipher.data = cipher_buf; 36559b546586SArkadiusz Kusztal self->op->asym->rsa.cipher.length = 0; 36569b546586SArkadiusz Kusztal SET_RSA_PARAM(self->op->asym->rsa, vector, message); 36579b546586SArkadiusz Kusztal 36589b546586SArkadiusz Kusztal rte_crypto_op_attach_asym_session(self->op, self->sess); 36599b546586SArkadiusz Kusztal TEST_ASSERT_SUCCESS(send_one(), 36609b546586SArkadiusz Kusztal "Failed to process crypto op (Enryption)"); 36619b546586SArkadiusz Kusztal 36629b546586SArkadiusz Kusztal return 0; 36639b546586SArkadiusz Kusztal } 36649b546586SArkadiusz Kusztal 36659b546586SArkadiusz Kusztal static int 3666226f1ca0SArkadiusz Kusztal rsa_decrypt(const struct rsa_test_data_2 *vector, uint8_t *plaintext, 36679b546586SArkadiusz Kusztal const int use_op) 36689b546586SArkadiusz Kusztal { 36699b546586SArkadiusz Kusztal uint8_t cipher[TEST_DATA_SIZE] = { 0 }; 36709b546586SArkadiusz Kusztal 36719b546586SArkadiusz Kusztal if (use_op == 0) { 36729b546586SArkadiusz Kusztal memcpy(cipher, vector->cipher.data, vector->cipher.len); 36739b546586SArkadiusz Kusztal self->op->asym->rsa.cipher.data = cipher; 36749b546586SArkadiusz Kusztal self->op->asym->rsa.cipher.length = vector->cipher.len; 36759b546586SArkadiusz Kusztal } 36769b546586SArkadiusz Kusztal self->result_op = NULL; 36779b546586SArkadiusz Kusztal self->op->asym->rsa.message.data = plaintext; 36789b546586SArkadiusz Kusztal self->op->asym->rsa.message.length = 0; 36799b546586SArkadiusz Kusztal self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT; 36809b546586SArkadiusz Kusztal rte_crypto_op_attach_asym_session(self->op, self->sess); 36819b546586SArkadiusz Kusztal TEST_ASSERT_SUCCESS(send_one(), 36829b546586SArkadiusz Kusztal "Failed to process crypto op (Decryption)"); 36839b546586SArkadiusz Kusztal return 0; 36849b546586SArkadiusz Kusztal } 36859b546586SArkadiusz Kusztal 36869b546586SArkadiusz Kusztal static int 3687226f1ca0SArkadiusz Kusztal rsa_init_session(struct rte_crypto_asym_xform *xform) 36889b546586SArkadiusz Kusztal { 36899b546586SArkadiusz Kusztal const uint8_t dev_id = params->valid_devs[0]; 36909b546586SArkadiusz Kusztal struct rte_cryptodev_info dev_info; 36919b546586SArkadiusz Kusztal int ret = 0; 36929b546586SArkadiusz Kusztal 3693226f1ca0SArkadiusz Kusztal xform->xform_type = RTE_CRYPTO_ASYM_XFORM_RSA; 36949b546586SArkadiusz Kusztal 36959b546586SArkadiusz Kusztal rte_cryptodev_info_get(dev_id, &dev_info); 36969b546586SArkadiusz Kusztal if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) { 36979b546586SArkadiusz Kusztal RTE_LOG(INFO, USER1, 36989b546586SArkadiusz Kusztal "Device doesn't support decrypt op with quintuple key type. Test skipped\n"); 36999b546586SArkadiusz Kusztal return TEST_SKIPPED; 37009b546586SArkadiusz Kusztal } 3701226f1ca0SArkadiusz Kusztal ret = rte_cryptodev_asym_session_create(dev_id, xform, 37029b546586SArkadiusz Kusztal params->session_mpool, &self->sess); 37039b546586SArkadiusz Kusztal if (ret < 0) { 37049b546586SArkadiusz Kusztal RTE_LOG(ERR, USER1, 37059b546586SArkadiusz Kusztal "Session creation failed for enc_dec_crt\n"); 37069b546586SArkadiusz Kusztal return (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; 37079b546586SArkadiusz Kusztal } 37089b546586SArkadiusz Kusztal return 0; 37099b546586SArkadiusz Kusztal } 37109b546586SArkadiusz Kusztal 37119b546586SArkadiusz Kusztal static int 3712226f1ca0SArkadiusz Kusztal kat_rsa_encrypt(const void *data) 37139b546586SArkadiusz Kusztal { 37149b546586SArkadiusz Kusztal uint8_t cipher_buf[TEST_DATA_SIZE] = {0}; 37159b546586SArkadiusz Kusztal const struct rsa_test_data_2 *vector = data; 3716226f1ca0SArkadiusz Kusztal struct rte_crypto_asym_xform xform = { }; 3717226f1ca0SArkadiusz Kusztal 3718226f1ca0SArkadiusz Kusztal SET_RSA_PARAM(xform.rsa, vector, n); 3719226f1ca0SArkadiusz Kusztal SET_RSA_PARAM(xform.rsa, vector, e); 3720226f1ca0SArkadiusz Kusztal SET_RSA_PARAM(xform.rsa, vector, d); 37218a97564bSGowrishankar Muthukrishnan xform.rsa.padding.type = vector->padding; 3722226f1ca0SArkadiusz Kusztal xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP; 3723226f1ca0SArkadiusz Kusztal int ret = rsa_init_session(&xform); 37249b546586SArkadiusz Kusztal 37259b546586SArkadiusz Kusztal if (ret) { 37269b546586SArkadiusz Kusztal RTE_LOG(ERR, USER1, "Failed to init session for RSA\n"); 37279b546586SArkadiusz Kusztal return ret; 37289b546586SArkadiusz Kusztal } 3729226f1ca0SArkadiusz Kusztal TEST_ASSERT_SUCCESS(rsa_encrypt(vector, cipher_buf), 37309b546586SArkadiusz Kusztal "RSA: Failed to encrypt"); 37319b546586SArkadiusz Kusztal TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data, 37329b546586SArkadiusz Kusztal self->result_op->asym->rsa.cipher.data, 37339b546586SArkadiusz Kusztal self->result_op->asym->rsa.cipher.length, 37349b546586SArkadiusz Kusztal "operation verification failed\n"); 37359b546586SArkadiusz Kusztal return 0; 37369b546586SArkadiusz Kusztal } 37379b546586SArkadiusz Kusztal 37389b546586SArkadiusz Kusztal static int 3739226f1ca0SArkadiusz Kusztal kat_rsa_encrypt_crt(const void *data) 37409b546586SArkadiusz Kusztal { 37419b546586SArkadiusz Kusztal uint8_t cipher_buf[TEST_DATA_SIZE] = {0}; 37429b546586SArkadiusz Kusztal const struct rsa_test_data_2 *vector = data; 3743226f1ca0SArkadiusz Kusztal struct rte_crypto_asym_xform xform = { }; 37449b546586SArkadiusz Kusztal 3745226f1ca0SArkadiusz Kusztal SET_RSA_PARAM(xform.rsa, vector, n); 3746226f1ca0SArkadiusz Kusztal SET_RSA_PARAM(xform.rsa, vector, e); 3747226f1ca0SArkadiusz Kusztal SET_RSA_PARAM_QT(xform.rsa, vector, p); 3748226f1ca0SArkadiusz Kusztal SET_RSA_PARAM_QT(xform.rsa, vector, q); 3749226f1ca0SArkadiusz Kusztal SET_RSA_PARAM_QT(xform.rsa, vector, dP); 3750226f1ca0SArkadiusz Kusztal SET_RSA_PARAM_QT(xform.rsa, vector, dQ); 3751226f1ca0SArkadiusz Kusztal SET_RSA_PARAM_QT(xform.rsa, vector, qInv); 37528a97564bSGowrishankar Muthukrishnan xform.rsa.padding.type = vector->padding; 3753226f1ca0SArkadiusz Kusztal xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT; 3754226f1ca0SArkadiusz Kusztal int ret = rsa_init_session(&xform); 37559b546586SArkadiusz Kusztal if (ret) { 37569b546586SArkadiusz Kusztal RTE_LOG(ERR, USER1, "Failed to init session for RSA\n"); 37579b546586SArkadiusz Kusztal return ret; 37589b546586SArkadiusz Kusztal } 3759226f1ca0SArkadiusz Kusztal TEST_ASSERT_SUCCESS(rsa_encrypt(vector, cipher_buf), 37609b546586SArkadiusz Kusztal "RSA: Failed to encrypt"); 37619b546586SArkadiusz Kusztal TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data, 37629b546586SArkadiusz Kusztal self->result_op->asym->rsa.cipher.data, 37639b546586SArkadiusz Kusztal self->result_op->asym->rsa.cipher.length, 37649b546586SArkadiusz Kusztal "operation verification failed\n"); 37659b546586SArkadiusz Kusztal return 0; 37669b546586SArkadiusz Kusztal } 37679b546586SArkadiusz Kusztal 37689b546586SArkadiusz Kusztal static int 3769226f1ca0SArkadiusz Kusztal kat_rsa_decrypt(const void *data) 37709b546586SArkadiusz Kusztal { 37719b546586SArkadiusz Kusztal uint8_t message[TEST_DATA_SIZE] = {0}; 37729b546586SArkadiusz Kusztal const struct rsa_test_data_2 *vector = data; 3773226f1ca0SArkadiusz Kusztal struct rte_crypto_asym_xform xform = { }; 3774226f1ca0SArkadiusz Kusztal 3775226f1ca0SArkadiusz Kusztal SET_RSA_PARAM(xform.rsa, vector, n); 3776226f1ca0SArkadiusz Kusztal SET_RSA_PARAM(xform.rsa, vector, e); 3777226f1ca0SArkadiusz Kusztal SET_RSA_PARAM(xform.rsa, vector, d); 37788a97564bSGowrishankar Muthukrishnan xform.rsa.padding.type = vector->padding; 3779226f1ca0SArkadiusz Kusztal xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP; 3780226f1ca0SArkadiusz Kusztal int ret = rsa_init_session(&xform); 37819b546586SArkadiusz Kusztal 37829b546586SArkadiusz Kusztal if (ret) { 37839b546586SArkadiusz Kusztal RTE_LOG(ERR, USER1, "Failed to init session for RSA\n"); 37849b546586SArkadiusz Kusztal return ret; 37859b546586SArkadiusz Kusztal } 3786226f1ca0SArkadiusz Kusztal TEST_ASSERT_SUCCESS(rsa_decrypt(vector, message, 0), 37879b546586SArkadiusz Kusztal "RSA: Failed to encrypt"); 37889b546586SArkadiusz Kusztal TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->message.data, 37899b546586SArkadiusz Kusztal self->result_op->asym->rsa.message.data, 37909b546586SArkadiusz Kusztal self->result_op->asym->rsa.message.length, 37919b546586SArkadiusz Kusztal "operation verification failed\n"); 37929b546586SArkadiusz Kusztal return 0; 37939b546586SArkadiusz Kusztal } 37949b546586SArkadiusz Kusztal 37959b546586SArkadiusz Kusztal static int 3796226f1ca0SArkadiusz Kusztal kat_rsa_decrypt_crt(const void *data) 37979b546586SArkadiusz Kusztal { 37989b546586SArkadiusz Kusztal uint8_t message[TEST_DATA_SIZE] = {0}; 37999b546586SArkadiusz Kusztal const struct rsa_test_data_2 *vector = data; 3800226f1ca0SArkadiusz Kusztal struct rte_crypto_asym_xform xform = { }; 38019b546586SArkadiusz Kusztal 3802226f1ca0SArkadiusz Kusztal SET_RSA_PARAM(xform.rsa, vector, n); 3803226f1ca0SArkadiusz Kusztal SET_RSA_PARAM(xform.rsa, vector, e); 3804226f1ca0SArkadiusz Kusztal SET_RSA_PARAM_QT(xform.rsa, vector, p); 3805226f1ca0SArkadiusz Kusztal SET_RSA_PARAM_QT(xform.rsa, vector, q); 3806226f1ca0SArkadiusz Kusztal SET_RSA_PARAM_QT(xform.rsa, vector, dP); 3807226f1ca0SArkadiusz Kusztal SET_RSA_PARAM_QT(xform.rsa, vector, dQ); 3808226f1ca0SArkadiusz Kusztal SET_RSA_PARAM_QT(xform.rsa, vector, qInv); 38098a97564bSGowrishankar Muthukrishnan xform.rsa.padding.type = vector->padding; 3810226f1ca0SArkadiusz Kusztal xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT; 3811226f1ca0SArkadiusz Kusztal int ret = rsa_init_session(&xform); 38129b546586SArkadiusz Kusztal if (ret) { 38139b546586SArkadiusz Kusztal RTE_LOG(ERR, USER1, "Failed to init session for RSA\n"); 38149b546586SArkadiusz Kusztal return ret; 38159b546586SArkadiusz Kusztal } 3816226f1ca0SArkadiusz Kusztal TEST_ASSERT_SUCCESS(rsa_decrypt(vector, message, 0), 38179b546586SArkadiusz Kusztal "RSA: Failed to encrypt"); 38189b546586SArkadiusz Kusztal TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->message.data, 38199b546586SArkadiusz Kusztal self->result_op->asym->rsa.message.data, 38209b546586SArkadiusz Kusztal self->result_op->asym->rsa.message.length, 38219b546586SArkadiusz Kusztal "operation verification failed\n"); 38229b546586SArkadiusz Kusztal return 0; 38239b546586SArkadiusz Kusztal } 38249b546586SArkadiusz Kusztal 3825a9de470cSBruce Richardson static struct unit_test_suite cryptodev_openssl_asym_testsuite = { 3826a9de470cSBruce Richardson .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite", 3827a9de470cSBruce Richardson .setup = testsuite_setup, 3828a9de470cSBruce Richardson .teardown = testsuite_teardown, 3829a9de470cSBruce Richardson .unit_test_cases = { 3830da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability), 3831da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dsa), 3832da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, 3833ea7b0e1aSSivaramakrishnan Venkat test_dh_key_generation), 38342eef1a64SGowrishankar Muthukrishnan TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign), 38352d970c66SGowrishankar Muthukrishnan TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify), 38362eef1a64SGowrishankar Muthukrishnan TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_enc), 38372d970c66SGowrishankar Muthukrishnan TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_dec), 3838da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec), 3839da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, 3840da74df7dSCiara Power test_rsa_sign_verify), 3841da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, 3842da74df7dSCiara Power test_rsa_enc_dec_crt), 3843da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, 3844da74df7dSCiara Power test_rsa_sign_verify_crt), 3845da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv), 3846da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp), 38471ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 3848efcc8d93SGowrishankar Muthukrishnan "Modex test for zero padding", 3849efcc8d93SGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 3850efcc8d93SGowrishankar Muthukrishnan modular_exponentiation, &modex_test_cases[0]), 3851efcc8d93SGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 3852efcc8d93SGowrishankar Muthukrishnan "Modex test for zero padding (2)", 3853efcc8d93SGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 3854efcc8d93SGowrishankar Muthukrishnan modular_exponentiation, &modex_test_cases[1]), 3855efcc8d93SGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 38561ee76d3aSGowrishankar Muthukrishnan "Modex Group 5 test", 38571ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 38581ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[0]), 38591ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 38601ee76d3aSGowrishankar Muthukrishnan "Modex Group 14 test", 38611ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 38621ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[1]), 38631ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 38641ee76d3aSGowrishankar Muthukrishnan "Modex Group 15 test", 38651ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 38661ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[2]), 38671ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 38681ee76d3aSGowrishankar Muthukrishnan "Modex Group 16 test", 38691ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 38701ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[3]), 38711ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 38721ee76d3aSGowrishankar Muthukrishnan "Modex Group 17 test", 38731ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 38741ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[4]), 38751ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 38761ee76d3aSGowrishankar Muthukrishnan "Modex Group 18 test", 38771ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 38781ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[5]), 38792fba5232SGowrishankar Muthukrishnan TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_eddsa_sign_verify_all_curve), 3880488f5a23SDamian Nowak TEST_CASES_END() /**< NULL terminate unit test array */ 3881488f5a23SDamian Nowak } 3882488f5a23SDamian Nowak }; 3883488f5a23SDamian Nowak 3884488f5a23SDamian Nowak static struct unit_test_suite cryptodev_qat_asym_testsuite = { 3885488f5a23SDamian Nowak .suite_name = "Crypto Device QAT ASYM Unit Test Suite", 3886488f5a23SDamian Nowak .setup = testsuite_setup, 3887488f5a23SDamian Nowak .teardown = testsuite_teardown, 3888488f5a23SDamian Nowak .unit_test_cases = { 38891ffefe00SArkadiusz Kusztal TEST_CASE_NAMED_WITH_DATA( 38901ffefe00SArkadiusz Kusztal "Modular Exponentiation (mod=128, base=20, exp=3, res=128)", 38911ffefe00SArkadiusz Kusztal ut_setup_asym, ut_teardown_asym, 38921ffefe00SArkadiusz Kusztal modular_exponentiation, &modex_test_case_m128_b20_e3), 38931ffefe00SArkadiusz Kusztal /* Modular Multiplicative Inverse */ 38941ffefe00SArkadiusz Kusztal TEST_CASE_NAMED_WITH_DATA( 38951ffefe00SArkadiusz Kusztal "Modular Inverse (mod=128, base=20, exp=3, inv=128)", 38961ffefe00SArkadiusz Kusztal ut_setup_asym, ut_teardown_asym, 38971ffefe00SArkadiusz Kusztal modular_multiplicative_inverse, &modinv_test_case), 38989b546586SArkadiusz Kusztal /* RSA EXP */ 38999b546586SArkadiusz Kusztal TEST_CASE_NAMED_WITH_DATA( 39009b546586SArkadiusz Kusztal "RSA Encryption (n=128, pt=20, e=3) EXP, Padding: NONE", 39019b546586SArkadiusz Kusztal ut_setup_asym, ut_teardown_asym, 3902226f1ca0SArkadiusz Kusztal kat_rsa_encrypt, &rsa_vector_128_20_3_none), 39039b546586SArkadiusz Kusztal TEST_CASE_NAMED_WITH_DATA( 39049b546586SArkadiusz Kusztal "RSA Decryption (n=128, pt=20, e=3) EXP, Padding: NONE", 39059b546586SArkadiusz Kusztal ut_setup_asym, ut_teardown_asym, 3906226f1ca0SArkadiusz Kusztal kat_rsa_decrypt, &rsa_vector_128_20_3_none), 39079b546586SArkadiusz Kusztal /* RSA CRT */ 39089b546586SArkadiusz Kusztal TEST_CASE_NAMED_WITH_DATA( 39099b546586SArkadiusz Kusztal "RSA Encryption (n=128, pt=20, e=3) CRT, Padding: NONE", 39109b546586SArkadiusz Kusztal ut_setup_asym, ut_teardown_asym, 3911226f1ca0SArkadiusz Kusztal kat_rsa_encrypt_crt, &rsa_vector_128_20_3_none), 39129b546586SArkadiusz Kusztal TEST_CASE_NAMED_WITH_DATA( 39139b546586SArkadiusz Kusztal "RSA Decryption (n=128, pt=20, e=3) CRT, Padding: NONE", 39149b546586SArkadiusz Kusztal ut_setup_asym, ut_teardown_asym, 3915226f1ca0SArkadiusz Kusztal kat_rsa_decrypt_crt, &rsa_vector_128_20_3_none), 3916a9de470cSBruce Richardson TEST_CASES_END() /**< NULL terminate unit test array */ 3917a9de470cSBruce Richardson } 3918a9de470cSBruce Richardson }; 3919a9de470cSBruce Richardson 392088d664aaSSunila Sahu static struct unit_test_suite cryptodev_octeontx_asym_testsuite = { 392188d664aaSSunila Sahu .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite", 392288d664aaSSunila Sahu .setup = testsuite_setup, 392388d664aaSSunila Sahu .teardown = testsuite_teardown, 392488d664aaSSunila Sahu .unit_test_cases = { 3925da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability), 3926da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, 3927da74df7dSCiara Power test_rsa_enc_dec_crt), 3928da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, 3929da74df7dSCiara Power test_rsa_sign_verify_crt), 3930da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp), 39311ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 3932efcc8d93SGowrishankar Muthukrishnan "Modex test for zero padding", 3933efcc8d93SGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 3934efcc8d93SGowrishankar Muthukrishnan modular_exponentiation, &modex_test_cases[0]), 3935efcc8d93SGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 3936efcc8d93SGowrishankar Muthukrishnan "Modex test for zero padding (2)", 3937efcc8d93SGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 3938efcc8d93SGowrishankar Muthukrishnan modular_exponentiation, &modex_test_cases[1]), 3939efcc8d93SGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 39401ee76d3aSGowrishankar Muthukrishnan "Modex Group 5 test", 39411ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 39421ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[0]), 39431ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 39441ee76d3aSGowrishankar Muthukrishnan "Modex Group 14 test", 39451ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 39461ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[1]), 39471ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 39481ee76d3aSGowrishankar Muthukrishnan "Modex Group 15 test", 39491ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 39501ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[2]), 39511ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 39521ee76d3aSGowrishankar Muthukrishnan "Modex Group 16 test", 39531ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 39541ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[3]), 39551ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 39561ee76d3aSGowrishankar Muthukrishnan "Modex Group 17 test", 39571ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 39581ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[4]), 39591ee76d3aSGowrishankar Muthukrishnan TEST_CASE_NAMED_WITH_DATA( 39601ee76d3aSGowrishankar Muthukrishnan "Modex Group 18 test", 39611ee76d3aSGowrishankar Muthukrishnan ut_setup_asym, ut_teardown_asym, 39621ee76d3aSGowrishankar Muthukrishnan modular_exponentiation, &modex_group_test_cases[5]), 3963da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, 3964d90e58a7SAyuj Verma test_ecdsa_sign_verify_all_curve), 39652eef1a64SGowrishankar Muthukrishnan TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign), 39662eef1a64SGowrishankar Muthukrishnan TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify), 3967da74df7dSCiara Power TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, 396831dd9ddfSGowrishankar Muthukrishnan test_ecdh_all_curve), 396931dd9ddfSGowrishankar Muthukrishnan TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, 3970da74df7dSCiara Power test_ecpm_all_curve), 39712fba5232SGowrishankar Muthukrishnan TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_eddsa_sign_verify_all_curve), 397288d664aaSSunila Sahu TEST_CASES_END() /**< NULL terminate unit test array */ 397388d664aaSSunila Sahu } 397488d664aaSSunila Sahu }; 397588d664aaSSunila Sahu 3976a9de470cSBruce Richardson static int 3977a9de470cSBruce Richardson test_cryptodev_openssl_asym(void) 3978a9de470cSBruce Richardson { 3979a9de470cSBruce Richardson gbl_driver_id = rte_cryptodev_driver_id_get( 3980a9de470cSBruce Richardson RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)); 3981a9de470cSBruce Richardson 3982a9de470cSBruce Richardson if (gbl_driver_id == -1) { 3983c2c92c5dSCiara Power RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n"); 398477222f30SCiara Power return TEST_SKIPPED; 3985a9de470cSBruce Richardson } 3986a9de470cSBruce Richardson 3987a9de470cSBruce Richardson return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite); 3988a9de470cSBruce Richardson } 3989a9de470cSBruce Richardson 3990488f5a23SDamian Nowak static int 3991488f5a23SDamian Nowak test_cryptodev_qat_asym(void) 3992488f5a23SDamian Nowak { 3993488f5a23SDamian Nowak gbl_driver_id = rte_cryptodev_driver_id_get( 3994488f5a23SDamian Nowak RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD)); 3995488f5a23SDamian Nowak 3996488f5a23SDamian Nowak if (gbl_driver_id == -1) { 3997c2c92c5dSCiara Power RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n"); 399877222f30SCiara Power return TEST_SKIPPED; 3999488f5a23SDamian Nowak } 4000488f5a23SDamian Nowak 4001488f5a23SDamian Nowak return unit_test_suite_runner(&cryptodev_qat_asym_testsuite); 4002488f5a23SDamian Nowak } 4003488f5a23SDamian Nowak 400488d664aaSSunila Sahu static int 400588d664aaSSunila Sahu test_cryptodev_octeontx_asym(void) 400688d664aaSSunila Sahu { 400788d664aaSSunila Sahu gbl_driver_id = rte_cryptodev_driver_id_get( 400888d664aaSSunila Sahu RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD)); 400988d664aaSSunila Sahu if (gbl_driver_id == -1) { 4010c2c92c5dSCiara Power RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n"); 401177222f30SCiara Power return TEST_SKIPPED; 401288d664aaSSunila Sahu } 401388d664aaSSunila Sahu return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite); 401488d664aaSSunila Sahu } 401588d664aaSSunila Sahu 4016116e447aSSunila Sahu static int 4017c7e6ab78SKiran Kumar K test_cryptodev_cn9k_asym(void) 4018c7e6ab78SKiran Kumar K { 4019c7e6ab78SKiran Kumar K gbl_driver_id = rte_cryptodev_driver_id_get( 4020c7e6ab78SKiran Kumar K RTE_STR(CRYPTODEV_NAME_CN9K_PMD)); 4021c7e6ab78SKiran Kumar K if (gbl_driver_id == -1) { 4022c7e6ab78SKiran Kumar K RTE_LOG(ERR, USER1, "CN9K PMD must be loaded.\n"); 402377222f30SCiara Power return TEST_SKIPPED; 4024c7e6ab78SKiran Kumar K } 4025c7e6ab78SKiran Kumar K 4026c7e6ab78SKiran Kumar K /* Use test suite registered for crypto_octeontx PMD */ 4027c7e6ab78SKiran Kumar K return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite); 4028c7e6ab78SKiran Kumar K } 4029c7e6ab78SKiran Kumar K 4030c7e6ab78SKiran Kumar K static int 4031c7e6ab78SKiran Kumar K test_cryptodev_cn10k_asym(void) 4032c7e6ab78SKiran Kumar K { 4033c7e6ab78SKiran Kumar K gbl_driver_id = rte_cryptodev_driver_id_get( 4034c7e6ab78SKiran Kumar K RTE_STR(CRYPTODEV_NAME_CN10K_PMD)); 4035c7e6ab78SKiran Kumar K if (gbl_driver_id == -1) { 4036c7e6ab78SKiran Kumar K RTE_LOG(ERR, USER1, "CN10K PMD must be loaded.\n"); 403777222f30SCiara Power return TEST_SKIPPED; 4038c7e6ab78SKiran Kumar K } 4039c7e6ab78SKiran Kumar K 4040c7e6ab78SKiran Kumar K /* Use test suite registered for crypto_octeontx PMD */ 4041c7e6ab78SKiran Kumar K return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite); 4042c7e6ab78SKiran Kumar K } 4043c7e6ab78SKiran Kumar K 4044d83fb967SDavid Marchand REGISTER_DRIVER_TEST(cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym); 4045e0a8442cSBruce Richardson REGISTER_DRIVER_TEST(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym); 40462de2d6efSDavid Marchand REGISTER_DRIVER_TEST(cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym); 40472de2d6efSDavid Marchand REGISTER_DRIVER_TEST(cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym); 40482de2d6efSDavid Marchand REGISTER_DRIVER_TEST(cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym); 4049