1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* Copyright(c) 2007-2022 Intel Corporation */ 3 /* $FreeBSD$ */ 4 5 /** 6 *************************************************************************** 7 * @file lac_sym_qat_constants_table.c 8 * 9 * @ingroup LacSymQat 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 26 #include "lac_common.h" 27 #include "icp_qat_fw_la.h" 28 #include "lac_log.h" 29 #include "lac_mem.h" 30 #include "sal_string_parse.h" 31 #include "lac_sal_types_crypto.h" 32 #include "sal_types_compression.h" 33 34 static uint8_t icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_DELIMITER] 35 [ICP_QAT_HW_CIPHER_MODE_DELIMITER][2] 36 [2]; /* IA version */ 37 static uint8_t icp_qat_hw_auth_lookup_tbl[ICP_QAT_HW_AUTH_ALGO_DELIMITER] 38 [ICP_QAT_HW_AUTH_MODE_DELIMITER] 39 [2]; /* IA version */ 40 41 #define ICP_QAT_HW_FILL_LOOKUP_TBLS \ 42 { \ 43 \ 44 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_DES] \ 45 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 46 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 47 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 48 9; \ 49 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_DES] \ 50 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 51 [ICP_QAT_HW_CIPHER_DECRYPT] \ 52 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 53 10; \ 54 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_DES] \ 55 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 56 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 57 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 58 11; \ 59 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_DES] \ 60 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 61 [ICP_QAT_HW_CIPHER_DECRYPT] \ 62 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 63 12; \ 64 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_DES] \ 65 [ICP_QAT_HW_CIPHER_CTR_MODE] \ 66 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 67 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 68 13; \ 69 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 70 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 71 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 72 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 73 14; \ 74 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 75 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 76 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 77 [ICP_QAT_HW_CIPHER_KEY_CONVERT] = \ 78 15; \ 79 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 80 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 81 [ICP_QAT_HW_CIPHER_DECRYPT] \ 82 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 83 16; \ 84 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 85 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 86 [ICP_QAT_HW_CIPHER_DECRYPT] \ 87 [ICP_QAT_HW_CIPHER_KEY_CONVERT] = \ 88 17; \ 89 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 90 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 91 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 92 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 93 18; \ 94 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 95 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 96 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 97 [ICP_QAT_HW_CIPHER_KEY_CONVERT] = \ 98 19; \ 99 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 100 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 101 [ICP_QAT_HW_CIPHER_DECRYPT] \ 102 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 103 20; \ 104 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 105 [ICP_QAT_HW_CIPHER_CBC_MODE] \ 106 [ICP_QAT_HW_CIPHER_DECRYPT] \ 107 [ICP_QAT_HW_CIPHER_KEY_CONVERT] = \ 108 21; \ 109 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 110 [ICP_QAT_HW_CIPHER_CTR_MODE] \ 111 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 112 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 113 22; \ 114 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_AES128] \ 115 [ICP_QAT_HW_CIPHER_F8_MODE] \ 116 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 117 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 118 23; \ 119 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_ARC4] \ 120 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 121 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 122 [ICP_QAT_HW_CIPHER_NO_CONVERT] = \ 123 24; \ 124 icp_qat_hw_cipher_lookup_tbl[ICP_QAT_HW_CIPHER_ALGO_ARC4] \ 125 [ICP_QAT_HW_CIPHER_ECB_MODE] \ 126 [ICP_QAT_HW_CIPHER_ENCRYPT] \ 127 [ICP_QAT_HW_CIPHER_KEY_CONVERT] = \ 128 25; \ 129 \ 130 icp_qat_hw_auth_lookup_tbl \ 131 [ICP_QAT_HW_AUTH_ALGO_MD5][ICP_QAT_HW_AUTH_MODE0] \ 132 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 37; \ 133 icp_qat_hw_auth_lookup_tbl \ 134 [ICP_QAT_HW_AUTH_ALGO_SHA1][ICP_QAT_HW_AUTH_MODE0] \ 135 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 41; \ 136 icp_qat_hw_auth_lookup_tbl \ 137 [ICP_QAT_HW_AUTH_ALGO_SHA1][ICP_QAT_HW_AUTH_MODE1] \ 138 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 46; \ 139 icp_qat_hw_auth_lookup_tbl \ 140 [ICP_QAT_HW_AUTH_ALGO_SHA224][ICP_QAT_HW_AUTH_MODE0] \ 141 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 48; \ 142 icp_qat_hw_auth_lookup_tbl \ 143 [ICP_QAT_HW_AUTH_ALGO_SHA256][ICP_QAT_HW_AUTH_MODE0] \ 144 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 54; \ 145 icp_qat_hw_auth_lookup_tbl \ 146 [ICP_QAT_HW_AUTH_ALGO_SHA384][ICP_QAT_HW_AUTH_MODE0] \ 147 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 60; \ 148 icp_qat_hw_auth_lookup_tbl \ 149 [ICP_QAT_HW_AUTH_ALGO_SHA512][ICP_QAT_HW_AUTH_MODE0] \ 150 [ICP_QAT_FW_AUTH_HDR_FLAG_NO_NESTED] = 70; \ 151 } 152 153 /** 154 ***************************************************************************** 155 * @ingroup LacSymQat 156 * LacSymQat_ConstantsInitLookupTables 157 * 158 * 159 *****************************************************************************/ 160 void 161 LacSymQat_ConstantsInitLookupTables(CpaInstanceHandle instanceHandle) 162 { 163 sal_service_t *pService = (sal_service_t *)instanceHandle; 164 lac_sym_qat_constants_t *pConstantsLookupTables; 165 166 /* Note the global tables are initialised first, then copied 167 * to the service which probably seems like a waste of memory 168 * and processing cycles as the global tables are never needed again 169 * but this allows use of the ICP_QAT_HW_FILL_LOOKUP_TBLS macro 170 * supplied by FW without modification */ 171 172 if (SAL_SERVICE_TYPE_COMPRESSION == pService->type) { 173 /* DC chaining not supported yet */ 174 return; 175 } else { 176 pConstantsLookupTables = &( 177 ((sal_crypto_service_t *)pService)->constantsLookupTables); 178 } 179 180 /* First fill the global lookup tables with zeroes. */ 181 memset(icp_qat_hw_cipher_lookup_tbl, 182 0, 183 sizeof(icp_qat_hw_cipher_lookup_tbl)); 184 memset(icp_qat_hw_auth_lookup_tbl, 185 0, 186 sizeof(icp_qat_hw_auth_lookup_tbl)); 187 188 /* Override lookup tables with the offsets into the SHRAM table 189 * for supported algorithms/modes */ 190 ICP_QAT_HW_FILL_LOOKUP_TBLS; 191 192 /* Copy the global tables to the service instance */ 193 memcpy(pConstantsLookupTables->cipher_offset, 194 icp_qat_hw_cipher_lookup_tbl, 195 sizeof(pConstantsLookupTables->cipher_offset)); 196 memcpy(pConstantsLookupTables->auth_offset, 197 icp_qat_hw_auth_lookup_tbl, 198 sizeof(pConstantsLookupTables->auth_offset)); 199 } 200 201 /** 202 ***************************************************************************** 203 * @ingroup LacSymQat 204 * LacSymQat_ConstantsGetCipherOffset 205 * 206 * 207 *****************************************************************************/ 208 void 209 LacSymQat_ConstantsGetCipherOffset(CpaInstanceHandle instanceHandle, 210 uint8_t algo, 211 uint8_t mode, 212 uint8_t direction, 213 uint8_t convert, 214 uint8_t *poffset) 215 { 216 sal_service_t *pService = (sal_service_t *)instanceHandle; 217 lac_sym_qat_constants_t *pConstantsLookupTables; 218 219 if (SAL_SERVICE_TYPE_COMPRESSION == pService->type) { 220 /* DC chaining not supported yet */ 221 return; 222 } else { 223 pConstantsLookupTables = &( 224 ((sal_crypto_service_t *)pService)->constantsLookupTables); 225 } 226 227 *poffset = pConstantsLookupTables 228 ->cipher_offset[algo][mode][direction][convert]; 229 } 230 231 /** 232 ***************************************************************************** 233 * @ingroup LacSymQat 234 * LacSymQat_ConstantsGetAuthOffset 235 * 236 * 237 *****************************************************************************/ 238 void 239 LacSymQat_ConstantsGetAuthOffset(CpaInstanceHandle instanceHandle, 240 uint8_t algo, 241 uint8_t mode, 242 uint8_t nested, 243 uint8_t *poffset) 244 { 245 sal_service_t *pService = (sal_service_t *)instanceHandle; 246 lac_sym_qat_constants_t *pConstantsLookupTables; 247 248 if (SAL_SERVICE_TYPE_COMPRESSION == pService->type) { 249 /* DC chaining not supported yet */ 250 return; 251 } else { 252 pConstantsLookupTables = &( 253 ((sal_crypto_service_t *)pService)->constantsLookupTables); 254 } 255 256 *poffset = pConstantsLookupTables->auth_offset[algo][mode][nested]; 257 } 258