1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2016 Intel Corporation
5 #ifndef _RTE_AESNI_MB_PMD_PRIVATE_H_
6 #define _RTE_AESNI_MB_PMD_PRIVATE_H_
8 #include <intel-ipsec-mb.h>
12 * IMB_VERSION_NUM macro was introduced in version Multi-buffer 0.50,
13 * so if macro is not defined, it means that the version is 0.49.
15 #if !defined(IMB_VERSION_NUM)
16 #define IMB_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
17 #define IMB_VERSION_NUM IMB_VERSION(0, 49, 0)
20 #if IMB_VERSION_NUM < IMB_VERSION(0, 52, 0)
21 #include "aesni_mb_ops.h"
24 #if IMB_VERSION_NUM >= IMB_VERSION(0, 52, 0)
25 enum aesni_mb_vector_mode {
26 RTE_AESNI_MB_NOT_SUPPORTED = 0,
35 #define CRYPTODEV_NAME_AESNI_MB_PMD crypto_aesni_mb
36 /**< AES-NI Multi buffer PMD device name */
38 /** AESNI_MB PMD LOGTYPE DRIVER */
39 int aesni_mb_logtype_driver;
41 #define AESNI_MB_LOG(level, fmt, ...) \
42 rte_log(RTE_LOG_ ## level, aesni_mb_logtype_driver, \
43 "%s() line %u: " fmt "\n", __func__, __LINE__, \
47 #define HMAC_IPAD_VALUE (0x36)
48 #define HMAC_OPAD_VALUE (0x5C)
50 /* Maximum length for digest */
51 #define DIGEST_LENGTH_MAX 64
52 static const unsigned auth_blocksize[] = {
64 * Get the blocksize in bytes for a specified authentication algorithm
66 * @Note: this function will not return a valid value for a non-valid
67 * authentication algorithm
69 static inline unsigned
70 get_auth_algo_blocksize(JOB_HASH_ALG algo)
72 return auth_blocksize[algo];
75 static const unsigned auth_truncated_digest_byte_lengths[] = {
89 * Get the IPsec specified truncated length in bytes of the HMAC digest for a
90 * specified authentication algorithm
92 * @Note: this function will not return a valid value for a non-valid
93 * authentication algorithm
95 static inline unsigned
96 get_truncated_digest_byte_length(JOB_HASH_ALG algo)
98 return auth_truncated_digest_byte_lengths[algo];
101 static const unsigned auth_digest_byte_lengths[] = {
112 /**< Vector mode dependent pointer table of the multi-buffer APIs */
117 * Get the full digest size in bytes for a specified authentication algorithm
118 * (if available in the Multi-buffer library)
120 * @Note: this function will not return a valid value for a non-valid
121 * authentication algorithm
123 static inline unsigned
124 get_digest_byte_length(JOB_HASH_ALG algo)
126 return auth_digest_byte_lengths[algo];
129 enum aesni_mb_operation {
130 AESNI_MB_OP_HASH_CIPHER,
131 AESNI_MB_OP_CIPHER_HASH,
132 AESNI_MB_OP_HASH_ONLY,
133 AESNI_MB_OP_CIPHER_ONLY,
134 AESNI_MB_OP_AEAD_HASH_CIPHER,
135 AESNI_MB_OP_AEAD_CIPHER_HASH,
136 AESNI_MB_OP_NOT_SUPPORTED
139 /** private data structure for each virtual AESNI device */
140 struct aesni_mb_private {
141 enum aesni_mb_vector_mode vector_mode;
142 /**< CPU vector instruction set mode */
143 unsigned max_nb_queue_pairs;
144 /**< Max number of queue pairs supported by device */
145 #if IMB_VERSION_NUM >= IMB_VERSION(0, 52, 0)
147 /**< Multi-buffer instance */
151 /** AESNI Multi buffer queue pair */
154 /**< Queue Pair Identifier */
155 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
156 #if IMB_VERSION_NUM < IMB_VERSION(0, 52, 0)
157 /**< Unique Queue Pair Name */
158 const struct aesni_mb_op_fns *op_fns;
160 /**< Unique Queue Pair Name */
162 /**< Multi-buffer instance */
163 struct rte_ring *ingress_queue;
164 /**< Ring for placing operations ready for processing */
165 struct rte_mempool *sess_mp;
166 /**< Session Mempool */
167 struct rte_cryptodev_stats stats;
168 /**< Queue pair statistics */
170 /**< Index of the next slot to be used in temp_digests,
171 * to store the digest for a given operation
173 uint8_t temp_digests[MAX_JOBS][DIGEST_LENGTH_MAX];
174 /**< Buffers used to store the digest generated
175 * by the driver when verifying a digest provided
176 * by the user (using authentication verify operation)
178 } __rte_cache_aligned;
180 /** AES-NI multi-buffer private session structure */
181 struct aesni_mb_session {
182 JOB_CHAIN_ORDER chain_order;
187 /**< IV parameters */
189 /** Cipher Parameters */const struct aesni_mb_op_fns *op_fns;
190 /**< Vector mode dependent pointer table of the multi-buffer APIs */
193 /** Cipher direction - encrypt / decrypt */
194 JOB_CIPHER_DIRECTION direction;
195 /** Cipher mode - CBC / Counter */
196 JOB_CIPHER_MODE mode;
198 uint64_t key_length_in_bytes;
202 uint32_t encode[60] __rte_aligned(16);
204 uint32_t decode[60] __rte_aligned(16);
208 const void *ks_ptr[3];
212 struct gcm_key_data gcm_key;
214 /**< Expanded AES keys - Allocating space to
215 * contain the maximum expanded key size which
216 * is 240 bytes for 256 bit AES, calculate by:
217 * ((key size (bytes)) *
218 * ((number of rounds) + 1))
222 /** Authentication Parameters */
224 JOB_HASH_ALG algo; /**< Authentication Algorithm */
225 enum rte_crypto_auth_operation operation;
226 /**< auth operation generate or verify */
229 uint8_t inner[128] __rte_aligned(16);
231 uint8_t outer[128] __rte_aligned(16);
234 /**< HMAC Authentication pads -
235 * allocating space for the maximum pad
236 * size supported which is 128 bytes for
241 uint32_t k1_expanded[44] __rte_aligned(16);
242 /**< k1 (expanded key). */
243 uint8_t k2[16] __rte_aligned(16);
245 uint8_t k3[16] __rte_aligned(16);
250 uint32_t expkey[60] __rte_aligned(16);
251 /**< k1 (expanded key). */
252 uint32_t skey1[4] __rte_aligned(16);
254 uint32_t skey2[4] __rte_aligned(16);
257 /**< Expanded XCBC authentication keys */
259 /** Generated digest size by the Multi-buffer library */
260 uint16_t gen_digest_len;
261 /** Requested digest size from Cryptodev */
262 uint16_t req_digest_len;
266 /** AAD data length */
269 } __rte_cache_aligned;
273 #if IMB_VERSION_NUM >= IMB_VERSION(0, 52, 0)
278 aesni_mb_set_session_parameters(const MB_MGR *mb_mgr,
279 struct aesni_mb_session *sess,
280 const struct rte_crypto_sym_xform *xform);
283 aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
284 struct aesni_mb_session *sess,
285 const struct rte_crypto_sym_xform *xform);
288 /** device specific operations function pointer structure */
289 extern struct rte_cryptodev_ops *rte_aesni_mb_pmd_ops;
293 #endif /* _RTE_AESNI_MB_PMD_PRIVATE_H_ */