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 #define LAC_SYM_SNOW3G_CIPHER_CONFIG_FOR_HASH_SZ 40
49 /* Snow3g cipher config required for performing a Snow3g hash operation.
50  * It contains 8 Bytes of config for hardware, 16 Bytes of Key and requires
51  * 16 Bytes for the IV.
52  */
53 
54 /* Key Modifier (KM) 4 bytes used in Kasumi algorithm in F8 mode to XOR
55  * Cipher Key (CK) */
56 #define LAC_CIPHER_KASUMI_F8_KEY_MODIFIER_4_BYTES 0x55555555
57 
58 /* The IV length for Kasumi Kgcore is 8 bytes */
59 #define LAC_CIPHER_KASUMI_F8_IV_LENGTH 8
60 
61 /* The Counter length for Kasumi Kgcore is 8 bytes */
62 #define LAC_CIPHER_KASUMI_F8_COUNTER_LENGTH 8
63 
64 /* The IV length for AES F8 is 16 bytes */
65 #define LAC_CIPHER_AES_F8_IV_LENGTH 16
66 
67 /* For Snow3G UEA2, need to make sure last 8 Bytes of IV buffer are
68  * zero. */
69 #define LAC_CIPHER_SNOW3G_UEA2_IV_BUFFER_ZERO_LENGTH 8
70 
71 /* Reserve enough space for max length cipher state
72  * (can be IV , counter or ARC4 state)  */
73 #define LAC_CIPHER_STATE_SIZE_MAX LAC_CIPHER_ARC4_STATE_LEN_BYTES
74 
75 /* Reserve enough space for max length cipher IV
76  * (can be A value for Kasumi(passed in as IV), IV or counter,
77  * but not ARC4 state)  */
78 #define LAC_CIPHER_IV_SIZE_MAX ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ
79 
80 /* 96-bit case of IV for GCM algorithm */
81 #define LAC_CIPHER_IV_SIZE_GCM_12 12
82 
83 /* 96-bit case of IV for CCP/GCM single pass algorithm */
84 #define LAC_CIPHER_SPC_IV_SIZE 12
85 /*
86  * Constants value for NULL algorithm
87  */
88 /* NULL algorithm block size */
89 #define LAC_CIPHER_NULL_BLOCK_LEN_BYTES 8
90 
91 /* Macro to check if the Algorithm is SM4 */
92 #define LAC_CIPHER_IS_SM4(algo)                                                \
93 	((algo == CPA_CY_SYM_CIPHER_SM4_ECB) ||                                \
94 	 (algo == CPA_CY_SYM_CIPHER_SM4_CBC) ||                                \
95 	 (algo == CPA_CY_SYM_CIPHER_SM4_CTR))
96 
97 /* Macro to check if the Algorithm is CHACHA */
98 #define LAC_CIPHER_IS_CHACHA(algo) (algo == CPA_CY_SYM_CIPHER_CHACHA)
99 /* Macro to check if the Algorithm is AES */
100 #define LAC_CIPHER_IS_AES(algo)                                                \
101 	((algo == CPA_CY_SYM_CIPHER_AES_ECB) ||                                \
102 	 (algo == CPA_CY_SYM_CIPHER_AES_CBC) ||                                \
103 	 (algo == CPA_CY_SYM_CIPHER_AES_CTR) ||                                \
104 	 (algo == CPA_CY_SYM_CIPHER_AES_CCM) ||                                \
105 	 (algo == CPA_CY_SYM_CIPHER_AES_GCM) ||                                \
106 	 (algo == CPA_CY_SYM_CIPHER_AES_XTS))
107 
108 /* Macro to check if the Algorithm is DES */
109 #define LAC_CIPHER_IS_DES(algo)                                                \
110 	((algo == CPA_CY_SYM_CIPHER_DES_ECB) ||                                \
111 	 (algo == CPA_CY_SYM_CIPHER_DES_CBC))
112 
113 /* Macro to check if the Algorithm is Triple DES */
114 #define LAC_CIPHER_IS_TRIPLE_DES(algo)                                         \
115 	((algo == CPA_CY_SYM_CIPHER_3DES_ECB) ||                               \
116 	 (algo == CPA_CY_SYM_CIPHER_3DES_CBC) ||                               \
117 	 (algo == CPA_CY_SYM_CIPHER_3DES_CTR))
118 
119 /* Macro to check if the Algorithm is Kasumi */
120 #define LAC_CIPHER_IS_KASUMI(algo) (algo == CPA_CY_SYM_CIPHER_KASUMI_F8)
121 
122 /* Macro to check if the Algorithm is Snow3G UEA2 */
123 #define LAC_CIPHER_IS_SNOW3G_UEA2(algo) (algo == CPA_CY_SYM_CIPHER_SNOW3G_UEA2)
124 
125 /* Macro to check if the Algorithm is ARC4 */
126 #define LAC_CIPHER_IS_ARC4(algo) (algo == CPA_CY_SYM_CIPHER_ARC4)
127 
128 /* Macro to check if the Algorithm is ZUC EEA3 */
129 #define LAC_CIPHER_IS_ZUC_EEA3(algo) (algo == CPA_CY_SYM_CIPHER_ZUC_EEA3)
130 
131 /* Macro to check if the Algorithm is NULL */
132 #define LAC_CIPHER_IS_NULL(algo) (algo == CPA_CY_SYM_CIPHER_NULL)
133 
134 /* Macro to check if the Mode is CTR */
135 #define LAC_CIPHER_IS_CTR_MODE(algo)                                           \
136 	((algo == CPA_CY_SYM_CIPHER_AES_CTR) ||                                \
137 	 (algo == CPA_CY_SYM_CIPHER_3DES_CTR) || (LAC_CIPHER_IS_CCM(algo)) ||  \
138 	 (LAC_CIPHER_IS_GCM(algo)) || (LAC_CIPHER_IS_CHACHA(algo)) ||          \
139 	 (algo == CPA_CY_SYM_CIPHER_SM4_CTR))
140 
141 /* Macro to check if the Algorithm is ECB */
142 #define LAC_CIPHER_IS_ECB_MODE(algo)                                           \
143 	((algo == CPA_CY_SYM_CIPHER_AES_ECB) ||                                \
144 	 (algo == CPA_CY_SYM_CIPHER_DES_ECB) ||                                \
145 	 (algo == CPA_CY_SYM_CIPHER_3DES_ECB) ||                               \
146 	 (algo == CPA_CY_SYM_CIPHER_NULL) ||                                   \
147 	 (algo == CPA_CY_SYM_CIPHER_SNOW3G_UEA2) ||                            \
148 	 (algo == CPA_CY_SYM_CIPHER_SM4_ECB))
149 
150 /* Macro to check if the Algorithm Mode is F8 */
151 #define LAC_CIPHER_IS_F8_MODE(algo)                                            \
152 	((algo == CPA_CY_SYM_CIPHER_KASUMI_F8) ||                              \
153 	 (algo == CPA_CY_SYM_CIPHER_AES_F8))
154 
155 /* Macro to check if the Algorithm is CBC */
156 #define LAC_CIPHER_IS_CBC_MODE(algo)                                           \
157 	((algo == CPA_CY_SYM_CIPHER_AES_CBC) ||                                \
158 	 (algo == CPA_CY_SYM_CIPHER_DES_CBC) ||                                \
159 	 (algo == CPA_CY_SYM_CIPHER_3DES_CBC) ||                               \
160 	 (algo == CPA_CY_SYM_CIPHER_SM4_CBC))
161 
162 /* Macro to check if the Algorithm is CCM */
163 #define LAC_CIPHER_IS_CCM(algo) (algo == CPA_CY_SYM_CIPHER_AES_CCM)
164 
165 /* Macro to check if the Algorithm is GCM */
166 #define LAC_CIPHER_IS_GCM(algo) (algo == CPA_CY_SYM_CIPHER_AES_GCM)
167 
168 /* Macro to check if the Algorithm is AES-F8 */
169 #define LAC_CIPHER_IS_AES_F8(algo) (algo == CPA_CY_SYM_CIPHER_AES_F8)
170 
171 /* Macro to check if the Algorithm Mode is XTS */
172 #define LAC_CIPHER_IS_XTS_MODE(algo) (algo == CPA_CY_SYM_CIPHER_AES_XTS)
173 
174 /* Macro to check if the Algorithm is single pass */
175 #define LAC_CIPHER_IS_SPC(cipher, hash, mask)                                  \
176 	((LAC_CIPHER_IS_CHACHA(cipher) && (CPA_CY_SYM_HASH_POLY == hash) &&    \
177 	  ((mask)&ICP_ACCEL_CAPABILITIES_CHACHA_POLY)) ||                      \
178 	 (LAC_CIPHER_IS_GCM(cipher) && ((CPA_CY_SYM_HASH_AES_GCM == hash) ||   \
179 					(CPA_CY_SYM_HASH_AES_GMAC == hash)) && \
180 	  ((mask)&ICP_ACCEL_CAPABILITIES_AESGCM_SPC)))
181 
182 #endif /* LAC_CIPHER_DEFS_H */
183