]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | }; | |
92 | ||
93 | /** | |
94 | * Get the IPsec specified truncated length in bytes of the HMAC digest for a | |
95 | * specified authentication algorithm | |
96 | * | |
97 | * @Note: this function will not return a valid value for a non-valid | |
98 | * authentication algorithm | |
99 | */ | |
100 | static inline unsigned | |
101 | get_truncated_digest_byte_length(JOB_HASH_ALG algo) | |
102 | { | |
103 | return auth_truncated_digest_byte_lengths[algo]; | |
104 | } | |
105 | ||
106 | static const unsigned auth_digest_byte_lengths[] = { | |
107 | [MD5] = 16, | |
108 | [SHA1] = 20, | |
109 | [SHA_224] = 28, | |
110 | [SHA_256] = 32, | |
111 | [SHA_384] = 48, | |
112 | [SHA_512] = 64, | |
113 | [AES_XCBC] = 16, | |
114 | }; | |
115 | ||
116 | /** | |
117 | * Get the output digest size in bytes for a specified authentication algorithm | |
118 | * | |
119 | * @Note: this function will not return a valid value for a non-valid | |
120 | * authentication algorithm | |
121 | */ | |
122 | static inline unsigned | |
123 | get_digest_byte_length(JOB_HASH_ALG algo) | |
124 | { | |
125 | return auth_digest_byte_lengths[algo]; | |
126 | } | |
127 | ||
128 | ||
129 | /** private data structure for each virtual AESNI device */ | |
130 | struct aesni_mb_private { | |
131 | enum aesni_mb_vector_mode vector_mode; | |
132 | /**< CPU vector instruction set mode */ | |
133 | unsigned max_nb_queue_pairs; | |
134 | /**< Max number of queue pairs supported by device */ | |
135 | unsigned max_nb_sessions; | |
136 | /**< Max number of sessions supported by device */ | |
137 | }; | |
138 | ||
139 | /** AESNI Multi buffer queue pair */ | |
140 | struct aesni_mb_qp { | |
141 | uint16_t id; | |
142 | /**< Queue Pair Identifier */ | |
143 | char name[RTE_CRYPTODEV_NAME_LEN]; | |
144 | /**< Unique Queue Pair Name */ | |
145 | const struct aesni_mb_ops *ops; | |
146 | /**< Vector mode dependent pointer table of the multi-buffer APIs */ | |
147 | MB_MGR mb_mgr; | |
148 | /**< Multi-buffer instance */ | |
149 | struct rte_ring *processed_ops; | |
150 | /**< Ring for placing process operations */ | |
151 | struct rte_mempool *sess_mp; | |
152 | /**< Session Mempool */ | |
153 | struct rte_cryptodev_stats stats; | |
154 | /**< Queue pair statistics */ | |
155 | } __rte_cache_aligned; | |
156 | ||
157 | ||
158 | /** AES-NI multi-buffer private session structure */ | |
159 | struct aesni_mb_session { | |
160 | JOB_CHAIN_ORDER chain_order; | |
161 | ||
162 | /** Cipher Parameters */ | |
163 | struct { | |
164 | /** Cipher direction - encrypt / decrypt */ | |
165 | JOB_CIPHER_DIRECTION direction; | |
166 | /** Cipher mode - CBC / Counter */ | |
167 | JOB_CIPHER_MODE mode; | |
168 | ||
169 | uint64_t key_length_in_bytes; | |
170 | ||
171 | struct { | |
172 | uint32_t encode[60] __rte_aligned(16); | |
173 | /**< encode key */ | |
174 | uint32_t decode[60] __rte_aligned(16); | |
175 | /**< decode key */ | |
176 | } expanded_aes_keys; | |
177 | /**< Expanded AES keys - Allocating space to | |
178 | * contain the maximum expanded key size which | |
179 | * is 240 bytes for 256 bit AES, calculate by: | |
180 | * ((key size (bytes)) * | |
181 | * ((number of rounds) + 1)) | |
182 | */ | |
183 | } cipher; | |
184 | ||
185 | /** Authentication Parameters */ | |
186 | struct { | |
187 | JOB_HASH_ALG algo; /**< Authentication Algorithm */ | |
188 | union { | |
189 | struct { | |
190 | uint8_t inner[128] __rte_aligned(16); | |
191 | /**< inner pad */ | |
192 | uint8_t outer[128] __rte_aligned(16); | |
193 | /**< outer pad */ | |
194 | } pads; | |
195 | /**< HMAC Authentication pads - | |
196 | * allocating space for the maximum pad | |
197 | * size supported which is 128 bytes for | |
198 | * SHA512 | |
199 | */ | |
200 | ||
201 | struct { | |
202 | uint32_t k1_expanded[44] __rte_aligned(16); | |
203 | /**< k1 (expanded key). */ | |
204 | uint8_t k2[16] __rte_aligned(16); | |
205 | /**< k2. */ | |
206 | uint8_t k3[16] __rte_aligned(16); | |
207 | /**< k3. */ | |
208 | } xcbc; | |
209 | /**< Expanded XCBC authentication keys */ | |
210 | }; | |
211 | } auth; | |
212 | } __rte_cache_aligned; | |
213 | ||
214 | ||
215 | /** | |
216 | * | |
217 | */ | |
218 | extern int | |
219 | aesni_mb_set_session_parameters(const struct aesni_mb_ops *mb_ops, | |
220 | struct aesni_mb_session *sess, | |
221 | const struct rte_crypto_sym_xform *xform); | |
222 | ||
223 | ||
224 | /** device specific operations function pointer structure */ | |
225 | extern struct rte_cryptodev_ops *rte_aesni_mb_pmd_ops; | |
226 | ||
227 | ||
228 | ||
229 | #endif /* _RTE_AESNI_MB_PMD_PRIVATE_H_ */ |