6676948efb3bf7e9d30c52f8cea9408b96ac2794
[deb_dpdk.git] / drivers / crypto / aesni_mb / rte_aesni_mb_pmd_private.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Intel Corporation nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _RTE_AESNI_MB_PMD_PRIVATE_H_
34 #define _RTE_AESNI_MB_PMD_PRIVATE_H_
35
36 #include "aesni_mb_ops.h"
37
38 #define CRYPTODEV_NAME_AESNI_MB_PMD     crypto_aesni_mb
39 /**< AES-NI Multi buffer PMD device name */
40
41 #define MB_LOG_ERR(fmt, args...) \
42         RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n",  \
43                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), \
44                         __func__, __LINE__, ## args)
45
46 #ifdef RTE_LIBRTE_AESNI_MB_DEBUG
47 #define MB_LOG_INFO(fmt, args...) \
48         RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
49                         CRYPTODEV_NAME_AESNI_MB_PMD, \
50                         __func__, __LINE__, ## args)
51
52 #define MB_LOG_DBG(fmt, args...) \
53         RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
54                         CRYPTODEV_NAME_AESNI_MB_PMD, \
55                         __func__, __LINE__, ## args)
56 #else
57 #define MB_LOG_INFO(fmt, args...)
58 #define MB_LOG_DBG(fmt, args...)
59 #endif
60
61 #define HMAC_IPAD_VALUE                 (0x36)
62 #define HMAC_OPAD_VALUE                 (0x5C)
63
64 static const unsigned auth_blocksize[] = {
65                 [MD5]           = 64,
66                 [SHA1]          = 64,
67                 [SHA_224]       = 64,
68                 [SHA_256]       = 64,
69                 [SHA_384]       = 128,
70                 [SHA_512]       = 128,
71                 [AES_XCBC]      = 16,
72 };
73
74 /**
75  * Get the blocksize in bytes for a specified authentication algorithm
76  *
77  * @Note: this function will not return a valid value for a non-valid
78  * authentication algorithm
79  */
80 static inline unsigned
81 get_auth_algo_blocksize(JOB_HASH_ALG algo)
82 {
83         return auth_blocksize[algo];
84 }
85
86 static const unsigned auth_truncated_digest_byte_lengths[] = {
87                 [MD5]           = 12,
88                 [SHA1]          = 12,
89                 [SHA_224]       = 14,
90                 [SHA_256]       = 16,
91                 [SHA_384]       = 24,
92                 [SHA_512]       = 32,
93                 [AES_XCBC]      = 12,
94                 [NULL_HASH]     = 0
95 };
96
97 /**
98  * Get the IPsec specified truncated length in bytes of the HMAC digest for a
99  * specified authentication algorithm
100  *
101  * @Note: this function will not return a valid value for a non-valid
102  * authentication algorithm
103  */
104 static inline unsigned
105 get_truncated_digest_byte_length(JOB_HASH_ALG algo)
106 {
107         return auth_truncated_digest_byte_lengths[algo];
108 }
109
110 static const unsigned auth_digest_byte_lengths[] = {
111                 [MD5]           = 16,
112                 [SHA1]          = 20,
113                 [SHA_224]       = 28,
114                 [SHA_256]       = 32,
115                 [SHA_384]       = 48,
116                 [SHA_512]       = 64,
117                 [AES_XCBC]      = 16,
118                 [NULL_HASH]     = 0
119 };
120
121 /**
122  * Get the output digest size in bytes for a specified authentication algorithm
123  *
124  * @Note: this function will not return a valid value for a non-valid
125  * authentication algorithm
126  */
127 static inline unsigned
128 get_digest_byte_length(JOB_HASH_ALG algo)
129 {
130         return auth_digest_byte_lengths[algo];
131 }
132
133 enum aesni_mb_operation {
134         AESNI_MB_OP_HASH_CIPHER,
135         AESNI_MB_OP_CIPHER_HASH,
136         AESNI_MB_OP_HASH_ONLY,
137         AESNI_MB_OP_CIPHER_ONLY,
138         AESNI_MB_OP_NOT_SUPPORTED
139 };
140
141 /** private data structure for each virtual AESNI device */
142 struct aesni_mb_private {
143         enum aesni_mb_vector_mode vector_mode;
144         /**< CPU vector instruction set mode */
145         unsigned max_nb_queue_pairs;
146         /**< Max number of queue pairs supported by device */
147         unsigned max_nb_sessions;
148         /**< Max number of sessions supported by device */
149 };
150
151 /** AESNI Multi buffer queue pair */
152 struct aesni_mb_qp {
153         uint16_t id;
154         /**< Queue Pair Identifier */
155         char name[RTE_CRYPTODEV_NAME_LEN];
156         /**< Unique Queue Pair Name */
157         const struct aesni_mb_op_fns *op_fns;
158         /**< Vector mode dependent pointer table of the multi-buffer APIs */
159         MB_MGR mb_mgr;
160         /**< Multi-buffer instance */
161         struct rte_ring *ingress_queue;
162        /**< Ring for placing operations ready for processing */
163         struct rte_mempool *sess_mp;
164         /**< Session Mempool */
165         struct rte_cryptodev_stats stats;
166         /**< Queue pair statistics */
167 } __rte_cache_aligned;
168
169
170 /** AES-NI multi-buffer private session structure */
171 struct aesni_mb_session {
172         JOB_CHAIN_ORDER chain_order;
173         struct {
174                 uint16_t length;
175                 uint16_t offset;
176         } iv;
177         /**< IV parameters */
178
179         /** Cipher Parameters */
180         struct {
181                 /** Cipher direction - encrypt / decrypt */
182                 JOB_CIPHER_DIRECTION direction;
183                 /** Cipher mode - CBC / Counter */
184                 JOB_CIPHER_MODE mode;
185
186                 uint64_t key_length_in_bytes;
187
188                 struct {
189                         uint32_t encode[60] __rte_aligned(16);
190                         /**< encode key */
191                         uint32_t decode[60] __rte_aligned(16);
192                         /**< decode key */
193                 } expanded_aes_keys;
194                 /**< Expanded AES keys - Allocating space to
195                  * contain the maximum expanded key size which
196                  * is 240 bytes for 256 bit AES, calculate by:
197                  * ((key size (bytes)) *
198                  * ((number of rounds) + 1))
199                  */
200         } cipher;
201
202         /** Authentication Parameters */
203         struct {
204                 JOB_HASH_ALG algo; /**< Authentication Algorithm */
205                 enum rte_crypto_auth_operation operation;
206                 /**< auth operation generate or verify */
207                 union {
208                         struct {
209                                 uint8_t inner[128] __rte_aligned(16);
210                                 /**< inner pad */
211                                 uint8_t outer[128] __rte_aligned(16);
212                                 /**< outer pad */
213                         } pads;
214                         /**< HMAC Authentication pads -
215                          * allocating space for the maximum pad
216                          * size supported which is 128 bytes for
217                          * SHA512
218                          */
219
220                         struct {
221                             uint32_t k1_expanded[44] __rte_aligned(16);
222                             /**< k1 (expanded key). */
223                             uint8_t k2[16] __rte_aligned(16);
224                             /**< k2. */
225                             uint8_t k3[16] __rte_aligned(16);
226                             /**< k3. */
227                         } xcbc;
228                         /**< Expanded XCBC authentication keys */
229                 };
230         } auth;
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_ */