0d82699c3c36ee54489dcd6557f731b19ee9241b
[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 MB_LOG_ERR(fmt, args...) \
39         RTE_LOG(ERR, CRYPTODEV, "[%s] %s() line %u: " fmt "\n",  \
40                         RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), \
41                         __func__, __LINE__, ## args)
42
43 #ifdef RTE_LIBRTE_AESNI_MB_DEBUG
44 #define MB_LOG_INFO(fmt, args...) \
45         RTE_LOG(INFO, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
46                         CRYPTODEV_NAME_AESNI_MB_PMD, \
47                         __func__, __LINE__, ## args)
48
49 #define MB_LOG_DBG(fmt, args...) \
50         RTE_LOG(DEBUG, CRYPTODEV, "[%s] %s() line %u: " fmt "\n", \
51                         CRYPTODEV_NAME_AESNI_MB_PMD, \
52                         __func__, __LINE__, ## args)
53 #else
54 #define MB_LOG_INFO(fmt, args...)
55 #define MB_LOG_DBG(fmt, args...)
56 #endif
57
58 #define HMAC_IPAD_VALUE                 (0x36)
59 #define HMAC_OPAD_VALUE                 (0x5C)
60
61 static const unsigned auth_blocksize[] = {
62                 [MD5]           = 64,
63                 [SHA1]          = 64,
64                 [SHA_224]       = 64,
65                 [SHA_256]       = 64,
66                 [SHA_384]       = 128,
67                 [SHA_512]       = 128,
68                 [AES_XCBC]      = 16,
69 };
70
71 /**
72  * Get the blocksize in bytes for a specified authentication algorithm
73  *
74  * @Note: this function will not return a valid value for a non-valid
75  * authentication algorithm
76  */
77 static inline unsigned
78 get_auth_algo_blocksize(JOB_HASH_ALG algo)
79 {
80         return auth_blocksize[algo];
81 }
82
83 static const unsigned auth_truncated_digest_byte_lengths[] = {
84                 [MD5]           = 12,
85                 [SHA1]          = 12,
86                 [SHA_224]       = 14,
87                 [SHA_256]       = 16,
88                 [SHA_384]       = 24,
89                 [SHA_512]       = 32,
90                 [AES_XCBC]      = 12,
91                 [NULL_HASH]     = 0
92 };
93
94 /**
95  * Get the IPsec specified truncated length in bytes of the HMAC digest for a
96  * 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_truncated_digest_byte_length(JOB_HASH_ALG algo)
103 {
104         return auth_truncated_digest_byte_lengths[algo];
105 }
106
107 static const unsigned auth_digest_byte_lengths[] = {
108                 [MD5]           = 16,
109                 [SHA1]          = 20,
110                 [SHA_224]       = 28,
111                 [SHA_256]       = 32,
112                 [SHA_384]       = 48,
113                 [SHA_512]       = 64,
114                 [AES_XCBC]      = 16,
115                 [NULL_HASH]     = 0
116 };
117
118 /**
119  * Get the output digest size in bytes for a specified authentication algorithm
120  *
121  * @Note: this function will not return a valid value for a non-valid
122  * authentication algorithm
123  */
124 static inline unsigned
125 get_digest_byte_length(JOB_HASH_ALG algo)
126 {
127         return auth_digest_byte_lengths[algo];
128 }
129
130 enum aesni_mb_operation {
131         AESNI_MB_OP_HASH_CIPHER,
132         AESNI_MB_OP_CIPHER_HASH,
133         AESNI_MB_OP_HASH_ONLY,
134         AESNI_MB_OP_CIPHER_ONLY,
135         AESNI_MB_OP_NOT_SUPPORTED
136 };
137
138 /** private data structure for each virtual AESNI device */
139 struct aesni_mb_private {
140         enum aesni_mb_vector_mode vector_mode;
141         /**< CPU vector instruction set mode */
142         unsigned max_nb_queue_pairs;
143         /**< Max number of queue pairs supported by device */
144         unsigned max_nb_sessions;
145         /**< Max number of sessions supported by device */
146 };
147
148 /** AESNI Multi buffer queue pair */
149 struct aesni_mb_qp {
150         uint16_t id;
151         /**< Queue Pair Identifier */
152         char name[RTE_CRYPTODEV_NAME_LEN];
153         /**< Unique Queue Pair Name */
154         const struct aesni_mb_op_fns *op_fns;
155         /**< Vector mode dependent pointer table of the multi-buffer APIs */
156         MB_MGR mb_mgr;
157         /**< Multi-buffer instance */
158         struct rte_ring *ingress_queue;
159        /**< Ring for placing operations ready for processing */
160         struct rte_mempool *sess_mp;
161         /**< Session Mempool */
162         struct rte_cryptodev_stats stats;
163         /**< Queue pair statistics */
164 } __rte_cache_aligned;
165
166
167 /** AES-NI multi-buffer private session structure */
168 struct aesni_mb_session {
169         JOB_CHAIN_ORDER chain_order;
170
171         /** Cipher Parameters */
172         struct {
173                 /** Cipher direction - encrypt / decrypt */
174                 JOB_CIPHER_DIRECTION direction;
175                 /** Cipher mode - CBC / Counter */
176                 JOB_CIPHER_MODE mode;
177
178                 uint64_t key_length_in_bytes;
179
180                 struct {
181                         uint32_t encode[60] __rte_aligned(16);
182                         /**< encode key */
183                         uint32_t decode[60] __rte_aligned(16);
184                         /**< decode key */
185                 } expanded_aes_keys;
186                 /**< Expanded AES keys - Allocating space to
187                  * contain the maximum expanded key size which
188                  * is 240 bytes for 256 bit AES, calculate by:
189                  * ((key size (bytes)) *
190                  * ((number of rounds) + 1))
191                  */
192         } cipher;
193
194         /** Authentication Parameters */
195         struct {
196                 JOB_HASH_ALG algo; /**< Authentication Algorithm */
197                 enum rte_crypto_auth_operation operation;
198                 /**< auth operation generate or verify */
199                 union {
200                         struct {
201                                 uint8_t inner[128] __rte_aligned(16);
202                                 /**< inner pad */
203                                 uint8_t outer[128] __rte_aligned(16);
204                                 /**< outer pad */
205                         } pads;
206                         /**< HMAC Authentication pads -
207                          * allocating space for the maximum pad
208                          * size supported which is 128 bytes for
209                          * SHA512
210                          */
211
212                         struct {
213                             uint32_t k1_expanded[44] __rte_aligned(16);
214                             /**< k1 (expanded key). */
215                             uint8_t k2[16] __rte_aligned(16);
216                             /**< k2. */
217                             uint8_t k3[16] __rte_aligned(16);
218                             /**< k3. */
219                         } xcbc;
220                         /**< Expanded XCBC authentication keys */
221                 };
222         } auth;
223 } __rte_cache_aligned;
224
225
226 /**
227  *
228  */
229 extern int
230 aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
231                 struct aesni_mb_session *sess,
232                 const struct rte_crypto_sym_xform *xform);
233
234
235 /** device specific operations function pointer structure */
236 extern struct rte_cryptodev_ops *rte_aesni_mb_pmd_ops;
237
238
239
240 #endif /* _RTE_AESNI_MB_PMD_PRIVATE_H_ */