70a264aa8c53fba21307d96203223bb6e131eba8
[dpdk.git] / app / test / test_cryptodev_security_ipsec.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #ifndef _TEST_CRYPTODEV_SECURITY_IPSEC_H_
6 #define _TEST_CRYPTODEV_SECURITY_IPSEC_H_
7
8 #include <rte_cryptodev.h>
9 #include <rte_security.h>
10
11 #define IPSEC_TEST_PACKETS_MAX 32
12
13 struct ipsec_test_data {
14         struct {
15                 uint8_t data[32];
16         } key;
17         struct {
18                 uint8_t data[32];
19         } auth_key;
20
21         struct {
22                 uint8_t data[1024];
23                 unsigned int len;
24         } input_text;
25
26         struct {
27                 uint8_t data[1024];
28                 unsigned int len;
29         } output_text;
30
31         struct {
32                 uint8_t data[4];
33                 unsigned int len;
34         } salt;
35
36         struct {
37                 uint8_t data[16];
38         } iv;
39
40         struct rte_security_ipsec_xform ipsec_xform;
41
42         bool aead;
43
44         union {
45                 struct {
46                         struct rte_crypto_sym_xform cipher;
47                         struct rte_crypto_sym_xform auth;
48                 } chain;
49                 struct rte_crypto_sym_xform aead;
50         } xform;
51 };
52
53 struct ipsec_test_flags {
54         bool display_alg;
55         bool sa_expiry_pkts_soft;
56         bool sa_expiry_pkts_hard;
57         bool icv_corrupt;
58         bool iv_gen;
59         uint32_t tunnel_hdr_verify;
60         bool udp_encap;
61         bool udp_ports_verify;
62         bool ip_csum;
63         bool l4_csum;
64 };
65
66 struct crypto_param {
67         enum rte_crypto_sym_xform_type type;
68         union {
69                 enum rte_crypto_cipher_algorithm cipher;
70                 enum rte_crypto_auth_algorithm auth;
71                 enum rte_crypto_aead_algorithm aead;
72         } alg;
73         uint16_t key_length;
74 };
75
76 static const struct crypto_param aead_list[] = {
77         {
78                 .type = RTE_CRYPTO_SYM_XFORM_AEAD,
79                 .alg.aead =  RTE_CRYPTO_AEAD_AES_GCM,
80                 .key_length = 16,
81         },
82         {
83                 .type = RTE_CRYPTO_SYM_XFORM_AEAD,
84                 .alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
85                 .key_length = 24,
86         },
87         {
88                 .type = RTE_CRYPTO_SYM_XFORM_AEAD,
89                 .alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
90                 .key_length = 32
91         },
92 };
93
94 int test_ipsec_sec_caps_verify(struct rte_security_ipsec_xform *ipsec_xform,
95                                const struct rte_security_capability *sec_cap,
96                                bool silent);
97
98 int test_ipsec_crypto_caps_aead_verify(
99                 const struct rte_security_capability *sec_cap,
100                 struct rte_crypto_sym_xform *aead);
101
102 int test_ipsec_crypto_caps_cipher_verify(
103                 const struct rte_security_capability *sec_cap,
104                 struct rte_crypto_sym_xform *cipher);
105
106 int test_ipsec_crypto_caps_auth_verify(
107                 const struct rte_security_capability *sec_cap,
108                 struct rte_crypto_sym_xform *auth);
109
110 void test_ipsec_td_in_from_out(const struct ipsec_test_data *td_out,
111                                struct ipsec_test_data *td_in);
112
113 void test_ipsec_td_prepare(const struct crypto_param *param1,
114                            const struct crypto_param *param2,
115                            const struct ipsec_test_flags *flags,
116                            struct ipsec_test_data *td_array,
117                            int nb_td);
118
119 void test_ipsec_td_update(struct ipsec_test_data td_inb[],
120                           const struct ipsec_test_data td_outb[],
121                           int nb_td,
122                           const struct ipsec_test_flags *flags);
123
124 void test_ipsec_display_alg(const struct crypto_param *param1,
125                             const struct crypto_param *param2);
126
127 int test_ipsec_post_process(struct rte_mbuf *m,
128                             const struct ipsec_test_data *td,
129                             struct ipsec_test_data *res_d, bool silent,
130                             const struct ipsec_test_flags *flags);
131
132 int test_ipsec_status_check(struct rte_crypto_op *op,
133                             const struct ipsec_test_flags *flags,
134                             enum rte_security_ipsec_sa_direction dir,
135                             int pkt_num);
136
137 #endif