drivers: use SPDX tag for Intel copyright files
[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 #define MB_LOG_ERR(fmt, args...) \
14         RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n",  \
15                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), \
16                         __func__, __LINE__, ## args)
17
18 #ifdef RTE_LIBRTE_AESNI_MB_DEBUG
19 #define MB_LOG_INFO(fmt, args...) \
20         RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
21                         CRYPTODEV_NAME_AESNI_MB_PMD, \
22                         __func__, __LINE__, ## args)
23
24 #define MB_LOG_DBG(fmt, args...) \
25         RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
26                         CRYPTODEV_NAME_AESNI_MB_PMD, \
27                         __func__, __LINE__, ## args)
28 #else
29 #define MB_LOG_INFO(fmt, args...)
30 #define MB_LOG_DBG(fmt, args...)
31 #endif
32
33 #define HMAC_IPAD_VALUE                 (0x36)
34 #define HMAC_OPAD_VALUE                 (0x5C)
35
36 /* Maximum length for digest (SHA-512 truncated needs 32 bytes) */
37 #define DIGEST_LENGTH_MAX 32
38 static const unsigned auth_blocksize[] = {
39                 [MD5]           = 64,
40                 [SHA1]          = 64,
41                 [SHA_224]       = 64,
42                 [SHA_256]       = 64,
43                 [SHA_384]       = 128,
44                 [SHA_512]       = 128,
45                 [AES_XCBC]      = 16,
46 };
47
48 /**
49  * Get the blocksize in bytes for a specified authentication algorithm
50  *
51  * @Note: this function will not return a valid value for a non-valid
52  * authentication algorithm
53  */
54 static inline unsigned
55 get_auth_algo_blocksize(JOB_HASH_ALG algo)
56 {
57         return auth_blocksize[algo];
58 }
59
60 static const unsigned auth_truncated_digest_byte_lengths[] = {
61                 [MD5]           = 12,
62                 [SHA1]          = 12,
63                 [SHA_224]       = 14,
64                 [SHA_256]       = 16,
65                 [SHA_384]       = 24,
66                 [SHA_512]       = 32,
67                 [AES_XCBC]      = 12,
68                 [NULL_HASH]     = 0
69 };
70
71 /**
72  * Get the IPsec specified truncated length in bytes of the HMAC digest for a
73  * specified authentication algorithm
74  *
75  * @Note: this function will not return a valid value for a non-valid
76  * authentication algorithm
77  */
78 static inline unsigned
79 get_truncated_digest_byte_length(JOB_HASH_ALG algo)
80 {
81         return auth_truncated_digest_byte_lengths[algo];
82 }
83
84 static const unsigned auth_digest_byte_lengths[] = {
85                 [MD5]           = 16,
86                 [SHA1]          = 20,
87                 [SHA_224]       = 28,
88                 [SHA_256]       = 32,
89                 [SHA_384]       = 48,
90                 [SHA_512]       = 64,
91                 [AES_XCBC]      = 16,
92                 [NULL_HASH]     = 0
93 };
94
95 /**
96  * Get the output digest size in bytes for a specified authentication algorithm
97  *
98  * @Note: this function will not return a valid value for a non-valid
99  * authentication algorithm
100  */
101 static inline unsigned
102 get_digest_byte_length(JOB_HASH_ALG algo)
103 {
104         return auth_digest_byte_lengths[algo];
105 }
106
107 enum aesni_mb_operation {
108         AESNI_MB_OP_HASH_CIPHER,
109         AESNI_MB_OP_CIPHER_HASH,
110         AESNI_MB_OP_HASH_ONLY,
111         AESNI_MB_OP_CIPHER_ONLY,
112         AESNI_MB_OP_NOT_SUPPORTED
113 };
114
115 /** private data structure for each virtual AESNI device */
116 struct aesni_mb_private {
117         enum aesni_mb_vector_mode vector_mode;
118         /**< CPU vector instruction set mode */
119         unsigned max_nb_queue_pairs;
120         /**< Max number of queue pairs supported by device */
121         unsigned max_nb_sessions;
122         /**< Max number of sessions supported by device */
123 };
124
125 /** AESNI Multi buffer queue pair */
126 struct aesni_mb_qp {
127         uint16_t id;
128         /**< Queue Pair Identifier */
129         char name[RTE_CRYPTODEV_NAME_LEN];
130         /**< Unique Queue Pair Name */
131         const struct aesni_mb_op_fns *op_fns;
132         /**< Vector mode dependent pointer table of the multi-buffer APIs */
133         MB_MGR mb_mgr;
134         /**< Multi-buffer instance */
135         struct rte_ring *ingress_queue;
136        /**< Ring for placing operations ready for processing */
137         struct rte_mempool *sess_mp;
138         /**< Session Mempool */
139         struct rte_cryptodev_stats stats;
140         /**< Queue pair statistics */
141         uint8_t digest_idx;
142         /**< Index of the next slot to be used in temp_digests,
143          * to store the digest for a given operation
144          */
145         uint8_t temp_digests[MAX_JOBS][DIGEST_LENGTH_MAX];
146         /**< Buffers used to store the digest generated
147          * by the driver when verifying a digest provided
148          * by the user (using authentication verify operation)
149          */
150 } __rte_cache_aligned;
151
152 /** AES-NI multi-buffer private session structure */
153 struct aesni_mb_session {
154         JOB_CHAIN_ORDER chain_order;
155         struct {
156                 uint16_t length;
157                 uint16_t offset;
158         } iv;
159         /**< IV parameters */
160
161         /** Cipher Parameters */
162         struct {
163                 /** Cipher direction - encrypt / decrypt */
164                 JOB_CIPHER_DIRECTION direction;
165                 /** Cipher mode - CBC / Counter */
166                 JOB_CIPHER_MODE mode;
167
168                 uint64_t key_length_in_bytes;
169
170                 struct {
171                         uint32_t encode[60] __rte_aligned(16);
172                         /**< encode key */
173                         uint32_t decode[60] __rte_aligned(16);
174                         /**< decode key */
175                 } expanded_aes_keys;
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                         /**< Expanded XCBC authentication keys */
211                 };
212         } auth;
213 } __rte_cache_aligned;
214
215
216 /**
217  *
218  */
219 extern int
220 aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
221                 struct aesni_mb_session *sess,
222                 const struct rte_crypto_sym_xform *xform);
223
224
225 /** device specific operations function pointer structure */
226 extern struct rte_cryptodev_ops *rte_aesni_mb_pmd_ops;
227
228
229
230 #endif /* _RTE_AESNI_MB_PMD_PRIVATE_H_ */