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 "aesni_mb_ops.h"
11 * IMB_VERSION_NUM macro was introduced in version Multi-buffer 0.50,
12 * so if macro is not defined, it means that the version is 0.49.
14 #if !defined(IMB_VERSION_NUM)
15 #define IMB_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
16 #define IMB_VERSION_NUM IMB_VERSION(0, 49, 0)
19 #define CRYPTODEV_NAME_AESNI_MB_PMD crypto_aesni_mb
20 /**< AES-NI Multi buffer PMD device name */
22 /** AESNI_MB PMD LOGTYPE DRIVER */
23 int aesni_mb_logtype_driver;
25 #define AESNI_MB_LOG(level, fmt, ...) \
26 rte_log(RTE_LOG_ ## level, aesni_mb_logtype_driver, \
27 "%s() line %u: " fmt "\n", __func__, __LINE__, \
31 #define HMAC_IPAD_VALUE (0x36)
32 #define HMAC_OPAD_VALUE (0x5C)
34 /* Maximum length for digest (SHA-512 truncated needs 32 bytes) */
35 #define DIGEST_LENGTH_MAX 32
36 static const unsigned auth_blocksize[] = {
48 * Get the blocksize in bytes for a specified authentication algorithm
50 * @Note: this function will not return a valid value for a non-valid
51 * authentication algorithm
53 static inline unsigned
54 get_auth_algo_blocksize(JOB_HASH_ALG algo)
56 return auth_blocksize[algo];
59 static const unsigned auth_truncated_digest_byte_lengths[] = {
73 * Get the IPsec specified truncated length in bytes of the HMAC digest for a
74 * specified authentication algorithm
76 * @Note: this function will not return a valid value for a non-valid
77 * authentication algorithm
79 static inline unsigned
80 get_truncated_digest_byte_length(JOB_HASH_ALG algo)
82 return auth_truncated_digest_byte_lengths[algo];
85 static const unsigned auth_digest_byte_lengths[] = {
98 * Get the output digest size in bytes for a specified authentication algorithm
100 * @Note: this function will not return a valid value for a non-valid
101 * authentication algorithm
103 static inline unsigned
104 get_digest_byte_length(JOB_HASH_ALG algo)
106 return auth_digest_byte_lengths[algo];
109 enum aesni_mb_operation {
110 AESNI_MB_OP_HASH_CIPHER,
111 AESNI_MB_OP_CIPHER_HASH,
112 AESNI_MB_OP_HASH_ONLY,
113 AESNI_MB_OP_CIPHER_ONLY,
114 AESNI_MB_OP_AEAD_HASH_CIPHER,
115 AESNI_MB_OP_AEAD_CIPHER_HASH,
116 AESNI_MB_OP_NOT_SUPPORTED
119 /** private data structure for each virtual AESNI device */
120 struct aesni_mb_private {
121 enum aesni_mb_vector_mode vector_mode;
122 /**< CPU vector instruction set mode */
123 unsigned max_nb_queue_pairs;
124 /**< Max number of queue pairs supported by device */
127 /** AESNI Multi buffer queue pair */
130 /**< Queue Pair Identifier */
131 char name[RTE_CRYPTODEV_NAME_MAX_LEN];
132 /**< Unique Queue Pair Name */
133 const struct aesni_mb_op_fns *op_fns;
134 /**< Vector mode dependent pointer table of the multi-buffer APIs */
136 /**< Multi-buffer instance */
137 struct rte_ring *ingress_queue;
138 /**< Ring for placing operations ready for processing */
139 struct rte_mempool *sess_mp;
140 /**< Session Mempool */
141 struct rte_cryptodev_stats stats;
142 /**< Queue pair statistics */
144 /**< Index of the next slot to be used in temp_digests,
145 * to store the digest for a given operation
147 uint8_t temp_digests[MAX_JOBS][DIGEST_LENGTH_MAX];
148 /**< Buffers used to store the digest generated
149 * by the driver when verifying a digest provided
150 * by the user (using authentication verify operation)
152 } __rte_cache_aligned;
154 /** AES-NI multi-buffer private session structure */
155 struct aesni_mb_session {
156 JOB_CHAIN_ORDER chain_order;
161 /**< IV parameters */
163 /** Cipher Parameters */
165 /** Cipher direction - encrypt / decrypt */
166 JOB_CIPHER_DIRECTION direction;
167 /** Cipher mode - CBC / Counter */
168 JOB_CIPHER_MODE mode;
170 uint64_t key_length_in_bytes;
174 uint32_t encode[60] __rte_aligned(16);
176 uint32_t decode[60] __rte_aligned(16);
180 const void *ks_ptr[3];
184 /**< Expanded AES keys - Allocating space to
185 * contain the maximum expanded key size which
186 * is 240 bytes for 256 bit AES, calculate by:
187 * ((key size (bytes)) *
188 * ((number of rounds) + 1))
192 /** Authentication Parameters */
194 JOB_HASH_ALG algo; /**< Authentication Algorithm */
195 enum rte_crypto_auth_operation operation;
196 /**< auth operation generate or verify */
199 uint8_t inner[128] __rte_aligned(16);
201 uint8_t outer[128] __rte_aligned(16);
204 /**< HMAC Authentication pads -
205 * allocating space for the maximum pad
206 * size supported which is 128 bytes for
211 uint32_t k1_expanded[44] __rte_aligned(16);
212 /**< k1 (expanded key). */
213 uint8_t k2[16] __rte_aligned(16);
215 uint8_t k3[16] __rte_aligned(16);
220 uint32_t expkey[60] __rte_aligned(16);
221 /**< k1 (expanded key). */
222 uint32_t skey1[4] __rte_aligned(16);
224 uint32_t skey2[4] __rte_aligned(16);
227 /**< Expanded XCBC authentication keys */
234 /** AAD data length */
237 } __rte_cache_aligned;
244 aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
245 struct aesni_mb_session *sess,
246 const struct rte_crypto_sym_xform *xform);
249 /** device specific operations function pointer structure */
250 extern struct rte_cryptodev_ops *rte_aesni_mb_pmd_ops;
254 #endif /* _RTE_AESNI_MB_PMD_PRIVATE_H_ */