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;
46 /* Antireplay packet */
51 struct rte_crypto_sym_xform cipher;
52 struct rte_crypto_sym_xform auth;
54 struct rte_crypto_sym_xform aead;
59 TEST_IPSEC_COPY_DF_INNER_0 = 1,
60 TEST_IPSEC_COPY_DF_INNER_1,
61 TEST_IPSEC_SET_DF_0_INNER_1,
62 TEST_IPSEC_SET_DF_1_INNER_0,
65 #define TEST_IPSEC_DSCP_VAL 0x12
68 TEST_IPSEC_COPY_DSCP_INNER_0 = 1,
69 TEST_IPSEC_COPY_DSCP_INNER_1,
70 TEST_IPSEC_SET_DSCP_0_INNER_1,
71 TEST_IPSEC_SET_DSCP_1_INNER_0,
74 struct ipsec_test_flags {
76 bool sa_expiry_pkts_soft;
77 bool sa_expiry_pkts_hard;
80 uint32_t tunnel_hdr_verify;
82 bool udp_ports_verify;
93 bool dec_ttl_or_hop_limit;
98 enum rte_crypto_sym_xform_type type;
100 enum rte_crypto_cipher_algorithm cipher;
101 enum rte_crypto_auth_algorithm auth;
102 enum rte_crypto_aead_algorithm aead;
106 uint16_t digest_length;
109 static const struct crypto_param aead_list[] = {
111 .type = RTE_CRYPTO_SYM_XFORM_AEAD,
112 .alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
116 .type = RTE_CRYPTO_SYM_XFORM_AEAD,
117 .alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
121 .type = RTE_CRYPTO_SYM_XFORM_AEAD,
122 .alg.aead = RTE_CRYPTO_AEAD_AES_GCM,
127 static const struct crypto_param cipher_list[] = {
129 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,
130 .alg.cipher = RTE_CRYPTO_CIPHER_NULL,
135 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,
136 .alg.cipher = RTE_CRYPTO_CIPHER_AES_CBC,
141 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,
142 .alg.cipher = RTE_CRYPTO_CIPHER_AES_CTR,
147 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,
148 .alg.cipher = RTE_CRYPTO_CIPHER_AES_CTR,
153 .type = RTE_CRYPTO_SYM_XFORM_CIPHER,
154 .alg.cipher = RTE_CRYPTO_CIPHER_AES_CTR,
160 static const struct crypto_param auth_list[] = {
162 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
163 .alg.auth = RTE_CRYPTO_AUTH_NULL,
166 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
167 .alg.auth = RTE_CRYPTO_AUTH_SHA256_HMAC,
172 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
173 .alg.auth = RTE_CRYPTO_AUTH_SHA384_HMAC,
178 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
179 .alg.auth = RTE_CRYPTO_AUTH_SHA512_HMAC,
184 .type = RTE_CRYPTO_SYM_XFORM_AUTH,
185 .alg.auth = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
191 struct crypto_param_comb {
192 const struct crypto_param *param1;
193 const struct crypto_param *param2;
196 extern struct ipsec_test_data pkt_aes_256_gcm;
197 extern struct ipsec_test_data pkt_aes_256_gcm_v6;
198 extern struct ipsec_test_data pkt_aes_128_cbc_hmac_sha256;
199 extern struct ipsec_test_data pkt_aes_128_cbc_hmac_sha256_v6;
201 extern struct crypto_param_comb alg_list[RTE_DIM(aead_list) +
202 (RTE_DIM(cipher_list) *
203 RTE_DIM(auth_list))];
205 extern struct crypto_param_comb ah_alg_list[2 * (RTE_DIM(auth_list) - 1)];
207 void test_ipsec_alg_list_populate(void);
209 void test_ipsec_ah_alg_list_populate(void);
211 int test_ipsec_sec_caps_verify(struct rte_security_ipsec_xform *ipsec_xform,
212 const struct rte_security_capability *sec_cap,
215 int test_ipsec_crypto_caps_aead_verify(
216 const struct rte_security_capability *sec_cap,
217 struct rte_crypto_sym_xform *aead);
219 int test_ipsec_crypto_caps_cipher_verify(
220 const struct rte_security_capability *sec_cap,
221 struct rte_crypto_sym_xform *cipher);
223 int test_ipsec_crypto_caps_auth_verify(
224 const struct rte_security_capability *sec_cap,
225 struct rte_crypto_sym_xform *auth);
227 void test_ipsec_td_in_from_out(const struct ipsec_test_data *td_out,
228 struct ipsec_test_data *td_in);
230 void test_ipsec_td_prepare(const struct crypto_param *param1,
231 const struct crypto_param *param2,
232 const struct ipsec_test_flags *flags,
233 struct ipsec_test_data *td_array,
236 void test_ipsec_td_update(struct ipsec_test_data td_inb[],
237 const struct ipsec_test_data td_outb[],
239 const struct ipsec_test_flags *flags);
241 void test_ipsec_display_alg(const struct crypto_param *param1,
242 const struct crypto_param *param2);
244 int test_ipsec_post_process(struct rte_mbuf *m,
245 const struct ipsec_test_data *td,
246 struct ipsec_test_data *res_d, bool silent,
247 const struct ipsec_test_flags *flags);
249 int test_ipsec_status_check(const struct ipsec_test_data *td,
250 struct rte_crypto_op *op,
251 const struct ipsec_test_flags *flags,
252 enum rte_security_ipsec_sa_direction dir,
255 int test_ipsec_stats_verify(struct rte_security_ctx *ctx,
256 struct rte_security_session *sess,
257 const struct ipsec_test_flags *flags,
258 enum rte_security_ipsec_sa_direction dir);
260 int test_ipsec_pkt_update(uint8_t *pkt, const struct ipsec_test_flags *flags);