net/af_xdp: use libxdp if available
[dpdk.git] / app / test / test_cryptodev.c
index 7f121dc..8842e19 100644 (file)
@@ -3,6 +3,8 @@
  * Copyright 2020 NXP
  */
 
+#ifndef RTE_EXEC_ENV_WINDOWS
+
 #include <time.h>
 
 #include <rte_common.h>
@@ -9162,15 +9164,26 @@ test_ipsec_proto_process(const struct ipsec_test_data td[],
                        dst += 1;
        }
 
-       if (td->ipsec_xform.tunnel.type ==
-                       RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
-               memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src));
-               memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst));
-       } else {
-               memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src,
-                       sizeof(v6_src));
-               memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst,
-                       sizeof(v6_dst));
+       if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
+               if (td->ipsec_xform.tunnel.type ==
+                               RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
+                       memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src,
+                              sizeof(src));
+                       memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst,
+                              sizeof(dst));
+
+                       if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1)
+                               ipsec_xform.tunnel.ipv4.df = 0;
+
+                       if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0)
+                               ipsec_xform.tunnel.ipv4.df = 1;
+
+               } else {
+                       memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src,
+                              sizeof(v6_src));
+                       memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst,
+                              sizeof(v6_dst));
+               }
        }
 
        ctx = rte_cryptodev_get_sec_ctx(dev_id);
@@ -9278,6 +9291,9 @@ test_ipsec_proto_process(const struct ipsec_test_data td[],
                memcpy(input_text, td[i].input_text.data,
                       td[i].input_text.len);
 
+               if (test_ipsec_pkt_update(input_text, flags))
+                       return TEST_FAILED;
+
                /* Generate crypto op data structure */
                ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
                                        RTE_CRYPTO_OP_TYPE_SYMMETRIC);
@@ -9328,6 +9344,11 @@ test_ipsec_proto_process(const struct ipsec_test_data td[],
                if (ret != TEST_SUCCESS)
                        goto crypto_op_free;
 
+               ret = test_ipsec_stats_verify(ctx, ut_params->sec_session,
+                                             flags, dir);
+               if (ret != TEST_SUCCESS)
+                       goto crypto_op_free;
+
                rte_crypto_op_free(ut_params->op);
                ut_params->op = NULL;
 
@@ -9359,8 +9380,11 @@ test_ipsec_proto_known_vec(const void *test_data)
 
        memcpy(&td_outb, test_data, sizeof(td_outb));
 
-       /* Disable IV gen to be able to test with known vectors */
-       td_outb.ipsec_xform.options.iv_gen_disable = 1;
+       if (td_outb.aead ||
+           td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL) {
+               /* Disable IV gen to be able to test with known vectors */
+               td_outb.ipsec_xform.options.iv_gen_disable = 1;
+       }
 
        return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
 }
@@ -9382,6 +9406,23 @@ test_ipsec_proto_known_vec_inb(const void *test_data)
        return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
 }
 
+static int
+test_ipsec_proto_known_vec_fragmented(const void *test_data)
+{
+       struct ipsec_test_data td_outb;
+       struct ipsec_test_flags flags;
+
+       memset(&flags, 0, sizeof(flags));
+       flags.fragment = true;
+
+       memcpy(&td_outb, test_data, sizeof(td_outb));
+
+       /* Disable IV gen to be able to test with known vectors */
+       td_outb.ipsec_xform.options.iv_gen_disable = 1;
+
+       return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
+}
+
 static int
 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
 {
@@ -9402,6 +9443,24 @@ test_ipsec_proto_all(const struct ipsec_test_flags *flags)
                                      td_outb,
                                      nb_pkts);
 
+               if (!td_outb->aead) {
+                       enum rte_crypto_cipher_algorithm cipher_alg;
+                       enum rte_crypto_auth_algorithm auth_alg;
+
+                       cipher_alg = td_outb->xform.chain.cipher.cipher.algo;
+                       auth_alg = td_outb->xform.chain.auth.auth.algo;
+
+                       /* ICV is not applicable for NULL auth */
+                       if (flags->icv_corrupt &&
+                           auth_alg == RTE_CRYPTO_AUTH_NULL)
+                               continue;
+
+                       /* IV is not applicable for NULL cipher */
+                       if (flags->iv_gen &&
+                           cipher_alg == RTE_CRYPTO_CIPHER_NULL)
+                               continue;
+               }
+
                ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
                                               flags);
                if (ret == TEST_SKIPPED)
@@ -9618,6 +9677,92 @@ test_ipsec_proto_tunnel_v6_in_v4(const void *data __rte_unused)
        return test_ipsec_proto_all(&flags);
 }
 
+static int
+test_ipsec_proto_transport_v4(const void *data __rte_unused)
+{
+       struct ipsec_test_flags flags;
+
+       memset(&flags, 0, sizeof(flags));
+
+       flags.ipv6 = false;
+       flags.transport = true;
+
+       return test_ipsec_proto_all(&flags);
+}
+
+static int
+test_ipsec_proto_stats(const void *data __rte_unused)
+{
+       struct ipsec_test_flags flags;
+
+       memset(&flags, 0, sizeof(flags));
+
+       flags.stats_success = true;
+
+       return test_ipsec_proto_all(&flags);
+}
+
+static int
+test_ipsec_proto_pkt_fragment(const void *data __rte_unused)
+{
+       struct ipsec_test_flags flags;
+
+       memset(&flags, 0, sizeof(flags));
+
+       flags.fragment = true;
+
+       return test_ipsec_proto_all(&flags);
+
+}
+
+static int
+test_ipsec_proto_copy_df_inner_0(const void *data __rte_unused)
+{
+       struct ipsec_test_flags flags;
+
+       memset(&flags, 0, sizeof(flags));
+
+       flags.df = TEST_IPSEC_COPY_DF_INNER_0;
+
+       return test_ipsec_proto_all(&flags);
+}
+
+static int
+test_ipsec_proto_copy_df_inner_1(const void *data __rte_unused)
+{
+       struct ipsec_test_flags flags;
+
+       memset(&flags, 0, sizeof(flags));
+
+       flags.df = TEST_IPSEC_COPY_DF_INNER_1;
+
+       return test_ipsec_proto_all(&flags);
+}
+
+static int
+test_ipsec_proto_set_df_0_inner_1(const void *data __rte_unused)
+{
+       struct ipsec_test_flags flags;
+
+       memset(&flags, 0, sizeof(flags));
+
+       flags.df = TEST_IPSEC_SET_DF_0_INNER_1;
+
+       return test_ipsec_proto_all(&flags);
+}
+
+static int
+test_ipsec_proto_set_df_1_inner_0(const void *data __rte_unused)
+{
+       struct ipsec_test_flags flags;
+
+       memset(&flags, 0, sizeof(flags));
+
+       flags.df = TEST_IPSEC_SET_DF_1_INNER_0;
+
+       return test_ipsec_proto_all(&flags);
+}
+
 static int
 test_PDCP_PROTO_all(void)
 {
@@ -14513,6 +14658,16 @@ static struct unit_test_suite ipsec_proto_testsuite  = {
                        ut_setup_security, ut_teardown,
                        test_ipsec_proto_known_vec,
                        &pkt_aes_128_cbc_hmac_sha256_v6),
+               TEST_CASE_NAMED_WITH_DATA(
+                       "Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
+                       ut_setup_security, ut_teardown,
+                       test_ipsec_proto_known_vec,
+                       &pkt_null_aes_xcbc),
+               TEST_CASE_NAMED_WITH_DATA(
+                       "Outbound fragmented packet",
+                       ut_setup_security, ut_teardown,
+                       test_ipsec_proto_known_vec_fragmented,
+                       &pkt_aes_128_gcm_frag),
                TEST_CASE_NAMED_WITH_DATA(
                        "Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
                        ut_setup_security, ut_teardown,
@@ -14553,6 +14708,11 @@ static struct unit_test_suite ipsec_proto_testsuite  = {
                        ut_setup_security, ut_teardown,
                        test_ipsec_proto_known_vec_inb,
                        &pkt_aes_128_cbc_hmac_sha256_v6),
+               TEST_CASE_NAMED_WITH_DATA(
+                       "Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
+                       ut_setup_security, ut_teardown,
+                       test_ipsec_proto_known_vec_inb,
+                       &pkt_null_aes_xcbc),
                TEST_CASE_NAMED_ST(
                        "Combined test alg list",
                        ut_setup_security, ut_teardown,
@@ -14613,6 +14773,34 @@ static struct unit_test_suite ipsec_proto_testsuite  = {
                        "Tunnel IPv6 in IPv4",
                        ut_setup_security, ut_teardown,
                        test_ipsec_proto_tunnel_v6_in_v4),
+               TEST_CASE_NAMED_ST(
+                       "Transport IPv4",
+                       ut_setup_security, ut_teardown,
+                       test_ipsec_proto_transport_v4),
+               TEST_CASE_NAMED_ST(
+                       "Statistics: success",
+                       ut_setup_security, ut_teardown,
+                       test_ipsec_proto_stats),
+               TEST_CASE_NAMED_ST(
+                       "Fragmented packet",
+                       ut_setup_security, ut_teardown,
+                       test_ipsec_proto_pkt_fragment),
+               TEST_CASE_NAMED_ST(
+                       "Tunnel header copy DF (inner 0)",
+                       ut_setup_security, ut_teardown,
+                       test_ipsec_proto_copy_df_inner_0),
+               TEST_CASE_NAMED_ST(
+                       "Tunnel header copy DF (inner 1)",
+                       ut_setup_security, ut_teardown,
+                       test_ipsec_proto_copy_df_inner_1),
+               TEST_CASE_NAMED_ST(
+                       "Tunnel header set DF 0 (inner 1)",
+                       ut_setup_security, ut_teardown,
+                       test_ipsec_proto_set_df_0_inner_1),
+               TEST_CASE_NAMED_ST(
+                       "Tunnel header set DF 1 (inner 0)",
+                       ut_setup_security, ut_teardown,
+                       test_ipsec_proto_set_df_1_inner_0),
                TEST_CASES_END() /**< NULL terminate unit test array */
        }
 };
@@ -15907,3 +16095,5 @@ REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
+
+#endif /* !RTE_EXEC_ENV_WINDOWS */