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