1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #ifndef _TEST_CRYPTODEV_SECURITY_IPSEC_H_
6 #define _TEST_CRYPTODEV_SECURITY_IPSEC_H_
8 #include <rte_cryptodev.h>
9 #include <rte_security.h>
11 #define IPSEC_TEST_PACKETS_MAX 32
13 struct ipsec_test_data {
40 struct rte_security_ipsec_xform ipsec_xform;
48 /* Antireplay packet */
53 struct rte_crypto_sym_xform cipher;
54 struct rte_crypto_sym_xform auth;
56 struct rte_crypto_sym_xform aead;
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,
67 #define TEST_IPSEC_DSCP_VAL 0x12
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,
76 struct ipsec_test_flags {
78 bool sa_expiry_pkts_soft;
79 bool sa_expiry_pkts_hard;
82 uint32_t tunnel_hdr_verify;
84 bool udp_ports_verify;
95 bool dec_ttl_or_hop_limit;
100 enum rte_crypto_sym_xform_type type;
102 enum rte_crypto_cipher_algorithm cipher;
103 enum rte_crypto_auth_algorithm auth;
104 enum rte_crypto_aead_algorithm aead;
108 uint16_t digest_length;
111 static const struct crypto_param aead_list[] = {
113 .type = RTE_CRYPTO_SYM_XFORM_AEAD,
114 .alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
118 .type = RTE_CRYPTO_SYM_XFORM_AEAD,
119 .alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
123 .type = RTE_CRYPTO_SYM_XFORM_AEAD,
124 .alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
129 static const struct crypto_param cipher_list[] = {
131 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,
132 .alg.cipher = RTE_CRYPTO_CIPHER_NULL,
137 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,
138 .alg.cipher = RTE_CRYPTO_CIPHER_AES_CBC,
143 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,
144 .alg.cipher = RTE_CRYPTO_CIPHER_AES_CTR,
149 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,
150 .alg.cipher = RTE_CRYPTO_CIPHER_AES_CTR,
155 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,
156 .alg.cipher = RTE_CRYPTO_CIPHER_AES_CTR,
162 static const struct crypto_param auth_list[] = {
164 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
165 .alg.auth = RTE_CRYPTO_AUTH_NULL,
168 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
169 .alg.auth = RTE_CRYPTO_AUTH_SHA256_HMAC,
174 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
175 .alg.auth = RTE_CRYPTO_AUTH_SHA384_HMAC,
180 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
181 .alg.auth = RTE_CRYPTO_AUTH_SHA512_HMAC,
186 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
187 .alg.auth = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
192 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
193 .alg.auth = RTE_CRYPTO_AUTH_AES_GMAC,
200 struct crypto_param_comb {
201 const struct crypto_param *param1;
202 const struct crypto_param *param2;
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;
210 extern struct crypto_param_comb alg_list[RTE_DIM(aead_list) +
211 (RTE_DIM(cipher_list) *
212 RTE_DIM(auth_list))];
214 extern struct crypto_param_comb ah_alg_list[2 * (RTE_DIM(auth_list) - 1)];
216 void test_ipsec_alg_list_populate(void);
218 void test_ipsec_ah_alg_list_populate(void);
220 int test_ipsec_sec_caps_verify(struct rte_security_ipsec_xform *ipsec_xform,
221 const struct rte_security_capability *sec_cap,
224 int test_ipsec_crypto_caps_aead_verify(
225 const struct rte_security_capability *sec_cap,
226 struct rte_crypto_sym_xform *aead);
228 int test_ipsec_crypto_caps_cipher_verify(
229 const struct rte_security_capability *sec_cap,
230 struct rte_crypto_sym_xform *cipher);
232 int test_ipsec_crypto_caps_auth_verify(
233 const struct rte_security_capability *sec_cap,
234 struct rte_crypto_sym_xform *auth);
236 void test_ipsec_td_in_from_out(const struct ipsec_test_data *td_out,
237 struct ipsec_test_data *td_in);
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,
245 void test_ipsec_td_update(struct ipsec_test_data td_inb[],
246 const struct ipsec_test_data td_outb[],
248 const struct ipsec_test_flags *flags);
250 void test_ipsec_display_alg(const struct crypto_param *param1,
251 const struct crypto_param *param2);
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);
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,
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);
269 int test_ipsec_pkt_update(uint8_t *pkt, const struct ipsec_test_flags *flags);