xref: /dpdk/app/test/test_cryptodev_security_ipsec.h (revision 97b914f4e715565d53d38ac6e04815b9be5e58a9)
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[64];
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 	bool aes_gmac;
45 
46 	bool auth_only;
47 
48 	/* Antireplay packet */
49 	bool ar_packet;
50 
51 	union {
52 		struct {
53 			struct rte_crypto_sym_xform cipher;
54 			struct rte_crypto_sym_xform auth;
55 		} chain;
56 		struct rte_crypto_sym_xform aead;
57 	} xform;
58 };
59 
60 enum df_flags {
61 	TEST_IPSEC_COPY_DF_INNER_0 = 1,
62 	TEST_IPSEC_COPY_DF_INNER_1,
63 	TEST_IPSEC_SET_DF_0_INNER_1,
64 	TEST_IPSEC_SET_DF_1_INNER_0,
65 };
66 
67 #define TEST_IPSEC_DSCP_VAL 0x12
68 
69 enum dscp_flags {
70 	TEST_IPSEC_COPY_DSCP_INNER_0 = 1,
71 	TEST_IPSEC_COPY_DSCP_INNER_1,
72 	TEST_IPSEC_SET_DSCP_0_INNER_1,
73 	TEST_IPSEC_SET_DSCP_1_INNER_0,
74 };
75 
76 struct ipsec_test_flags {
77 	bool display_alg;
78 	bool sa_expiry_pkts_soft;
79 	bool sa_expiry_pkts_hard;
80 	bool icv_corrupt;
81 	bool iv_gen;
82 	uint32_t tunnel_hdr_verify;
83 	bool udp_encap;
84 	bool udp_ports_verify;
85 	bool ip_csum;
86 	bool l4_csum;
87 	bool ipv6;
88 	bool tunnel_ipv6;
89 	bool transport;
90 	bool fragment;
91 	bool stats_success;
92 	bool antireplay;
93 	enum df_flags df;
94 	enum dscp_flags dscp;
95 	bool dec_ttl_or_hop_limit;
96 	bool ah;
97 };
98 
99 struct crypto_param {
100 	enum rte_crypto_sym_xform_type type;
101 	union {
102 		enum rte_crypto_cipher_algorithm cipher;
103 		enum rte_crypto_auth_algorithm auth;
104 		enum rte_crypto_aead_algorithm aead;
105 	} alg;
106 	uint16_t key_length;
107 	uint16_t iv_length;
108 	uint16_t digest_length;
109 };
110 
111 static const struct crypto_param aead_list[] = {
112 	{
113 		.type = RTE_CRYPTO_SYM_XFORM_AEAD,
114 		.alg.aead =  RTE_CRYPTO_AEAD_AES_GCM,
115 		.key_length = 16,
116 	},
117 	{
118 		.type = RTE_CRYPTO_SYM_XFORM_AEAD,
119 		.alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
120 		.key_length = 24,
121 	},
122 	{
123 		.type = RTE_CRYPTO_SYM_XFORM_AEAD,
124 		.alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
125 		.key_length = 32
126 	},
127 };
128 
129 static const struct crypto_param cipher_list[] = {
130 	{
131 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
132 		.alg.cipher =  RTE_CRYPTO_CIPHER_NULL,
133 		.key_length = 0,
134 		.iv_length = 0,
135 	},
136 	{
137 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
138 		.alg.cipher =  RTE_CRYPTO_CIPHER_AES_CBC,
139 		.key_length = 16,
140 		.iv_length = 16,
141 	},
142 	{
143 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
144 		.alg.cipher =  RTE_CRYPTO_CIPHER_AES_CTR,
145 		.key_length = 16,
146 		.iv_length = 16,
147 	},
148 	{
149 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
150 		.alg.cipher =  RTE_CRYPTO_CIPHER_AES_CTR,
151 		.key_length = 24,
152 		.iv_length = 16,
153 	},
154 	{
155 		.type = RTE_CRYPTO_SYM_XFORM_CIPHER,
156 		.alg.cipher =  RTE_CRYPTO_CIPHER_AES_CTR,
157 		.key_length = 32,
158 		.iv_length = 16,
159 	},
160 };
161 
162 static const struct crypto_param auth_list[] = {
163 	{
164 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
165 		.alg.auth =  RTE_CRYPTO_AUTH_NULL,
166 	},
167 	{
168 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
169 		.alg.auth =  RTE_CRYPTO_AUTH_SHA256_HMAC,
170 		.key_length = 32,
171 		.digest_length = 16,
172 	},
173 	{
174 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
175 		.alg.auth =  RTE_CRYPTO_AUTH_SHA384_HMAC,
176 		.key_length = 48,
177 		.digest_length = 24,
178 	},
179 	{
180 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
181 		.alg.auth =  RTE_CRYPTO_AUTH_SHA512_HMAC,
182 		.key_length = 64,
183 		.digest_length = 32,
184 	},
185 	{
186 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
187 		.alg.auth =  RTE_CRYPTO_AUTH_AES_XCBC_MAC,
188 		.key_length = 16,
189 		.digest_length = 12,
190 	},
191 	{
192 		.type = RTE_CRYPTO_SYM_XFORM_AUTH,
193 		.alg.auth =  RTE_CRYPTO_AUTH_AES_GMAC,
194 		.key_length = 16,
195 		.digest_length = 16,
196 		.iv_length = 12,
197 	},
198 };
199 
200 struct crypto_param_comb {
201 	const struct crypto_param *param1;
202 	const struct crypto_param *param2;
203 };
204 
205 extern struct ipsec_test_data pkt_aes_256_gcm;
206 extern struct ipsec_test_data pkt_aes_256_gcm_v6;
207 extern struct ipsec_test_data pkt_aes_128_cbc_hmac_sha256;
208 extern struct ipsec_test_data pkt_aes_128_cbc_hmac_sha256_v6;
209 
210 extern struct crypto_param_comb alg_list[RTE_DIM(aead_list) +
211 					 (RTE_DIM(cipher_list) *
212 					  RTE_DIM(auth_list))];
213 
214 extern struct crypto_param_comb ah_alg_list[2 * (RTE_DIM(auth_list) - 1)];
215 
216 void test_ipsec_alg_list_populate(void);
217 
218 void test_ipsec_ah_alg_list_populate(void);
219 
220 int test_ipsec_sec_caps_verify(struct rte_security_ipsec_xform *ipsec_xform,
221 			       const struct rte_security_capability *sec_cap,
222 			       bool silent);
223 
224 int test_ipsec_crypto_caps_aead_verify(
225 		const struct rte_security_capability *sec_cap,
226 		struct rte_crypto_sym_xform *aead);
227 
228 int test_ipsec_crypto_caps_cipher_verify(
229 		const struct rte_security_capability *sec_cap,
230 		struct rte_crypto_sym_xform *cipher);
231 
232 int test_ipsec_crypto_caps_auth_verify(
233 		const struct rte_security_capability *sec_cap,
234 		struct rte_crypto_sym_xform *auth);
235 
236 void test_ipsec_td_in_from_out(const struct ipsec_test_data *td_out,
237 			       struct ipsec_test_data *td_in);
238 
239 void test_ipsec_td_prepare(const struct crypto_param *param1,
240 			   const struct crypto_param *param2,
241 			   const struct ipsec_test_flags *flags,
242 			   struct ipsec_test_data *td_array,
243 			   int nb_td);
244 
245 void test_ipsec_td_update(struct ipsec_test_data td_inb[],
246 			  const struct ipsec_test_data td_outb[],
247 			  int nb_td,
248 			  const struct ipsec_test_flags *flags);
249 
250 void test_ipsec_display_alg(const struct crypto_param *param1,
251 			    const struct crypto_param *param2);
252 
253 int test_ipsec_post_process(struct rte_mbuf *m,
254 			    const struct ipsec_test_data *td,
255 			    struct ipsec_test_data *res_d, bool silent,
256 			    const struct ipsec_test_flags *flags);
257 
258 int test_ipsec_status_check(const struct ipsec_test_data *td,
259 			    struct rte_crypto_op *op,
260 			    const struct ipsec_test_flags *flags,
261 			    enum rte_security_ipsec_sa_direction dir,
262 			    int pkt_num);
263 
264 int test_ipsec_stats_verify(struct rte_security_ctx *ctx,
265 			    struct rte_security_session *sess,
266 			    const struct ipsec_test_flags *flags,
267 			    enum rte_security_ipsec_sa_direction dir);
268 
269 int test_ipsec_pkt_update(uint8_t *pkt, const struct ipsec_test_flags *flags);
270 
271 #endif
272