test/crypto: enable feature flag for security
[dpdk.git] / app / test / test_cryptodev.c
index d63958d..70bf6fe 100644 (file)
@@ -631,7 +631,7 @@ testsuite_teardown(void)
 }
 
 static int
-ut_setup(void)
+dev_configure_and_start(uint64_t ff_disable)
 {
        struct crypto_testsuite_params *ts_params = &testsuite_params;
        struct crypto_unittest_params *ut_params = &unittest_params;
@@ -643,7 +643,7 @@ ut_setup(void)
 
        /* Reconfigure device to default parameters */
        ts_params->conf.socket_id = SOCKET_ID_ANY;
-       ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
+       ts_params->conf.ff_disable = ff_disable;
        ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
        ts_params->qp_conf.mp_session = ts_params->session_mpool;
        ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
@@ -673,6 +673,20 @@ ut_setup(void)
        return TEST_SUCCESS;
 }
 
+static int
+ut_setup(void)
+{
+       /* Configure and start the device with security feature disabled */
+       return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
+}
+
+static int
+ut_setup_security(void)
+{
+       /* Configure and start the device with no features disabled */
+       return dev_configure_and_start(0);
+}
+
 static void
 ut_teardown(void)
 {
@@ -7073,7 +7087,8 @@ test_authenticated_encryption(const struct aead_test_data *tdata)
 
 #ifdef RTE_LIBRTE_SECURITY
 static int
-security_proto_supported(enum rte_security_session_protocol proto)
+security_proto_supported(enum rte_security_session_action_type action,
+       enum rte_security_session_protocol proto)
 {
        struct crypto_testsuite_params *ts_params = &testsuite_params;
 
@@ -7093,7 +7108,8 @@ security_proto_supported(enum rte_security_session_protocol proto)
 
        while ((capability = &capabilities[i++])->action !=
                        RTE_SECURITY_ACTION_TYPE_NONE) {
-               if (capability->protocol == proto)
+               if (capability->action == action &&
+                               capability->protocol == proto)
                        return 0;
        }
 
@@ -7125,7 +7141,7 @@ test_pdcp_proto(int i, int oop,
        /* Verify the capabilities */
        struct rte_security_capability_idx sec_cap_idx;
 
-       sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
+       sec_cap_idx.action = ut_params->type;
        sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
        sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
        if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
@@ -7151,9 +7167,6 @@ test_pdcp_proto(int i, int oop,
                rte_pktmbuf_append(ut_params->obuf, output_vec_len);
        }
 
-       /* Set crypto type as IPSEC */
-       ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
-
        /* Setup Cipher Parameters */
        ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
        ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
@@ -7181,7 +7194,7 @@ test_pdcp_proto(int i, int oop,
        }
 
        struct rte_security_session_conf sess_conf = {
-               .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
+               .action_type = ut_params->type,
                .protocol = RTE_SECURITY_PROTOCOL_PDCP,
                {.pdcp = {
                        .bearer = pdcp_test_bearer[i],
@@ -7315,7 +7328,7 @@ test_pdcp_proto_SGL(int i, int oop,
        /* Verify the capabilities */
        struct rte_security_capability_idx sec_cap_idx;
 
-       sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
+       sec_cap_idx.action = ut_params->type;
        sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
        sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
        if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
@@ -7425,8 +7438,6 @@ test_pdcp_proto_SGL(int i, int oop,
                ut_params->obuf->nb_segs = segs;
        }
 
-       ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
-
        /* Setup Cipher Parameters */
        ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
        ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
@@ -7452,7 +7463,7 @@ test_pdcp_proto_SGL(int i, int oop,
        }
 
        struct rte_security_session_conf sess_conf = {
-               .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
+               .action_type = ut_params->type,
                .protocol = RTE_SECURITY_PROTOCOL_PDCP,
                {.pdcp = {
                        .bearer = pdcp_test_bearer[i],
@@ -7711,6 +7722,7 @@ static int
 test_PDCP_PROTO_all(void)
 {
        struct crypto_testsuite_params *ts_params = &testsuite_params;
+       struct crypto_unittest_params *ut_params = &unittest_params;
        struct rte_cryptodev_info dev_info;
        int status;
 
@@ -7720,7 +7732,13 @@ test_PDCP_PROTO_all(void)
        if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
                return -ENOTSUP;
 
-       if (security_proto_supported(RTE_SECURITY_PROTOCOL_PDCP) < 0)
+       /* Set action type */
+       ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
+               RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
+               gbl_action_type;
+
+       if (security_proto_supported(ut_params->type,
+                       RTE_SECURITY_PROTOCOL_PDCP) < 0)
                return -ENOTSUP;
 
        status = test_PDCP_PROTO_cplane_encap_all();
@@ -7760,7 +7778,7 @@ test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
        const struct rte_cryptodev_symmetric_capability *sym_cap;
        int j = 0;
 
-       sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
+       sec_cap_idx.action = ut_params->type;
        sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
        sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
 
@@ -7796,9 +7814,6 @@ test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
 
        memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
 
-       /* Set session action type */
-       ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
-
        /* Setup cipher session parameters */
        ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
        ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
@@ -7938,7 +7953,7 @@ test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
        const struct rte_cryptodev_symmetric_capability *sym_cap;
        int j = 0;
 
-       sec_cap_idx.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
+       sec_cap_idx.action = ut_params->type;
        sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
        sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
 
@@ -7974,9 +7989,6 @@ test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
 
        memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
 
-       /* Set session action type */
-       ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
-
        /* Setup cipher session parameters */
        ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
        ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
@@ -8192,6 +8204,7 @@ static int
 test_DOCSIS_PROTO_all(void)
 {
        struct crypto_testsuite_params *ts_params = &testsuite_params;
+       struct crypto_unittest_params *ut_params = &unittest_params;
        struct rte_cryptodev_info dev_info;
        int status;
 
@@ -8201,7 +8214,13 @@ test_DOCSIS_PROTO_all(void)
        if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
                return -ENOTSUP;
 
-       if (security_proto_supported(RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
+       /* Set action type */
+       ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
+               RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
+               gbl_action_type;
+
+       if (security_proto_supported(ut_params->type,
+                       RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
                return -ENOTSUP;
 
        status = test_DOCSIS_PROTO_uplink_all();
@@ -10381,7 +10400,7 @@ aes128cbc_hmac_sha1_test_vector = {
 static const struct test_crypto_vector
 aes128cbc_hmac_sha1_aad_test_vector = {
        .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
-       .cipher_offset = 12,
+       .cipher_offset = 8,
        .cipher_len = 496,
        .cipher_key = {
                .data = {
@@ -10417,9 +10436,9 @@ aes128cbc_hmac_sha1_aad_test_vector = {
        },
        .digest = {
                .data = {
-                       0x1F, 0x6A, 0xD2, 0x8B, 0x4B, 0xB3, 0xC0, 0x9E,
-                       0x86, 0x9B, 0x3A, 0xF2, 0x00, 0x5B, 0x4F, 0x08,
-                       0x62, 0x8D, 0x62, 0x65
+                       0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
+                       0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
+                       0x62, 0x0F, 0xFB, 0x10
                },
                .len = 20
        }
@@ -11679,6 +11698,18 @@ auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
                        &aes128cbc_hmac_sha1_aad_test_vector);
 }
 
+static int
+test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
+{
+       return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
+}
+
+static int
+test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
+{
+       return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
+}
+
 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
 
 /* global AESNI slave IDs for the scheduler test */
@@ -12133,7 +12164,11 @@ static struct unit_test_suite cryptodev_testsuite  = {
                        test_AES_GMAC_authentication_test_case_4),
                TEST_CASE_ST(ut_setup, ut_teardown,
                        test_AES_GMAC_authentication_verify_test_case_4),
-
+               /** Chacha20-Poly1305 */
+               TEST_CASE_ST(ut_setup, ut_teardown,
+                       test_chacha20_poly1305_encrypt_test_case_rfc8439),
+               TEST_CASE_ST(ut_setup, ut_teardown,
+                       test_chacha20_poly1305_decrypt_test_case_rfc8439),
                /** SNOW 3G encrypt only (UEA2) */
                TEST_CASE_ST(ut_setup, ut_teardown,
                        test_snow3g_encryption_test_case_1),
@@ -12517,9 +12552,9 @@ static struct unit_test_suite cryptodev_testsuite  = {
                        test_verify_auth_aes_cmac_cipher_null_test_case_1),
 
 #ifdef RTE_LIBRTE_SECURITY
-               TEST_CASE_ST(ut_setup, ut_teardown,
+               TEST_CASE_ST(ut_setup_security, ut_teardown,
                        test_PDCP_PROTO_all),
-               TEST_CASE_ST(ut_setup, ut_teardown,
+               TEST_CASE_ST(ut_setup_security, ut_teardown,
                        test_DOCSIS_PROTO_all),
 #endif
                TEST_CASES_END() /**< NULL terminate unit test array */