test/security: add ESN and anti-replay for inline IPsec
[dpdk.git] / app / test / test_cryptodev_asym.c
index 283b38e..573af2a 100644 (file)
@@ -46,7 +46,7 @@ struct crypto_testsuite_params_asym {
 };
 
 struct crypto_unittest_params {
-       struct rte_cryptodev_asym_session *sess;
+       void *sess;
        struct rte_crypto_op *op;
 };
 
@@ -67,7 +67,7 @@ static uint32_t test_index;
 static struct crypto_testsuite_params_asym testsuite_params = { NULL };
 
 static int
-queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
+queue_ops_rsa_sign_verify(void *sess)
 {
        struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
        struct rte_mempool *op_mpool = ts_params->op_mpool;
@@ -158,7 +158,7 @@ error_exit:
 }
 
 static int
-queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
+queue_ops_rsa_enc_dec(void *sess)
 {
        struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
        struct rte_mempool *op_mpool = ts_params->op_mpool;
@@ -310,14 +310,14 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
        struct rte_crypto_op *op = NULL;
        struct rte_crypto_op *result_op = NULL;
        struct rte_crypto_asym_xform xform_tc;
-       struct rte_cryptodev_asym_session *sess = NULL;
+       void *sess = NULL;
        struct rte_cryptodev_asym_capability_idx cap_idx;
        const struct rte_cryptodev_asymmetric_xform_capability *capability;
        uint8_t dev_id = ts_params->valid_devs[0];
        uint8_t input[TEST_DATA_SIZE] = {0};
        uint8_t *result = NULL;
 
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
 
        xform_tc.next = NULL;
        xform_tc.xform_type = data_tc->modex.xform_type;
@@ -452,14 +452,14 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
        }
 
        if (!sessionless) {
-               sess = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
-                               ts_params->session_mpool);
-               if (!sess) {
+               ret = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
+                               ts_params->session_mpool, &sess);
+               if (ret < 0) {
                        snprintf(test_msg, ASYM_TEST_MSG_LEN,
                                        "line %u "
                                        "FAILED: %s", __LINE__,
                                        "Session creation failed");
-                       status = TEST_FAILED;
+                       status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                        goto error_exit;
                }
 
@@ -549,7 +549,7 @@ test_one_case(const void *test_case, int sessionless)
                                                status = test_cryptodev_asym_op(
                                                        &testsuite_params,
                                                        &tc, test_msg, sessionless, i,
-                                                       RTE_RSA_KET_TYPE_QT);
+                                                       RTE_RSA_KEY_TYPE_QT);
                                        }
                                        if (status)
                                                break;
@@ -643,9 +643,9 @@ test_rsa_sign_verify(void)
        struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
        struct rte_mempool *sess_mpool = ts_params->session_mpool;
        uint8_t dev_id = ts_params->valid_devs[0];
-       struct rte_cryptodev_asym_session *sess;
+       void *sess = NULL;
        struct rte_cryptodev_info dev_info;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
 
        /* Test case supports op with exponent key only,
         * Check in PMD feature flag for RSA exponent key type support.
@@ -658,12 +658,12 @@ test_rsa_sign_verify(void)
                return TEST_SKIPPED;
        }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+       ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-       if (!sess) {
+       if (ret < 0) {
                RTE_LOG(ERR, USER1, "Session creation failed for "
                        "sign_verify\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -683,9 +683,9 @@ test_rsa_enc_dec(void)
        struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
        struct rte_mempool *sess_mpool = ts_params->session_mpool;
        uint8_t dev_id = ts_params->valid_devs[0];
-       struct rte_cryptodev_asym_session *sess;
+       void *sess = NULL;
        struct rte_cryptodev_info dev_info;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
 
        /* Test case supports op with exponent key only,
         * Check in PMD feature flag for RSA exponent key type support.
@@ -698,11 +698,11 @@ test_rsa_enc_dec(void)
                return TEST_SKIPPED;
        }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool);
+       ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
-       if (!sess) {
+       if (ret < 0) {
                RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -723,9 +723,9 @@ test_rsa_sign_verify_crt(void)
        struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
        struct rte_mempool *sess_mpool = ts_params->session_mpool;
        uint8_t dev_id = ts_params->valid_devs[0];
-       struct rte_cryptodev_asym_session *sess;
+       void *sess = NULL;
        struct rte_cryptodev_info dev_info;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
 
        /* Test case supports op with quintuple format key only,
         * Check im PMD feature flag for RSA quintuple key type support.
@@ -737,12 +737,12 @@ test_rsa_sign_verify_crt(void)
                return TEST_SKIPPED;
        }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+       ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-       if (!sess) {
+       if (ret < 0) {
                RTE_LOG(ERR, USER1, "Session creation failed for "
                        "sign_verify_crt\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -763,9 +763,9 @@ test_rsa_enc_dec_crt(void)
        struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
        struct rte_mempool *sess_mpool = ts_params->session_mpool;
        uint8_t dev_id = ts_params->valid_devs[0];
-       struct rte_cryptodev_asym_session *sess;
+       void *sess = NULL;
        struct rte_cryptodev_info dev_info;
-       int status = TEST_SUCCESS;
+       int ret, status = TEST_SUCCESS;
 
        /* Test case supports op with quintuple format key only,
         * Check in PMD feature flag for RSA quintuple key type support.
@@ -777,12 +777,12 @@ test_rsa_enc_dec_crt(void)
                return TEST_SKIPPED;
        }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool);
+       ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
 
-       if (!sess) {
+       if (ret < 0) {
                RTE_LOG(ERR, USER1, "Session creation failed for "
                        "enc_dec_crt\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -893,7 +893,7 @@ testsuite_setup(void)
        }
 
        ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
-                       "test_asym_sess_mp", TEST_NUM_SESSIONS, 0,
+                       "test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
                        SOCKET_ID_ANY);
 
        TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
@@ -1045,8 +1045,8 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
        uint8_t dev_id = ts_params->valid_devs[0];
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
-       struct rte_cryptodev_asym_session *sess = NULL;
-       int status = TEST_SUCCESS;
+       void *sess = NULL;
+       int ret, status = TEST_SUCCESS;
        uint8_t output[TEST_DH_MOD_LEN];
        struct rte_crypto_asym_xform xform = *xfrm;
        uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
@@ -1073,12 +1073,12 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
        asym_op->dh.shared_secret.data = output;
        asym_op->dh.shared_secret.length = sizeof(output);
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1128,8 +1128,8 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
        uint8_t dev_id = ts_params->valid_devs[0];
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
-       struct rte_cryptodev_asym_session *sess = NULL;
-       int status = TEST_SUCCESS;
+       void *sess = NULL;
+       int ret, status = TEST_SUCCESS;
        uint8_t output[TEST_DH_MOD_LEN];
        struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1151,12 +1151,12 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
        asym_op->dh.priv_key.data = output;
        asym_op->dh.priv_key.length = sizeof(output);
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1209,8 +1209,8 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
        uint8_t dev_id = ts_params->valid_devs[0];
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
-       struct rte_cryptodev_asym_session *sess = NULL;
-       int status = TEST_SUCCESS;
+       void *sess = NULL;
+       int ret, status = TEST_SUCCESS;
        uint8_t output[TEST_DH_MOD_LEN];
        struct rte_crypto_asym_xform xform = *xfrm;
 
@@ -1240,12 +1240,12 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
                                        0);
        asym_op->dh.priv_key = dh_test_params.priv_key;
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1298,8 +1298,8 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
        uint8_t dev_id = ts_params->valid_devs[0];
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
-       struct rte_cryptodev_asym_session *sess = NULL;
-       int status = TEST_SUCCESS;
+       void *sess = NULL;
+       int ret, status = TEST_SUCCESS;
        uint8_t out_pub_key[TEST_DH_MOD_LEN];
        uint8_t out_prv_key[TEST_DH_MOD_LEN];
        struct rte_crypto_asym_xform pub_key_xform;
@@ -1329,12 +1329,12 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
        asym_op->dh.priv_key.data = out_prv_key;
        asym_op->dh.priv_key.length = sizeof(out_prv_key);
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1385,7 +1385,7 @@ test_mod_inv(void)
        uint8_t dev_id = ts_params->valid_devs[0];
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
-       struct rte_cryptodev_asym_session *sess = NULL;
+       void *sess = NULL;
        int status = TEST_SUCCESS;
        struct rte_cryptodev_asym_capability_idx cap_idx;
        const struct rte_cryptodev_asymmetric_xform_capability *capability;
@@ -1418,12 +1418,12 @@ test_mod_inv(void)
                                return TEST_SKIPPED;
                }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool);
-       if (!sess) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1, "line %u "
                                "FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1498,7 +1498,7 @@ test_mod_exp(void)
        uint8_t dev_id = ts_params->valid_devs[0];
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
-       struct rte_cryptodev_asym_session *sess = NULL;
+       void *sess = NULL;
        int status = TEST_SUCCESS;
        struct rte_cryptodev_asym_capability_idx cap_idx;
        const struct rte_cryptodev_asymmetric_xform_capability *capability;
@@ -1542,13 +1542,13 @@ test_mod_exp(void)
                goto error_exit;
        }
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool);
-       if (!sess) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                 "line %u "
                                "FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
 
@@ -1647,18 +1647,19 @@ test_dsa_sign(void)
        uint8_t dev_id = ts_params->valid_devs[0];
        struct rte_crypto_asym_op *asym_op = NULL;
        struct rte_crypto_op *op = NULL, *result_op = NULL;
-       struct rte_cryptodev_asym_session *sess = NULL;
+       void *sess = NULL;
        int status = TEST_SUCCESS;
        uint8_t r[TEST_DH_MOD_LEN];
        uint8_t s[TEST_DH_MOD_LEN];
        uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
+       int ret;
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                 "line %u FAILED: %s", __LINE__,
                                "Session creation failed");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto error_exit;
        }
        /* set up crypto op data structure */
@@ -1778,7 +1779,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
        struct rte_mempool *sess_mpool = ts_params->session_mpool;
        struct rte_mempool *op_mpool = ts_params->op_mpool;
        struct crypto_testsuite_ecdsa_params input_params;
-       struct rte_cryptodev_asym_session *sess = NULL;
+       void *sess = NULL;
        uint8_t dev_id = ts_params->valid_devs[0];
        struct rte_crypto_op *result_op = NULL;
        uint8_t output_buf_r[TEST_DATA_SIZE];
@@ -1787,7 +1788,7 @@ test_ecdsa_sign_verify(enum curve curve_id)
        struct rte_crypto_asym_op *asym_op;
        struct rte_cryptodev_info dev_info;
        struct rte_crypto_op *op = NULL;
-       int status = TEST_SUCCESS, ret;
+       int ret, status = TEST_SUCCESS;
 
        switch (curve_id) {
        case SECP192R1:
@@ -1832,12 +1833,12 @@ test_ecdsa_sign_verify(enum curve curve_id)
        xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
        xform.ec.curve_id = input_params.curve;
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto exit;
        }
 
@@ -1980,7 +1981,7 @@ test_ecpm(enum curve curve_id)
        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;
+       void *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];
@@ -1989,7 +1990,7 @@ test_ecpm(enum curve curve_id)
        struct rte_crypto_asym_op *asym_op;
        struct rte_cryptodev_info dev_info;
        struct rte_crypto_op *op = NULL;
-       int status = TEST_SUCCESS, ret;
+       int ret, status = TEST_SUCCESS;
 
        switch (curve_id) {
        case SECP192R1:
@@ -2034,12 +2035,12 @@ test_ecpm(enum curve curve_id)
        xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
        xform.ec.curve_id = input_params.curve;
 
-       sess = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool);
-       if (sess == NULL) {
+       ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
+       if (ret < 0) {
                RTE_LOG(ERR, USER1,
                                "line %u FAILED: %s", __LINE__,
                                "Session creation failed\n");
-               status = TEST_FAILED;
+               status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
                goto exit;
        }