8c027a87e4d7464912911734b64d37ce330a6ebf
[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                 [NULL_HASH]             = 0
86 };
87
88 /**
89  * Get the full digest size in bytes for a specified authentication algorithm
90  * (if available in the Multi-buffer library)
91  *
92  * @Note: this function will not return a valid value for a non-valid
93  * authentication algorithm
94  */
95 static inline unsigned
96 get_digest_byte_length(JOB_HASH_ALG algo)
97 {
98         return auth_digest_byte_lengths[algo];
99 }
100
101 enum aesni_mb_operation {
102         AESNI_MB_OP_HASH_CIPHER,
103         AESNI_MB_OP_CIPHER_HASH,
104         AESNI_MB_OP_HASH_ONLY,
105         AESNI_MB_OP_CIPHER_ONLY,
106         AESNI_MB_OP_AEAD_HASH_CIPHER,
107         AESNI_MB_OP_AEAD_CIPHER_HASH,
108         AESNI_MB_OP_NOT_SUPPORTED
109 };
110
111 /** private data structure for each virtual AESNI device */
112 struct aesni_mb_private {
113         enum aesni_mb_vector_mode vector_mode;
114         /**< CPU vector instruction set mode */
115         unsigned max_nb_queue_pairs;
116         /**< Max number of queue pairs supported by device */
117 };
118
119 /** AESNI Multi buffer queue pair */
120 struct aesni_mb_qp {
121         uint16_t id;
122         /**< Queue Pair Identifier */
123         char name[RTE_CRYPTODEV_NAME_MAX_LEN];
124         /**< Unique Queue Pair Name */
125         const struct aesni_mb_op_fns *op_fns;
126         /**< Vector mode dependent pointer table of the multi-buffer APIs */
127         MB_MGR *mb_mgr;
128         /**< Multi-buffer instance */
129         struct rte_ring *ingress_queue;
130        /**< Ring for placing operations ready for processing */
131         struct rte_mempool *sess_mp;
132         /**< Session Mempool */
133         struct rte_cryptodev_stats stats;
134         /**< Queue pair statistics */
135         uint8_t digest_idx;
136         /**< Index of the next slot to be used in temp_digests,
137          * to store the digest for a given operation
138          */
139         uint8_t temp_digests[MAX_JOBS][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 } __rte_cache_aligned;
145
146 /** AES-NI multi-buffer private session structure */
147 struct aesni_mb_session {
148         JOB_CHAIN_ORDER chain_order;
149         struct {
150                 uint16_t length;
151                 uint16_t offset;
152         } iv;
153         /**< IV parameters */
154
155         /** Cipher Parameters */
156         struct {
157                 /** Cipher direction - encrypt / decrypt */
158                 JOB_CIPHER_DIRECTION direction;
159                 /** Cipher mode - CBC / Counter */
160                 JOB_CIPHER_MODE mode;
161
162                 uint64_t key_length_in_bytes;
163
164                 union {
165                         struct {
166                                 uint32_t encode[60] __rte_aligned(16);
167                                 /**< encode key */
168                                 uint32_t decode[60] __rte_aligned(16);
169                                 /**< decode key */
170                         } expanded_aes_keys;
171                         struct {
172                                 const void *ks_ptr[3];
173                                 uint64_t key[3][16];
174                         } exp_3des_keys;
175                 };
176                 /**< Expanded AES keys - Allocating space to
177                  * contain the maximum expanded key size which
178                  * is 240 bytes for 256 bit AES, calculate by:
179                  * ((key size (bytes)) *
180                  * ((number of rounds) + 1))
181                  */
182         } cipher;
183
184         /** Authentication Parameters */
185         struct {
186                 JOB_HASH_ALG algo; /**< Authentication Algorithm */
187                 enum rte_crypto_auth_operation operation;
188                 /**< auth operation generate or verify */
189                 union {
190                         struct {
191                                 uint8_t inner[128] __rte_aligned(16);
192                                 /**< inner pad */
193                                 uint8_t outer[128] __rte_aligned(16);
194                                 /**< outer pad */
195                         } pads;
196                         /**< HMAC Authentication pads -
197                          * allocating space for the maximum pad
198                          * size supported which is 128 bytes for
199                          * SHA512
200                          */
201
202                         struct {
203                             uint32_t k1_expanded[44] __rte_aligned(16);
204                             /**< k1 (expanded key). */
205                             uint8_t k2[16] __rte_aligned(16);
206                             /**< k2. */
207                             uint8_t k3[16] __rte_aligned(16);
208                             /**< k3. */
209                         } xcbc;
210
211                         struct {
212                                 uint32_t expkey[60] __rte_aligned(16);
213                                                     /**< k1 (expanded key). */
214                                 uint32_t skey1[4] __rte_aligned(16);
215                                                     /**< k2. */
216                                 uint32_t skey2[4] __rte_aligned(16);
217                                                     /**< k3. */
218                         } cmac;
219                         /**< Expanded XCBC authentication keys */
220                 };
221         /** Generated digest size by the Multi-buffer library */
222         uint16_t gen_digest_len;
223         /** Requested digest size from Cryptodev */
224         uint16_t req_digest_len;
225
226         } auth;
227         struct {
228                 /** AAD data length */
229                 uint16_t aad_len;
230         } aead;
231 } __rte_cache_aligned;
232
233
234 /**
235  *
236  */
237 extern int
238 aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
239                 struct aesni_mb_session *sess,
240                 const struct rte_crypto_sym_xform *xform);
241
242
243 /** device specific operations function pointer structure */
244 extern struct rte_cryptodev_ops *rte_aesni_mb_pmd_ops;
245
246
247
248 #endif /* _RTE_AESNI_MB_PMD_PRIVATE_H_ */