1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /* $FreeBSD$ */
4
5 /**
6 *****************************************************************************
7 * @file lac_sym_cipher_defs.h
8 *
9 * @ingroup LacCipher
10 *
11 * @description
12 * This file defines constants for the cipher operations.
13 *
14 *****************************************************************************/
15
16 /***************************************************************************/
17
18 #ifndef LAC_SYM_CIPHER_DEFS_H
19 #define LAC_SYM_CIPHER_DEFS_H
20
21 /*
22 ******************************************************************************
23 * Include public/global header files
24 ******************************************************************************
25 */
26
27 #include "cpa.h"
28 #include "cpa_cy_sym.h"
29
30 /*
31 *******************************************************************************
32 * Include private header files
33 *******************************************************************************
34 */
35
36 /***************************************************************************/
37
38 /*
39 * Constants value for ARC4 algorithm
40 */
41 /* ARC4 algorithm block size */
42 #define LAC_CIPHER_ARC4_BLOCK_LEN_BYTES 8
43 /* ARC4 key matrix size (bytes) */
44 #define LAC_CIPHER_ARC4_KEY_MATRIX_LEN_BYTES 256
45 /* ARC4 256 bytes for key matrix, 2 for i and j and 6 bytes for padding */
46 #define LAC_CIPHER_ARC4_STATE_LEN_BYTES 264
47
48 /*
49 * Constant values for CCM AAD buffer
50 */
51 #define LAC_CIPHER_CCM_B0_SIZE 16
52 #define LAC_CIPHER_CCM_ENCODED_AAD_LEN_SIZE 2
53 #define LAC_CIPHER_CCM_AAD_OFFSET \
54 (LAC_CIPHER_CCM_B0_SIZE + LAC_CIPHER_CCM_ENCODED_AAD_LEN_SIZE)
55
56 #define LAC_SYM_SNOW3G_CIPHER_CONFIG_FOR_HASH_SZ 40
57 /* Snow3g cipher config required for performing a Snow3g hash operation.
58 * It contains 8 Bytes of config for hardware, 16 Bytes of Key and requires
59 * 16 Bytes for the IV.
60 */
61
62 /* Key Modifier (KM) 4 bytes used in Kasumi algorithm in F8 mode to XOR
63 * Cipher Key (CK) */
64 #define LAC_CIPHER_KASUMI_F8_KEY_MODIFIER_4_BYTES 0x55555555
65
66 /* The IV length for Kasumi Kgcore is 8 bytes */
67 #define LAC_CIPHER_KASUMI_F8_IV_LENGTH 8
68
69 /* The Counter length for Kasumi Kgcore is 8 bytes */
70 #define LAC_CIPHER_KASUMI_F8_COUNTER_LENGTH 8
71
72 /* The IV length for AES F8 is 16 bytes */
73 #define LAC_CIPHER_AES_F8_IV_LENGTH 16
74
75 /* The max key length for AES XTS 32 is bytes*/
76 #define LAC_CIPHER_AES_XTS_KEY_MAX_LENGTH 32
77
78 /* For Snow3G UEA2, need to make sure last 8 Bytes of IV buffer are
79 * zero. */
80 #define LAC_CIPHER_SNOW3G_UEA2_IV_BUFFER_ZERO_LENGTH 8
81
82 /* Reserve enough space for max length cipher state
83 * (can be IV , counter or ARC4 state) */
84 #define LAC_CIPHER_STATE_SIZE_MAX LAC_CIPHER_ARC4_STATE_LEN_BYTES
85
86 /* Reserve enough space for max length cipher IV
87 * (can be A value for Kasumi(passed in as IV), IV or counter,
88 * but not ARC4 state) */
89 #define LAC_CIPHER_IV_SIZE_MAX ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ
90
91 /* 96-bit case of IV for GCM algorithm */
92 #define LAC_CIPHER_IV_SIZE_GCM_12 12
93
94 /* 96-bit case of IV for CCP/GCM single pass algorithm */
95 #define LAC_CIPHER_SPC_IV_SIZE 12
96 /*
97 * Constants value for NULL algorithm
98 */
99 /* NULL algorithm block size */
100 #define LAC_CIPHER_NULL_BLOCK_LEN_BYTES 8
101
102 /* Macro to check if the Algorithm is SM4 */
103 #define LAC_CIPHER_IS_SM4(algo) \
104 ((algo == CPA_CY_SYM_CIPHER_SM4_ECB) || \
105 (algo == CPA_CY_SYM_CIPHER_SM4_CBC) || \
106 (algo == CPA_CY_SYM_CIPHER_SM4_CTR))
107
108 /* Macro to check if the Algorithm is CHACHA */
109 #define LAC_CIPHER_IS_CHACHA(algo) (algo == CPA_CY_SYM_CIPHER_CHACHA)
110 /* Macro to check if the Algorithm is AES */
111 #define LAC_CIPHER_IS_AES(algo) \
112 ((algo == CPA_CY_SYM_CIPHER_AES_ECB) || \
113 (algo == CPA_CY_SYM_CIPHER_AES_CBC) || \
114 (algo == CPA_CY_SYM_CIPHER_AES_CTR) || \
115 (algo == CPA_CY_SYM_CIPHER_AES_CCM) || \
116 (algo == CPA_CY_SYM_CIPHER_AES_GCM) || \
117 (algo == CPA_CY_SYM_CIPHER_AES_XTS))
118
119 /* Macro to check if the Algorithm is DES */
120 #define LAC_CIPHER_IS_DES(algo) \
121 ((algo == CPA_CY_SYM_CIPHER_DES_ECB) || \
122 (algo == CPA_CY_SYM_CIPHER_DES_CBC))
123
124 /* Macro to check if the Algorithm is Triple DES */
125 #define LAC_CIPHER_IS_TRIPLE_DES(algo) \
126 ((algo == CPA_CY_SYM_CIPHER_3DES_ECB) || \
127 (algo == CPA_CY_SYM_CIPHER_3DES_CBC) || \
128 (algo == CPA_CY_SYM_CIPHER_3DES_CTR))
129
130 /* Macro to check if the Algorithm is Kasumi */
131 #define LAC_CIPHER_IS_KASUMI(algo) (algo == CPA_CY_SYM_CIPHER_KASUMI_F8)
132
133 /* Macro to check if the Algorithm is Snow3G UEA2 */
134 #define LAC_CIPHER_IS_SNOW3G_UEA2(algo) (algo == CPA_CY_SYM_CIPHER_SNOW3G_UEA2)
135
136 /* Macro to check if the Algorithm is ARC4 */
137 #define LAC_CIPHER_IS_ARC4(algo) (algo == CPA_CY_SYM_CIPHER_ARC4)
138
139 /* Macro to check if the Algorithm is ZUC EEA3 */
140 #define LAC_CIPHER_IS_ZUC_EEA3(algo) (algo == CPA_CY_SYM_CIPHER_ZUC_EEA3)
141
142 /* Macro to check if the Algorithm is NULL */
143 #define LAC_CIPHER_IS_NULL(algo) (algo == CPA_CY_SYM_CIPHER_NULL)
144
145 /* Macro to check if the Mode is CTR */
146 #define LAC_CIPHER_IS_CTR_MODE(algo) \
147 ((algo == CPA_CY_SYM_CIPHER_AES_CTR) || \
148 (algo == CPA_CY_SYM_CIPHER_3DES_CTR) || (LAC_CIPHER_IS_CCM(algo)) || \
149 (LAC_CIPHER_IS_GCM(algo)) || (LAC_CIPHER_IS_CHACHA(algo)) || \
150 (algo == CPA_CY_SYM_CIPHER_SM4_CTR))
151
152 /* Macro to check if the Algorithm is ECB */
153 #define LAC_CIPHER_IS_ECB_MODE(algo) \
154 ((algo == CPA_CY_SYM_CIPHER_AES_ECB) || \
155 (algo == CPA_CY_SYM_CIPHER_DES_ECB) || \
156 (algo == CPA_CY_SYM_CIPHER_3DES_ECB) || \
157 (algo == CPA_CY_SYM_CIPHER_NULL) || \
158 (algo == CPA_CY_SYM_CIPHER_SNOW3G_UEA2) || \
159 (algo == CPA_CY_SYM_CIPHER_SM4_ECB))
160
161 /* Macro to check if the Algorithm Mode is F8 */
162 #define LAC_CIPHER_IS_F8_MODE(algo) \
163 ((algo == CPA_CY_SYM_CIPHER_KASUMI_F8) || \
164 (algo == CPA_CY_SYM_CIPHER_AES_F8))
165
166 /* Macro to check if the Algorithm is CBC */
167 #define LAC_CIPHER_IS_CBC_MODE(algo) \
168 ((algo == CPA_CY_SYM_CIPHER_AES_CBC) || \
169 (algo == CPA_CY_SYM_CIPHER_DES_CBC) || \
170 (algo == CPA_CY_SYM_CIPHER_3DES_CBC) || \
171 (algo == CPA_CY_SYM_CIPHER_SM4_CBC))
172
173 /* Macro to check if the Algorithm is CCM */
174 #define LAC_CIPHER_IS_CCM(algo) (algo == CPA_CY_SYM_CIPHER_AES_CCM)
175
176 /* Macro to check if the Algorithm is GCM */
177 #define LAC_CIPHER_IS_GCM(algo) (algo == CPA_CY_SYM_CIPHER_AES_GCM)
178
179 /* Macro to check if the Algorithm is AES-F8 */
180 #define LAC_CIPHER_IS_AES_F8(algo) (algo == CPA_CY_SYM_CIPHER_AES_F8)
181
182 /* Macro to check if the Algorithm Mode is XTS */
183 #define LAC_CIPHER_IS_XTS_MODE(algo) (algo == CPA_CY_SYM_CIPHER_AES_XTS)
184
185 /* Macro to check if the accelerator has AES V2 capability */
186 #define LAC_CIPHER_AES_V2(mask) ((mask)&ICP_ACCEL_CAPABILITIES_AES_V2)
187
188 /* Macro to check if the Algorithm is single pass */
189 #define LAC_CIPHER_IS_SPC(cipher, hash, mask) \
190 (((mask)&ICP_ACCEL_CAPABILITIES_CHACHA_POLY && \
191 LAC_CIPHER_IS_CHACHA(cipher) && (CPA_CY_SYM_HASH_POLY == hash)) || \
192 (((mask)&ICP_ACCEL_CAPABILITIES_AESGCM_SPC) && \
193 LAC_CIPHER_IS_GCM(cipher) && \
194 ((CPA_CY_SYM_HASH_AES_GCM == hash) || \
195 (CPA_CY_SYM_HASH_AES_GMAC == hash))) || \
196 (LAC_CIPHER_IS_CCM(cipher) && LAC_CIPHER_AES_V2(mask)))
197
198 #endif /* LAC_CIPHER_DEFS_H */
Cache object: 4d3b5eafa5ff85b37e0711d9bb5ff498
|