1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4
5 /**
6 ***************************************************************************
7 * @file lac_sym_hash_defs.h
8 *
9 * @defgroup LacHashDefs Hash Definitions
10 *
11 * @ingroup LacHash
12 *
13 * Constants for hash algorithms
14 *
15 ***************************************************************************/
16
17 #ifndef LAC_SYM_HASH_DEFS_H
18 #define LAC_SYM_HASH_DEFS_H
19
20 /* Constant for MD5 algorithm */
21 #define LAC_HASH_MD5_BLOCK_SIZE 64
22 /**< @ingroup LacHashDefs
23 * MD5 block size in bytes */
24 #define LAC_HASH_MD5_DIGEST_SIZE 16
25 /**< @ingroup LacHashDefs
26 * MD5 digest length in bytes */
27 #define LAC_HASH_MD5_STATE_SIZE 16
28 /**< @ingroup LacHashDefs
29 * MD5 state size */
30
31 /* Constants for SHA1 algorithm */
32 #define LAC_HASH_SHA1_BLOCK_SIZE 64
33 /**< @ingroup LacHashDefs
34 * SHA1 Block size in bytes */
35 #define LAC_HASH_SHA1_DIGEST_SIZE 20
36 /**< @ingroup LacHashDefs
37 * SHA1 digest length in bytes */
38 #define LAC_HASH_SHA1_STATE_SIZE 20
39 /**< @ingroup LacHashDefs
40 * SHA1 state size */
41
42 /* Constants for SHA224 algorithm */
43 #define LAC_HASH_SHA224_BLOCK_SIZE 64
44 /**< @ingroup LacHashDefs
45 * SHA224 block size in bytes */
46 #define LAC_HASH_SHA224_DIGEST_SIZE 28
47 /**< @ingroup LacHashDefs
48 * SHA224 digest length in bytes */
49 #define LAC_HASH_SHA224_STATE_SIZE 32
50 /**< @ingroup LacHashDefs
51 * SHA224 state size */
52
53 /* Constants for SHA256 algorithm */
54 #define LAC_HASH_SHA256_BLOCK_SIZE 64
55 /**< @ingroup LacHashDefs
56 * SHA256 block size in bytes */
57 #define LAC_HASH_SHA256_DIGEST_SIZE 32
58 /**< @ingroup LacHashDefs
59 * SHA256 digest length */
60 #define LAC_HASH_SHA256_STATE_SIZE 32
61 /**< @ingroup LacHashDefs
62 * SHA256 state size */
63
64 /* Constants for SHA384 algorithm */
65 #define LAC_HASH_SHA384_BLOCK_SIZE 128
66 /**< @ingroup LacHashDefs
67 * SHA384 block size in bytes */
68 #define LAC_HASH_SHA384_DIGEST_SIZE 48
69 /**< @ingroup LacHashDefs
70 * SHA384 digest length in bytes */
71 #define LAC_HASH_SHA384_STATE_SIZE 64
72 /**< @ingroup LacHashDefs
73 * SHA384 state size */
74
75 /* Constants for SHA512 algorithm */
76 #define LAC_HASH_SHA512_BLOCK_SIZE 128
77 /**< @ingroup LacHashDefs
78 * SHA512 block size in bytes */
79 #define LAC_HASH_SHA512_DIGEST_SIZE 64
80 /**< @ingroup LacHashDefs
81 * SHA512 digest length in bytes */
82 #define LAC_HASH_SHA512_STATE_SIZE 64
83 /**< @ingroup LacHashDefs
84 * SHA512 state size */
85
86 /* Constants for SHA3_224 algorithm */
87 #define LAC_HASH_SHA3_224_BLOCK_SIZE 144
88 /**< @ingroup LacHashDefs
89 * SHA3_224 block size in bytes */
90 #define LAC_HASH_SHA3_224_DIGEST_SIZE 28
91 /**< @ingroup LacHashDefs
92 * SHA3_224 digest length in bytes */
93 #define LAC_HASH_SHA3_224_STATE_SIZE 28
94 /**< @ingroup LacHashDefs
95 * SHA3_224 state size */
96
97 /* Constants for SHA3_256 algorithm */
98 #define LAC_HASH_SHA3_256_BLOCK_SIZE 136
99 /**< @ingroup LacHashDefs
100 * SHA3_256 block size in bytes */
101 #define LAC_HASH_SHA3_256_DIGEST_SIZE 32
102 /**< @ingroup LacHashDefs
103 * SHA3_256 digest length in bytes */
104 #define LAC_HASH_SHA3_256_STATE_SIZE 32
105 /**< @ingroup LacHashDefs
106 * SHA3_256 state size */
107
108 /* Constants for SHA3_384 algorithm */
109 #define LAC_HASH_SHA3_384_BLOCK_SIZE 104
110 /**< @ingroup LacHashDefs
111 * SHA3_384 block size in bytes */
112 #define LAC_HASH_SHA3_384_DIGEST_SIZE 48
113 /**< @ingroup LacHashDefs
114 * SHA3_384 digest length in bytes */
115 #define LAC_HASH_SHA3_384_STATE_SIZE 48
116 /**< @ingroup LacHashDefs
117 * SHA3_384 state size */
118
119 /* Constants for SHA3_512 algorithm */
120 #define LAC_HASH_SHA3_512_BLOCK_SIZE 72
121 /**< @ingroup LacHashDefs
122 * SHA3_512 block size in bytes */
123 #define LAC_HASH_SHA3_512_DIGEST_SIZE 64
124 /**< @ingroup LacHashDefs
125 * SHA3_512 digest length in bytes */
126 #define LAC_HASH_SHA3_512_STATE_SIZE 64
127 /**< @ingroup LacHashDefs
128 * SHA3_512 state size */
129
130 #define LAC_HASH_SHA3_STATEFUL_STATE_SIZE 200
131
132 /* Constants for SM3 algorithm */
133 #define LAC_HASH_SM3_BLOCK_SIZE 64
134 /**< @ingroup LacHashDefs
135 * SM3 block size in bytes */
136 #define LAC_HASH_SM3_DIGEST_SIZE 32
137 /**< @ingroup LacHashDefs
138 * SM3 digest length */
139 #define LAC_HASH_SM3_STATE_SIZE 32
140 /**< @ingroup LacHashDefs
141 * SM3 state size */
142
143 /* Constants for POLY algorithm */
144 #define LAC_HASH_POLY_BLOCK_SIZE 64
145 /**< @ingroup LacHashDefs
146 * POLY block size in bytes */
147 #define LAC_HASH_POLY_DIGEST_SIZE 16
148 /**< @ingroup LacHashDefs
149 * POLY digest length */
150 #define LAC_HASH_POLY_STATE_SIZE 0
151 /**< @ingroup LacHashDefs
152 * POLY state size */
153
154 /* Constants for XCBC precompute algorithm */
155 #define LAC_HASH_XCBC_PRECOMP_KEY_NUM 3
156 /**< @ingroup LacHashDefs
157 * The Pre-compute operation involves deriving 3 128-bit
158 * keys (K1, K2 and K3) */
159
160 /* Constants for XCBC MAC algorithm */
161 #define LAC_HASH_XCBC_MAC_BLOCK_SIZE 16
162 /**< @ingroup LacHashDefs
163 * XCBC_MAC block size in bytes */
164 #define LAC_HASH_XCBC_MAC_128_DIGEST_SIZE 16
165 /**< @ingroup LacHashDefs
166 * XCBC_MAC_PRF_128 digest length in bytes */
167
168 /* Constants for AES CMAC algorithm */
169 #define LAC_HASH_CMAC_BLOCK_SIZE 16
170 /**< @ingroup LacHashDefs
171 * AES CMAC block size in bytes */
172 #define LAC_HASH_CMAC_128_DIGEST_SIZE 16
173 /**< @ingroup LacHashDefs
174 * AES CMAC digest length in bytes */
175
176 /* constants for AES CCM */
177 #define LAC_HASH_AES_CCM_BLOCK_SIZE 16
178 /**< @ingroup LacHashDefs
179 * block size for CBC-MAC part of CCM */
180 #define LAC_HASH_AES_CCM_DIGEST_SIZE 16
181 /**< @ingroup LacHashDefs
182 * untruncated size of authentication field */
183
184 /* constants for AES GCM */
185 #define LAC_HASH_AES_GCM_BLOCK_SIZE 16
186 /**< @ingroup LacHashDefs
187 * block size for Galois Hash 128 part of CCM */
188 #define LAC_HASH_AES_GCM_DIGEST_SIZE 16
189 /**< @ingroup LacHashDefs
190 * untruncated size of authentication field */
191
192 /* constants for KASUMI F9 */
193 #define LAC_HASH_KASUMI_F9_BLOCK_SIZE 8
194 /**< @ingroup LacHashDefs
195 * KASUMI_F9 block size in bytes */
196 #define LAC_HASH_KASUMI_F9_DIGEST_SIZE 4
197 /**< @ingroup LacHashDefs
198 * KASUMI_F9 digest size in bytes */
199
200 /* constants for SNOW3G UIA2 */
201 #define LAC_HASH_SNOW3G_UIA2_BLOCK_SIZE 8
202 /**< @ingroup LacHashDefs
203 * SNOW3G UIA2 block size in bytes */
204 #define LAC_HASH_SNOW3G_UIA2_DIGEST_SIZE 4
205 /**< @ingroup LacHashDefs
206 * SNOW3G UIA2 digest size in bytes */
207
208 /* constants for AES CBC MAC */
209 #define LAC_HASH_AES_CBC_MAC_BLOCK_SIZE 16
210 /**< @ingroup LacHashDefs
211 * AES CBC MAC block size in bytes */
212 #define LAC_HASH_AES_CBC_MAC_DIGEST_SIZE 16
213 /**< @ingroup LacHashDefs
214 * AES CBC MAC digest size in bytes */
215
216 #define LAC_HASH_ZUC_EIA3_BLOCK_SIZE 4
217 /**< @ingroup LacHashDefs
218 * ZUC EIA3 block size in bytes */
219 #define LAC_HASH_ZUC_EIA3_DIGEST_SIZE 4
220 /**< @ingroup LacHashDefs
221 * ZUC EIA3 digest size in bytes */
222
223 /* constants for AES GCM ICV allowed sizes */
224 #define LAC_HASH_AES_GCM_ICV_SIZE_8 8
225 #define LAC_HASH_AES_GCM_ICV_SIZE_12 12
226 #define LAC_HASH_AES_GCM_ICV_SIZE_16 16
227
228 /* constants for AES CCM ICV allowed sizes */
229 #define LAC_HASH_AES_CCM_ICV_SIZE_MIN 4
230 #define LAC_HASH_AES_CCM_ICV_SIZE_MAX 16
231
232 /* constants for authentication algorithms */
233 #define LAC_HASH_IPAD_BYTE 0x36
234 /**< @ingroup LacHashDefs
235 * Ipad Byte */
236 #define LAC_HASH_OPAD_BYTE 0x5c
237 /**< @ingroup LacHashDefs
238 * Opad Byte */
239
240 #define LAC_HASH_IPAD_4_BYTES 0x36363636
241 /**< @ingroup LacHashDefs
242 * Ipad for 4 Bytes */
243 #define LAC_HASH_OPAD_4_BYTES 0x5c5c5c5c
244 /**< @ingroup LacHashDefs
245 * Opad for 4 Bytes */
246
247 /* Key Modifier (KM) value used in Kasumi algorithm in F9 mode to XOR
248 * Integrity Key (IK) */
249 #define LAC_HASH_KASUMI_F9_KEY_MODIFIER_4_BYTES 0xAAAAAAAA
250 /**< @ingroup LacHashDefs
251 * Kasumi F9 Key Modifier for 4 bytes */
252
253 #define LAC_SYM_QAT_HASH_IV_REQ_MAX_SIZE_QW 2
254 /**< @ingroup LacSymQatHash
255 * Maximum size of IV embedded in the request.
256 * This is set to 2, namely 4 LONGWORDS. */
257
258 #define LAC_SYM_QAT_HASH_STATE1_MAX_SIZE_BYTES LAC_HASH_SHA512_BLOCK_SIZE
259 /**< @ingroup LacSymQatHash
260 * Maximum size of state1 in the hash setup block of the content descriptor.
261 * This is set to the block size of SHA512. */
262
263 #define LAC_SYM_QAT_HASH_STATE2_MAX_SIZE_BYTES LAC_HASH_SHA512_BLOCK_SIZE
264 /**< @ingroup LacSymQatHash
265 * Maximum size of state2 in the hash setup block of the content descriptor.
266 * This is set to the block size of SHA512. */
267
268 #define LAC_MAX_INNER_OUTER_PREFIX_SIZE_BYTES 255
269 /**< Maximum size of the inner and outer prefix for nested hashing operations.
270 * This is got from the maximum size supported by the accelerator which stores
271 * the size in an 8bit field */
272
273 #define LAC_MAX_HASH_STATE_STORAGE_SIZE \
274 (sizeof(icp_qat_hw_auth_counter_t) + LAC_HASH_SHA3_STATEFUL_STATE_SIZE)
275 /**< Maximum size of the hash state storage section of the hash state prefix
276 * buffer */
277
278 #define LAC_MAX_HASH_STATE_BUFFER_SIZE_BYTES \
279 LAC_MAX_HASH_STATE_STORAGE_SIZE + \
280 (LAC_ALIGN_POW2_ROUNDUP(LAC_MAX_INNER_OUTER_PREFIX_SIZE_BYTES, \
281 LAC_QUAD_WORD_IN_BYTES) * \
282 2)
283 /**< Maximum size of the hash state prefix buffer will be for nested hash when
284 * there is the maximum sized inner prefix and outer prefix */
285
286 #define LAC_MAX_AAD_SIZE_BYTES 256
287 /**< Maximum size of AAD in bytes */
288
289 #define IS_HMAC_ALG(algorithm) \
290 ((algorithm == CPA_CY_SYM_HASH_MD5) || \
291 (algorithm == CPA_CY_SYM_HASH_SHA1) || \
292 (algorithm == CPA_CY_SYM_HASH_SHA224) || \
293 (algorithm == CPA_CY_SYM_HASH_SHA256) || \
294 (algorithm == CPA_CY_SYM_HASH_SHA384) || \
295 (algorithm == CPA_CY_SYM_HASH_SHA512) || \
296 (algorithm == CPA_CY_SYM_HASH_SM3)) || \
297 (LAC_HASH_IS_SHA3(algorithm))
298 /**< @ingroup LacSymQatHash
299 * Macro to detect if the hash algorithm is a HMAC algorithm */
300
301 #define IS_HASH_MODE_1(qatHashMode) (ICP_QAT_HW_AUTH_MODE1 == qatHashMode)
302 /**< @ingroup LacSymQatHash
303 * Macro to detect is qat hash mode is set to 1 (precompute mode)
304 * only used with algorithms in hash mode CPA_CY_SYM_HASH_MODE_AUTH */
305
306 #define IS_HASH_MODE_2(qatHashMode) (ICP_QAT_HW_AUTH_MODE2 == qatHashMode)
307 /**< @ingroup LacSymQatHash
308 * Macro to detect is qat hash mode is set to 2. This is used for TLS and
309 * mode 2 HMAC (no preompute mode) */
310
311 #define IS_HASH_MODE_2_AUTH(qatHashMode, hashMode) \
312 ((IS_HASH_MODE_2(qatHashMode)) && \
313 (CPA_CY_SYM_HASH_MODE_AUTH == hashMode))
314 /**< @ingroup LacSymQatHash
315 * Macro to check for qat hash mode is set to 2 and the hash mode is
316 * Auth. This applies to HMAC algorithms (no pre compute). This is used
317 * to differntiate between TLS and HMAC */
318
319 #define IS_HASH_MODE_2_NESTED(qatHashMode, hashMode) \
320 ((IS_HASH_MODE_2(qatHashMode)) && \
321 (CPA_CY_SYM_HASH_MODE_NESTED == hashMode))
322 /**< @ingroup LacSymQatHash
323 * Macro to check for qat hash mode is set to 2 and the LAC hash mode is
324 * Nested. This applies to TLS. This is used to differentiate between
325 * TLS and HMAC */
326
327 #define LAC_HASH_IS_SHA3(algo) \
328 ((algo == CPA_CY_SYM_HASH_SHA3_224) || \
329 (algo == CPA_CY_SYM_HASH_SHA3_256) || \
330 (algo == CPA_CY_SYM_HASH_SHA3_384) || \
331 (algo == CPA_CY_SYM_HASH_SHA3_512))
332 /**< @ingroup LacSymQatHash
333 * Macro to check if the hash algorithm is SHA3 */
334
335 #endif /* LAC_SYM_HASH_DEFS_H */
Cache object: f6c323c33d56ade6082a9cd040a6ac4e
|