X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;ds=inline;f=app%2Ftest%2Ftest_cryptodev_asym.c;h=b8e05004816bde1f76def4825f40a61d7402d2bd;hb=554bb73c253293abd4438a8c8dfead5963530a33;hp=08479bbfb9affdb61dd9f4377a187e4bd4d3f3bf;hpb=d90e58a7834530132988890d86910d0b4a0e856f;p=dpdk.git diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c index 08479bbfb9..b8e0500481 100644 --- a/app/test/test_cryptodev_asym.c +++ b/app/test/test_cryptodev_asym.c @@ -19,6 +19,7 @@ #include "test_cryptodev_dh_test_vectors.h" #include "test_cryptodev_dsa_test_vectors.h" #include "test_cryptodev_ecdsa_test_vectors.h" +#include "test_cryptodev_ecpm_test_vectors.h" #include "test_cryptodev_mod_test_vectors.h" #include "test_cryptodev_rsa_test_vectors.h" #include "test_cryptodev_asym_util.h" @@ -1044,6 +1045,7 @@ static inline void print_asym_capa( capa->modlen.increment); break; case RTE_CRYPTO_ASYM_XFORM_ECDSA: + case RTE_CRYPTO_ASYM_XFORM_ECPM: default: break; } @@ -2108,6 +2110,179 @@ test_ecdsa_sign_verify_all_curve(void) return overall_status; } +static int +test_ecpm(enum curve curve_id) +{ + struct crypto_testsuite_params *ts_params = &testsuite_params; + struct rte_mempool *sess_mpool = ts_params->session_mpool; + struct rte_mempool *op_mpool = ts_params->op_mpool; + struct crypto_testsuite_ecpm_params input_params; + struct rte_cryptodev_asym_session *sess = NULL; + uint8_t dev_id = ts_params->valid_devs[0]; + struct rte_crypto_op *result_op = NULL; + uint8_t output_buf_x[TEST_DATA_SIZE]; + uint8_t output_buf_y[TEST_DATA_SIZE]; + struct rte_crypto_asym_xform xform; + struct rte_crypto_asym_op *asym_op; + struct rte_cryptodev_info dev_info; + struct rte_crypto_op *op = NULL; + int status = TEST_SUCCESS, ret; + + switch (curve_id) { + case SECP192R1: + input_params = ecpm_param_secp192r1; + break; + case SECP224R1: + input_params = ecpm_param_secp224r1; + break; + case SECP256R1: + input_params = ecpm_param_secp256r1; + break; + case SECP384R1: + input_params = ecpm_param_secp384r1; + break; + case SECP521R1: + input_params = ecpm_param_secp521r1; + break; + default: + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Unsupported curve id\n"); + status = TEST_FAILED; + goto exit; + } + + rte_cryptodev_info_get(dev_id, &dev_info); + + sess = rte_cryptodev_asym_session_create(sess_mpool); + if (sess == NULL) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Session creation failed\n"); + status = TEST_FAILED; + goto exit; + } + + /* Setup crypto op data structure */ + op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); + if (op == NULL) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to allocate asymmetric crypto " + "operation struct\n"); + status = TEST_FAILED; + goto exit; + } + asym_op = op->asym; + + /* Setup asym xform */ + xform.next = NULL; + xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM; + xform.ec.curve_id = input_params.curve; + + if (rte_cryptodev_asym_session_init(dev_id, sess, &xform, + sess_mpool) < 0) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Unable to config asym session\n"); + status = TEST_FAILED; + goto exit; + } + + /* Attach asymmetric crypto session to crypto operations */ + rte_crypto_op_attach_asym_session(op, sess); + + /* Populate op with operational details */ + op->asym->ecpm.p.x.data = input_params.gen_x.data; + op->asym->ecpm.p.x.length = input_params.gen_x.length; + op->asym->ecpm.p.y.data = input_params.gen_y.data; + op->asym->ecpm.p.y.length = input_params.gen_y.length; + op->asym->ecpm.scalar.data = input_params.privkey.data; + op->asym->ecpm.scalar.length = input_params.privkey.length; + + /* Init out buf */ + op->asym->ecpm.r.x.data = output_buf_x; + op->asym->ecpm.r.y.data = output_buf_y; + + RTE_LOG(DEBUG, USER1, "Process ASYM operation\n"); + + /* Process crypto operation */ + if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Error sending packet for operation\n"); + status = TEST_FAILED; + goto exit; + } + + while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0) + rte_pause(); + + if (result_op == NULL) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to process asym crypto op\n"); + status = TEST_FAILED; + goto exit; + } + + if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to process asym crypto op\n"); + status = TEST_FAILED; + goto exit; + } + + asym_op = result_op->asym; + + debug_hexdump(stdout, "r x:", + asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length); + debug_hexdump(stdout, "r y:", + asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length); + + ret = verify_ecpm(input_params.pubkey_x.data, + input_params.pubkey_y.data, result_op); + if (ret) { + status = TEST_FAILED; + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "EC Point Multiplication failed.\n"); + goto exit; + } + +exit: + if (sess != NULL) { + rte_cryptodev_asym_session_clear(dev_id, sess); + rte_cryptodev_asym_session_free(sess); + } + if (op != NULL) + rte_crypto_op_free(op); + return status; +} + +static int +test_ecpm_all_curve(void) +{ + int status, overall_status = TEST_SUCCESS; + enum curve curve_id; + int test_index = 0; + const char *msg; + + for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { + status = test_ecpm(curve_id); + if (status == TEST_SUCCESS) { + msg = "succeeded"; + } else { + msg = "failed"; + overall_status = status; + } + printf(" %u) TestCase EC Point Mul Curve %s %s\n", + test_index ++, curve[curve_id], msg); + } + return overall_status; +} + static struct unit_test_suite cryptodev_openssl_asym_testsuite = { .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite", .setup = testsuite_setup, @@ -2148,6 +2323,7 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp), TEST_CASE_ST(ut_setup, ut_teardown, test_ecdsa_sign_verify_all_curve), + TEST_CASE_ST(ut_setup, ut_teardown, test_ecpm_all_curve), TEST_CASES_END() /**< NULL terminate unit test array */ } };