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