492521930f34c2f9a82cde28a8e6defdf8dab484
[dpdk.git] / lib / librte_ipsec / sa.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #ifndef _SA_H_
6 #define _SA_H_
7
8 #define IPSEC_MAX_HDR_SIZE      64
9 #define IPSEC_MAX_IV_SIZE       16
10 #define IPSEC_MAX_IV_QWORD      (IPSEC_MAX_IV_SIZE / sizeof(uint64_t))
11
12 /* padding alignment for different algorithms */
13 enum {
14         IPSEC_PAD_DEFAULT = 4,
15         IPSEC_PAD_AES_CBC = IPSEC_MAX_IV_SIZE,
16         IPSEC_PAD_AES_GCM = IPSEC_PAD_DEFAULT,
17         IPSEC_PAD_NULL = IPSEC_PAD_DEFAULT,
18 };
19
20 /* these definitions probably has to be in rte_crypto_sym.h */
21 union sym_op_ofslen {
22         uint64_t raw;
23         struct {
24                 uint32_t offset;
25                 uint32_t length;
26         };
27 };
28
29 union sym_op_data {
30 #ifdef __SIZEOF_INT128__
31         __uint128_t raw;
32 #endif
33         struct {
34                 uint8_t *va;
35                 rte_iova_t pa;
36         };
37 };
38
39 struct replay_sqn {
40         uint64_t sqn;
41         __extension__ uint64_t window[0];
42 };
43
44 struct rte_ipsec_sa {
45         uint64_t type;     /* type of given SA */
46         uint64_t udata;    /* user defined */
47         uint32_t size;     /* size of given sa object */
48         uint32_t spi;
49         /* sqn calculations related */
50         uint64_t sqn_mask;
51         struct {
52                 uint32_t win_sz;
53                 uint16_t nb_bucket;
54                 uint16_t bucket_index_mask;
55         } replay;
56         /* template for crypto op fields */
57         struct {
58                 union sym_op_ofslen cipher;
59                 union sym_op_ofslen auth;
60         } ctp;
61         uint32_t salt;
62         uint8_t proto;    /* next proto */
63         uint8_t aad_len;
64         uint8_t hdr_len;
65         uint8_t hdr_l3_off;
66         uint8_t icv_len;
67         uint8_t sqh_len;
68         uint8_t iv_ofs; /* offset for algo-specific IV inside crypto op */
69         uint8_t iv_len;
70         uint8_t pad_align;
71
72         /* template for tunnel header */
73         uint8_t hdr[IPSEC_MAX_HDR_SIZE];
74
75         /*
76          * sqn and replay window
77          */
78         union {
79                 uint64_t outb;
80                 struct replay_sqn *inb;
81         } sqn;
82
83 } __rte_cache_aligned;
84
85 #endif /* _SA_H_ */