New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / crypto / aesni_mb / rte_aesni_mb_pmd_private.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2016 Intel Corporation
3  */
4
5 #ifndef _RTE_AESNI_MB_PMD_PRIVATE_H_
6 #define _RTE_AESNI_MB_PMD_PRIVATE_H_
7
8 #include "aesni_mb_ops.h"
9
10 #define CRYPTODEV_NAME_AESNI_MB_PMD     crypto_aesni_mb
11 /**< AES-NI Multi buffer PMD device name */
12
13 /** AESNI_MB PMD LOGTYPE DRIVER */
14 int aesni_mb_logtype_driver;
15
16 #define AESNI_MB_LOG(level, fmt, ...)  \
17         rte_log(RTE_LOG_ ## level, aesni_mb_logtype_driver,  \
18                         "%s() line %u: " fmt "\n", __func__, __LINE__,  \
19                                         ## __VA_ARGS__)
20
21
22 #define HMAC_IPAD_VALUE                 (0x36)
23 #define HMAC_OPAD_VALUE                 (0x5C)
24
25 /* Maximum length for digest */
26 #define DIGEST_LENGTH_MAX 64
27 static const unsigned auth_blocksize[] = {
28                 [MD5]           = 64,
29                 [SHA1]          = 64,
30                 [SHA_224]       = 64,
31                 [SHA_256]       = 64,
32                 [SHA_384]       = 128,
33                 [SHA_512]       = 128,
34                 [AES_XCBC]      = 16,
35                 [AES_CCM]       = 16,
36 };
37
38 /**
39  * Get the blocksize in bytes for a specified authentication algorithm
40  *
41  * @Note: this function will not return a valid value for a non-valid
42  * authentication algorithm
43  */
44 static inline unsigned
45 get_auth_algo_blocksize(JOB_HASH_ALG algo)
46 {
47         return auth_blocksize[algo];
48 }
49
50 static const unsigned auth_truncated_digest_byte_lengths[] = {
51                 [MD5]           = 12,
52                 [SHA1]          = 12,
53                 [SHA_224]       = 14,
54                 [SHA_256]       = 16,
55                 [SHA_384]       = 24,
56                 [SHA_512]       = 32,
57                 [AES_XCBC]      = 12,
58                 [AES_CMAC]      = 12,
59                 [AES_CCM]       = 8,
60                 [NULL_HASH]     = 0
61 };
62
63 /**
64  * Get the IPsec specified truncated length in bytes of the HMAC digest for a
65  * specified authentication algorithm
66  *
67  * @Note: this function will not return a valid value for a non-valid
68  * authentication algorithm
69  */
70 static inline unsigned
71 get_truncated_digest_byte_length(JOB_HASH_ALG algo)
72 {
73         return auth_truncated_digest_byte_lengths[algo];
74 }
75
76 static const unsigned auth_digest_byte_lengths[] = {
77                 [MD5]           = 16,
78                 [SHA1]          = 20,
79                 [SHA_224]       = 28,
80                 [SHA_256]       = 32,
81                 [SHA_384]       = 48,
82                 [SHA_512]       = 64,
83                 [AES_XCBC]      = 16,
84                 [AES_CMAC]      = 16,
85                 [AES_GMAC]      = 12,
86                 [NULL_HASH]             = 0
87 };
88
89 /**
90  * Get the full digest size in bytes for a specified authentication algorithm
91  * (if available in the Multi-buffer library)
92  *
93  * @Note: this function will not return a valid value for a non-valid
94  * authentication algorithm
95  */
96 static inline unsigned
97 get_digest_byte_length(JOB_HASH_ALG algo)
98 {
99         return auth_digest_byte_lengths[algo];
100 }
101
102 enum aesni_mb_operation {
103         AESNI_MB_OP_HASH_CIPHER,
104         AESNI_MB_OP_CIPHER_HASH,
105         AESNI_MB_OP_HASH_ONLY,
106         AESNI_MB_OP_CIPHER_ONLY,
107         AESNI_MB_OP_AEAD_HASH_CIPHER,
108         AESNI_MB_OP_AEAD_CIPHER_HASH,
109         AESNI_MB_OP_NOT_SUPPORTED
110 };
111
112 /** private data structure for each virtual AESNI device */
113 struct aesni_mb_private {
114         enum aesni_mb_vector_mode vector_mode;
115         /**< CPU vector instruction set mode */
116         unsigned max_nb_queue_pairs;
117         /**< Max number of queue pairs supported by device */
118 };
119
120 /** AESNI Multi buffer queue pair */
121 struct aesni_mb_qp {
122         uint16_t id;
123         /**< Queue Pair Identifier */
124         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
125         /**< Unique Queue Pair Name */
126         const struct aesni_mb_op_fns *op_fns;
127         /**< Vector mode dependent pointer table of the multi-buffer APIs */
128         MB_MGR *mb_mgr;
129         /**< Multi-buffer instance */
130         struct rte_ring *ingress_queue;
131        /**< Ring for placing operations ready for processing */
132         struct rte_mempool *sess_mp;
133         /**< Session Mempool */
134         struct rte_cryptodev_stats stats;
135         /**< Queue pair statistics */
136         uint8_t digest_idx;
137         /**< Index of the next slot to be used in temp_digests,
138          * to store the digest for a given operation
139          */
140         uint8_t temp_digests[MAX_JOBS][DIGEST_LENGTH_MAX];
141         /**< Buffers used to store the digest generated
142          * by the driver when verifying a digest provided
143          * by the user (using authentication verify operation)
144          */
145 } __rte_cache_aligned;
146
147 /** AES-NI multi-buffer private session structure */
148 struct aesni_mb_session {
149         JOB_CHAIN_ORDER chain_order;
150         struct {
151                 uint16_t length;
152                 uint16_t offset;
153         } iv;
154         /**< IV parameters */
155
156         /** Cipher Parameters */
157         struct {
158                 /** Cipher direction - encrypt / decrypt */
159                 JOB_CIPHER_DIRECTION direction;
160                 /** Cipher mode - CBC / Counter */
161                 JOB_CIPHER_MODE mode;
162
163                 uint64_t key_length_in_bytes;
164
165                 union {
166                         struct {
167                                 uint32_t encode[60] __rte_aligned(16);
168                                 /**< encode key */
169                                 uint32_t decode[60] __rte_aligned(16);
170                                 /**< decode key */
171                         } expanded_aes_keys;
172                         struct {
173                                 const void *ks_ptr[3];
174                                 uint64_t key[3][16];
175                         } exp_3des_keys;
176
177                         struct gcm_key_data gcm_key;
178                 };
179                 /**< Expanded AES keys - Allocating space to
180                  * contain the maximum expanded key size which
181                  * is 240 bytes for 256 bit AES, calculate by:
182                  * ((key size (bytes)) *
183                  * ((number of rounds) + 1))
184                  */
185         } cipher;
186
187         /** Authentication Parameters */
188         struct {
189                 JOB_HASH_ALG algo; /**< Authentication Algorithm */
190                 enum rte_crypto_auth_operation operation;
191                 /**< auth operation generate or verify */
192                 union {
193                         struct {
194                                 uint8_t inner[128] __rte_aligned(16);
195                                 /**< inner pad */
196                                 uint8_t outer[128] __rte_aligned(16);
197                                 /**< outer pad */
198                         } pads;
199                         /**< HMAC Authentication pads -
200                          * allocating space for the maximum pad
201                          * size supported which is 128 bytes for
202                          * SHA512
203                          */
204
205                         struct {
206                             uint32_t k1_expanded[44] __rte_aligned(16);
207                             /**< k1 (expanded key). */
208                             uint8_t k2[16] __rte_aligned(16);
209                             /**< k2. */
210                             uint8_t k3[16] __rte_aligned(16);
211                             /**< k3. */
212                         } xcbc;
213
214                         struct {
215                                 uint32_t expkey[60] __rte_aligned(16);
216                                                     /**< k1 (expanded key). */
217                                 uint32_t skey1[4] __rte_aligned(16);
218                                                     /**< k2. */
219                                 uint32_t skey2[4] __rte_aligned(16);
220                                                     /**< k3. */
221                         } cmac;
222                         /**< Expanded XCBC authentication keys */
223                 };
224         /** Generated digest size by the Multi-buffer library */
225         uint16_t gen_digest_len;
226         /** Requested digest size from Cryptodev */
227         uint16_t req_digest_len;
228
229         } auth;
230         struct {
231                 /** AAD data length */
232                 uint16_t aad_len;
233         } aead;
234 } __rte_cache_aligned;
235
236
237 /**
238  *
239  */
240 extern int
241 aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
242                 struct aesni_mb_session *sess,
243                 const struct rte_crypto_sym_xform *xform);
244
245
246 /** device specific operations function pointer structure */
247 extern struct rte_cryptodev_ops *rte_aesni_mb_pmd_ops;
248
249
250
251 #endif /* _RTE_AESNI_MB_PMD_PRIVATE_H_ */