aboutsummaryrefslogtreecommitdiff
path: root/test/validation/api/ipsec/ipsec.h
blob: a2bb478a3b20f175e91f5d6b8a43d6ae49c92431 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* Copyright (c) 2017-2018, Linaro Limited
 * Copyright (c) 2020, Marvell
 * Copyright (c) 2020, Nokia
 * All rights reserved.
 *
 * SPDX-License-Identifier:     BSD-3-Clause
 */

#ifndef _ODP_TEST_IPSEC_H_
#define _ODP_TEST_IPSEC_H_

#include <odp_cunit_common.h>

#define IPV4ADDR(a, b, c, d) odp_cpu_to_be_32(((a) << 24) | \
					      ((b) << 16) | \
					      ((c) << 8) | \
					      ((d) << 0))

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

/* test arrays: */
extern odp_testinfo_t ipsec_in_suite[];
extern odp_testinfo_t ipsec_out_suite[];

int ipsec_init(odp_instance_t *inst, odp_ipsec_op_mode_t mode);
int ipsec_term(odp_instance_t inst);
int ipsec_config(odp_instance_t inst);

int ipsec_in_inline_init(void);
int ipsec_out_inline_init(void);

int ipsec_suite_sync_init(void);
int ipsec_suite_plain_init(void);
int ipsec_suite_sched_init(void);
int ipsec_suite_term(void);
int ipsec_in_term(void);
int ipsec_out_term(void);

struct suite_context_s {
	odp_bool_t reass_ipv4;
	odp_bool_t reass_ipv6;
	odp_ipsec_op_mode_t inbound_op_mode;
	odp_ipsec_op_mode_t outbound_op_mode;
	odp_pool_t pool;
	odp_queue_t default_queue;
	odp_queue_t queue;
	odp_pktio_t pktio;
	odp_queue_type_t q_type;
};

extern struct suite_context_s suite_context;

#define MAX_FRAG_LEN 1500
#define MAX_FRAGS 4
#define MAX_PKT_LEN (MAX_FRAG_LEN * MAX_FRAGS)

typedef struct {
	uint32_t len;
	uint32_t l2_offset;
	uint32_t l3_offset;
	uint32_t l4_offset;
	uint8_t data[MAX_PKT_LEN];
} ipsec_test_packet;

#define _ODP_PROTO_L3_TYPE_UNDEF ((odp_proto_l3_type_t)-1)
#define _ODP_PROTO_L4_TYPE_UNDEF ((odp_proto_l4_type_t)-1)

enum ipsec_test_stats {
	IPSEC_TEST_STATS_NONE = 0,
	IPSEC_TEST_STATS_SUCCESS,
	IPSEC_TEST_STATS_PROTO_ERR,
	IPSEC_TEST_STATS_AUTH_ERR,
};

typedef struct {
	odp_bool_t lookup;
	odp_bool_t inline_hdr_in_packet;
	odp_bool_t test_sa_seq_num;
} ipsec_test_part_flags_t;

typedef struct {
	ipsec_test_part_flags_t flags;

	/* Input for the inbound or outbound IPsec operation */
	const ipsec_test_packet *pkt_in;
	int num_opt;
	odp_ipsec_out_opt_t opt;

	/* Expected output */
	int num_pkt;
	struct {
		odp_ipsec_op_status_t status;
		odp_packet_reass_status_t reass_status;
		uint16_t num_frags;
		const ipsec_test_packet *pkt_res;
		odp_proto_l3_type_t l3_type;
		odp_proto_l4_type_t l4_type;
		uint32_t seq_num;
		/*
		 * Expected original IP length. Non zero only when expected len
		 * differs from that of input test packet (pkt_in).
		 */
		uint32_t orig_ip_len;
	} out[MAX_FRAGS];
} ipsec_test_part;

void ipsec_sa_param_fill(odp_ipsec_sa_param_t *param,
			 odp_ipsec_dir_t dir,
			 odp_ipsec_protocol_t proto,
			 uint32_t spi,
			 odp_ipsec_tunnel_param_t *tun,
			 odp_cipher_alg_t cipher_alg,
			 const odp_crypto_key_t *cipher_key,
			 odp_auth_alg_t auth_alg,
			 const odp_crypto_key_t *auth_key,
			 const odp_crypto_key_t *cipher_key_extra,
			 const odp_crypto_key_t *auth_key_extra);

void ipsec_sa_destroy(odp_ipsec_sa_t sa);
odp_packet_t ipsec_packet(const ipsec_test_packet *itp);
void ipsec_check_in_one(const ipsec_test_part *part, odp_ipsec_sa_t sa);
int ipsec_check_out(const ipsec_test_part *part,
		    odp_ipsec_sa_t sa,
		    odp_packet_t *pkto);
void ipsec_check_out_one(const ipsec_test_part *part, odp_ipsec_sa_t sa);
int ipsec_test_sa_update_seq_num(odp_ipsec_sa_t sa, uint32_t seq_num);
void ipsec_test_packet_from_pkt(ipsec_test_packet *test_pkt, odp_packet_t *pkt);
int ipsec_check(odp_bool_t ah,
		odp_cipher_alg_t cipher,
		uint32_t cipher_bits,
		odp_auth_alg_t auth,
		uint32_t auth_bits);
#define ipsec_check_ah(auth, auth_bits) \
	ipsec_check(true, ODP_CIPHER_ALG_NULL, 0, auth, auth_bits)
#define ipsec_check_esp(cipher, cipher_bits, auth, auth_bits) \
	ipsec_check(false, cipher, cipher_bits, auth, auth_bits)
int ipsec_check_ah_sha256(void);
int ipsec_check_esp_null_sha256(void);
int ipsec_check_esp_aes_cbc_128_null(void);
int ipsec_check_esp_aes_cbc_128_sha1(void);
int ipsec_check_esp_aes_cbc_128_sha256(void);
int ipsec_check_esp_aes_cbc_128_sha384(void);
int ipsec_check_esp_aes_cbc_128_sha512(void);
int ipsec_check_esp_aes_ctr_128_null(void);
int ipsec_check_esp_aes_gcm_128(void);
int ipsec_check_esp_aes_gcm_256(void);
int ipsec_check_ah_aes_gmac_128(void);
int ipsec_check_esp_null_aes_gmac_128(void);
int ipsec_check_esp_chacha20_poly1305(void);
int ipsec_check_test_sa_update_seq_num(void);
int ipsec_check_esp_aes_gcm_128_reass_ipv4(void);
int ipsec_check_esp_aes_gcm_128_reass_ipv6(void);
int ipsec_check_esp_null_aes_xcbc(void);

#endif