crypto/ipsec_mb: move aesni_gcm PMD
[dpdk.git] / drivers / crypto / ipsec_mb / pmd_aesni_gcm_priv.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2021 Intel Corporation
3  */
4
5 #ifndef _PMD_AESNI_GCM_PRIV_H_
6 #define _PMD_AESNI_GCM_PRIV_H_
7
8 #include <intel-ipsec-mb.h>
9
10 #include "ipsec_mb_private.h"
11
12 #define AESNI_GCM_IV_LENGTH 12
13
14 static const struct rte_cryptodev_capabilities aesni_gcm_capabilities[] = {
15         {       /* AES GMAC (AUTH) */
16                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
17                 {.sym = {
18                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
19                         {.auth = {
20                                 .algo = RTE_CRYPTO_AUTH_AES_GMAC,
21                                 .block_size = 16,
22                                 .key_size = {
23                                         .min = 16,
24                                         .max = 32,
25                                         .increment = 8
26                                 },
27                                 .digest_size = {
28                                         .min = 1,
29                                         .max = 16,
30                                         .increment = 1
31                                 },
32                                 .iv_size = {
33                                         .min = AESNI_GCM_IV_LENGTH,
34                                         .max = AESNI_GCM_IV_LENGTH,
35                                         .increment = 0
36                                 }
37                         }, }
38                 }, }
39         },
40         {       /* AES GCM */
41                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
42                 {.sym = {
43                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
44                         {.aead = {
45                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
46                                 .block_size = 16,
47                                 .key_size = {
48                                         .min = 16,
49                                         .max = 32,
50                                         .increment = 8
51                                 },
52                                 .digest_size = {
53                                         .min = 1,
54                                         .max = 16,
55                                         .increment = 1
56                                 },
57                                 .aad_size = {
58                                         .min = 0,
59                                         .max = 65535,
60                                         .increment = 1
61                                 },
62                                 .iv_size = {
63                                         .min = AESNI_GCM_IV_LENGTH,
64                                         .max = AESNI_GCM_IV_LENGTH,
65                                         .increment = 0
66                                 }
67                         }, }
68                 }, }
69         },
70         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
71 };
72
73 uint8_t pmd_driver_id_aesni_gcm;
74
75 enum aesni_gcm_key_length {
76         GCM_KEY_128 = 0,
77         GCM_KEY_192,
78         GCM_KEY_256,
79         GCM_NUM_KEY_TYPES
80 };
81
82 typedef void (*aesni_gcm_t)(const struct gcm_key_data *gcm_key_data,
83                             struct gcm_context_data *gcm_ctx_data,
84                             uint8_t *out, const uint8_t *in,
85                             uint64_t plaintext_len, const uint8_t *iv,
86                             const uint8_t *aad, uint64_t aad_len,
87                             uint8_t *auth_tag, uint64_t auth_tag_len);
88
89 typedef void (*aesni_gcm_pre_t)(const void *key,
90                                 struct gcm_key_data *gcm_data);
91
92 typedef void (*aesni_gcm_init_t)(const struct gcm_key_data *gcm_key_data,
93                                  struct gcm_context_data *gcm_ctx_data,
94                                  const uint8_t *iv, uint8_t const *aad,
95                                  uint64_t aad_len);
96
97 typedef void (*aesni_gcm_update_t)(const struct gcm_key_data *gcm_key_data,
98                                    struct gcm_context_data *gcm_ctx_data,
99                                    uint8_t *out, const uint8_t *in,
100                                    uint64_t plaintext_len);
101
102 typedef void (*aesni_gcm_finalize_t)(const struct gcm_key_data *gcm_key_data,
103                                      struct gcm_context_data *gcm_ctx_data,
104                                      uint8_t *auth_tag, uint64_t auth_tag_len);
105
106 typedef void (*aesni_gmac_init_t)(const struct gcm_key_data *gcm_key_data,
107                                   struct gcm_context_data *gcm_ctx_data,
108                                   const uint8_t *iv, const uint64_t iv_len);
109
110 typedef void (*aesni_gmac_update_t)(const struct gcm_key_data *gcm_key_data,
111                                     struct gcm_context_data *gcm_ctx_data,
112                                     const uint8_t *in,
113                                     const uint64_t plaintext_len);
114
115 typedef void (*aesni_gmac_finalize_t)(const struct gcm_key_data *gcm_key_data,
116                                       struct gcm_context_data *gcm_ctx_data,
117                                       uint8_t *auth_tag,
118                                       const uint64_t auth_tag_len);
119
120 /** GCM operation handlers */
121 struct aesni_gcm_ops {
122         aesni_gcm_t enc;
123         aesni_gcm_t dec;
124         aesni_gcm_pre_t pre;
125         aesni_gcm_init_t init;
126         aesni_gcm_update_t update_enc;
127         aesni_gcm_update_t update_dec;
128         aesni_gcm_finalize_t finalize_enc;
129         aesni_gcm_finalize_t finalize_dec;
130         aesni_gmac_init_t gmac_init;
131         aesni_gmac_update_t gmac_update;
132         aesni_gmac_finalize_t gmac_finalize;
133 };
134
135 RTE_DEFINE_PER_LCORE(struct aesni_gcm_ops[GCM_NUM_KEY_TYPES], gcm_ops);
136
137 struct aesni_gcm_qp_data {
138         struct gcm_context_data gcm_ctx_data;
139         uint8_t temp_digest[DIGEST_LENGTH_MAX];
140         /* *< Buffers used to store the digest generated
141          * by the driver when verifying a digest provided
142          * by the user (using authentication verify operation)
143          */
144         struct aesni_gcm_ops ops[GCM_NUM_KEY_TYPES];
145         /**< Operation Handlers */
146 };
147
148 /** AESNI GCM private session structure */
149 struct aesni_gcm_session {
150         struct {
151                 uint16_t length;
152                 uint16_t offset;
153         } iv;
154         /**< IV parameters */
155         uint16_t aad_length;
156         /**< AAD length */
157         uint16_t req_digest_length;
158         /**< Requested digest length */
159         uint16_t gen_digest_length;
160         /**< Generated digest length */
161         enum ipsec_mb_operation op;
162         /**< GCM operation type */
163         struct gcm_key_data gdata_key;
164         /**< GCM parameters */
165         enum aesni_gcm_key_length key_length;
166         /** Key Length */
167 };
168
169 #endif /* _PMD_AESNI_GCM_PRIV_H_ */