1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4 
5 /**
6  ***************************************************************************
7  * @file lac_sym_qat_hash_defs_lookup.c      Hash Definitions Lookup
8  *
9  * @ingroup LacHashDefsLookup
10  ***************************************************************************/
11 
12 /*
13 *******************************************************************************
14 * Include public/global header files
15 *******************************************************************************
16 */
17 
18 #include "cpa.h"
19 
20 /*
21 *******************************************************************************
22 * Include private header files
23 *******************************************************************************
24 */
25 #include "lac_common.h"
26 #include "icp_accel_devices.h"
27 #include "icp_adf_debug.h"
28 #include "icp_adf_transport.h"
29 #include "lac_sym.h"
30 #include "icp_qat_fw_la.h"
31 #include "lac_sym_qat_hash_defs_lookup.h"
32 #include "lac_sal_types_crypto.h"
33 #include "lac_sym_hash_defs.h"
34 
35 /* state size for xcbc mac consists of 3 * 16 byte keys */
36 #define LAC_SYM_QAT_XCBC_STATE_SIZE ((LAC_HASH_XCBC_MAC_BLOCK_SIZE)*3)
37 
38 #define LAC_SYM_QAT_CMAC_STATE_SIZE ((LAC_HASH_CMAC_BLOCK_SIZE)*3)
39 
40 /* This type is used for the mapping between the hash algorithm and
41  * the corresponding hash definitions structure */
42 typedef struct lac_sym_qat_hash_def_map_s {
43 	CpaCySymHashAlgorithm hashAlgorithm;
44 	/* hash algorithm */
45 	lac_sym_qat_hash_defs_t hashDefs;
46 	/* hash defintions pointers */
47 } lac_sym_qat_hash_def_map_t;
48 
49 /*
50 *******************************************************************************
51 * Static Variables
52 *******************************************************************************
53 */
54 
55 /* initialisers as defined in FIPS and RFCS for digest operations */
56 
57 /* md5 16 bytes - Initialiser state can be found in RFC 1321*/
58 static Cpa8U md5InitialState[LAC_HASH_MD5_STATE_SIZE] = {
59 	0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
60 	0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10,
61 };
62 
63 /* SHA1 - 20 bytes - Initialiser state can be found in FIPS stds 180-2 */
64 static Cpa8U sha1InitialState[LAC_HASH_SHA1_STATE_SIZE] = {
65 	0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x98, 0xba,
66 	0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0
67 };
68 
69 /* SHA 224 - 32 bytes - Initialiser state can be found in FIPS stds 180-2 */
70 static Cpa8U sha224InitialState[LAC_HASH_SHA224_STATE_SIZE] = {
71 	0xc1, 0x05, 0x9e, 0xd8, 0x36, 0x7c, 0xd5, 0x07, 0x30, 0x70, 0xdd,
72 	0x17, 0xf7, 0x0e, 0x59, 0x39, 0xff, 0xc0, 0x0b, 0x31, 0x68, 0x58,
73 	0x15, 0x11, 0x64, 0xf9, 0x8f, 0xa7, 0xbe, 0xfa, 0x4f, 0xa4
74 };
75 
76 /* SHA 256 - 32 bytes - Initialiser state can be found in FIPS stds 180-2 */
77 static Cpa8U sha256InitialState[LAC_HASH_SHA256_STATE_SIZE] =
78     { 0x6a, 0x09, 0xe6, 0x67, 0xbb, 0x67, 0xae, 0x85, 0x3c, 0x6e, 0xf3,
79       0x72, 0xa5, 0x4f, 0xf5, 0x3a, 0x51, 0x0e, 0x52, 0x7f, 0x9b, 0x05,
80       0x68, 0x8c, 0x1f, 0x83, 0xd9, 0xab, 0x5b, 0xe0, 0xcd, 0x19 };
81 
82 /* SHA 384 - 64 bytes - Initialiser state can be found in FIPS stds 180-2 */
83 static Cpa8U sha384InitialState[LAC_HASH_SHA384_STATE_SIZE] =
84     { 0xcb, 0xbb, 0x9d, 0x5d, 0xc1, 0x05, 0x9e, 0xd8, 0x62, 0x9a, 0x29,
85       0x2a, 0x36, 0x7c, 0xd5, 0x07, 0x91, 0x59, 0x01, 0x5a, 0x30, 0x70,
86       0xdd, 0x17, 0x15, 0x2f, 0xec, 0xd8, 0xf7, 0x0e, 0x59, 0x39, 0x67,
87       0x33, 0x26, 0x67, 0xff, 0xc0, 0x0b, 0x31, 0x8e, 0xb4, 0x4a, 0x87,
88       0x68, 0x58, 0x15, 0x11, 0xdb, 0x0c, 0x2e, 0x0d, 0x64, 0xf9, 0x8f,
89       0xa7, 0x47, 0xb5, 0x48, 0x1d, 0xbe, 0xfa, 0x4f, 0xa4 };
90 
91 /* SHA 512 - 64 bytes - Initialiser state can be found in FIPS stds 180-2 */
92 static Cpa8U sha512InitialState[LAC_HASH_SHA512_STATE_SIZE] =
93     { 0x6a, 0x09, 0xe6, 0x67, 0xf3, 0xbc, 0xc9, 0x08, 0xbb, 0x67, 0xae,
94       0x85, 0x84, 0xca, 0xa7, 0x3b, 0x3c, 0x6e, 0xf3, 0x72, 0xfe, 0x94,
95       0xf8, 0x2b, 0xa5, 0x4f, 0xf5, 0x3a, 0x5f, 0x1d, 0x36, 0xf1, 0x51,
96       0x0e, 0x52, 0x7f, 0xad, 0xe6, 0x82, 0xd1, 0x9b, 0x05, 0x68, 0x8c,
97       0x2b, 0x3e, 0x6c, 0x1f, 0x1f, 0x83, 0xd9, 0xab, 0xfb, 0x41, 0xbd,
98       0x6b, 0x5b, 0xe0, 0xcd, 0x19, 0x13, 0x7e, 0x21, 0x79 };
99 
100 /* SHA3 224 - 28 bytes  */
101 static Cpa8U sha3_224InitialState[LAC_HASH_SHA3_224_STATE_SIZE] =
102     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
103       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
104       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
105 
106 /* SHA3 256 - 32 bytes  */
107 static Cpa8U sha3_256InitialState[LAC_HASH_SHA3_256_STATE_SIZE] =
108     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
111 
112 /* SHA3 384 - 48 bytes  */
113 static Cpa8U sha3_384InitialState[LAC_HASH_SHA3_384_STATE_SIZE] =
114     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
116       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
118 
119 /* SHA3 512 - 64 bytes  */
120 static Cpa8U sha3_512InitialState[LAC_HASH_SHA3_512_STATE_SIZE] =
121     { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
124       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
125       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
127 
128 /* SM3 - 32 bytes */
129 static Cpa8U sm3InitialState[LAC_HASH_SM3_STATE_SIZE] =
130     { 0x73, 0x80, 0x16, 0x6f, 0x49, 0x14, 0xb2, 0xb9, 0x17, 0x24, 0x42,
131       0xd7, 0xda, 0x8a, 0x06, 0x00, 0xa9, 0x6f, 0x30, 0xbc, 0x16, 0x31,
132       0x38, 0xaa, 0xe3, 0x8d, 0xee, 0x4d, 0xb0, 0xfb, 0x0e, 0x4e };
133 
134 /* Constants used in generating K1, K2, K3 from a Key for AES_XCBC_MAC
135  * State defined in RFC 3566 */
136 static Cpa8U aesXcbcKeySeed[LAC_SYM_QAT_XCBC_STATE_SIZE] = {
137 	0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
138 	0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
139 	0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03,
140 	0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
141 };
142 
143 static Cpa8U aesCmacKeySeed[LAC_HASH_CMAC_BLOCK_SIZE] = { 0x00, 0x00, 0x00,
144 							  0x00, 0x00, 0x00,
145 							  0x00, 0x00, 0x00,
146 							  0x00, 0x00, 0x00,
147 							  0x00, 0x00, 0x00,
148 							  0x00 };
149 
150 /* Hash Algorithm specific structure */
151 
152 static lac_sym_qat_hash_alg_info_t md5Info = { LAC_HASH_MD5_DIGEST_SIZE,
153 					       LAC_HASH_MD5_BLOCK_SIZE,
154 					       md5InitialState,
155 					       LAC_HASH_MD5_STATE_SIZE };
156 
157 static lac_sym_qat_hash_alg_info_t sha1Info = { LAC_HASH_SHA1_DIGEST_SIZE,
158 						LAC_HASH_SHA1_BLOCK_SIZE,
159 						sha1InitialState,
160 						LAC_HASH_SHA1_STATE_SIZE };
161 
162 static lac_sym_qat_hash_alg_info_t sha224Info = { LAC_HASH_SHA224_DIGEST_SIZE,
163 						  LAC_HASH_SHA224_BLOCK_SIZE,
164 						  sha224InitialState,
165 						  LAC_HASH_SHA224_STATE_SIZE };
166 
167 static lac_sym_qat_hash_alg_info_t sha256Info = { LAC_HASH_SHA256_DIGEST_SIZE,
168 						  LAC_HASH_SHA256_BLOCK_SIZE,
169 						  sha256InitialState,
170 						  LAC_HASH_SHA256_STATE_SIZE };
171 
172 static lac_sym_qat_hash_alg_info_t sha384Info = { LAC_HASH_SHA384_DIGEST_SIZE,
173 						  LAC_HASH_SHA384_BLOCK_SIZE,
174 						  sha384InitialState,
175 						  LAC_HASH_SHA384_STATE_SIZE };
176 
177 static lac_sym_qat_hash_alg_info_t sha512Info = { LAC_HASH_SHA512_DIGEST_SIZE,
178 						  LAC_HASH_SHA512_BLOCK_SIZE,
179 						  sha512InitialState,
180 						  LAC_HASH_SHA512_STATE_SIZE };
181 
182 static lac_sym_qat_hash_alg_info_t sha3_224Info =
183     { LAC_HASH_SHA3_224_DIGEST_SIZE,
184       LAC_HASH_SHA3_224_BLOCK_SIZE,
185       sha3_224InitialState,
186       LAC_HASH_SHA3_224_STATE_SIZE };
187 
188 static lac_sym_qat_hash_alg_info_t sha3_256Info =
189     { LAC_HASH_SHA3_256_DIGEST_SIZE,
190       LAC_HASH_SHA3_256_BLOCK_SIZE,
191       sha3_256InitialState,
192       LAC_HASH_SHA3_256_STATE_SIZE };
193 
194 static lac_sym_qat_hash_alg_info_t sha3_384Info =
195     { LAC_HASH_SHA3_384_DIGEST_SIZE,
196       LAC_HASH_SHA3_384_BLOCK_SIZE,
197       sha3_384InitialState,
198       LAC_HASH_SHA3_384_STATE_SIZE };
199 
200 static lac_sym_qat_hash_alg_info_t sha3_512Info =
201     { LAC_HASH_SHA3_512_DIGEST_SIZE,
202       LAC_HASH_SHA3_512_BLOCK_SIZE,
203       sha3_512InitialState,
204       LAC_HASH_SHA3_512_STATE_SIZE };
205 
206 static lac_sym_qat_hash_alg_info_t polyInfo = { LAC_HASH_POLY_DIGEST_SIZE,
207 						LAC_HASH_POLY_BLOCK_SIZE,
208 						NULL, /* intial state */
209 						LAC_HASH_POLY_STATE_SIZE };
210 
211 static lac_sym_qat_hash_alg_info_t shake_128Info =
212     { LAC_HASH_SHAKE_128_DIGEST_SIZE, LAC_HASH_SHAKE_128_BLOCK_SIZE, NULL, 0 };
213 
214 static lac_sym_qat_hash_alg_info_t shake_256Info =
215     { LAC_HASH_SHAKE_256_DIGEST_SIZE, LAC_HASH_SHAKE_256_BLOCK_SIZE, NULL, 0 };
216 
217 static lac_sym_qat_hash_alg_info_t sm3Info = { LAC_HASH_SM3_DIGEST_SIZE,
218 					       LAC_HASH_SM3_BLOCK_SIZE,
219 					       sm3InitialState,
220 					       LAC_HASH_SM3_STATE_SIZE };
221 
222 static lac_sym_qat_hash_alg_info_t xcbcMacInfo =
223     { LAC_HASH_XCBC_MAC_128_DIGEST_SIZE,
224       LAC_HASH_XCBC_MAC_BLOCK_SIZE,
225       aesXcbcKeySeed,
226       LAC_SYM_QAT_XCBC_STATE_SIZE };
227 
228 static lac_sym_qat_hash_alg_info_t aesCmacInfo =
229     { LAC_HASH_CMAC_128_DIGEST_SIZE,
230       LAC_HASH_CMAC_BLOCK_SIZE,
231       aesCmacKeySeed,
232       LAC_SYM_QAT_CMAC_STATE_SIZE };
233 
234 static lac_sym_qat_hash_alg_info_t aesCcmInfo = {
235 	LAC_HASH_AES_CCM_DIGEST_SIZE,
236 	LAC_HASH_AES_CCM_BLOCK_SIZE,
237 	NULL, /* intial state */
238 	0     /* state size */
239 };
240 
241 static lac_sym_qat_hash_alg_info_t aesGcmInfo = {
242 	LAC_HASH_AES_GCM_DIGEST_SIZE,
243 	LAC_HASH_AES_GCM_BLOCK_SIZE,
244 	NULL, /* initial state */
245 	0     /* state size */
246 };
247 
248 static lac_sym_qat_hash_alg_info_t kasumiF9Info = {
249 	LAC_HASH_KASUMI_F9_DIGEST_SIZE,
250 	LAC_HASH_KASUMI_F9_BLOCK_SIZE,
251 	NULL, /* initial state */
252 	0     /* state size */
253 };
254 
255 static lac_sym_qat_hash_alg_info_t snow3gUia2Info = {
256 	LAC_HASH_SNOW3G_UIA2_DIGEST_SIZE,
257 	LAC_HASH_SNOW3G_UIA2_BLOCK_SIZE,
258 	NULL, /* initial state */
259 	0     /* state size */
260 };
261 
262 static lac_sym_qat_hash_alg_info_t aesCbcMacInfo =
263     { LAC_HASH_AES_CBC_MAC_DIGEST_SIZE,
264       LAC_HASH_AES_CBC_MAC_BLOCK_SIZE,
265       NULL,
266       0 };
267 
268 static lac_sym_qat_hash_alg_info_t zucEia3Info = {
269 	LAC_HASH_ZUC_EIA3_DIGEST_SIZE,
270 	LAC_HASH_ZUC_EIA3_BLOCK_SIZE,
271 	NULL, /* initial state */
272 	0     /* state size */
273 };
274 /* Hash QAT specific structures */
275 
276 static lac_sym_qat_hash_qat_info_t md5Config = { ICP_QAT_HW_AUTH_ALGO_MD5,
277 						 LAC_HASH_MD5_BLOCK_SIZE,
278 						 ICP_QAT_HW_MD5_STATE1_SZ,
279 						 ICP_QAT_HW_MD5_STATE2_SZ };
280 
281 static lac_sym_qat_hash_qat_info_t sha1Config = { ICP_QAT_HW_AUTH_ALGO_SHA1,
282 						  LAC_HASH_SHA1_BLOCK_SIZE,
283 						  ICP_QAT_HW_SHA1_STATE1_SZ,
284 						  ICP_QAT_HW_SHA1_STATE2_SZ };
285 
286 static lac_sym_qat_hash_qat_info_t sha224Config =
287     { ICP_QAT_HW_AUTH_ALGO_SHA224,
288       LAC_HASH_SHA224_BLOCK_SIZE,
289       ICP_QAT_HW_SHA224_STATE1_SZ,
290       ICP_QAT_HW_SHA224_STATE2_SZ };
291 
292 static lac_sym_qat_hash_qat_info_t sha256Config =
293     { ICP_QAT_HW_AUTH_ALGO_SHA256,
294       LAC_HASH_SHA256_BLOCK_SIZE,
295       ICP_QAT_HW_SHA256_STATE1_SZ,
296       ICP_QAT_HW_SHA256_STATE2_SZ };
297 
298 static lac_sym_qat_hash_qat_info_t sha384Config =
299     { ICP_QAT_HW_AUTH_ALGO_SHA384,
300       LAC_HASH_SHA384_BLOCK_SIZE,
301       ICP_QAT_HW_SHA384_STATE1_SZ,
302       ICP_QAT_HW_SHA384_STATE2_SZ };
303 
304 static lac_sym_qat_hash_qat_info_t sha512Config =
305     { ICP_QAT_HW_AUTH_ALGO_SHA512,
306       LAC_HASH_SHA512_BLOCK_SIZE,
307       ICP_QAT_HW_SHA512_STATE1_SZ,
308       ICP_QAT_HW_SHA512_STATE2_SZ };
309 
310 static lac_sym_qat_hash_qat_info_t sha3_224Config =
311     { ICP_QAT_HW_AUTH_ALGO_SHA3_224,
312       LAC_HASH_SHA3_224_BLOCK_SIZE,
313       ICP_QAT_HW_SHA3_224_STATE1_SZ,
314       ICP_QAT_HW_SHA3_224_STATE2_SZ };
315 
316 static lac_sym_qat_hash_qat_info_t sha3_256Config =
317     { ICP_QAT_HW_AUTH_ALGO_SHA3_256,
318       LAC_HASH_SHA3_256_BLOCK_SIZE,
319       ICP_QAT_HW_SHA3_256_STATE1_SZ,
320       ICP_QAT_HW_SHA3_256_STATE2_SZ };
321 
322 static lac_sym_qat_hash_qat_info_t sha3_384Config =
323     { ICP_QAT_HW_AUTH_ALGO_SHA3_384,
324       LAC_HASH_SHA3_384_BLOCK_SIZE,
325       ICP_QAT_HW_SHA3_384_STATE1_SZ,
326       ICP_QAT_HW_SHA3_384_STATE2_SZ };
327 
328 static lac_sym_qat_hash_qat_info_t sha3_512Config =
329     { ICP_QAT_HW_AUTH_ALGO_SHA3_512,
330       LAC_HASH_SHA3_512_BLOCK_SIZE,
331       ICP_QAT_HW_SHA3_512_STATE1_SZ,
332       ICP_QAT_HW_SHA3_512_STATE2_SZ };
333 
334 static lac_sym_qat_hash_qat_info_t shake_128Config =
335     { ICP_QAT_HW_AUTH_ALGO_SHAKE_128, LAC_HASH_SHAKE_128_BLOCK_SIZE, 0, 0 };
336 
337 static lac_sym_qat_hash_qat_info_t shake_256Config =
338     { ICP_QAT_HW_AUTH_ALGO_SHAKE_256, LAC_HASH_SHAKE_256_BLOCK_SIZE, 0, 0 };
339 
340 static lac_sym_qat_hash_qat_info_t polyConfig = { ICP_QAT_HW_AUTH_ALGO_POLY,
341 						  LAC_HASH_POLY_BLOCK_SIZE,
342 						  0,
343 						  0 };
344 
345 static lac_sym_qat_hash_qat_info_t sm3Config = { ICP_QAT_HW_AUTH_ALGO_SM3,
346 						 LAC_HASH_SM3_BLOCK_SIZE,
347 						 ICP_QAT_HW_SM3_STATE1_SZ,
348 						 ICP_QAT_HW_SM3_STATE2_SZ };
349 
350 static lac_sym_qat_hash_qat_info_t xcbcMacConfig =
351     { ICP_QAT_HW_AUTH_ALGO_AES_XCBC_MAC,
352       0,
353       ICP_QAT_HW_AES_XCBC_MAC_STATE1_SZ,
354       LAC_SYM_QAT_XCBC_STATE_SIZE };
355 
356 static lac_sym_qat_hash_qat_info_t aesCmacConfig =
357     { ICP_QAT_HW_AUTH_ALGO_AES_XCBC_MAC,
358       0,
359       ICP_QAT_HW_AES_XCBC_MAC_STATE1_SZ,
360       LAC_SYM_QAT_CMAC_STATE_SIZE };
361 
362 static lac_sym_qat_hash_qat_info_t aesCcmConfig =
363     { ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC,
364       0,
365       ICP_QAT_HW_AES_CBC_MAC_STATE1_SZ,
366       ICP_QAT_HW_AES_CBC_MAC_KEY_SZ + ICP_QAT_HW_AES_CCM_CBC_E_CTR0_SZ };
367 
368 static lac_sym_qat_hash_qat_info_t aesGcmConfig =
369     { ICP_QAT_HW_AUTH_ALGO_GALOIS_128,
370       0,
371       ICP_QAT_HW_GALOIS_128_STATE1_SZ,
372       ICP_QAT_HW_GALOIS_H_SZ + ICP_QAT_HW_GALOIS_LEN_A_SZ +
373 	  ICP_QAT_HW_GALOIS_E_CTR0_SZ };
374 
375 static lac_sym_qat_hash_qat_info_t kasumiF9Config =
376     { ICP_QAT_HW_AUTH_ALGO_KASUMI_F9,
377       0,
378       ICP_QAT_HW_KASUMI_F9_STATE1_SZ,
379       ICP_QAT_HW_KASUMI_F9_STATE2_SZ };
380 
381 static lac_sym_qat_hash_qat_info_t snow3gUia2Config =
382     { ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2,
383       0,
384       ICP_QAT_HW_SNOW_3G_UIA2_STATE1_SZ,
385       ICP_QAT_HW_SNOW_3G_UIA2_STATE2_SZ };
386 
387 static lac_sym_qat_hash_qat_info_t aesCbcMacConfig =
388     { ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC,
389       0,
390       ICP_QAT_HW_AES_CBC_MAC_STATE1_SZ,
391       ICP_QAT_HW_AES_CBC_MAC_STATE1_SZ + ICP_QAT_HW_AES_CBC_MAC_STATE1_SZ };
392 
393 static lac_sym_qat_hash_qat_info_t zucEia3Config =
394     { ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3,
395       0,
396       ICP_QAT_HW_ZUC_3G_EIA3_STATE1_SZ,
397       ICP_QAT_HW_ZUC_3G_EIA3_STATE2_SZ };
398 
399 /* Array of mappings between algorithm and info structure
400  * This array is used to populate the lookup table */
401 static lac_sym_qat_hash_def_map_t lacHashDefsMapping[] =
402     { { CPA_CY_SYM_HASH_MD5, { &md5Info, &md5Config } },
403       { CPA_CY_SYM_HASH_SHA1, { &sha1Info, &sha1Config } },
404       { CPA_CY_SYM_HASH_SHA224, { &sha224Info, &sha224Config } },
405       { CPA_CY_SYM_HASH_SHA256, { &sha256Info, &sha256Config } },
406       { CPA_CY_SYM_HASH_SHA384, { &sha384Info, &sha384Config } },
407       { CPA_CY_SYM_HASH_SHA512, { &sha512Info, &sha512Config } },
408       { CPA_CY_SYM_HASH_SHA3_224, { &sha3_224Info, &sha3_224Config } },
409       { CPA_CY_SYM_HASH_SHA3_256, { &sha3_256Info, &sha3_256Config } },
410       { CPA_CY_SYM_HASH_SHA3_384, { &sha3_384Info, &sha3_384Config } },
411       { CPA_CY_SYM_HASH_SHA3_512, { &sha3_512Info, &sha3_512Config } },
412       { CPA_CY_SYM_HASH_SHAKE_128, { &shake_128Info, &shake_128Config } },
413       { CPA_CY_SYM_HASH_SHAKE_256, { &shake_256Info, &shake_256Config } },
414       { CPA_CY_SYM_HASH_POLY, { &polyInfo, &polyConfig } },
415       { CPA_CY_SYM_HASH_SM3, { &sm3Info, &sm3Config } },
416       { CPA_CY_SYM_HASH_AES_XCBC, { &xcbcMacInfo, &xcbcMacConfig } },
417       { CPA_CY_SYM_HASH_AES_CMAC, { &aesCmacInfo, &aesCmacConfig } },
418       { CPA_CY_SYM_HASH_AES_CCM, { &aesCcmInfo, &aesCcmConfig } },
419       { CPA_CY_SYM_HASH_AES_GCM, { &aesGcmInfo, &aesGcmConfig } },
420       { CPA_CY_SYM_HASH_KASUMI_F9, { &kasumiF9Info, &kasumiF9Config } },
421       { CPA_CY_SYM_HASH_SNOW3G_UIA2, { &snow3gUia2Info, &snow3gUia2Config } },
422       { CPA_CY_SYM_HASH_AES_GMAC, { &aesGcmInfo, &aesGcmConfig } },
423       { CPA_CY_SYM_HASH_ZUC_EIA3, { &zucEia3Info, &zucEia3Config } },
424       { CPA_CY_SYM_HASH_AES_CBC_MAC, { &aesCbcMacInfo, &aesCbcMacConfig } } };
425 
426 /*
427  * LacSymQat_HashLookupInit
428  */
429 CpaStatus
430 LacSymQat_HashLookupInit(CpaInstanceHandle instanceHandle)
431 {
432 	Cpa32U entry = 0;
433 	Cpa32U numEntries = 0;
434 	Cpa32U arraySize = 0;
435 	CpaStatus status = CPA_STATUS_SUCCESS;
436 	CpaCySymHashAlgorithm hashAlg = CPA_CY_SYM_HASH_NONE;
437 	sal_crypto_service_t *pService = (sal_crypto_service_t *)instanceHandle;
438 
439 	arraySize =
440 	    (CPA_CY_HASH_ALG_END + 1) * sizeof(lac_sym_qat_hash_defs_t *);
441 	/* Size round up for performance */
442 	arraySize = LAC_ALIGN_POW2_ROUNDUP(arraySize, LAC_64BYTE_ALIGNMENT);
443 
444 	pService->pLacHashLookupDefs = LAC_OS_MALLOC(arraySize);
445 
446 	if (NULL != pService->pLacHashLookupDefs) {
447 		LAC_OS_BZERO(pService->pLacHashLookupDefs, arraySize);
448 
449 		numEntries = sizeof(lacHashDefsMapping) /
450 		    sizeof(lac_sym_qat_hash_def_map_t);
451 
452 		/* initialise the hash lookup definitions table so that the
453 		 * algorithm
454 		 * can be used to index into the table */
455 		for (entry = 0; entry < numEntries; entry++) {
456 			hashAlg = lacHashDefsMapping[entry].hashAlgorithm;
457 
458 			pService->pLacHashLookupDefs[hashAlg] =
459 			    &(lacHashDefsMapping[entry].hashDefs);
460 		}
461 	} else {
462 		status = CPA_STATUS_RESOURCE;
463 	}
464 	return status;
465 }
466 
467 /*
468  * LacSymQat_HashAlgLookupGet
469  */
470 void
471 LacSymQat_HashAlgLookupGet(CpaInstanceHandle instanceHandle,
472 			   CpaCySymHashAlgorithm hashAlgorithm,
473 			   lac_sym_qat_hash_alg_info_t **ppHashAlgInfo)
474 {
475 	sal_crypto_service_t *pService = (sal_crypto_service_t *)instanceHandle;
476 
477 	*ppHashAlgInfo = pService->pLacHashLookupDefs[hashAlgorithm]->algInfo;
478 }
479 
480 /*
481  * LacSymQat_HashDefsLookupGet
482  */
483 void
484 LacSymQat_HashDefsLookupGet(CpaInstanceHandle instanceHandle,
485 			    CpaCySymHashAlgorithm hashAlgorithm,
486 			    lac_sym_qat_hash_defs_t **ppHashDefsInfo)
487 {
488 	sal_crypto_service_t *pService = (sal_crypto_service_t *)instanceHandle;
489 
490 	*ppHashDefsInfo = pService->pLacHashLookupDefs[hashAlgorithm];
491 }
492